diff --git a/.gitignore b/.gitignore index 5f43b23a..53734d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -265,3 +265,17 @@ AWSConstants.cs /ControlRoomApplication/ControlRoomApplication/Constants/AWSConstants.cs /ControlRoomApplication/results.xml /ControlRoomApplication/ControlRoomApplication.dll + +# Not an AES key or IV so don't look here +/ControlRoomApplication/ControlRoomApplication/Constants/AESConstants.cs + +# Sensitive push notification data +/ControlRoomApplication/ControlRoomApplication/Controllers/Communications/pushNotification.cs +\ControlRoomApplication\ControlRoom\Application\Controllers\Communications\pushNotification.cs +/ControlRoomApplication/ControlRoomApplication/Controllers/Communications/EmailPartConstants.cs +\ControlRoomApplication\ControlRoom\Application\Controllers\Communications\EmailPartConstants.cs + + +# Gradle stuff +/.gradle +ControlRoomApplication/ControlRoomApplicationTest/ControlRoomApplicationTest.csproj diff --git a/ControlRoomApplication/.editorconfig b/ControlRoomApplication/.editorconfig new file mode 100644 index 00000000..8f0432e4 --- /dev/null +++ b/ControlRoomApplication/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS1591: Missing XML comment for publicly visible type or member +dotnet_diagnostic.CS1591.severity = none diff --git a/ControlRoomApplication/ControlRoomApplication.sln b/ControlRoomApplication/ControlRoomApplication.sln index 0375bbdf..a91e783a 100644 --- a/ControlRoomApplication/ControlRoomApplication.sln +++ b/ControlRoomApplication/ControlRoomApplication.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.2016 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControlRoomApplication", "ControlRoomApplication\ControlRoomApplication.csproj", "{A9AF6C2B-B653-48AC-8DAD-791197740034}" EndProject diff --git a/ControlRoomApplication/ControlRoomApplication/App.config b/ControlRoomApplication/ControlRoomApplication/App.config index 61ecdbd3..f9f96b61 100644 --- a/ControlRoomApplication/ControlRoomApplication/App.config +++ b/ControlRoomApplication/ControlRoomApplication/App.config @@ -38,7 +38,7 @@ - + @@ -114,6 +114,22 @@ + + + + + + + + + + + + + + + + diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/AbstractSpectraCyberConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/AbstractSpectraCyberConstants.cs index bbae65f2..843cc821 100644 --- a/ControlRoomApplication/ControlRoomApplication/Constants/AbstractSpectraCyberConstants.cs +++ b/ControlRoomApplication/ControlRoomApplication/Constants/AbstractSpectraCyberConstants.cs @@ -10,7 +10,7 @@ public sealed class AbstractSpectraCyberConstants public const StopBits STOP_BITS = StopBits.One; public const int BUFFER_SIZE = 4; public const int TIMEOUT_MS = 1000; - public const int WAIT_TIME_MS = 70; // TODO: confirm that this is enough time to wait + public const int WAIT_TIME_MS = 70; public const bool CLIP_BUFFER_RESPONSE = true; public const string DEFAULT_COMM_PORT = "COM5"; diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/MCUConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/MCUConstants.cs index 95b11a95..ffb5f075 100644 --- a/ControlRoomApplication/ControlRoomApplication/Constants/MCUConstants.cs +++ b/ControlRoomApplication/ControlRoomApplication/Constants/MCUConstants.cs @@ -1,11 +1,9 @@ -namespace ControlRoomApplication.Constants -{ - public sealed class MCUConstants - { +namespace ControlRoomApplication.Constants { + public sealed class MCUConstants { public const double SIMULATION_MCU_PEAK_VELOCITY = 22.5; // steps/s public const double SIMULATION_MCU_PEAK_ACCELERATION = 32.0; // steps/s^2 - public const int ACTUAL_MCU_DEFAULT_PEAK_VELOCITY = 500000; // steps/s + public const int ACTUAL_MCU_DEFAULT_PEAK_VELOCITY = 500_000; // steps/s public const int ACTUAL_MCU_DEFAULT_ACCELERATION = 1000; // steps/ms/s public const double ACTUAL_MCU_STEPS_PER_DEGREE = 166 + (2.0 / 3); @@ -16,7 +14,235 @@ public sealed class MCUConstants public const ushort ACTUAL_MCU_READ_INPUT_REGISTER_CURRENT_POSITION_ADDRESS = 2; public const ushort ACTUAL_MCU_WRITE_REGISTER_START_ADDRESS = 1024; public const int ACTUAL_MCU_AZIMUTH_ENCODER_BIT_RESOLUTION = 12; - public const int ACTUAL_MCU_MOVE_PEAK_VELOCITY_WITH_GEARING = 100000; + public const int ACTUAL_MCU_MOVE_PEAK_VELOCITY_WITH_GEARING = 100_000; public const ushort ACTUAL_MCU_MOVE_ACCELERATION_WITH_GEARING = 50; + + + /// + /// this enum represents the data that comes out of the MCU starting in position = 0 of its registers + /// + public enum MCUOutputRegs : ushort { + /// + /// most signifigant word (16 bits) of the az axsys status for description of eacs bit + /// + AZ_Status_Bist_MSW = 0, + /// + /// least signifigant word (16 bits) of the az axsys status for description of eacs bit + /// + AZ_Status_Bist_LSW = 1, + /// + /// this is the position of the axsys in terms of motor step count (most signifigant word) + /// + AZ_Current_Position_MSW = 2, + /// + /// this is the position of the axsys in terms of motor step count (least signifigant word) + /// + AZ_Current_Position_LSW = 3, + /// + /// if we were using encoders on the motors this is where the data from those encoders would be + /// + AZ_MTR_Encoder_Pos_MSW=4, + /// + /// if we were using encoders on the motors this is where the data from those encoders would be + /// + AZ_MTR_Encoder_Pos_LSW = 5, + /// + /// if the MCU is told to capture the current position this is where that data will be stored + /// + AZ_Capture_Data_MSW=6, + /// + /// if the MCU is told to capture the current position this is where that data will be stored + /// + AZ_Capture_Data_LSW = 7, + RESERVED1 =8, + /// + /// used to track network conectivity bit 14 of this register will flip every .5 seconds, + /// bit 13 is set when the MCU looses or has previously lost ethernet conectivity + /// + NetworkConnectivity = 9, + /// + /// most signifigant word (16 bits) of the EL axsys status for description of eacs bit + /// + EL_Status_Bist_MSW = 10, + /// + /// least signifigant word (16 bits) of the EL axsys status for description of eacs bit + /// + EL_Status_Bist_LSW = 11, + /// + /// this is the position of the axsys in terms of motor step count (most signifigant word) + /// + EL_Current_Position_MSW = 12, + /// + /// this is the position of the axsys in terms of motor step count (least signifigant word) + /// + EL_Current_Position_LSW = 13, + /// + /// if we were using encoders on the motors this is where the data from those encoders would be + /// + EL_MTR_Encoder_Pos_MSW = 14, + /// + /// if we were using encoders on the motors this is where the data from those encoders would be + /// + EL_MTR_Encoder_Pos_LSW = 15, + /// + /// if the MCU is told to capture the current position this is where that data will be stored + /// + EL_Capture_Data_MSW = 16, + /// + /// if the MCU is told to capture the current position this is where that data will be stored + /// + EL_Capture_Data_LSW = 17, + RESERVED2 = 18, + RESERVED3 = 19 + + } + + + + /// + /// desciptions taken from anf1-anf2-motion-controller-user-manual.pdf page 76 - 78 + /// + public enum MCUStatusBitsMSW : int { + /// + /// Set when the ANF1/2 axis is outputting pulses for clockwise motion + /// + CW_Motion = 0, + /// + /// Set when the ANF1/2 axis is outputting pulses for counter-clockwise motion + /// + CCW_Motion = 1, + /// + /// Set when the ANF1/2 axis has stopped motion as a result of a Hold Move Command + /// + Hold_State = 2, + /// + /// Set when the ANF1/2 axis is not in motion for any reason + /// + Axis_Stopped = 3, + /// + /// This bit is only set after the successful completion of a homing command + /// + At_Home = 4, + /// + /// Set when the ANF1/2 axis is accelerating during any move + /// + Move_Accelerating = 5, + /// + /// Set when the ANF1/2 axis is decelerating during any move + /// + Move_Decelerating = 6, + /// + /// Set when the ANF1/2 axis has successfully completed an Absolute, Relative, + /// Blend, or Interpolated Move + /// + Move_Complete = 7, + /// + /// Set when the ANF1/2 could not home the axis because of an error durring homeing see MCU documaentation for list of potential eroorrs + /// + Home_Invalid_Error = 8, + /// + /// Set when there was an error in the last Program Blend Profile data block //we don't use blend move so this shouldnt come up + /// + Profile_Invalid = 9, + /// + /// this bit is set when the position stored in the MCU could be incorrect. + /// set under the fowling conditions, Axis switched to Command Mode | An Immediate Stop command was issued | An Emergency Stop input was activated | CW or CCW Limit reached + /// + Position_Invalid = 10, + /// + /// see MCU documaentation for list of potential eroorrs + /// + Input_Error = 11, + /// + /// Set when the last command issued to the ANF1/2 axis forced an error + /// + Command_Error = 12, + /// + /// set when the axis has a configuration error + /// + Configuration_Error = 13, + /// + /// Set when the axis is enabled. Axis 2 of an ANF2 is disabled by default. An + /// axis is automatically enabled when valid configuration data is written to it + /// + Axis_Enabled = 14, + /// + /// Set to “1” when the axis is in Configuration Mode. Reset to “0” when the axis is in Command Mode + /// + Axis_Configuration_Mode = 15, + } + + /// + /// desciptions taken from anf1-anf2-motion-controller-user-manual.pdf page 76 - 78 + /// + public enum MCUStutusBitsLSW : int { + /// + /// Set when the Capture Input is active + /// + Capture_Input_Active = 0, + /// + /// Set when the External Input is active + /// + External_Input = 1, + /// + /// Set when the Home Input is active + /// + Home_Input = 2, + /// + /// Set when the CW Input/E-Stop Input is active + /// + CW_Limit = 3, + /// + /// Set when the CCW Input/E-Stop Input is active + /// + CCW_Limit = 4, + /// + /// see MCU documaentation + /// + No_Fault_Output_State = 5, + /// + /// see MCU documaentation (unused) + /// + On_Line_Output_State = 6, + /// + /// see MCU documaentation (unused) + /// + Move_Complete_Output_State = 7, + /// + /// Set when the axis is presently running a Blend Move Profile (unused) + /// + Running_Blend_Move = 8, + /// + /// Set when ANF1/2 has accepted a Blend Move Profile programming block (unused) + /// + Blend_Move_Acknowledge = 9, + /// + /// Set when the Minimum Registration Move Distance + /// parameter is programmed to a non-zero value (unused) + /// + NonZero_Registration_Distance = 10, + /// + /// Set when the ANF1/2 is running an Interpolated Move. only valid for axis one + /// + Running_Interpolated_Move = 11, + /// + /// This bit always equals the state of the Backplane Home + /// Proximity bit, which is bit 6 in the Command Bits LSW for the axis + /// + Backplane_Home_Proximity = 12, + /// + /// Set when the axis is in Encoder Follower Mode + /// + Encoder_Follower_Mode = 13, + /// + /// These bits will always equal zero + /// + Reserved1 = 14, + /// + /// These bits will always equal zero + /// + reserved2 = 15, + } } } + diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousConstants.cs index eedee30f..3f4ee6e3 100644 --- a/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousConstants.cs +++ b/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousConstants.cs @@ -5,11 +5,65 @@ namespace ControlRoomApplication.Constants public sealed class MiscellaneousConstants { public const int MAX_USERNAME_LENGTH = 15; - public const string LOCAL_DATABASE_NAME = "rtdatabase"; + public const string LOCAL_DATABASE_NAME = "radio_telescope"; // Can't create const instances, we have to use this as static readonly, sadly - public static readonly Location JOHN_RUDY_PARK = new Location(76.7046, 40.0244, 395.0); + public static readonly Location JOHN_RUDY_PARK = new Location(76.7046, 40.0244, 395.0, ""); public const double NEGLIGIBLE_POSITION_CHANGE_DEGREES = 0.1; + + public static readonly Orientation THERMAL_CALIBRATION_ORIENTATION = new Orientation(200, 20); + + public static readonly double THERMAL_CALIBRATION_OFFSET = 0.01; + + // Software stop elevation thresholds + + /// + /// The maximum degree threshold for software stops to stop the telescope + /// + public const double MAX_SOFTWARE_STOP_EL_DEGREES = 91.0; + + /// + /// The minimum degree threshold for software stops to stop the telescope + /// + public const double MIN_SOFTWARE_STOP_EL_DEGREES = -5.0; + + // constants used for user input validation + public const int MAX_PORT_VALUE = 65535; + + public const int MIN_PORT_VALUE = 1; // 0 is reserved! + + public const double MAX_SPEED_RPM = 2.00; + + public const double MIN_SPEED_RPM = 0.00; + + // Constants for orientations that we use in various places + + /// + /// The stow position of the telescope. This position has it pointing straight up in the air + /// + public static readonly Orientation Stow = new Orientation(0, 90); + + + //constants for acceleration blob + + /// + /// The number of acceleration datapoints in one blob to be added to the database + /// + public const int BLOB_SIZE = 4000; + + // Constant for deleting CSV file attempts + + /// + /// This constant is used to represent the maximum number of attempts that are taken to delete the CSV file + /// + public static readonly int MAX_ATTEMPTS = 9; + + + + + + + } } \ No newline at end of file diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousHardwareConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousHardwareConstants.cs index 8aaba6ad..b6bb4032 100644 --- a/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousHardwareConstants.cs +++ b/ControlRoomApplication/ControlRoomApplication/Constants/MiscellaneousHardwareConstants.cs @@ -6,8 +6,14 @@ public sealed class MiscellaneousHardwareConstants public const double LIMIT_SWITCH_EL_THRESHOLD_DEGREES = 2.0; public const int WEATHER_STATION_DEFAULT_CHECKIN_FREQUENCY_MS = 1000; + public const double WEATHER_STATION_WARNING_WIND_SPEED_MPH = 40.0; public const double WEATHER_STATION_MAXIMUM_ALLOWABLE_WIND_SPEED_MPH = 50.0; public const double SIMULATION_WEATHER_STATION_AVERAGE_WIND_SPEED_MPH = 20.0; public const double SIMULATION_WEATHER_STATION_MAXIMUM_ALLOWABLE_WIND_SPEED_MPH_STD_DEV = (WEATHER_STATION_MAXIMUM_ALLOWABLE_WIND_SPEED_MPH - SIMULATION_WEATHER_STATION_AVERAGE_WIND_SPEED_MPH) / 6.0; + + public const int MOVE_BY_X_DEGREES_AZ_MAX = 720; + + public const double SPECTRACYBER_VOLTS_PER_STEP = 0.0024414; + public const double SPECTRACYBER_BANDWIDTH_STEP = 5; // Measured in Khz } } \ No newline at end of file diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/MotorConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/MotorConstants.cs index 69ad5b41..4f7d699f 100644 --- a/ControlRoomApplication/ControlRoomApplication/Constants/MotorConstants.cs +++ b/ControlRoomApplication/ControlRoomApplication/Constants/MotorConstants.cs @@ -2,7 +2,12 @@ { public sealed class MotorConstants { - public static int STEPS_PER_REVOLUTION_BEFORE_GEARING = 20000; + /// + /// set by the as a the dip switches on the motordriver default = 20_000 + /// + public static int STEPS_PER_REVOLUTION_BEFORE_GEARING = 20_000; + + public static int ENCODER_COUNTS_PER_REVOLUTION_BEFORE_GEARING = 8000; public const int GEARING_RATIO_AZIMUTH = 500; public const int GEARING_RATIO_ELEVATION = 50; diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/SimulationConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/SimulationConstants.cs new file mode 100644 index 00000000..b8a09a2e --- /dev/null +++ b/ControlRoomApplication/ControlRoomApplication/Constants/SimulationConstants.cs @@ -0,0 +1,29 @@ +namespace ControlRoomApplication.Constants +{ + public sealed class SimulationConstants + { + public const double STABLE_MOTOR_TEMP = 50; // Measured in fahrenheit + public const double OVERHEAT_MOTOR_TEMP = 150; + public const double MIN_MOTOR_TEMP = 0; + public const double MAX_MOTOR_TEMP = 200; + + public const double AZIMUTH_UPDATE_RATE = 1.0; // Measured as degrees per second + public const double ELEVATION_UPDATE_RATE = 0.5; + public const double MAX_AZIMUTH_ANGLE = 369; //Measured in degrees + public const double MIN_AZIMUTH_ANGLE = -9; + public const double MAX_ELEVATION_ANGLE = 94; + public const double MIN_ELEVATION_ANGLE = -15; + + public const double LIMIT_CW_AZ_DEGREES = -5; + public const double LIMIT_CCW_AZ_DEGREES = 365; + public const double LIMIT_LOW_EL_DEGREES = -7; // Changed from -15 + public const double LIMIT_HIGH_EL_DEGREES = 93; // Changed from 93 + + public const double PROX_CW_AZ_DEGREES = 10; + public const double PROX_CCW_AZ_DEGREES = 345; + public const double PROX_LOW_EL_DEGREES = -5; + public const double PROX_HIGH_EL_DEGREES = 85; + + + } +} diff --git a/ControlRoomApplication/ControlRoomApplication/Constants/TCPCommunicationConstants.cs b/ControlRoomApplication/ControlRoomApplication/Constants/TCPCommunicationConstants.cs new file mode 100644 index 00000000..01495116 --- /dev/null +++ b/ControlRoomApplication/ControlRoomApplication/Constants/TCPCommunicationConstants.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ControlRoomApplication.Constants +{ + /// + /// This class contains all of the error message strings we will be sending back to the mobile app + /// or the front-end team while communicating with the control room via RemoteListener. + /// + public sealed class TCPCommunicationConstants + { + public static String VERSION_CONVERSION_ERR = "Error converting version from string to double: "; + + public static String VERSION_NOT_FOUND = "The specified version was not found: "; + + public static String AZ_EL_CONVERSION_ERR = "Error converting azimuth or elevation from string to double: "; + + public static String MISSING_AZ_EL_ARGS = "Arguments for AZ or EL not supplied."; + + public static String ORIENTATION_MOVE_ERR = "Command ORIENTATION_MOVE failed with result: "; + + public static String RELATIVE_MOVE_ERR = "Command RELATIVE_MOVE failed with result: "; + + public static String MISSING_OVERRIDE_ARG = "No sensor name supplied for SET_OVERRIDE."; + + public static String MISSING_SET_OVERRIDE_ARG = "No true/false value supplied for SET_OVERRIDE."; + + public static String INVALID_SENSOR_OVERRIDE = "The following sensor was not found to override: "; + + public static String SCRIPT_ERR = "The selected script failed with error: "; + + public static String ALL_STOP_ERR = "The All Stop command failed with error: TimedOut "; + + public static String MISSING_SENSOR_INIT_ARGS = "SENSOR_INIT command is missing arguments; supply all 10 of them. 1" + + "means initialize this sensor, 0 means do not initialize."; + public static String COMMAND_NOT_FOUND = "The specified command was not found or is invalid: "; + + public static String SCRIPT_NOT_FOUND = "The specified script was not found or is invalid: "; + + public static String MISSING_SCRIPT_TYPE_ARG = "Missing a script name after 'SCRIPT'"; + + public static String MISSING_COMMAND_ARGS = "The total number of arguments is invalid for this type of command: "; + + public static String INVALID_REQUEST_TYPE = "The specified REQUEST type was not found or is invalid: "; + + public static String INVALID_VERSION = "This version of TCP does not support this command."; + + public static String[] SCRIPT_NAME_ARRAY = new String[] { "DUMP", "FULL_EV", "THERMAL_CALIBRATE", "STOW", "FULL_CLOCK", "FULL_COUNTER", "HOME", "HARDWARE_MVMT_SCRIPT" }; + + public static String[] SENSORS_ARRAY = new String[] { "WEATHER_STATION", "MAIN_GATE", "ELEVATION_LIMIT_0", "ELEVATION_LIMIT_90", "AZ_ABS_ENC", "EL_ABS_ENC", "AZ_ACC", "EL_ACC", "CB_ACC", + "AZIMUTH_MOT_TEMP", "ELEVATION_MOT_TEMP" }; + + public static String[] ALL_VERSIONS_LIST = new String[] { "1.0", "1.1" }; + + + // Integers for indexing array of command pieces + // General numbers + public static int VERSION_NUM = 0; + public static int COMMAND_TYPE = 1; + public static int MIN_NUM_PARAMS = 3; // case of STOP_RT, will only have Version, stopRT, time --> | STOP_RT |