using DTS.Common.Converters; using System; using System.ComponentModel; using System.IO.Ports; namespace DTS.Common.Enums.Sensors { public abstract class SensorConstants { /// /// Whether TOM squibs should record initiation signal or voltage /// http://manuscript.dts.local/f/cases/44299/SW-Re-Implement-GM-ISF-Style-Real-Time-tags-for-EQX-import /// does not populate value, only holds the value between processes /// public static bool UseInitSignalTOM { get; set; } = false; public const string VOLTAGE_INSERTION_UNIT = "mV"; public const string TSRAIR_ACCEL_UNIT = "g"; public const string TSRAIR_ARS_UNIT = "deg/sec"; public const string TSRAIR_TEMPERATURE_UNIT = "C"; public const string TSRAIR_HUMIDITY_UNIT = "%"; public const string TSRAIR_PRESSURE_UNIT = "PSI"; //these are 3D IR-TRACC values for equations //taken originally from config file for //http://manuscript.dts.local/f/cases/29720/config-file-properties-not-being-used-in-view-3D-IRTRACC-channel-add public static double δThorax { get; set; } = 15.65; public static double δAbdomen { get; set; } = 0; public static double D0Thorax { get; set; } = 141.8; public static double D0Abdomen { get; set; } = 150.9; public static double δThoraxLower { get; set; } = -15.65; public static double D0ThoraxLower { get; set; } = 141.8; //EU string for degrees public const string DEGREES = "deg"; //EUstring for degrees used by GM public const string DEGREE_ANGLE = "deg-ang"; /// /// these are the units we accept when filtering channels for add calculated channel /// 25513 GM requests option to filter channels available for pots for 3d-IR TRACC to include sensors with "deg-ang" /// public static readonly string[] POTUnits = new[] { DEGREES, DEGREE_ANGLE }; public const double MIN_BRIDGE_RESISTANCE_OHMS = 1; public const double MAX_BRIDGE_RESISTANCE_OHMS = 32000; /// /// the DEFAULT value for whether sensor calibrations intervals start after calibration or first use /// public const bool SENSOR_FIRST_USE_DEFAULT = false; public const bool ALLOW_INSPECT_BEFORE_USE_DEFAULT = false; /// /// The DEFAULT value for whether or not to keep track of, and validate a Test Setup based on, sensor use. /// public const bool SENSOR_OVERUSE_DEFAULT = false; /// /// The DEFAULT value for when a warning will be displayed if a sensor's usage is within this amount of its maximum. /// public const int SENSOR_USAGE_REMAINING_FOR_WARNING_DEFAULT = 5; /// /// The DEFAULT value for the default maximum number of uses for sensors /// public const int SENSOR_DEFAULT_MAX_USAGE_DEFAULT = 2500; /// /// the current value for whether sensor calibration intervals start after calibration or first use /// note does not query the value, just holds the value between different modules /// public static bool UseSensorFirstUseDate { get; set; } = false; /// /// The current value for whether or not to keep track of, and validate Test Setups based on, sensor use. /// public static bool DontAllowDataCollectionIfOverused { get; set; } = false; /// /// The current value for whether or not allow Inspect before use feature /// public static bool AllowInspectBeforeUse { get; set; } = false; /// /// A warning will be displayed if a sensor's usage is within this amount of its maximum. /// public static int UsageRemainingForWarning { get; set; } /// /// The default maximum number of uses for sensors /// public static int DefaultMaxUsageAllowed { get; set; } /// /// a cached indicator of whether to use isocode filter mapping or not /// is updated whenever the setting is updated by the application, and on startup /// public static bool UseISOCodeFilterMapping { get; set; } = true; /// /// FB12764 a cached value for default zero method type /// is updated whenever the setting is updated by the application, and on startup /// public static ZeroMethodType DefaultZeroMethodType { get; set; } = ZeroMethodType.AverageOverTime; /// /// FB12764 a cached value for default window start time, if zero method type is Average Over Time /// is updated whenever the setting is updated by the application, and on startup /// public static double DefaultZeroMethodStart { get; set; } = -0.05D; /// /// FB12764 a cached value for default window end time, if zero method type is Average Over Time /// is updated whenever the setting is updated by the application, and on startup /// public static double DefaultZeroMethodEnd { get; set; } = -0.02D; /// /// 29759 the default range for TSR AIR HiG channels /// public static double DefaultRangeHiG { get; set; } = 400D; /// /// 29759 the default range for TSR AIR LowG channels /// public static double DefaultRangeLowG { get; set; } = 64D; public static double DefaultRangeLowGDisplay { get; set; } = 50D; /// /// 29759 the default range for TSR AIR ARS channels /// public static double DefaultRangeARS { get; set; } = 2000D; /// /// 29917 the default range for the TSR AIR Temperature channel /// public static double DefaultRangeTemperature { get; set; } = 85D; /// /// 29917 the default range for the TSR AIR Humidity channel /// public static double DefaultRangeHumidity { get; set; } = 100D; /// /// 29917 the default range for the TSR AIR Pressure channel /// public static double DefaultRangePressure { get; set; } = 16D; //Actually 15.95 PSI (1100 hPa x 0.0145) /// /// represents the _original_ default for SQUIB DELAY in ms (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double SQUIB_DELAY_CONSTANT = 0D; /// /// represents the _original_ default for whether to limit squib output (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const bool SQUIB_LIMIT_DURATION_CONSTANT = true; /// /// represents the _original_ default for squib output duration (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double SQUIB_DURATION_CONSTANT = 10D; /// /// represents the _original_ default for squib low tolerance (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double SQUIB_LOW_TOLERANCE_CONSTANT = 1D; /// /// represents the _original_ default for squib high tolerance (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// 26826 Max Squib Resistance Limit needs to be raised from 8.0 ohms to 10.0 ohms /// public const double SQUIB_HIGH_TOLERANCE_CONSTANT = 10D; /// /// represents the _original_ default for squib fire mode (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const SquibFireMode SQUIB_FIREMODE_CONSTANT = SquibFireMode.CAP; /// /// represents the _original_ default for squib output current (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double SQUIB_CURRENT_CONSTANT = 1.5D; /// /// represents the _original_ default for digital output mode (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const DigitalOutputModes DIGITALOUT_MODE_CONSTANT = DigitalOutputModes.FVLH; /// /// represents the _original_ default for digital output delay (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double DIGITALOUT_DELAY_CONSTANT = 0D; /// /// represents the _original_ default for digital output limit duration (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const bool DIGITALOUT_LIMITDURATION_CONSTANT = true; /// /// represents the _original_ default for digital output duration (not the default in the db) /// used for restoring defaults /// 13677 Restore defaults page button not functional for sensor settings nav step in system settings tile. /// public const double DIGITALOUT_DURATION_CONSTANT = 10D; /// /// represents the _original_ default for uart data bits (not the default in the db) /// used for restoring defaults /// public const uint UART_DATABITS_CONSTANT = 8; /// /// represents the _original_ default for uart stop bits (not the default in the db) /// used for restoring defaults /// public const StopBits UART_STOPBITS_CONSTANT = StopBits.One; /// /// represents the _original_ default for uart parity (not the default in the db) /// used for restoring defaults /// public const Parity UART_PARITY_CONSTANT = Parity.None; /// /// represents the _original_ default for uart flow control (not the default in the db) /// used for restoring defaults /// public const Handshake UART_FLOWCONTROL_CONSTANT = Handshake.None; /// /// represents the _original_ default for uart data format (not the default in the db) /// used for restoring defaults /// public const UartDataFormat UART_DATAFORMAT_CONSTANT = UartDataFormat.Binary; /// /// represents the _original_ default for stream input udp address (not the default in the db) /// used for restoring defaults /// public const string STREAMIN_ADDRESS_CONSTANT = "UDP://239.1.2.10:8400"; /// /// represents the _original_ default for stream output udp profile (not the default in the db) /// used for restoring defaults /// public const UDPStreamProfile STREAMOUT_PROFILE_CONSTANT = UDPStreamProfile.CH10_PCM_128BIT_2HDR; /// /// represents the _original_ default for stream output udp address (not the default in the db) /// used for restoring defaults /// public const string STREAMOUT_ADDRESS_CONSTANT = "UDP://239.1.2.10:8400"; /// /// represents the _original_ default for stream output time channel id (not the default in the db) /// used for restoring defaults /// public const ushort STREAMOUT_TIME_CHID_CONSTANT = 1; /// /// represents the _original_ default for stream output data channel id (not the default in the db) /// used for restoring defaults /// public const ushort STREAMOUT_DATA_CHID_CONSTANT = 3; /// /// represents the _original_ default for stream output TmNS configuration (not the default in the db) /// used for restoring defaults /// public const string STREAMOUT_TMNS_CONFIG_CONSTANT = "(1,6,60,0,0,0,0,0)"; /// /// represents the _original_ default for stream output irig time data packet interval (in milliseconds) (not the default in the db) /// used for restoring defaults /// public const ushort STREAMOUT_IRIG_TDP_INTERVAL_CONSTANT = 500; public const string TEST_SPECIFIC_DOUT = "TSD_"; public const string TEST_SPECIFIC_SQUIB = "TSQ_"; public const string TEST_SPECIFIC_DIN = "TSI_"; public const string TEST_SPECIFIC_EMB = "TSA_"; public const string TEST_SPECIFIC_THERMO = "TST_"; public const string TEST_SPECIFIC_EMB_CLK = "TSC_"; public const string TEST_SPECIFIC_UART = "TSU_"; public const string TEST_SPECIFIC_STREAM_OUT = "TSS_"; public const string TEST_SPECIFIC_STREAM_IN = "TSN_"; public const string TEST_SPECIFIC_CAN = "TSF_"; public const string TEST_SPECIFIC_DIGITAL_IN_SERIAL = "TSI_TestSpecific"; public const string TEST_SPECIFIC_DIGITAL_OUT_SERIAL = "TSD_TestSpecific"; public const string TEST_SPECIFIC_SQUIB_SERIAL = "TSQ_TestSpecific"; public const string TEST_SPECIFIC_ANALOG_SERIAL = "TSA_Embedded"; public const string TEST_SPECIFIC_CLOCK_SERIAL = "TSC_Embedded"; public const string TEST_SPECIFIC_UART_SERIAL = "TSU_TestSpecific"; public const string TEST_SPECIFIC_STREAM_OUT_SERIAL = "TSS_TestSpecific"; public const string TEST_SPECIFIC_STREAM_IN_SERIAL = "TSN_TestSpecific"; public const string VOLTAGE_INPUT = "Voltage input"; public const string TEST_SPECIFIC_THERMOCOUPLER = "TST_TestSpecific"; public const string TEST_SPECIFIC_CAN_SERIAL = "TSF_TestSpecific"; public static bool IsTestSpecificDigitalOut(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_DOUT)) return false; return true; } public static bool IsTestSpecificSquib(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_SQUIB)) return false; return true; } /// /// returns true if the serial number belongs to a test specific digital input /// public static bool IsTestSpecificDigitalIn(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_DIN)) return false; return true; } public static bool IsTestSpecificEmbedded(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_EMB)) { return false; } return true; } public static bool IsTestSpecificThermoCouple(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_THERMO)) { return false; } return true; } public static bool IsTestSpecificEmbeddedClock(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_EMB_CLK)) return false; return true; } public static bool IsTestSpecificStreamOut(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_STREAM_OUT)) return false; return true; } public static bool IsTestSpecificStreamIn(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_STREAM_IN)) return false; return true; } public static bool IsTestSpecificUart(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_UART)) return false; return true; } public static bool IsTestSpecificThermocoupler(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_THERMOCOUPLER)) return false; return true; } public static bool IsTestSpecificCAN(string sn) { if (string.IsNullOrWhiteSpace(sn)) { return false; } if (!sn.StartsWith(TEST_SPECIFIC_CAN)) return false; return true; } public const string EditObjectSensorChannelDragFormat = "EditObjectSensorsChannelTable.UserData []"; public enum SensorSettings { Range, CFC, Polarity, Position, LimitDuration, //deprecated in 2.1 Duration, //deprecated in 2.1 Delay, //deprecated in 2.1 OutputMode, SQMode, DIMode, DefaultValue, ActiveValue, //12 LAST value in V2.0 settings //new in 2.1 SquibLimitDuration, SquibDuration, SquibDelay, DigitalOutLimitDuration, DigitalOutDuration, DigitalOutDelay, SquibCurrent, //new in 3.0 ZeroMethod, ZeroMethodStart, ZeroMethodEnd, UserValue1, UserValue2, UserValue3, InitialOffset, //FB 13120 added filter class FilterClass, //new in 4.0 //18363 Uart Channels UartBaudRate, UartDataBits, UartStopBits, UartParity, UartFlowControl, UartDataFormat, //18364 Stream Out Channels StreamOutUDPProfile, StreamOutUDPAddress, StreamOutUDPTimeChannelId, StreamOutUDPDataChannelId, StreamOutUDPTmNSConfig, StreamOutIRIGTimeDataPacketIntervalMs, //26828 Stream In Channels StreamInUDPAddress, //29760 Implement ACCoupleEnable ACCouplingEnabled, //33145 Voltage insertion channel should be half-bridge BridgeType } public enum SensorType { Analog, DigitalIn, DigitalOut, Squib, Clock, UART, StreamOut, StreamIn, Thermocoupler } /// /// Separator for encoding an added linear calibration with a non-linear calibrated sensor /// public const string LinearValuesSeparator = "||"; /// /// used to convert between different formats and SensivityUnits /// 14448 Error when trying to import sensors. /// public abstract class SensUnitStringConverter { public static SensUnits ConvertFromString(string s) { s = s.Trim().ToLower(); switch (s) { case "none": return SensUnits.NONE; case "mv": return SensUnits.mV; case "mv/v": case "mvperv": return SensUnits.mVperV; case "mv/v/eu": case "mvpervpereu": return SensUnits.mVperVperEU; case "mv/eu": case "mvpereu": return SensUnits.mVperEU; default: throw new InvalidCastException($"Can't convert {s} to SensUnits"); } } } /// /// All available Sensitivity Unit types. /// public enum SensUnits { /// /// No Sensitivity Units (Polynomial Sensor) /// [Description("NONE")] NONE = 0, /// /// Sensitivity expressed in mV with output at Capacity EU /// [Description("mV")] mV = 1, /// /// Excitation proportional sensitivity expressed in mV/V with output at Capacity EU /// [Description("mV/V")] mVperV = 2, /// /// Excitation proportional sensitivity expressed in mV/V/EU /// [Description("mV/V/EU")] mVperVperEU = 3, /// /// Sensitivity expressed in mV/EU /// [Description("mV/EU")] mVperEU = 4 } /// /// All available bridge types. /// public enum BridgeType { /// /// sensor uses IEPE setup /// [Description("IEPE")] IEPE = 1 << 0, /// /// sensor uses quarter bridge setup /// [Description("Quarter")] QuarterBridge = 1 << 1, /// /// sensor uses half bridge setup /// [Description("Bridge-Half")] HalfBridge = 1 << 2, /// /// sensor has a full bridge setup /// [Description("Bridge-Full")] FullBridge = 1 << 3, /// /// digital input setup /// [Description("DigitalInput")] DigitalInput = 1 << 4, /// /// squib output setup /// [Description("SQUIB")] SQUIB = 1 << 5, /// /// digital output setup /// [Description("TOMDigital")] TOMDigital = 1 << 6, /// /// sensor uses a G5 (signal plus) half bridge setup /// [Description("Bridge-Half SigPlus")] HalfBridge_SigPlus = 1 << 7, /// /// not a "sensor" but encoding the RTC /// [Description("RTC")] RTC = 1 << 8, /// /// not a "sensor" but values recorded on UART /// [Description("UART")] UART = 1 << 9, /// /// not a "sensor" but values sent out via stream /// [Description("StreamOut")] StreamOut = 1 << 10, /// /// not a "sensor" but values received via stream /// [Description("StreamIn")] StreamIn = 1 << 11, /// /// thermocoupler sensor /// [Description("Thermocoupler")] Thermocoupler = 1 << 12, /// /// not a "sensor" but values recorded on CAN /// [Description("CAN")] CAN = 1 << 13 } public static BridgeType ConvertIntToBridgeType(int bridge) { switch (bridge) { case 0: return BridgeType.IEPE; case 4: return BridgeType.HalfBridge_SigPlus; case 3: return BridgeType.FullBridge; case 2: return BridgeType.HalfBridge; case 1: return BridgeType.QuarterBridge; case 8: return BridgeType.RTC; default: return BridgeType.FullBridge; } } /// /// this is apparently needed for historical reasons /// as the sensor db apparently doesn't use the bitmask value for storage? /// /// /// public static int ConvertBridgeToInt(BridgeType bridge) { switch (bridge) { case BridgeType.IEPE: return 0; case BridgeType.QuarterBridge: return 1; case BridgeType.HalfBridge: return 2; case BridgeType.FullBridge: return 3; case BridgeType.HalfBridge_SigPlus: return 4; case BridgeType.RTC: return 8; default: return 3; } } /// /// how to handle sensor calibrations that are out of date /// 1) always allow sensors in a data collection, just warn /// 2) don't allow sensors which are out of date, warn if near out of date /// [TypeConverter(typeof(EnumDescriptionTypeConverter))] public enum SensorCalPolicy { [Description("SENSOR_CAL_POLICY_ALLOW_ALWAYS")] AllowAlways, [Description("SENSOR_CAL_POLICY_DONT_ALLOW")] DONT_ALLOW } /// /// allows for this field to be cached without having to be retrieved when processing a lot of channels /// public static int SensorCalOutOfDateWarningPeriodDays = 14; public static SensorCalPolicy SensorCalPolicyCurrent = SensorCalPolicy.DONT_ALLOW; /// /// the default policy for sensors is to not allow out of cal sensors /// public const SensorCalPolicy CAL_SENSOR_POLICY_DEFAULT = SensorCalPolicy.DONT_ALLOW; /// /// default warning period for sensors for calibration (in days) /// public const int CAL_SENSOR_POLICY_WARNING_DAYS_DEFAULT = 14; public enum CouplingModes { AC = 0, DC } /// /// signifies whether autosense for IEPE/analog will be performed /// this variable only holds the value for the property, it does not /// serialize, deserialize, the property must be set by any using /// applications first /// public static bool DisableAutoSense { get; set; } // FB16524: diagnostic result should include the resting voltage of an IEPE sensor // http://manuscript.dts.local/f/cases/16524/diagnostic-result-should-include-the-resting-voltage-of-an-IEPE-sensor public static double DefaultBridgeOffsetMVTolLow { get; set; } = -100; public static double DefaultBridgeOffsetMVTolHigh { get; set; } = 100; public static double DefaultIEPEOffsetMVTolLow { get; set; } = -2000; public static double DefaultIEPEOffsetMVTolHigh { get; set; } = 2000; //ARS valid ranges for TSR AIR public const int ARS2000 = 2000; //LowG valid ranges for TSR AIR public const int LowG64 = 64; [TypeConverter(typeof(EnumDescriptionTypeConverter))] public enum AvailableRangesLowG { [Description("TSRAIR_LOW_g_64")] LowG64D = LowG64 }; public enum AvailableRangesARS { ARS2000D = ARS2000, }; public const string HighG = "-High g"; public const string LowG = "-Low g"; public const string ARS = "-ARS"; public const string Atm = "-Atm"; public const int TSRAirTemperatureChannel = 9; public const int TSRAirHumidityChannel = 10; public const int TSRAirPressureChannel = 11; public static bool IsTSRAirHighGChannel(string moduleSerialNumber) { if (moduleSerialNumber.EndsWith(HighG)) { return true; } return false; } public static bool IsTSRAirLowGChannel(string moduleSerialNumber) { if (moduleSerialNumber.EndsWith(LowG)) { return true; } return false; } public static bool IsTSRAirARSChannel(string moduleSerialNumber) { if (moduleSerialNumber.EndsWith(ARS)) { return true; } return false; } public static bool IsTSRAirAtmChannel(string moduleSerialNumber) { if (moduleSerialNumber.EndsWith(Atm)) { return true; } return false; } public static bool IsTSRAirHumidityChannel(string moduleSerialNumber, int channelNumber) { return IsTSRAirAtmChannel(moduleSerialNumber) && (channelNumber == TSRAirHumidityChannel); } } }