Exemplo n.º 1
0
        public void TestProcessMessage_TestInvalidAzElArgs_ElOutOfRange()
        {
            string command = "1.0 | ORIENTATION_MOVE | AZ 50 | EL 500 | 12:00:00";
            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.ValidationError);
        }
Exemplo n.º 2
0
        public void TestProcessMessage_TestValidStopRT()
        {
            string command = "1.0 | STOP_RT | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(ParseTCPCommandResultEnum.Success, result.parseTCPCommandResultEnum);
            Assert.AreEqual(MovementResult.Success, mvmtResult.movementResult);
        }
Exemplo n.º 3
0
        public void TestProcessMessage_SetOverrideRemGate_RemovesGateOverride()
        {
            string command = "1.0 | SET_OVERRIDE | MAIN_GATE | FALSE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsFalse(RtController.overrides.overrideGate);
        }
Exemplo n.º 4
0
        public void TestProcessMessage_SetOverrideRemWeather_RemovesWeatherOverride()
        {
            string command = "1.0 | SET_OVERRIDE | WEATHER_STATION | FALSE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsFalse(ControlRoom.weatherStationOverride);
        }
Exemplo n.º 5
0
        public void TestProcessMessage_SetOverrideRemElMotTemp_RemovesElMotTempOverride()
        {
            string command = "1.0 | SET_OVERRIDE | ELEVATION_MOT_TEMP | FALSE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsFalse(RtController.overrides.overrideElevatMotTemp);
        }
Exemplo n.º 6
0
        public void TestProcessMessage_SetOverrideSetAzMotTemp_SetsAzMotTempOverride()
        {
            string command = "1.0 | SET_OVERRIDE | AZIMUTH_MOT_TEMP | TRUE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsTrue(RtController.overrides.overrideAzimuthMotTemp);
        }
Exemplo n.º 7
0
        public void TestProcessMessage_SetOverrideSetElProx0_SetsElProx0Override()
        {
            string command = "1.0 | SET_OVERRIDE | ELEVATION_LIMIT_0 | TRUE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsTrue(RtController.overrides.overrideElevatProx0);
        }
Exemplo n.º 8
0
        public void TestProcessMessage_SetOverrideSetCounterbalanceAcc_SetsCounterbalanceOverride()
        {
            string command = "1.0 | SET_OVERRIDE | CB_ACC | TRUE | 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);
            Assert.AreEqual(mvmtResult.movementResult, MovementResult.Success);
            Assert.IsTrue(RtController.overrides.overrideCounterbalanceAccelerometer);
        }
Exemplo n.º 9
0
        public void TestProcessMessage_SensorInit_RebootsSensorNetworkWithNewInit()
        {
            // Create and start SensorNetwork
            RadioTelescope.SensorNetworkServer.StartSensorMonitoringRoutine();

            // Build command to disable all sensors and set the timeouts to specific values
            byte   expectedDisabled    = 0;
            int    expectedDataTimeout = 6;
            int    expectedInitTimeout = 5;
            string command             = "1.0 | SENSOR_INIT | " +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDisabled}," +
                                         $"{expectedDataTimeout}," +
                                         $"{expectedInitTimeout}" + "| 12:00:00";

            ParseTCPCommandResult   result     = (ParseTCPCommandResult)PrivListener.Invoke("ParseRLString", command);
            ExecuteTCPCommandResult mvmtResult = (ExecuteTCPCommandResult)PrivListener.Invoke("ExecuteRLCommand", new object[] { result.parsedString });

            byte[] resultInitBytes   = RadioTelescope.SensorNetworkServer.InitializationClient.SensorNetworkConfig.GetSensorInitAsBytes();
            int    resultDataTimeout = RadioTelescope.SensorNetworkServer.InitializationClient.SensorNetworkConfig.TimeoutDataRetrieval / 1000;  // ms to seconds
            int    resultInitTimeout = RadioTelescope.SensorNetworkServer.InitializationClient.SensorNetworkConfig.TimeoutInitialization / 1000; // ms to seconds

            Assert.AreEqual(result.parseTCPCommandResultEnum, ParseTCPCommandResultEnum.Success);


            // Verify the init values are as expected
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.ElevationTemp]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.AzimuthTemp]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.ElevationEncoder]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.AzimuthEncoder]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.AzimuthAccelerometer]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.ElevationEncoder]);
            Assert.AreEqual(expectedDisabled, resultInitBytes[(int)SensorInitializationEnum.CounterbalanceAccelerometer]);

            // Verify init values are as expected
            Assert.AreEqual(expectedDataTimeout, resultDataTimeout);
            Assert.AreEqual(expectedInitTimeout, resultInitTimeout);

            // Bring down the server and delete config
            RadioTelescope.SensorNetworkServer.EndSensorMonitoringRoutine();
        }
Exemplo n.º 10
0
        public void TCPMonitoringRoutine()
        {
            // Buffer for reading data
            Byte[] bytes = new Byte[512];
            String data  = null;

            // Enter the listening loop.
            while (KeepTCPMonitoringThreadAlive)
            {
                if (waitingForConn)
                {
                    logger.Debug(Utilities.GetTimeStamp() + ": Waiting for a connection... ");
                    waitingForConn = false;
                }

                // Place each command in its own asynchronous thread so that we can run commands in parallel
                if (server.Pending())
                {
                    waitingForConn = true;
                    new Thread(() =>
                    {
                        TcpClient client = server.AcceptTcpClient();
                        logger.Debug(Utilities.GetTimeStamp() + ": TCP Client connected!");

                        data = null;
                        // Get a stream object for reading and writing
                        NetworkStream stream = client.GetStream();

                        int i;

                        // Loop to receive all the data sent by the client.
                        if ((i = readFromStream(stream, bytes)) != 0)
                        {
                            // Translate data bytes to ASCII string.
                            data = Encoding.ASCII.GetString(bytes, 0, i);

                            logger.Debug(Utilities.GetTimeStamp() + ": Received: " + data);

                            // Process the data sent by the client.
                            data = data.ToUpper();

                            string myWriteBuffer = null;

                            // Inform mobile command received
                            writeBackToClient("Received command: " + data, stream);

                            // if processing the data fails, report an error message
                            ParseTCPCommandResult parsedTCPCommandResult = ParseRLString(data);
                            if (parsedTCPCommandResult.parseTCPCommandResultEnum != ParseTCPCommandResultEnum.Success)
                            {
                                // send back a failure response
                                logger.Info("Parsing command failed with ERROR: " + parsedTCPCommandResult.errorMessage);
                                myWriteBuffer = "Parsing command failed with error: " + parsedTCPCommandResult.errorMessage;
                                writeBackToClient(myWriteBuffer, stream);
                            }
                            // else the parsing was successful, attempt to run the command
                            else
                            {
                                // if script inform which script is running, else just command type
                                if (parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE] == "SCRIPT")
                                {
                                    logger.Debug(Utilities.GetTimeStamp() + ": Successfully parsed command " + data + ". Beginning requested movement " +
                                                 parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE] + " " +
                                                 parsedTCPCommandResult.parsedString[TCPCommunicationConstants.SCRIPT_NAME] + "...");
                                    string startedCommandMsg = "Successfully parsed command " + data + ". Beginning requested movement " +
                                                               parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE] + " " +
                                                               parsedTCPCommandResult.parsedString[TCPCommunicationConstants.SCRIPT_NAME] + "...";
                                    writeBackToClient(startedCommandMsg, stream);
                                    // writeback eta to client
                                    int estMoveTime = ScriptETA(parsedTCPCommandResult.parsedString[TCPCommunicationConstants.SCRIPT_NAME]);
                                    logger.Info("Script " + parsedTCPCommandResult.parsedString[TCPCommunicationConstants.SCRIPT_NAME] +
                                                " has an estimated time of " + estMoveTime + " ms");
                                    writeBackToClient(("Script " + parsedTCPCommandResult.parsedString[TCPCommunicationConstants.SCRIPT_NAME] +
                                                       " has an estimated time of " + estMoveTime + " ms"), stream);
                                }
                                else
                                {
                                    logger.Debug(Utilities.GetTimeStamp() + ": Successfully parsed command " + data + ". Beginning requested movement " +
                                                 parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE] + "...");
                                    string startedCommandMsg = "Successfully parsed command " + data + ". Beginning requested movement " +
                                                               parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE] + "...";
                                    writeBackToClient(startedCommandMsg, stream);

                                    switch (parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE])
                                    {
                                    case "ORIENTATION_MOVE":
                                        try
                                        {
                                            // Attempt to parse double values
                                            double azAbs = Double.Parse(parsedTCPCommandResult.parsedString[TCPCommunicationConstants.ORIENTATION_MOVE_AZ]);
                                            double elAbs = Double.Parse(parsedTCPCommandResult.parsedString[TCPCommunicationConstants.ORIENTATION_MOVE_EL]);

                                            int mvmtTimeAbs = AbsoluteMovementETA(new Orientation(azAbs, elAbs));
                                            writeBackToClient("ORIENTATION_MOVE TO AZ " + azAbs + " and EL " + elAbs + " has an estimated time of " + mvmtTimeAbs + " ms", stream);
                                        }
                                        catch (Exception e)
                                        {
                                            writeBackToClient("An exception occurred attempting to parse AZ and/or EL values: " + e.Message, stream);
                                        }
                                        break;

                                    case "RELATIVE_MOVE":
                                        try
                                        {
                                            // Attempt to parse double values
                                            double azRelative    = Double.Parse(parsedTCPCommandResult.parsedString[TCPCommunicationConstants.RELATIVE_MOVE_AZ]);
                                            double elRelative    = Double.Parse(parsedTCPCommandResult.parsedString[TCPCommunicationConstants.RELATIVE_MOVE_EL]);
                                            int mvmtTimeRelative = RelativeMovementETA(new Orientation(azRelative, elRelative));

                                            writeBackToClient("RELATIVE_MOVE BY AZ " + azRelative + " and EL " + elRelative + " has an estimated time of " +
                                                              mvmtTimeRelative + " ms", stream);
                                        }
                                        catch (Exception e)
                                        {
                                            writeBackToClient("An exception occurred attempting to parse AZ and/or EL values: " + e.Message, stream);
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                // Now that we have finished parsing our command, execute it since it has been determined to be valid
                                ExecuteTCPCommandResult executeTCPCommandResult = ExecuteRLCommand(parsedTCPCommandResult.parsedString);

                                // inform user of the result of command
                                if (executeTCPCommandResult.movementResult != MovementResult.Success)
                                {
                                    logger.Debug(Utilities.GetTimeStamp() + ": Command " + data + " failed with error: " + executeTCPCommandResult.errorMessage);
                                    myWriteBuffer = "Command " + data + " failed with error: " + executeTCPCommandResult.errorMessage;
                                    writeBackToClient(myWriteBuffer, stream);
                                }
                                else
                                {
                                    switch (parsedTCPCommandResult.parsedString[TCPCommunicationConstants.COMMAND_TYPE])
                                    {
                                    // we write back different in the case of a request command. Otherwise, the default is just successfully completing a command
                                    case "REQUEST":
                                        switch (parsedTCPCommandResult.parsedString[TCPCommunicationConstants.REQUEST_TYPE])
                                        {
                                        case "MVMT_DATA":
                                            writeBackToClient(executeTCPCommandResult.errorMessage, stream);
                                            logger.Debug(Utilities.GetTimeStamp() + ": " + executeTCPCommandResult.errorMessage);
                                            break;
                                        }
                                        break;

                                    default:
                                        logger.Debug(Utilities.GetTimeStamp() + ": SUCCESSFULLY COMPLETED COMMAND: " + data);
                                        // send back a success response -- finished command
                                        myWriteBuffer = "SUCCESSFULLY COMPLETED COMMAND: " + data;
                                        writeBackToClient(myWriteBuffer, stream);
                                        break;
                                    }
                                }
                            }

                            // Shutdown and end connection
                            client.Close();
                            client.Dispose();
                            stream.Close();
                            stream.Dispose();
                        }
                    }).Start(); // begin our worker thread to execute our TCP command
                }
            }
        }