Example #1
0
        private static void _testServer_DataAvailable(object sender, FDA.TCPServer.TCPCommandEventArgs e)
        {
            // when data is received on the test server, echo it back
            string received = Encoding.UTF8.GetString(e.Data);

            _testServer.Send(e.ClientID, received);
        }
        private static void BasicServices_DataAvailable(object sender, FDA.TCPServer.TCPCommandEventArgs e)
        {
            string command = Encoding.UTF8.GetString(e.Data);


            // if the command is null terminated, remove the null so that the command is recognized in the switch statement below
            if (e.Data.Length > 0)
            {
                if (e.Data[e.Data.Length - 1] == 0)
                {
                    command = Encoding.UTF8.GetString(e.Data, 0, e.Data.Length - 1);
                }
            }

            //_logger.LogInformation("Received command '" + command + "'", new object[] { });

            command = command.ToUpper();

            switch (command)
            {
            case "START":
                _logger.LogInformation("Start command received, starting FDA", new object[] { });
                StartFDA();
                //_logger.LogInformation("Replying 'OK' to requestor", new object[] { });
                _basicServicesPort.Send(e.ClientID, "OK");
                break;

            case "PING":
                //_logger.LogInformation("replying with 'UP'", new object[] { });
                _basicServicesPort.Send(e.ClientID, "UP");     // yes, I'm here
                break;

            case "FDASTATUS":
                string jsonStatus = ControllerGlobals.BasicServicesClient.Status.JSON();
                _basicServicesPort.Send(e.ClientID, jsonStatus);
                break;

            default:
                //_logger.LogInformation("Forwarding command '" + command + "' to the FDA", new object[] { });
                if (ControllerGlobals.BasicServicesClient.FDAConnected)
                {
                    ControllerGlobals.BasicServicesClient.Send(command);  // forward all other messages to the FDA (Eg. SHUTDOWN command)
                    _basicServicesPort.Send(e.ClientID, "FORWARDED");     // reply  back to the requestor that the command was forwarded to the FDA
                }
                break;
            }
        }