private DCSBIOSProtocolParser()
 {
     _state                  = DCSBiosStateEnum.WAIT_FOR_SYNC;
     _syncByteCount          = 0;
     DCSBIOSProtocolParserSO = this;
     _shutdown               = false;
 }
Example #2
0
 private void ExtractDCSBIOSOutputsInFormula()
 {
     try
     {
         var found    = false;
         var controls = DCSBIOSControlLocator.GetControls();
         foreach (var dcsbiosControl in controls)
         {
             if (_formula.Contains(dcsbiosControl.identifier))
             {
                 //   Console.WriteLine("Variable " + dcsbiosControl.identifier + " set to 0");
                 _variables.Add(dcsbiosControl.identifier, 0);
                 var dcsbiosOutput = DCSBIOSControlLocator.GetDCSBIOSOutput(dcsbiosControl.identifier);
                 _dcsbiosOutputs.Add(dcsbiosOutput);
                 DCSBIOSProtocolParser.RegisterAddressToBroadCast(dcsbiosOutput.Address);
                 found = true;
             }
         }
         if (!found)
         {
             throw new Exception("Could not find any DCS-BIOS Controls in formula expression.");
         }
         //_expression = new Expression(_formula);
     }
     catch (Exception ex)
     {
         Common.LogError(1955594, ex, "ExtractDCSBIOSOutputsInFormula() function");
         throw;
     }
 }
 public void Consume(DCSBIOSControl dcsbiosControl)
 {
     _controlId          = dcsbiosControl.identifier;
     _controlDescription = dcsbiosControl.description;
     _controlType        = dcsbiosControl.physical_variant;
     try
     {
         _address    = dcsbiosControl.outputs[0].address;
         _mask       = dcsbiosControl.outputs[0].mask;
         _maxValue   = dcsbiosControl.outputs[0].max_value;
         _shiftvalue = dcsbiosControl.outputs[0].shift_by;
         if (dcsbiosControl.outputs[0].type.Equals("string"))
         {
             _dcsBiosOutputType = DCSBiosOutputType.STRING_TYPE;
         }
         else if (dcsbiosControl.outputs[0].type.Equals("integer"))
         {
             _dcsBiosOutputType = DCSBiosOutputType.INTEGER_TYPE;
         }
         //TODO Denna borde göras så att förutom _address så är mottagarens unika ID med så slipper alla lyssna eller ..? (prestanda)
         DCSBIOSProtocolParser.RegisterAddressToBroadCast(_address);
     }
     catch (Exception)
     {
         throw new Exception("Failed to copy control " + _controlId + ". Control output is missing." + Environment.NewLine);
     }
 }
 public static DCSBIOSProtocolParser GetParser()
 {
     if (DCSBIOSProtocolParserSO == null)
     {
         DCSBIOSProtocolParserSO = new DCSBIOSProtocolParser();
     }
     return(DCSBIOSProtocolParserSO);
 }
Example #5
0
        public void Startup()
        {
            try
            {
                /*
                 *  None, do as normal.
                 */

                /*
                 *  Client, try establish connection to the master FP on the network every two seconds. After connection listen to data from master and add that to the arraysToProcess queue.
                 */

                /*
                 *  Master, start listening TCP socket, for every client contacting via TCP add them as clients and send raw DCS-BIOS data to them
                 */
                Shutdown();
                if (_started)
                {
                    return;
                }
                _shutdown          = false;
                _dcsProtocolParser = DCSBIOSProtocolParser.GetParser();
                _dcsProtocolParser.Attach(_iDcsBiosDataListener);

                _ipEndPointReceiverUdp = new IPEndPoint(IPAddress.Any, ReceivePort);
                _ipEndPointSenderUdp   = new IPEndPoint(IPAddress.Parse(SendToIp), SendPort);

                _udpReceiveClient = new UdpClient();
                _udpReceiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                _udpReceiveClient.Client.Bind(_ipEndPointReceiverUdp);
                _udpReceiveClient.JoinMulticastGroup(IPAddress.Parse(ReceiveFromIp));

                _udpSendClient = new UdpClient();
                _udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                _udpSendClient.EnableBroadcast = true;

                _dcsbiosListeningThread = new Thread(ReceiveDataUdp);
                _dcsbiosListeningThread.Start();
                _dcsProtocolParser.Startup();

                _started = true;
            }
            catch (Exception e)
            {
                SetLastException(e);
                Common.LogError(e, "DCSBIOS.Startup()");
                if (_udpReceiveClient != null && _udpReceiveClient.Client.Connected)
                {
                    _udpReceiveClient.Close();
                    _udpReceiveClient = null;
                }
                if (_udpSendClient != null && _udpSendClient.Client != null && _udpSendClient.Client.Connected)
                {
                    _udpSendClient.Close();
                    _udpSendClient = null;
                }
            }
        }
 public DCSBIOSString(uint address, int length)
 {
     _address = address;
     for (var i = _address; i < _address + length; i = i + 2)
     {
         DCSBIOSProtocolParser.RegisterAddressToBroadCast(i);
         _receivedAddresses.Add(i);
     }
     _length         = length;
     _internalBuffer = new string[_length];
 }
Example #7
0
 public DCSBIOSString(uint address, int length)
 {
     _address = address;
     for (var i = _address; i < _address + length; i = i + 2)
     {
         //Common.DebugP("DCSBIOSString Registering()" + address + ", total length = " + _length);
         DCSBIOSProtocolParser.RegisterAddressToBroadCast(i);
         _receivedAddresses.Add(i);
     }
     _length         = length;
     _internalBuffer = new string[_length];
 }
Example #8
0
        public void Shutdown()
        {
            try
            {
                _udpReceiveClient?.Close();
                _udpReceiveClient?.Close();
                _dcsProtocolParser?.Detach(_iDcsBiosDataListener);
                _dcsProtocolParser?.Shutdown();

                _udpReceiveClient  = null;
                _udpReceiveClient  = null;
                _dcsProtocolParser = null;
                _isRunning         = false;
            }
            catch (Exception ex)
            {
                SetLastException(ex);
                Common.LogError(ex, "DCSBIOS.Shutdown()");
            }
        }
Example #9
0
        public DCSBIOS(IDcsBiosDataListener iDcsBiosDataListener, string ipFromUdp, string ipToUdp, int portFromUdp, int portToUdp, DcsBiosNotificationMode dcsNoficationMode)
        {
            IPAddress ipAddress;

            _iDcsBiosDataListener = iDcsBiosDataListener;
            if (!string.IsNullOrEmpty(ipFromUdp) && IPAddress.TryParse(ipFromUdp, out ipAddress))
            {
                _dcsbiosReceiveFromIPUdp = ipFromUdp;
            }
            if (!string.IsNullOrEmpty(ipToUdp) && IPAddress.TryParse(ipToUdp, out ipAddress))
            {
                _dcsbiosSendToIPUdp = ipToUdp;
            }
            if (portFromUdp > 0)
            {
                _dcsbiosReceivePortUdp = portFromUdp;
            }
            if (portToUdp > 0)
            {
                _dcsbiosSendPortUdp = portToUdp;
            }
            _dcsBiosNotificationMode = dcsNoficationMode;

            _dcsProtocolParser = DCSBIOSProtocolParser.GetParser();
            _dcsProtocolParser.Attach(_iDcsBiosDataListener);

            _ipEndPointReceiverUdp = new IPEndPoint(IPAddress.Any, ReceivePort);
            _ipEndPointSenderUdp   = new IPEndPoint(IPAddress.Parse(SendToIp), SendPort);

            _udpReceiveClient = new UdpClient();
            _udpReceiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            _udpReceiveClient.Client.Bind(_ipEndPointReceiverUdp);
            _udpReceiveClient.JoinMulticastGroup(IPAddress.Parse(ReceiveFromIp));

            _udpSendClient = new UdpClient();
            _udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            _udpSendClient.EnableBroadcast = true;

            //_tcpIpPort = tcpIpPort;
            _dcsBIOSInstance = this;
        }