Beispiel #1
0
        public void WriteData(TransmissionMode transmissionMode, ValidationMode validationMode, string msg)
        {
            var checkSum = validatorPool.get(validationMode).calculate(msg);

            _logger.Log(LogLevel.Trace, "Checksum: " + checkSum.ToString());
            senderPool.get(transmissionMode).SendMessage(comPort, msg + checkSum, validationMode);
            _logger.Log(LogLevel.Trace, transmissionMode.ToString() + " data sent to port " + comPort.PortName);
        }
Beispiel #2
0
        public string RecieveData()
        {
            TransmissionMode TMode = GetTransmissionMode();
            ValidationMode   VMode = GetValidationMode();

            _logger.Log(LogLevel.Trace, TMode.ToString() + " data recieved, with " + VMode + " validation");

            string data = recieverPool.get(TMode).RecieveMessage(comPort);

            bool isValid = validatorPool.get(VMode).check(data);

            if (!isValid)
            {
                _logger.Log(LogLevel.Error, "Recieved broken message: " + data);
            }
            else
            {
                _logger.Log(LogLevel.Trace, "Message valid");
            }
            return(validatorPool.get(VMode).removeCheckSum(data));
        }
        public RtspStatusCode Setup(string query, TransmissionMode transmissionmode)
        {
            RtspRequest  request;
            RtspResponse response;

            if ((_rtspSocket == null))
            {
                Connect();
            }
            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _rtspDevice.ServerAddress, 554, query), 1, 0);
                switch (transmissionmode)
                {
                case TransmissionMode.Multicast:
                    request.Headers.Add("Transport", string.Format("RTP/AVP;{0}", transmissionmode.ToString().ToLower()));
                    break;

                case TransmissionMode.Unicast:
                    var activeTcpConnections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections();
                    var usedPorts            = new HashSet <int>();
                    foreach (var connection in activeTcpConnections)
                    {
                        usedPorts.Add(connection.LocalEndPoint.Port);
                    }
                    for (var port = 40000; port <= 65534; port += 2)
                    {
                        if (!usedPorts.Contains(port) && !usedPorts.Contains(port + 1))
                        {
                            _clientRtpPort  = port;
                            _clientRtcpPort = port + 1;
                            break;
                        }
                    }
                    request.Headers.Add("Transport", string.Format("RTP/AVP;{0};client_port={1}-{2}", transmissionmode.ToString().ToLower(), _clientRtpPort, _clientRtcpPort));
                    break;
                }
            }
            else
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _rtspDevice.ServerAddress, 554, query), 1, 0);
                switch (transmissionmode)
                {
                case TransmissionMode.Multicast:
                    request.Headers.Add("Transport", string.Format("RTP/AVP;{0}", transmissionmode.ToString().ToLower()));
                    break;

                case TransmissionMode.Unicast:
                    request.Headers.Add("Transport", string.Format("RTP/AVP;{0};client_port={1}-{2}", transmissionmode.ToString().ToLower(), _clientRtpPort, _clientRtcpPort));
                    break;
                }
            }
            SendRequest(request);
            ReceiveResponse(out response);
            if (!response.Headers.TryGetValue("com.ses.streamID", out _rtspStreamId))
            {
                Logger.Error(string.Format("Failed to tune, not able to locate Stream ID header in RTSP SETUP response"));
            }
            string sessionHeader;

            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                Logger.Error(string.Format("Failed to tune, not able to locate Session header in RTSP SETUP response"));
            }
            ProcessSessionHeader(sessionHeader, "Setup");
            string transportHeader;

            if (!response.Headers.TryGetValue("Transport", out transportHeader))
            {
                Logger.Error(string.Format("Failed to tune, not able to locate Transport header in RTSP SETUP response"));
            }
            ProcessTransportHeader(transportHeader);
            return(response.StatusCode);
        }
Beispiel #4
0
 /// <summary>
 /// Sends a request to the kernel to connect to the currently selected wockets
 /// </summary>        
 public static void Connect(TransmissionMode tmode)
 {
     ThreadPool.QueueUserWorkItem(func =>
     {
         if (_Registered)
         {
             string commandPath = REGISTRY_REGISTERED_APPLICATIONS_PATH + "\\{" + _IcomingChannel + "}";
             NamedEvents namedEvent = new NamedEvents();
             kernelLock.WaitOne();
             RegistryKey rk = Registry.LocalMachine.OpenSubKey(commandPath, true);
             rk.SetValue("Message", KernelCommand.CONNECT.ToString(), RegistryValueKind.String);
             rk.SetValue("Param", "all", RegistryValueKind.String);
             rk.SetValue("TMode",tmode.ToString(), RegistryValueKind.String);
             rk.Flush();
             rk.Close();
             kernelLock.Release();
             namedEvent.Send(Core._OutgoingChannel);
         }
     });
 }
Beispiel #5
0
        /// <summary>
        /// Sends a request to the kernel to set the transmission mode of a wocket
        /// </summary>
        /// <param name="mac">MAC address of the wocket</param>
        /// <param name="mode">Mode of transmission</param>
        public static void SET_TRANSMISSION_MODE(string mac, TransmissionMode mode)
        {
            ThreadPool.QueueUserWorkItem(func =>
            {
                kernelLock.WaitOne();
                try
                {
                    if ((_Registered) && (_Connected))
                    {
                        string commandPath = REGISTRY_REGISTERED_APPLICATIONS_PATH + "\\{" + _IcomingChannel + "}";
                        NamedEvents namedEvent = new NamedEvents();

                        RegistryKey rk = Registry.LocalMachine.OpenSubKey(commandPath, true);
                        rk.SetValue("Message", KernelCommand.SET_TRANSMISSION_MODE.ToString(), RegistryValueKind.String);
                        rk.SetValue("Param", mac.ToString() + ":" + mode.ToString(), RegistryValueKind.String);
                        rk.Flush();
                        rk.Close();
                        namedEvent.Send(Core._OutgoingChannel);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Core.cs:SET_TRANSMISSION_MODE:" + e.ToString());
                }

                kernelLock.Release();
            });
        }