using DTS.Common.Interface.Sensors; using DTS.Common.Interface.TestSetups; using System; using System.Linq; namespace DTS.Common.Classes.TestSetups { public class ISFSensorRecord : IISFSensorRecord { private char[] _record1 = new char[ConstantsAndEnums.RECORD_LENGTH]; /// /// RECORD_LENGTH the whole first record /// public char[] Record1 { get => _record1; set { _record1.Fill(' '); Array.Copy(value, 0, _record1, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length)); } } /// /// 2 characters, starting at character 75 /// public char[] Tag { get => _record1.GetValues(75, 2); set => _record1.SetValues(value, 75, 2, ' '); } /// /// 5 characters start at character 7 /// public char[] DataChannelNumber { get => _record1.GetValues(7, 5); set => _record1.SetValues(value, 7, 5, ' '); } public void SetDataChannelNumber(short value) { DataChannelNumber = value.ToString().ToCharArray(); } /// /// 1 character, starting at character 15 /// public bool UserIdSensorIDIsNotSpecified { get => _record1[15] == '1'; set => _record1[15] = value ? '1' : '0'; } /// /// 11 characters start at 19 /// public char[] CapacityCharacters { get => _record1.GetValues(19, 11); set => _record1.SetValues(value, 19, 11, ' '); } public void SetCapacity(double capacity) { CapacityCharacters = capacity.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } public double GetCapacity() { var s = CapacityCharacters.ToString(); s = s.Trim(); if (double.TryParse(s, out var d)) { return d; } return double.NaN; } /// /// 12 characters, starting at 30 /// public char[] SerialNumber { get => _record1.GetValues(30, 12); set => _record1.SetValues(value, 30, 12, ' '); } /// /// 11 characters, start at 42 /// is Sensitivity/1000 (V) /// can also be c0 if polynomial /// public char[] Sensitivity { get => _record1.GetValues(42, 11); set => _record1.SetValues(value, 42, 11, ' '); } public void SetSensitivity(double sensitivity) { Sensitivity = sensitivity.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } public double GetSensitivity() { var s = Sensitivity.ToString().Trim(); if (double.TryParse(s, out var d)) { return d; } return double.NaN; } /// /// 11 characters starting at 53 /// public char[] BridgeResistance { get => _record1.GetValues(53, 11); set => _record1.SetValues(value, 53, 11, ' '); } public void SetBridgeResistance(double resistance) { BridgeResistance = resistance.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } private char[] _record2 = new char[ConstantsAndEnums.RECORD_LENGTH]; /// /// RECORD_LENGTH /// public char[] Record2 { get => _record2; set { _record2.Fill(' '); Array.Copy(value, 0, _record2, 0, ConstantsAndEnums.RECORD_LENGTH); } } /// /// 12 characters, starting at character 7 (of record 2) /// public char[] EngineeringUnits { get => _record2.GetValues(7, 12); set => _record2.SetValues(value, 7, 12, ' '); } /// /// 11 characters, starting at character 20 /// public char[] C1 { get => _record2.GetValues(20, 11); set => _record2.SetValues(value, 20, 11, ' '); } public void SetC1(double c1) { C1 = c1.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } public double GetC1() { var s = C1.ToString().Trim(); if (double.TryParse(s, out var d)) { return d; } return double.NaN; } /// /// 17 characters, starting at character 31 /// public char[] EID { get => _record2.GetValues(31, 17); set => _record2.SetValues(value, 31, 17, ' '); } /// /// 4 characters, starting at 49 /// public char[] Unknown1 { get => _record2.GetValues(49, 4); set => _record2.SetValues(value, 49, 4, ' '); } /// /// 2 characters, starting at 53 /// public char[] Unknown2 { get => _record2.GetValues(53, 2); set => _record2.SetValues(value, 53, 2, ' '); } /// /// 11 characters starting at 55 (TOM ONLY [sensortype TI]) /// is /1000 of ordinary /// public char[] FireDelay { get => _record2.GetValues(55, 11); set => _record2.SetValues(value, 55, 11, ' '); } public void SetFireDelay(double fireDelay) { FireDelay = fireDelay.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } /// /// 8 characters, starting at 66 /// STANDARD is the default value, we don't really support anything else currently /// public char[] TOMConfigurationName { get => _record2.GetValues(66, 8); set => _record2.SetValues(value, 66, 8, ' '); } private char[] _record3 = new char[ConstantsAndEnums.RECORD_LENGTH]; /// /// RECORD_LENGTH, third record of 4 /// public char[] Record3 { get => _record3; set { _record3.Fill(' '); Array.Copy(value, 0, _record3, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length)); } } /// /// 15 characters start at 14 of record 3 /// public char[] CommentPart1 { get => _record3.GetValues(14, 15); set => _record3.SetValues(value, 14, 15, ' '); } /// /// 40 characters starting at 33 /// public char[] CommentPart2 { get => _record3.GetValues(33, 40); set => _record3.SetValues(value, 33, 40, ' '); } private char[] _record4 = new char[ConstantsAndEnums.RECORD_LENGTH]; /// /// RECORD_LENGTH, the 4th record of 4 /// public char[] Record4 { get => _record4; set { _record4.Fill(' '); Array.Copy(value, 0, _record4, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length)); } } /// /// 15 characters, starting at character 12 /// public char[] CommentPart3 { get => _record4.GetValues(12, 15); set => _record4.SetValues(value, 12, 15, ' '); } /// /// sets CommentPart1, CommentPart2, CommentPart3 /// /// public void SetSensorComment(string s) { var newBuffer = new char[15 + 40 + 15]; newBuffer.SetValues(s.ToCharArray(), 0, newBuffer.Length, ' '); //comment1 - 15 chars CommentPart1 = newBuffer.GetValues(0, 15); //comment2 - 40chars CommentPart2 = newBuffer.GetValues(15, 40); //comment3 - 15chars CommentPart3 = newBuffer.GetValues(55, 15); } /// /// 20 characters starting at 30 /// checked for digital inputs (should contain N/O or N/C) /// public char[] SensorType { get => _record4.GetValues(30, 20); set => _record4.SetValues(value, 30, 20, ' '); } /// /// 11 characters starting at 50 /// public char[] C2 { get => _record4.GetValues(50, 11); set => _record4.SetValues(value, 50, 11, ' '); } public void SetC2(double c2) { C2 = c2.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } /// /// 11 characters starting at 61 /// notice for poly's we should be multiplying by 1000D? /// calibration.Records.Records.First().Poly.SetCoefficient(0, calibration.Records.Records[0].Sensitivity / 1000.0D); /// calibration.Records.Records.First().Poly.SetCoefficient(1, c1 / 1000.0D); /// calibration.Records.Records.First().Poly.SetCoefficient(2, c2 / 1000.0D); /// calibration.Records.Records.First().Poly.SetCoefficient(3, c3 / 1000.0D); /// public char[] C3 { get => _record4.GetValues(61, 11); set => _record4.SetValues(value, 61, 11, ' '); } public void SetC3(double c3) { C3 = c3.ToString(System.Globalization.CultureInfo.InvariantCulture).ToCharArray(); } /// /// writes record to stream /// /// public void Write(System.IO.BinaryWriter writer) { writer.Write(Record1); writer.Write(Record2); writer.Write(Record3); writer.Write(Record4); } public ISFSensorRecord() { _record1.Fill(' '); _record2.Fill(' '); _record3.Fill(' '); _record4.Fill(' '); TOMConfigurationName = "STANDARD".ToCharArray(); } public void SetSensor(ISensorData sensor) { SerialNumber = sensor.SerialNumber.ToCharArray(); var sc = sensor.GetLatestCalibration(); SetSensitivity(sc.Records.Records[0].Sensitivity); SetBridgeResistance(sensor.BridgeResistance); SetCapacity(sensor.Capacity); SetSensorComment(sensor.Comment); Tag = "VS".ToCharArray(); UserIdSensorIDIsNotSpecified = true; EID = sensor.EID.ToCharArray(); EngineeringUnits = sc.EngineeringUnits.ToCharArray(); } } }