381 lines
12 KiB
Plaintext
381 lines
12 KiB
Plaintext
|
|
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];
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RECORD_LENGTH the whole first record
|
||
|
|
/// </summary>
|
||
|
|
public char[] Record1
|
||
|
|
{
|
||
|
|
get => _record1;
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_record1.Fill(' ');
|
||
|
|
Array.Copy(value, 0, _record1, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 2 characters, starting at character 75
|
||
|
|
/// </summary>
|
||
|
|
public char[] Tag
|
||
|
|
{
|
||
|
|
get => _record1.GetValues(75, 2);
|
||
|
|
set => _record1.SetValues(value, 75, 2, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 5 characters start at character 7
|
||
|
|
/// </summary>
|
||
|
|
public char[] DataChannelNumber
|
||
|
|
{
|
||
|
|
get => _record1.GetValues(7, 5);
|
||
|
|
set => _record1.SetValues(value, 7, 5, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SetDataChannelNumber(short value)
|
||
|
|
{
|
||
|
|
DataChannelNumber = value.ToString().ToCharArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 1 character, starting at character 15
|
||
|
|
/// </summary>
|
||
|
|
public bool UserIdSensorIDIsNotSpecified
|
||
|
|
{
|
||
|
|
get => _record1[15] == '1';
|
||
|
|
set => _record1[15] = value? '1' : '0';
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters start at 19
|
||
|
|
/// </summary>
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 12 characters, starting at 30
|
||
|
|
/// </summary>
|
||
|
|
public char[] SerialNumber
|
||
|
|
{
|
||
|
|
get => _record1.GetValues(30, 12);
|
||
|
|
set => _record1.SetValues(value, 30, 12, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters, start at 42
|
||
|
|
/// is Sensitivity/1000 (V)
|
||
|
|
/// can also be c0 if polynomial
|
||
|
|
/// </summary>
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters starting at 53
|
||
|
|
/// </summary>
|
||
|
|
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];
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RECORD_LENGTH
|
||
|
|
/// </summary>
|
||
|
|
public char[] Record2
|
||
|
|
{
|
||
|
|
get => _record2;
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_record2.Fill(' ');
|
||
|
|
Array.Copy(value, 0, _record2, 0, ConstantsAndEnums.RECORD_LENGTH);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 12 characters, starting at character 7 (of record 2)
|
||
|
|
/// </summary>
|
||
|
|
public char[] EngineeringUnits
|
||
|
|
{
|
||
|
|
get => _record2.GetValues(7, 12);
|
||
|
|
set => _record2.SetValues(value, 7, 12, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters, starting at character 20
|
||
|
|
/// </summary>
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 17 characters, starting at character 31
|
||
|
|
/// </summary>
|
||
|
|
public char[] EID
|
||
|
|
{
|
||
|
|
get => _record2.GetValues(31, 17);
|
||
|
|
set => _record2.SetValues(value, 31, 17, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 4 characters, starting at 49
|
||
|
|
/// </summary>
|
||
|
|
public char[] Unknown1
|
||
|
|
{
|
||
|
|
get => _record2.GetValues(49, 4);
|
||
|
|
set => _record2.SetValues(value, 49, 4, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 2 characters, starting at 53
|
||
|
|
/// </summary>
|
||
|
|
public char[] Unknown2
|
||
|
|
{
|
||
|
|
get => _record2.GetValues(53, 2);
|
||
|
|
set => _record2.SetValues(value, 53, 2, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters starting at 55 (TOM ONLY [sensortype TI])
|
||
|
|
/// is /1000 of ordinary
|
||
|
|
/// </summary>
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 8 characters, starting at 66
|
||
|
|
/// STANDARD is the default value, we don't really support anything else currently
|
||
|
|
/// </summary>
|
||
|
|
public char[] TOMConfigurationName
|
||
|
|
{
|
||
|
|
get => _record2.GetValues(66, 8);
|
||
|
|
set => _record2.SetValues(value, 66, 8, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
private char[] _record3 = new char[ConstantsAndEnums.RECORD_LENGTH];
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RECORD_LENGTH, third record of 4
|
||
|
|
/// </summary>
|
||
|
|
public char[] Record3
|
||
|
|
{
|
||
|
|
get => _record3;
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_record3.Fill(' ');
|
||
|
|
Array.Copy(value, 0, _record3, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 15 characters start at 14 of record 3
|
||
|
|
/// </summary>
|
||
|
|
public char[] CommentPart1
|
||
|
|
{
|
||
|
|
get => _record3.GetValues(14, 15);
|
||
|
|
set => _record3.SetValues(value, 14, 15, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 40 characters starting at 33
|
||
|
|
/// </summary>
|
||
|
|
public char[] CommentPart2
|
||
|
|
{
|
||
|
|
get => _record3.GetValues(33, 40);
|
||
|
|
set => _record3.SetValues(value, 33, 40, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
private char[] _record4 = new char[ConstantsAndEnums.RECORD_LENGTH];
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RECORD_LENGTH, the 4th record of 4
|
||
|
|
/// </summary>
|
||
|
|
public char[] Record4
|
||
|
|
{
|
||
|
|
get => _record4;
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_record4.Fill(' ');
|
||
|
|
Array.Copy(value, 0, _record4, 0, Math.Min(ConstantsAndEnums.RECORD_LENGTH, value.Length));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 15 characters, starting at character 12
|
||
|
|
/// </summary>
|
||
|
|
public char[] CommentPart3
|
||
|
|
{
|
||
|
|
get => _record4.GetValues(12, 15);
|
||
|
|
set => _record4.SetValues(value, 12, 15, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// sets CommentPart1, CommentPart2, CommentPart3
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="s"></param>
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 20 characters starting at 30
|
||
|
|
/// checked for digital inputs (should contain N/O or N/C)
|
||
|
|
/// </summary>
|
||
|
|
public char[] SensorType
|
||
|
|
{
|
||
|
|
get => _record4.GetValues(30, 20);
|
||
|
|
set => _record4.SetValues(value, 30, 20, ' ');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 11 characters starting at 50
|
||
|
|
/// </summary>
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 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);
|
||
|
|
/// </summary>
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// writes record to stream
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="writer"></param>
|
||
|
|
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.First().Sensitivity);
|
||
|
|
SetBridgeResistance(sensor.BridgeResistance);
|
||
|
|
SetCapacity(sensor.Capacity);
|
||
|
|
SetSensorComment(sensor.Comment);
|
||
|
|
Tag = "VS".ToCharArray();//ConstantsAndEnums.ISFKnownChannelTypes.VS.ToString().ToCharArray();
|
||
|
|
UserIdSensorIDIsNotSpecified = true;
|
||
|
|
EID = sensor.EID.ToCharArray();
|
||
|
|
EngineeringUnits = sc.EngineeringUnits.ToCharArray();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|