Exemple #1
0
        private bool processMessage(String data)
        {
            if (data.IndexOf("COORDINATE_MOVE") != -1)
            {
                // we have a move command coming in
                rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);

                // get azimuth and orientation
                int    azimuthIndex   = data.IndexOf("AZIM");
                int    elevationIndex = data.IndexOf("ELEV");
                int    idIndex        = data.IndexOf("ID");
                double azimuth        = 0.0;
                double elevation      = 0.0;
                string userId         = "";

                if (azimuthIndex != -1 && elevationIndex != -1 && idIndex != -1)
                {
                    elevation = Convert.ToDouble(data.Substring(elevationIndex + 5, azimuthIndex - elevationIndex - 5));
                    azimuth   = Convert.ToDouble(data.Substring(azimuthIndex + 5, idIndex - azimuthIndex - 5));
                    userId    = data.Substring(idIndex + 3);
                }
                else
                {
                    return(false);
                }

                logger.Debug(Utilities.GetTimeStamp() + ": Azimuth " + azimuth);
                logger.Debug(Utilities.GetTimeStamp() + ": Elevation " + elevation);

                Orientation movingTo = new Orientation(azimuth, elevation);

                rtController.MoveRadioTelescopeToOrientation(movingTo, MovementPriority.Manual);

                // TODO: store the User Id and movement somewhere in the database (issue #392)

                return(true);
            }
            else if (data.IndexOf("SET_OVERRIDE") != -1)
            {
                // false = ENABLED; true = OVERRIDING
                // If "OVR" is contained in the data, will return true
                bool doOverride = data.Contains("OVR");

                // Non-PLC Overrides
                if (data.Contains("WEATHER_STATION"))
                {
                    controlRoom.weatherStationOverride = data.Contains("OVR");
                    rtController.setOverride("weather station", data.Contains("OVR"));
                    DatabaseOperations.SetOverrideForSensor(SensorItemEnum.WEATHER_STATION, doOverride);
                }

                // PLC Overrides
                else if (data.Contains("MAIN_GATE"))
                {
                    rtController.setOverride("main gate", doOverride);
                }

                // Proximity overrides
                else if (data.Contains("ELEVATION_LIMIT_0"))
                {
                    rtController.setOverride("elevation proximity (1)", doOverride);
                }
                else if (data.Contains("ELEVATION_LIMIT_90"))
                {
                    rtController.setOverride("elevation proximity (2)", doOverride);
                }

                // Sensor network overrides
                else if (data.Contains("AZ_ABS_ENC"))
                {
                    rtController.setOverride("azimuth absolute encoder", doOverride);
                }
                else if (data.Contains("EL_ABS_ENC"))
                {
                    rtController.setOverride("elevation absolute encoder", doOverride);
                }
                else if (data.Contains("AZ_ACC"))
                {
                    rtController.setOverride("azimuth motor accelerometer", doOverride);
                }
                else if (data.Contains("EL_ACC"))
                {
                    rtController.setOverride("elevation motor accelerometer", doOverride);
                }
                else if (data.Contains("CB_ACC"))
                {
                    rtController.setOverride("counterbalance accelerometer", doOverride);
                }
                else if (data.Contains("AZIMUTH_MOT_TEMP"))
                {
                    rtController.setOverride("azimuth motor temperature", doOverride);
                }
                else if (data.Contains("ELEVATION_MOT_TEMP"))
                {
                    rtController.setOverride("elevation motor temperature", doOverride);
                }
                else
                {
                    return(false);
                }

                return(true);
            }
            else if (data.IndexOf("SCRIPT") != -1)
            {
                // we have a move command coming in
                rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);

                // get azimuth and orientation
                int    colonIndex = data.IndexOf(":");
                string script     = "";

                if (colonIndex != -1)
                {
                    script = data.Substring(colonIndex + 2);
                }
                else
                {
                    return(false);
                }

                logger.Debug(Utilities.GetTimeStamp() + ": Script " + script);

                if (script.Contains("DUMP"))
                {
                    rtController.SnowDump(MovementPriority.Manual);
                }
                else if (script.Contains("FULL_EV"))
                {
                    rtController.FullElevationMove(MovementPriority.Manual);
                }
                else if (script.Contains("CALIBRATE"))
                {
                    rtController.ThermalCalibrateRadioTelescope(MovementPriority.Manual);
                }
                else if (script.Contains("STOW"))
                {
                    rtController.MoveRadioTelescopeToOrientation(MiscellaneousConstants.Stow, MovementPriority.Manual);
                }
                else if (script.Contains("FULL_CLOCK"))
                {
                    // TODO: Implement with MoveByX function (issue #379)
                }
                else if (script.Contains("FULL_COUNTER"))
                {
                    // TODO: Implement with MoveByX function (issue #379)
                }
                else
                {
                    return(false);
                }

                return(true);
            }
            else if (data.IndexOf("STOP_RT") != -1)
            {
                rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);
            }
            else if (data.IndexOf("SENSOR_INIT") != -1)
            {
                string[] splitData = data.Split(',');

                if (splitData.Length != 10)
                {
                    return(false);
                }

                var config = rtController.RadioTelescope.SensorNetworkServer.InitializationClient.SensorNetworkConfig;

                // Set all the sensors to their new initialization
                config.AzimuthTemp1Init                = splitData[(int)SensorInitializationEnum.AzimuthTemp].Equals("1");
                config.ElevationTemp1Init              = splitData[(int)SensorInitializationEnum.ElevationTemp].Equals("1");
                config.AzimuthAccelerometerInit        = splitData[(int)SensorInitializationEnum.AzimuthAccelerometer].Equals("1");
                config.ElevationAccelerometerInit      = splitData[(int)SensorInitializationEnum.ElevationAccelerometer].Equals("1");
                config.CounterbalanceAccelerometerInit = splitData[(int)SensorInitializationEnum.CounterbalanceAccelerometer].Equals("1");
                config.AzimuthEncoderInit              = splitData[(int)SensorInitializationEnum.AzimuthEncoder].Equals("1");
                config.ElevationEncoderInit            = splitData[(int)SensorInitializationEnum.ElevationEncoder].Equals("1");

                // Set the timeout values
                config.TimeoutDataRetrieval  = (int)(double.Parse(splitData[7]) * 1000);
                config.TimeoutInitialization = (int)(double.Parse(splitData[8]) * 1000);

                // Reboot
                rtController.RadioTelescope.SensorNetworkServer.RebootSensorNetwork();

                return(true);
            }

            // can't find a keyword then we fail
            return(false);
        }
Exemple #2
0
        public ExecuteTCPCommandResult ExecuteRLCommand(String[] splitCommandString)
        {
            // Convert version from string to double. This is the first value in our string before the "|" character.
            // From here we will direct to the appropriate parsing for said version
            double version = 0.0;

            try
            {
                version = Double.Parse(splitCommandString[TCPCommunicationConstants.VERSION_NUM]);
            }
            catch (Exception e)
            {
                String errMessage = TCPCommunicationConstants.VERSION_CONVERSION_ERR + e.Message;
                return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, errMessage));
            }

            // Use appropriate parsing for given version
            if (version == 1.0)
            {
                // command is placed after pike and before colon; get it here
                // <VERSION> | <COMMANDTYPE> | <NAME<VALUES>> | TIME
                string command = splitCommandString[TCPCommunicationConstants.COMMAND_TYPE];

                if (command == "ORIENTATION_MOVE")
                {
                    // we have a move command coming in
                    rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);

                    // get azimuth and orientation
                    double azimuth   = 0.0;
                    double elevation = 0.0;
                    try
                    {
                        azimuth   = Convert.ToDouble(splitCommandString[TCPCommunicationConstants.ORIENTATION_MOVE_AZ]);
                        elevation = Convert.ToDouble(splitCommandString[TCPCommunicationConstants.ORIENTATION_MOVE_EL]);
                    }
                    catch (Exception e)
                    {
                        String errMessage = TCPCommunicationConstants.AZ_EL_CONVERSION_ERR + e.Message;
                        return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, errMessage));
                    }

                    logger.Debug(Utilities.GetTimeStamp() + ": Azimuth " + azimuth);
                    logger.Debug(Utilities.GetTimeStamp() + ": Elevation " + elevation);

                    Orientation movingTo = new Orientation(azimuth, elevation);

                    // check result of movement, if it fails we return the result type along with an error message.
                    // The command parse was successful however, so we indicate that
                    MovementResult result = rtController.MoveRadioTelescopeToOrientation(movingTo, MovementPriority.Manual);
                    if (result != MovementResult.Success)
                    {
                        return(new ExecuteTCPCommandResult(result, TCPCommunicationConstants.ORIENTATION_MOVE_ERR + result.ToString()));
                    }
                    else
                    // everything was successful
                    {
                        return(new ExecuteTCPCommandResult(result));
                    }
                }
                else if (command == "RELATIVE_MOVE")
                {
                    // we have a relative movement command
                    rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);

                    // get azimuth and orientation
                    double azimuth   = 0.0;
                    double elevation = 0.0;

                    try
                    {
                        azimuth   = Convert.ToDouble(splitCommandString[TCPCommunicationConstants.RELATIVE_MOVE_AZ]);
                        elevation = Convert.ToDouble(splitCommandString[TCPCommunicationConstants.RELATIVE_MOVE_EL]);
                    }
                    catch (Exception e)
                    {
                        String errMessage = TCPCommunicationConstants.AZ_EL_CONVERSION_ERR + e.Message;
                        return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, errMessage));
                    }

                    logger.Debug(Utilities.GetTimeStamp() + ": Azimuth " + azimuth);
                    logger.Debug(Utilities.GetTimeStamp() + ": Elevation " + elevation);

                    Orientation movingBy = new Orientation(azimuth, elevation);

                    MovementResult result = rtController.MoveRadioTelescopeByXDegrees(movingBy, MovementPriority.Manual);
                    if (result != MovementResult.Success)
                    {
                        // the actual movement failed
                        return(new ExecuteTCPCommandResult(result, TCPCommunicationConstants.RELATIVE_MOVE_ERR + result.ToString()));
                    }
                    else
                    {
                        // everything was successful
                        return(new ExecuteTCPCommandResult(result));
                    }
                }
                else if (command == "SET_OVERRIDE")
                {
                    string sensorToOverride = splitCommandString[TCPCommunicationConstants.SENSOR_TO_OVERRIDE];
                    bool   doOverride       = splitCommandString[TCPCommunicationConstants.DO_OVERRIDE] == "TRUE" ? true : false;
                    switch (sensorToOverride)
                    {
                    // Non-PLC Overrides
                    case "WEATHER_STATION":
                        controlRoom.weatherStationOverride = doOverride;
                        rtController.setOverride("weather station", doOverride);
                        DatabaseOperations.SetOverrideForSensor(SensorItemEnum.WEATHER_STATION, doOverride);
                        break;

                    // PLC Overrides
                    case "MAIN_GATE":
                        rtController.setOverride("main gate", doOverride);
                        break;

                    // Proximity overrides
                    case "ELEVATION_LIMIT_0":
                        rtController.setOverride("elevation proximity (1)", doOverride);
                        break;

                    case "ELEVATION_LIMIT_90":
                        rtController.setOverride("elevation proximity (2)", doOverride);
                        break;

                    // Sensor network overrides
                    case "AZ_ABS_ENC":
                        rtController.setOverride("azimuth absolute encoder", doOverride);
                        break;

                    case "EL_ABS_ENC":
                        rtController.setOverride("elevation absolute encoder", doOverride);
                        break;

                    case "AZ_ACC":
                        rtController.setOverride("azimuth motor accelerometer", doOverride);
                        break;

                    case "EL_ACC":
                        rtController.setOverride("elevation motor accelerometer", doOverride);
                        break;

                    case "CB_ACC":
                        rtController.setOverride("counterbalance accelerometer", doOverride);
                        break;

                    case "AZIMUTH_MOT_TEMP":
                        rtController.setOverride("azimuth motor temperature", doOverride);
                        break;

                    case "ELEVATION_MOT_TEMP":
                        rtController.setOverride("elevation motor temperature", doOverride);
                        break;

                    // If no case is reached, the sensor is not valid. Return appropriately
                    default:
                        return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, TCPCommunicationConstants.INVALID_SENSOR_OVERRIDE + sensorToOverride));
                    }

                    return(new ExecuteTCPCommandResult(MovementResult.Success));
                }
                else if (command == "SCRIPT")
                {
                    // we have a move command coming in
                    rtController.ExecuteRadioTelescopeControlledStop(MovementPriority.GeneralStop);

                    // Retrieve script name used for switch case
                    string         script = splitCommandString[TCPCommunicationConstants.SCRIPT_NAME];
                    MovementResult result = MovementResult.None;

                    logger.Debug(Utilities.GetTimeStamp() + ": Script " + script);

                    switch (script)
                    {
                    case "DUMP":
                        result = rtController.SnowDump(MovementPriority.Manual);
                        break;

                    case "FULL_EV":
                        result = rtController.FullElevationMove(MovementPriority.Manual);
                        break;

                    case "THERMAL_CALIBRATE":
                        result = rtController.ThermalCalibrateRadioTelescope(MovementPriority.Manual);
                        break;

                    case "STOW":
                        result = rtController.MoveRadioTelescopeToOrientation(MiscellaneousConstants.Stow, MovementPriority.Manual);
                        break;

                    case "FULL_CLOCK":
                        result = rtController.MoveRadioTelescopeByXDegrees(new Orientation(360, 0), MovementPriority.Manual);
                        break;

                    case "FULL_COUNTER":
                        result = rtController.MoveRadioTelescopeByXDegrees(new Orientation(-360, 0), MovementPriority.Manual);
                        break;

                    case "HOME":
                        result = rtController.HomeTelescope(MovementPriority.Manual);
                        break;

                    case "HARDWARE_MVMT_SCRIPT":
                        result = rtController.ExecuteHardwareMovementScript(MovementPriority.Manual);
                        break;

                    default:
                        // If no command is found, result = invalid
                        result = MovementResult.InvalidCommand;
                        break;
                    }

                    // Return based off of movement result
                    if (result != MovementResult.Success)
                    {
                        return(new ExecuteTCPCommandResult(result, TCPCommunicationConstants.SCRIPT_ERR + result.ToString()));
                    }
                    else
                    {
                        // everything was successful
                        return(new ExecuteTCPCommandResult(result));
                    }
                }
                else if (command == "STOP_RT")
                {
                    rtController.RadioTelescope.PLCDriver.InterruptMovementAndWaitUntilStopped();

                    return(new ExecuteTCPCommandResult(MovementResult.Success, TCPCommunicationConstants.ALL_STOP_ERR));
                }
                else if (command == "SENSOR_INIT")
                {
                    // Retrieve sensor init values from the comma separated portion of the string
                    string[] splitData = splitCommandString[TCPCommunicationConstants.SENSOR_INIT_VALUES].Split(',');

                    var config = rtController.RadioTelescope.SensorNetworkServer.InitializationClient.SensorNetworkConfig;

                    // Set all the sensors to their new initialization
                    config.AzimuthTemp1Init                = splitData[(int)SensorInitializationEnum.AzimuthTemp].Equals("1");
                    config.ElevationTemp1Init              = splitData[(int)SensorInitializationEnum.ElevationTemp].Equals("1");
                    config.AzimuthAccelerometerInit        = splitData[(int)SensorInitializationEnum.AzimuthAccelerometer].Equals("1");
                    config.ElevationAccelerometerInit      = splitData[(int)SensorInitializationEnum.ElevationAccelerometer].Equals("1");
                    config.CounterbalanceAccelerometerInit = splitData[(int)SensorInitializationEnum.CounterbalanceAccelerometer].Equals("1");
                    config.AzimuthEncoderInit              = splitData[(int)SensorInitializationEnum.AzimuthEncoder].Equals("1");
                    config.ElevationEncoderInit            = splitData[(int)SensorInitializationEnum.ElevationEncoder].Equals("1");

                    // Set the timeout values
                    config.TimeoutDataRetrieval  = (int)(double.Parse(splitData[7]) * 1000);
                    config.TimeoutInitialization = (int)(double.Parse(splitData[8]) * 1000);

                    // Reboot
                    rtController.RadioTelescope.SensorNetworkServer.RebootSensorNetwork();

                    return(new ExecuteTCPCommandResult(MovementResult.Success));
                }
                else if (command == "REQUEST")
                {
                    switch (splitCommandString[TCPCommunicationConstants.REQUEST_TYPE])
                    {
                    case "MVMT_DATA":
                        return(new ExecuteTCPCommandResult(MovementResult.Success, GetMovementData()));

                    default:
                        return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, TCPCommunicationConstants.INVALID_REQUEST_TYPE + splitCommandString[TCPCommunicationConstants.REQUEST_TYPE]));
                    }
                }

                // can't find a keyword then we return Invalid Command sent
                return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, TCPCommunicationConstants.COMMAND_NOT_FOUND + command));
            }
            // Version is not found; add new versions here
            else
            {
                return(new ExecuteTCPCommandResult(MovementResult.InvalidCommand, TCPCommunicationConstants.VERSION_NOT_FOUND + version));
            }
        }