1199 lines
38 KiB
C#
1199 lines
38 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace TiltMIF
|
|
{
|
|
public class Tilt_MIF
|
|
{
|
|
public System.DateTime TimeStamp { get; set; }
|
|
public string SystemName { get; set; }
|
|
public string UserName { get; set; }
|
|
public string BuildVersion { get; set; }
|
|
|
|
public enum MIFAttributes
|
|
{
|
|
MIFVersion,
|
|
SerialNumber,
|
|
HardwareConfiguration,
|
|
TemperatureCF,
|
|
TemperatureOffset,
|
|
TiltSensorCF1,
|
|
TiltSensorCF2,
|
|
TiltSensorCF3,
|
|
TiltSensorOffset1,
|
|
TiltSensorOffset2,
|
|
TiltSensorOffset3,
|
|
TiltSensorRange1,
|
|
TiltSensorRange2,
|
|
TiltSensorRange3,
|
|
TiltCalibrationCF1,
|
|
TiltCalibrationCF2,
|
|
TiltCalibrationCF3,
|
|
TiltCalibrationCF4,
|
|
TiltCalibrationCF5,
|
|
TiltCalibrationCF6,
|
|
TiltCalibrationCF7,
|
|
TiltCalibrationCF8,
|
|
TiltCalibrationCF9,
|
|
TiltCalibrationCF10,
|
|
TiltCalibrationCF11,
|
|
TiltCalibrationCF12,
|
|
TiltCalibrationCF13,
|
|
TiltCalibrationCF14,
|
|
TiltCalibrationCF15,
|
|
TiltCalibrationCF16,
|
|
TiltCalibrationCF17,
|
|
TiltCalibrationCF18,
|
|
}
|
|
|
|
public List<MIFAttribute> GetTiltAttributes()
|
|
{
|
|
var rv = new List<MIFAttribute>();
|
|
var attributes = Enum.GetValues(typeof(MIFAttributes)).Cast<MIFAttributes>().ToArray();
|
|
foreach (var attr in attributes)
|
|
{
|
|
rv.Add(new MIFAttribute { Attribute = attr, MIFValue = GetMIFAttribute(attr).ToString() });
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
public Dictionary<string, object> GetTiltAttributeDictionary()
|
|
{
|
|
var rv = new Dictionary<string, object>();
|
|
var attributes = Enum.GetValues(typeof(MIFAttributes)).Cast<MIFAttributes>().ToArray();
|
|
foreach (var attr in attributes)
|
|
{
|
|
rv[attr.ToString()] = GetMIFAttribute(attr);
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
public class MIFAttribute
|
|
{
|
|
public MIFAttributes Attribute { get; set; }
|
|
public string MIFValue { get; set; }
|
|
}
|
|
|
|
public void SetMIFAttribute(MIFAttributes attribute, string newValue)
|
|
{
|
|
switch (attribute)
|
|
{
|
|
case MIFAttributes.HardwareConfiguration:
|
|
HardwareConfiguration = ushort.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.MIFVersion:
|
|
MIFVersion = ushort.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.SerialNumber:
|
|
SerialNumber = newValue;
|
|
break;
|
|
|
|
case MIFAttributes.TemperatureCF:
|
|
TemperatureCF = ushort.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TemperatureOffset:
|
|
TemperatureOffset = short.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF1:
|
|
TiltSensorCF1 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF2:
|
|
TiltSensorCF2 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF3:
|
|
TiltSensorCF3 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset1:
|
|
TiltSensorOffset1 = short.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset2:
|
|
TiltSensorOffset2 = short.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset3:
|
|
TiltSensorOffset3 = short.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange1:
|
|
TiltSensorRange1 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange2:
|
|
TiltSensorRange2 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange3:
|
|
TiltSensorRange3 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF1:
|
|
TiltCalibrationCF1 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF2:
|
|
TiltCalibrationCF2 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF3:
|
|
TiltCalibrationCF3 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF4:
|
|
TiltCalibrationCF4 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF5:
|
|
TiltCalibrationCF5 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF6:
|
|
TiltCalibrationCF6 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF7:
|
|
TiltCalibrationCF7 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF8:
|
|
TiltCalibrationCF8 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF9:
|
|
TiltCalibrationCF9 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF10:
|
|
TiltCalibrationCF10 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF11:
|
|
TiltCalibrationCF11 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF12:
|
|
TiltCalibrationCF12 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF13:
|
|
TiltCalibrationCF13 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF14:
|
|
TiltCalibrationCF14 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF15:
|
|
TiltCalibrationCF15 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF16:
|
|
TiltCalibrationCF16 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF17:
|
|
TiltCalibrationCF17 = float.Parse(newValue);
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF18:
|
|
TiltCalibrationCF18 = float.Parse(newValue);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public object GetMIFAttribute(MIFAttributes attribute)
|
|
{
|
|
object rv = null;
|
|
switch (attribute)
|
|
{
|
|
case MIFAttributes.HardwareConfiguration:
|
|
rv = HardwareConfiguration;
|
|
break;
|
|
|
|
case MIFAttributes.MIFVersion:
|
|
rv = MIFVersion;
|
|
break;
|
|
|
|
case MIFAttributes.SerialNumber:
|
|
rv = SerialNumber;
|
|
break;
|
|
|
|
case MIFAttributes.TemperatureCF:
|
|
rv = TemperatureCF;
|
|
break;
|
|
|
|
case MIFAttributes.TemperatureOffset:
|
|
rv = TemperatureOffset;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF1:
|
|
rv = TiltSensorCF1;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF2:
|
|
rv = TiltSensorCF2;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorCF3:
|
|
rv = TiltSensorCF3;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset1:
|
|
rv = TiltSensorOffset1;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset2:
|
|
rv = TiltSensorOffset2;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorOffset3:
|
|
rv = TiltSensorOffset3;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange1:
|
|
rv = TiltSensorRange1;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange2:
|
|
rv = TiltSensorRange2;
|
|
break;
|
|
|
|
case MIFAttributes.TiltSensorRange3:
|
|
rv = TiltSensorRange3;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF1:
|
|
rv = TiltCalibrationCF1;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF2:
|
|
rv = TiltCalibrationCF2;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF3:
|
|
rv = TiltCalibrationCF3;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF4:
|
|
rv = TiltCalibrationCF4;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF5:
|
|
rv = TiltCalibrationCF5;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF6:
|
|
rv = TiltCalibrationCF6;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF7:
|
|
rv = TiltCalibrationCF7;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF8:
|
|
rv = TiltCalibrationCF8;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF9:
|
|
rv = TiltCalibrationCF9;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF10:
|
|
rv = TiltCalibrationCF10;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF11:
|
|
rv = TiltCalibrationCF11;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF12:
|
|
rv = TiltCalibrationCF12;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF13:
|
|
rv = TiltCalibrationCF13;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF14:
|
|
rv = TiltCalibrationCF14;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF15:
|
|
rv = TiltCalibrationCF15;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF16:
|
|
rv = TiltCalibrationCF16;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF17:
|
|
rv = TiltCalibrationCF17;
|
|
break;
|
|
|
|
case MIFAttributes.TiltCalibrationCF18:
|
|
rv = TiltCalibrationCF18;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
public uint MIFVersion { get; set; }
|
|
private char[] _serialNumber = new char[10];
|
|
|
|
public string SerialNumber
|
|
{
|
|
get { return (new string(_serialNumber)).Replace('\0', ' ').Trim(); }
|
|
set
|
|
{
|
|
_serialNumber = new char[10];
|
|
value.ToCharArray().CopyTo(_serialNumber, 0);
|
|
}
|
|
}
|
|
|
|
public ushort HardwareConfiguration { get; set; }
|
|
|
|
public float TemperatureCF { get; set; }
|
|
|
|
public short TemperatureOffset { get; set; }
|
|
|
|
private float[] _tiltSensorCF = new float[] { 7.5f, 7.5f, 7.5f };
|
|
|
|
public float TiltSensorCF1
|
|
{
|
|
get { return _tiltSensorCF[0]; }
|
|
set { _tiltSensorCF[0] = value; }
|
|
}
|
|
|
|
public float TiltSensorCF2
|
|
{
|
|
get { return _tiltSensorCF[1]; }
|
|
set { _tiltSensorCF[1] = value; }
|
|
}
|
|
|
|
public float TiltSensorCF3
|
|
{
|
|
get { return _tiltSensorCF[2]; }
|
|
set { _tiltSensorCF[2] = value; }
|
|
}
|
|
|
|
private short[] _tiltSensorOffset = new short[3];
|
|
|
|
public short TiltSensorOffset1
|
|
{
|
|
get { return _tiltSensorOffset[0]; }
|
|
set { _tiltSensorOffset[0] = value; }
|
|
}
|
|
|
|
public short TiltSensorOffset2
|
|
{
|
|
get { return _tiltSensorOffset[1]; }
|
|
set { _tiltSensorOffset[1] = value; }
|
|
}
|
|
|
|
public short TiltSensorOffset3
|
|
{
|
|
get { return _tiltSensorOffset[2]; }
|
|
set { _tiltSensorOffset[2] = value; }
|
|
}
|
|
|
|
private float[] _tiltSensorRange = new float[] { 360, 360, 360 };
|
|
|
|
public float TiltSensorRange1
|
|
{
|
|
get { return _tiltSensorRange[0]; }
|
|
set { _tiltSensorRange[0] = value; }
|
|
}
|
|
|
|
public float TiltSensorRange2
|
|
{
|
|
get { return _tiltSensorRange[1]; }
|
|
set { _tiltSensorRange[1] = value; }
|
|
}
|
|
|
|
public float TiltSensorRange3
|
|
{
|
|
get { return _tiltSensorRange[2]; }
|
|
set { _tiltSensorRange[2] = value; }
|
|
}
|
|
|
|
private const int TILTCAL_COUNT = 18;
|
|
private float[] _tiltCalibrations = new float[TILTCAL_COUNT];
|
|
|
|
public double[] GetTiltCalibrations()
|
|
{
|
|
var rv = new List<double>(TILTCAL_COUNT);
|
|
foreach (var f in _tiltCalibrations)
|
|
{
|
|
rv.Add(f);
|
|
}
|
|
return rv.ToArray();
|
|
}
|
|
|
|
public void SetTiltCalibrations(float[] calibrations)
|
|
{
|
|
if (calibrations.Length != TILTCAL_COUNT) { throw new InvalidDataException(); }
|
|
_tiltCalibrations = calibrations;
|
|
}
|
|
|
|
public void SetTiltCalibrations(double[] calibrations)
|
|
{
|
|
SetTiltCalibrations(calibrations.Select(x => (float)x).ToArray());
|
|
}
|
|
|
|
public float TiltCalibrationCF1
|
|
{
|
|
get { return _tiltCalibrations[0]; }
|
|
set { _tiltCalibrations[0] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF2
|
|
{
|
|
get { return _tiltCalibrations[1]; }
|
|
set { _tiltCalibrations[1] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF3
|
|
{
|
|
get { return _tiltCalibrations[2]; }
|
|
set { _tiltCalibrations[2] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF4
|
|
{
|
|
get { return _tiltCalibrations[3]; }
|
|
set { _tiltCalibrations[3] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF5
|
|
{
|
|
get { return _tiltCalibrations[4]; }
|
|
set { _tiltCalibrations[4] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF6
|
|
{
|
|
get { return _tiltCalibrations[5]; }
|
|
set { _tiltCalibrations[5] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF7
|
|
{
|
|
get { return _tiltCalibrations[6]; }
|
|
set { _tiltCalibrations[6] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF8
|
|
{
|
|
get { return _tiltCalibrations[7]; }
|
|
set { _tiltCalibrations[7] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF9
|
|
{
|
|
get { return _tiltCalibrations[8]; }
|
|
set { _tiltCalibrations[8] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF10
|
|
{
|
|
get { return _tiltCalibrations[9]; }
|
|
set { _tiltCalibrations[9] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF11
|
|
{
|
|
get { return _tiltCalibrations[10]; }
|
|
set { _tiltCalibrations[10] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF12
|
|
{
|
|
get { return _tiltCalibrations[11]; }
|
|
set { _tiltCalibrations[11] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF13
|
|
{
|
|
get { return _tiltCalibrations[12]; }
|
|
set { _tiltCalibrations[12] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF14
|
|
{
|
|
get { return _tiltCalibrations[13]; }
|
|
set { _tiltCalibrations[13] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF15
|
|
{
|
|
get { return _tiltCalibrations[14]; }
|
|
set { _tiltCalibrations[14] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF16
|
|
{
|
|
get { return _tiltCalibrations[15]; }
|
|
set { _tiltCalibrations[15] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF17
|
|
{
|
|
get { return _tiltCalibrations[16]; }
|
|
set { _tiltCalibrations[16] = value; }
|
|
}
|
|
|
|
public float TiltCalibrationCF18
|
|
{
|
|
get { return _tiltCalibrations[17]; }
|
|
set { _tiltCalibrations[17] = value; }
|
|
}
|
|
|
|
private short _reservedU16;
|
|
|
|
public ushort MIF_CRC16 { get; set; }
|
|
|
|
public ushort ComputedCRC16 { get; set; }
|
|
|
|
public bool ReadError { get; set; }
|
|
|
|
#region Config Attributes
|
|
|
|
private bool _hasConfig = false;
|
|
|
|
public ushort Config_CRC16 { get; set; }
|
|
|
|
public ushort ComputedCRC16_Config { get; set; }
|
|
|
|
public bool ReadError_Config { get; set; }
|
|
|
|
public enum ConfigAttributes
|
|
{
|
|
SystemID,
|
|
Location,
|
|
Tolerance,
|
|
ArmChecklist,
|
|
AxisToIgnore,
|
|
AxisLabel1,
|
|
AxisLabel2,
|
|
AxisLabel3,
|
|
InvertAxis1,
|
|
InvertAxis2,
|
|
InvertAxis3,
|
|
MountOffsetAxis1,
|
|
MountOffsetAxis2,
|
|
MountOffsetAxis3,
|
|
TargetAngleAxis1,
|
|
TargetAngleAxis2,
|
|
TargetAngleAxis3,
|
|
PreEventADCAxis1,
|
|
PreEventADCAxis2,
|
|
PreEventADCAxis3,
|
|
PostEventADCAxis1,
|
|
PostEventADCAxis2,
|
|
PostEventADCAxis3,
|
|
}
|
|
|
|
public class ConfigAttribute
|
|
{
|
|
public ConfigAttributes Attribute { get; set; }
|
|
public string ConfigValue { get; set; }
|
|
}
|
|
|
|
public List<ConfigAttribute> GetTiltConfigAttributes()
|
|
{
|
|
var rv = new List<ConfigAttribute>();
|
|
var attributes = Enum.GetValues(typeof(ConfigAttributes)).Cast<ConfigAttributes>().ToArray();
|
|
foreach (var attr in attributes)
|
|
{
|
|
rv.Add(new ConfigAttribute { Attribute = attr, ConfigValue = GetConfigAttribute(attr).ToString() });
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
public Dictionary<string, object> GetTiltConfigAttributeDictionary()
|
|
{
|
|
var rv = new Dictionary<string, object>();
|
|
var attributes = Enum.GetValues(typeof(ConfigAttributes)).Cast<ConfigAttributes>().ToArray();
|
|
foreach (var attr in attributes)
|
|
{
|
|
rv[attr.ToString()] = GetConfigAttribute(attr);
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
public void SetConfigAttribute(ConfigAttributes attribute, string newValue)
|
|
{
|
|
switch (attribute)
|
|
{
|
|
case ConfigAttributes.SystemID:
|
|
SystemID = newValue;
|
|
break;
|
|
|
|
case ConfigAttributes.Location:
|
|
Location = newValue;
|
|
break;
|
|
|
|
case ConfigAttributes.Tolerance:
|
|
Tolerance = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.ArmChecklist:
|
|
ArmChecklist = bool.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.AxisToIgnore:
|
|
AxisToIgnore = byte.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel1:
|
|
AxisLabel1 = (Axis)Enum.Parse(typeof(Axis), newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel2:
|
|
AxisLabel2 = (Axis)Enum.Parse(typeof(Axis), newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel3:
|
|
AxisLabel3 = (Axis)Enum.Parse(typeof(Axis), newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis1:
|
|
InvertAxis1 = bool.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis2:
|
|
InvertAxis2 = bool.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis3:
|
|
InvertAxis3 = bool.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis1:
|
|
MountOffsetAxis1 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis2:
|
|
MountOffsetAxis2 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis3:
|
|
MountOffsetAxis3 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis1:
|
|
TargetAngleAxis1 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis2:
|
|
TargetAngleAxis2 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis3:
|
|
TargetAngleAxis3 = float.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis1:
|
|
PreEventADCAxis1 = short.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis2:
|
|
PreEventADCAxis2 = short.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis3:
|
|
PreEventADCAxis3 = short.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis1:
|
|
PostEventADCAxis1 = short.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis2:
|
|
PostEventADCAxis1 = short.Parse(newValue);
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis3:
|
|
PostEventADCAxis1 = short.Parse(newValue);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public object GetConfigAttribute(ConfigAttributes attribute)
|
|
{
|
|
object rv = null;
|
|
switch (attribute)
|
|
{
|
|
case ConfigAttributes.ArmChecklist:
|
|
rv = ArmChecklist;
|
|
break;
|
|
|
|
case ConfigAttributes.SystemID:
|
|
rv = SystemID;
|
|
break;
|
|
|
|
case ConfigAttributes.Location:
|
|
rv = Location;
|
|
break;
|
|
|
|
case ConfigAttributes.Tolerance:
|
|
rv = Tolerance;
|
|
break;
|
|
|
|
case ConfigAttributes.AxisToIgnore:
|
|
rv = AxisToIgnore;
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel1:
|
|
rv = AxisLabel1;
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel2:
|
|
rv = AxisLabel2;
|
|
break;
|
|
|
|
case ConfigAttributes.AxisLabel3:
|
|
rv = AxisLabel3;
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis1:
|
|
rv = InvertAxis1;
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis2:
|
|
rv = InvertAxis2;
|
|
break;
|
|
|
|
case ConfigAttributes.InvertAxis3:
|
|
rv = InvertAxis3;
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis1:
|
|
rv = MountOffsetAxis1;
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis2:
|
|
rv = MountOffsetAxis2;
|
|
break;
|
|
|
|
case ConfigAttributes.MountOffsetAxis3:
|
|
rv = MountOffsetAxis3;
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis1:
|
|
rv = TargetAngleAxis1;
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis2:
|
|
rv = TargetAngleAxis2;
|
|
break;
|
|
|
|
case ConfigAttributes.TargetAngleAxis3:
|
|
rv = TargetAngleAxis3;
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis1:
|
|
rv = PreEventADCAxis1;
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis2:
|
|
rv = PreEventADCAxis2;
|
|
break;
|
|
|
|
case ConfigAttributes.PreEventADCAxis3:
|
|
rv = PreEventADCAxis3;
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis1:
|
|
rv = PostEventADCAxis1;
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis2:
|
|
rv = PostEventADCAxis2;
|
|
break;
|
|
|
|
case ConfigAttributes.PostEventADCAxis3:
|
|
rv = PostEventADCAxis3;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
private char[] _systemID = new char[16];
|
|
|
|
public string SystemID
|
|
{
|
|
get { return (new string(_systemID)).Replace('\0', ' ').Trim(); }
|
|
set
|
|
{
|
|
_systemID = new char[16];
|
|
value.ToCharArray().CopyTo(_systemID, 0);
|
|
}
|
|
}
|
|
|
|
private char[] _location = new char[16];
|
|
|
|
public string Location
|
|
{
|
|
get { return (new string(_location)).Replace('\0', ' ').Trim(); }
|
|
set
|
|
{
|
|
_location = new char[16];
|
|
value.ToCharArray().CopyTo(_location, 0);
|
|
}
|
|
}
|
|
|
|
public float Tolerance { get; set; } = 2;
|
|
|
|
#region ConfigurationBits
|
|
|
|
private byte[] _configBits = new byte[2];
|
|
|
|
private void SetBit(int bitInByte, bool isSet, ref byte inByte)
|
|
{
|
|
if (isSet)
|
|
{
|
|
inByte |= (byte)(0x01 << bitInByte);
|
|
}
|
|
else
|
|
{
|
|
inByte &= (byte)~(0x01 << bitInByte);
|
|
}
|
|
}
|
|
|
|
private void SetTwoBits(int bitInByte, byte fistTwoBits, ref byte inByte)
|
|
{
|
|
SetBit(bitInByte, (fistTwoBits & 0x01) == 0x01, ref _configBits[1]);
|
|
SetBit(bitInByte + 1, (fistTwoBits & 0x02) >> 1 == 0x01, ref _configBits[1]);
|
|
}
|
|
|
|
public bool ArmChecklist
|
|
{
|
|
get { return ((_configBits[0] & 0x01) >> 0) == 1; }
|
|
set { SetBit(0, value, ref _configBits[0]); }
|
|
}
|
|
|
|
public bool InvertAxis1
|
|
{
|
|
get { return ((_configBits[0] & 0x02) >> 1) == 1; }
|
|
set { SetBit(1, value, ref _configBits[0]); }
|
|
}
|
|
|
|
public bool InvertAxis2
|
|
{
|
|
get { return ((_configBits[0] & 0x04) >> 2) == 1; }
|
|
set { SetBit(2, value, ref _configBits[0]); }
|
|
}
|
|
|
|
public bool InvertAxis3
|
|
{
|
|
get { return ((_configBits[0] & 0x08) >> 3) == 1; }
|
|
set { SetBit(3, value, ref _configBits[0]); }
|
|
}
|
|
|
|
public enum Axis
|
|
{
|
|
X = 0,
|
|
Y = 1,
|
|
Z = 2,
|
|
}
|
|
|
|
public byte AxisToIgnore
|
|
{
|
|
get { return (byte)((_configBits[1] & 0x03) >> 0); }
|
|
set { SetTwoBits(0, value, ref _configBits[1]); }
|
|
}
|
|
|
|
public Axis AxisLabel1
|
|
{
|
|
get { return (Axis)((_configBits[1] & 0x0C) >> 2); }
|
|
set { SetTwoBits(2, (byte)value, ref _configBits[1]); }
|
|
}
|
|
|
|
public Axis AxisLabel2
|
|
{
|
|
get { return (Axis)((_configBits[1] & 0x30) >> 4); }
|
|
set { SetTwoBits(4, (byte)value, ref _configBits[1]); }
|
|
}
|
|
|
|
public Axis AxisLabel3
|
|
{
|
|
get { return (Axis)((_configBits[1] & 0xC0) >> 6); }
|
|
set { SetTwoBits(6, (byte)value, ref _configBits[1]); }
|
|
}
|
|
|
|
#endregion ConfigurationBits
|
|
|
|
private float[] _mountOffset = new float[3];
|
|
|
|
public float MountOffsetAxis1
|
|
{
|
|
get { return _mountOffset[0]; }
|
|
set { _mountOffset[0] = value; }
|
|
}
|
|
|
|
public float MountOffsetAxis2
|
|
{
|
|
get { return _mountOffset[1]; }
|
|
set { _mountOffset[1] = value; }
|
|
}
|
|
|
|
public float MountOffsetAxis3
|
|
{
|
|
get { return _mountOffset[2]; }
|
|
set { _mountOffset[2] = value; }
|
|
}
|
|
|
|
private float[] _targetAngle = new float[3];
|
|
|
|
public float TargetAngleAxis1
|
|
{
|
|
get { return _targetAngle[0]; }
|
|
set { _targetAngle[0] = value; }
|
|
}
|
|
|
|
public float TargetAngleAxis2
|
|
{
|
|
get { return _targetAngle[1]; }
|
|
set { _targetAngle[1] = value; }
|
|
}
|
|
|
|
public float TargetAngleAxis3
|
|
{
|
|
get { return _targetAngle[2]; }
|
|
set { _targetAngle[2] = value; }
|
|
}
|
|
|
|
private short[] _preEventADC = new short[3];
|
|
public short PreEventADCAxis1
|
|
{
|
|
get { return _preEventADC[0]; }
|
|
set { _preEventADC[0] = value; }
|
|
}
|
|
|
|
public short PreEventADCAxis2
|
|
{
|
|
get { return _preEventADC[1]; }
|
|
set { _preEventADC[1] = value; }
|
|
}
|
|
|
|
public short PreEventADCAxis3
|
|
{
|
|
get { return _preEventADC[2]; }
|
|
set { _preEventADC[2] = value; }
|
|
}
|
|
|
|
private short[] _postEventADC = new short[3];
|
|
public short PostEventADCAxis1
|
|
{
|
|
get { return _postEventADC[0]; }
|
|
set { _postEventADC[0] = value; }
|
|
}
|
|
|
|
public short PostEventADCAxis2
|
|
{
|
|
get { return _postEventADC[1]; }
|
|
set { _postEventADC[1] = value; }
|
|
}
|
|
|
|
public short PostEventADCAxis3
|
|
{
|
|
get { return _postEventADC[2]; }
|
|
set { _postEventADC[2] = value; }
|
|
}
|
|
|
|
private byte[] _reservedConfigBytes = new byte[52];
|
|
|
|
#endregion Config Attributes
|
|
|
|
public static int MIF_BYTE_LENGTH = 128;
|
|
public static int MIF_CONFIG_BYTE_LENGTH = 256;
|
|
|
|
public Tilt_MIF() { }
|
|
|
|
public Tilt_MIF(bool hasConfig)
|
|
{
|
|
_hasConfig = hasConfig;
|
|
}
|
|
|
|
public Tilt_MIF(byte[] mifBytes)
|
|
{
|
|
if (mifBytes?.Length == MIF_BYTE_LENGTH
|
|
|| mifBytes?.Length == MIF_CONFIG_BYTE_LENGTH)
|
|
{
|
|
MIF_CRC16 = BitConverter.ToUInt16(mifBytes.Skip(MIF_BYTE_LENGTH - 2).Take(2).ToArray(), 0);
|
|
ComputedCRC16 = CRC16.ComputeChecksum(mifBytes.Take(MIF_BYTE_LENGTH - 2).ToArray());
|
|
if (MIF_CRC16 != ComputedCRC16 || MIF_CRC16 == 0)
|
|
{
|
|
ReadError = true;
|
|
return;
|
|
}
|
|
}
|
|
using (var stream = new MemoryStream(mifBytes))
|
|
{
|
|
using (var reader = new BinaryReader(stream))
|
|
{
|
|
#region Tilt MIF Read
|
|
|
|
MIFVersion = reader.ReadUInt32();
|
|
_serialNumber = reader.ReadChars(10);
|
|
HardwareConfiguration = reader.ReadUInt16();
|
|
|
|
TemperatureCF = reader.ReadSingle();
|
|
TemperatureOffset = reader.ReadInt16();
|
|
|
|
_tiltSensorCF = new float[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
|
_tiltSensorOffset = new short[] { reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), };
|
|
_tiltSensorRange = new float[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
|
|
|
for (int i = 0; i < _tiltCalibrations.Length; i++)
|
|
{
|
|
_tiltCalibrations[i] = reader.ReadSingle();
|
|
}
|
|
_reservedU16 = reader.ReadInt16();
|
|
var mif_CRC = reader.ReadUInt16();
|
|
_hasConfig = false;
|
|
|
|
#endregion Tilt MIF Read
|
|
|
|
#region Tilt Config Read
|
|
|
|
if (mifBytes.Length == MIF_CONFIG_BYTE_LENGTH)
|
|
{
|
|
Config_CRC16 = reader.ReadUInt16();
|
|
ComputedCRC16_Config = CRC16.ComputeChecksum(mifBytes.Skip(MIF_BYTE_LENGTH + 2).Take(MIF_CONFIG_BYTE_LENGTH - MIF_BYTE_LENGTH - 2).ToArray());
|
|
if (Config_CRC16 != ComputedCRC16_Config)
|
|
{
|
|
ReadError_Config = true;
|
|
}
|
|
else
|
|
{
|
|
_systemID = reader.ReadChars(16);
|
|
_location = reader.ReadChars(16);
|
|
Tolerance = reader.ReadSingle();
|
|
_configBits = reader.ReadBytes(2);
|
|
_mountOffset = new float[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
|
_targetAngle = new float[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
|
|
_preEventADC = new short[] { reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16() };
|
|
_postEventADC = new short[] { reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16() };
|
|
}
|
|
_hasConfig = true;
|
|
}
|
|
|
|
#endregion Tilt Config Read
|
|
}
|
|
}
|
|
}
|
|
|
|
public byte[] GetBytes()
|
|
{
|
|
var data = new List<byte>();
|
|
data.AddRange(BitConverter.GetBytes(MIFVersion));
|
|
data.AddRange(Encoding.UTF8.GetBytes(_serialNumber));
|
|
data.AddRange(BitConverter.GetBytes(HardwareConfiguration));
|
|
|
|
data.AddRange(BitConverter.GetBytes(TemperatureCF));
|
|
data.AddRange(BitConverter.GetBytes(TemperatureOffset));
|
|
|
|
foreach (var arrayValue in _tiltSensorCF)
|
|
{
|
|
data.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
foreach (var arrayValue in _tiltSensorOffset)
|
|
{
|
|
data.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
foreach (var arrayValue in _tiltSensorRange)
|
|
{
|
|
data.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
|
|
foreach (var arrayValue in _tiltCalibrations)
|
|
{
|
|
data.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
data.AddRange(BitConverter.GetBytes(_reservedU16));
|
|
ComputedCRC16 = CRC16.ComputeChecksum(data.ToArray());
|
|
data.AddRange(BitConverter.GetBytes(ComputedCRC16));
|
|
if (_hasConfig)
|
|
{
|
|
var configData = new List<byte>();
|
|
configData.AddRange(Encoding.UTF8.GetBytes(_systemID));
|
|
configData.AddRange(Encoding.UTF8.GetBytes(_location));
|
|
configData.AddRange(BitConverter.GetBytes(Tolerance));
|
|
configData.AddRange(_configBits);
|
|
foreach (var arrayValue in _mountOffset)
|
|
{
|
|
configData.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
foreach (var arrayValue in _targetAngle)
|
|
{
|
|
configData.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
foreach (var arrayValue in _preEventADC)
|
|
{
|
|
configData.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
foreach (var arrayValue in _postEventADC)
|
|
{
|
|
configData.AddRange(BitConverter.GetBytes(arrayValue));
|
|
}
|
|
configData.AddRange(_reservedConfigBytes);
|
|
|
|
ComputedCRC16_Config = CRC16.ComputeChecksum(configData.ToArray());
|
|
data.AddRange(BitConverter.GetBytes(ComputedCRC16_Config));
|
|
data.AddRange(configData);
|
|
}
|
|
return data.ToArray();
|
|
}
|
|
|
|
public void WriteXML(FileStream file)
|
|
{
|
|
try
|
|
{
|
|
TimeStamp = System.DateTime.UtcNow;
|
|
SystemName = System.Environment.MachineName;
|
|
UserName = System.Environment.UserName;
|
|
BuildVersion = GetVersionString();
|
|
|
|
System.Xml.Serialization.XmlSerializer writer =
|
|
new System.Xml.Serialization.XmlSerializer(typeof(Tilt_MIF));
|
|
writer.Serialize(file, this);
|
|
}
|
|
finally
|
|
{
|
|
file.Close();
|
|
}
|
|
}
|
|
public string GetVersionString()
|
|
{
|
|
try
|
|
{
|
|
System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
return string.Format("{0}.{1:00}.{2:0000}", v.Major, v.Minor, v.Build);
|
|
}
|
|
catch (System.Exception) { return "N/A"; }
|
|
}
|
|
}
|
|
} |