init
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Serialization.SoMat
|
||||
{
|
||||
public class SoMatChannel
|
||||
{
|
||||
public int LogicalChannel { get; set; }
|
||||
public string ChanType { get; set; } = "SEQUENTIAL";
|
||||
public string ChanName { get; set; } = "";
|
||||
public ulong NumDataPoints { get; set; } = 0;
|
||||
public int NumDims { get; set; } = 2;
|
||||
public int DataMode { get; set; } = 1;
|
||||
public string DataModeType { get; set; } = "TIMHIS";
|
||||
public string AxisLabelDim1 { get; set; } = "Time";
|
||||
public string AxisLabelDim2 { get; set; } = "";
|
||||
public string AxisUnitsDim1 { get; set; } = "Secs";
|
||||
public string AxisUnitsDim2 { get; set; } = "";
|
||||
public string SampleRate { get; set; } = "";
|
||||
public string TimeBase { get; set; } = "";
|
||||
public string MaxValue { get; set; } = "";
|
||||
public string MinValue { get; set; } = "";
|
||||
public string UserMax { get; set; } = "";
|
||||
public string UserMin { get; set; } = "";
|
||||
public string ChanDim2 { get; set; } = "1";
|
||||
public string DescDim2 { get; set; } = "";
|
||||
public string CTypeDim2 { get; set; } = "8";
|
||||
public string HDWParams { get; set; } = "";
|
||||
public string CalParams { get; set; } = "";
|
||||
public string DGParams { get; set; } = "";
|
||||
|
||||
public enum TriggerModes { ALWAYS_ON, GATE, TRIGGER, ONE_SHOT };
|
||||
public TriggerModes TriggerMode { get; set; } = TriggerModes.TRIGGER;
|
||||
|
||||
public string _elapsedTime = "";
|
||||
public string ElapsedTime
|
||||
{
|
||||
get => _elapsedTime;
|
||||
set => _elapsedTime = value;
|
||||
}
|
||||
public string HistType { get; set; } = "Other";
|
||||
public string AcquisitionRate { get; set; } = "";
|
||||
public string RTCStart { get; set; } = "";
|
||||
public string RTCEnd { get; set; } = "";
|
||||
public int PhysicalChannelNumber { get; set; }
|
||||
public void Serialize(System.IO.StreamWriter sw)
|
||||
{
|
||||
sw.Write("DM_LogicalChan=");
|
||||
sw.WriteLine(LogicalChannel.ToString());
|
||||
|
||||
sw.Write("DM_ChanType=");
|
||||
sw.WriteLine(ChanType);
|
||||
|
||||
sw.Write("DM_ChanName=");
|
||||
sw.WriteLine(ChanName);
|
||||
|
||||
sw.Write("DM_NumPoints=");
|
||||
sw.WriteLine(NumDataPoints.ToString());
|
||||
|
||||
sw.Write("DM_NumDims=");
|
||||
sw.WriteLine(NumDims.ToString());
|
||||
|
||||
sw.Write("DM_DataMode=");
|
||||
sw.WriteLine(DataMode.ToString());
|
||||
|
||||
sw.Write("DM_DataModeType=");
|
||||
sw.WriteLine(DataModeType);
|
||||
|
||||
sw.Write("DM_AxisLabel.Dim1=");
|
||||
sw.WriteLine(AxisLabelDim1);
|
||||
|
||||
sw.Write("DM_AxisLabel.Dim2=");
|
||||
sw.WriteLine(AxisLabelDim2);
|
||||
|
||||
sw.Write("DM_AxisUnits.Dim1=");
|
||||
sw.WriteLine(AxisUnitsDim1);
|
||||
|
||||
sw.Write("DM_AxisUnits.Dim2=");
|
||||
sw.WriteLine(AxisUnitsDim2);
|
||||
|
||||
sw.Write("DM_SampleRate=");
|
||||
sw.WriteLine(SampleRate);
|
||||
|
||||
sw.Write("DM_TimeBase=");
|
||||
sw.WriteLine(TimeBase);
|
||||
|
||||
sw.Write("DM_MaxValue=");
|
||||
sw.WriteLine(MaxValue);
|
||||
|
||||
sw.Write("DM_MinValue=");
|
||||
sw.WriteLine(MinValue);
|
||||
|
||||
sw.Write("DM_UserMax=");
|
||||
sw.WriteLine(UserMax);
|
||||
|
||||
sw.Write("DM_UserMin=");
|
||||
sw.WriteLine(UserMin);
|
||||
|
||||
sw.Write("2100_Chan.Dim2=");
|
||||
sw.WriteLine(ChanDim2);
|
||||
|
||||
sw.Write("2100_CDESC.Dim2=");
|
||||
sw.WriteLine(DescDim2);
|
||||
|
||||
sw.Write("2100_CTYPE.Dim2=");
|
||||
sw.WriteLine(CTypeDim2);
|
||||
|
||||
sw.Write("HDWParams=");
|
||||
sw.WriteLine(HDWParams);
|
||||
|
||||
sw.Write("CALParams=");
|
||||
sw.WriteLine(CalParams);
|
||||
|
||||
sw.Write("DGParams=");
|
||||
sw.WriteLine(DGParams);
|
||||
|
||||
sw.Write("Trig=");
|
||||
sw.WriteLine(TriggerMode);
|
||||
|
||||
sw.Write("DM_ElapsedTime=");
|
||||
sw.WriteLine(ElapsedTime);
|
||||
|
||||
sw.Write("DM_HistType=");
|
||||
sw.WriteLine(HistType);
|
||||
|
||||
sw.Write("DM_AcquisitionRate=");
|
||||
sw.WriteLine(AcquisitionRate);
|
||||
|
||||
sw.Write("RTCStart=");
|
||||
sw.WriteLine(RTCStart);
|
||||
|
||||
sw.Write("RTCEnd=");
|
||||
sw.WriteLine(RTCEnd);
|
||||
|
||||
sw.Write("DM_PhysicalChan=");
|
||||
sw.WriteLine(PhysicalChannelNumber);
|
||||
|
||||
sw.WriteLine();
|
||||
}
|
||||
public SoMatChannel(Test.Module.Channel channel, int logicalChannel, FilteredData filteredData, int moduleArrayIndex,
|
||||
int numChannelsPerModule, DateTime inceptionDateTime)
|
||||
{
|
||||
LogicalChannel = logicalChannel;
|
||||
var aic = channel as Test.Module.AnalogInputChannel;
|
||||
|
||||
ChanName = aic.ChannelDescriptionString;
|
||||
NumDataPoints = aic.ParentModule.NumberOfSamples;
|
||||
AxisLabelDim2 = aic.SerialNumber;
|
||||
AxisUnitsDim2 = aic.EngineeringUnits.TrimEnd();
|
||||
//0:0.###E+00
|
||||
SampleRate = aic.ParentModule.SampleRateHz.ToString("0.00000E+00");
|
||||
|
||||
if (aic.TimeOfFirstSampleValid) { TimeBase = aic.TimeOfFirstSampleSec.ToString("0.00000E+00"); }
|
||||
else
|
||||
{
|
||||
var start = aic.ParentModule.StartRecordSampleNumber - (double)aic.ParentModule.TriggerSampleNumbers[0];
|
||||
start /= aic.ParentModule.SampleRateHz;
|
||||
TimeBase = start.ToString("0.00000E+00");
|
||||
}
|
||||
|
||||
_filteredData = filteredData;
|
||||
MaxValue = filteredData.Data.Max().ToString("0.00000E+00");
|
||||
MinValue = filteredData.Data.Min().ToString("0.00000E+00");
|
||||
UserMax = aic.DesiredRange.ToString("0.00000E+00");
|
||||
UserMin = (-1D * aic.DesiredRange).ToString("0.00000E+00");
|
||||
DescDim2 = aic.SerialNumber;
|
||||
var elapsedTime = aic.ParentModule.NumberOfSamples / (double)aic.ParentModule.SampleRateHz;
|
||||
ElapsedTime = (elapsedTime).ToString("0.00000E+00");
|
||||
var elapsed = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(elapsedTime * 1000D));
|
||||
AcquisitionRate = aic.ParentModule.SampleRateHz.ToString("F4");
|
||||
var end = inceptionDateTime.Add(elapsed);
|
||||
RTCStart = $"{inceptionDateTime.ToShortDateString()} {inceptionDateTime.ToShortTimeString()} {end.ToShortDateString()} {end.ToShortTimeString()}";
|
||||
RTCEnd = $"{end.ToShortDateString()} {end.ToShortTimeString()}";
|
||||
PhysicalChannelNumber = 1 + moduleArrayIndex * numChannelsPerModule + aic.Number;
|
||||
}
|
||||
private readonly FilteredData _filteredData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace IRIGCh10
|
||||
{
|
||||
public class TMATSectionNumbered<T> where T : Enum
|
||||
{
|
||||
public AttributeIdentifiers Identifier { get; set; } = AttributeIdentifiers.GeneralInformation;
|
||||
public int Number { get; set; } = -1;
|
||||
|
||||
private Dictionary<T, string> _values = new Dictionary<T, string>();
|
||||
public void SetValue(T tag, string value) => _values[tag] = value;
|
||||
public string GetValue(T tag) => _values.ContainsKey(tag)?_values[tag] : null;
|
||||
public string Serialize(int number)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var tags = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
var s = Serialize(number, tag);
|
||||
if( string.IsNullOrWhiteSpace(s) ){ continue; }
|
||||
|
||||
sb.AppendLine(s);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string Serialize(int number, T tag)
|
||||
{
|
||||
var value = GetValue(tag);
|
||||
if( string.IsNullOrWhiteSpace(value) ){ return null; }
|
||||
var attr = DescriptionDecoder.GetDescription(tag);
|
||||
var identifier = DescriptionDecoder.GetDescription(Identifier);
|
||||
if (Number > 0)
|
||||
{
|
||||
return $"{identifier}-{Number}\\{attr}{number}:{value};";
|
||||
}
|
||||
else{ return $"{identifier}\\{attr}{number}:{value};"; }
|
||||
}
|
||||
public void SetValueWithLength(T tag, string value)
|
||||
{
|
||||
var maxLength = MaxLengthDecoder.GetMaxLength(tag);
|
||||
//maxlength is just a suggestion ...
|
||||
//if (maxLength < value.Length)
|
||||
//{
|
||||
// throw new FormatException($"{tag.ToString()} must be {maxLength} characters or less");
|
||||
//}
|
||||
SetValue(tag, value);
|
||||
}
|
||||
}
|
||||
|
||||
public class TMATSectionNumberedArray<T> where T:Enum
|
||||
{
|
||||
private List<TMATSectionNumbered<T>> _items = new List<TMATSectionNumbered<T>>();
|
||||
private AttributeIdentifiers _attributeIdentifier = AttributeIdentifiers.GeneralInformation;
|
||||
private readonly int _number = -1;
|
||||
private readonly int _maxNumber = -1;
|
||||
|
||||
private string _numberedTag;
|
||||
public TMATSectionNumberedArray(string numberedTag)
|
||||
{
|
||||
_numberedTag = numberedTag;
|
||||
}
|
||||
|
||||
public TMATSectionNumberedArray(string numberedTag, int maxNumber)
|
||||
{
|
||||
_numberedTag = numberedTag;
|
||||
_maxNumber = maxNumber;
|
||||
}
|
||||
|
||||
public TMATSectionNumberedArray(AttributeIdentifiers identifier, int number, string numberedTag, int maxNumber)
|
||||
{
|
||||
_number = number;
|
||||
_maxNumber = maxNumber;
|
||||
_numberedTag = numberedTag;
|
||||
_attributeIdentifier = identifier;
|
||||
}
|
||||
//private AttributeIdentifiers _attribute = AttributeIdentifiers.GeneralInformation;
|
||||
|
||||
public virtual void SetValue(int number, T tag, string value)
|
||||
{
|
||||
if (number > _items.Count)
|
||||
{
|
||||
SetCount(number);
|
||||
}
|
||||
|
||||
_items[number - 1].SetValueWithLength(tag, value);
|
||||
}
|
||||
|
||||
public string GetValue(int number, T tag) => number > _items.Count ? null : _items[number - 1].GetValue(tag);
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
if (!_items.Any())
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var attribute = DescriptionDecoder.GetDescription(_attributeIdentifier);
|
||||
if (_number > 0)
|
||||
{
|
||||
attribute = $"{attribute}-{_number}";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(_numberedTag))
|
||||
{
|
||||
sb.AppendLine($"{attribute}\\{_numberedTag}:{_items.Count()};");
|
||||
}
|
||||
|
||||
var number = 1;
|
||||
foreach (var item in _items)
|
||||
{
|
||||
var s = item.Serialize(number++);
|
||||
if( string.IsNullOrWhiteSpace(s) ){ continue; }
|
||||
sb.Append(s);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public int GetCount() => _items.Count;
|
||||
|
||||
public void SetCount(int count)
|
||||
{
|
||||
if (_maxNumber > 0 && count > _maxNumber)
|
||||
{
|
||||
throw new Exception($"count exceeds maximum number for array");
|
||||
}
|
||||
if( _items.Count == count ){ return; }
|
||||
if (_items.Count > count)
|
||||
{
|
||||
var toKeep = _items.Take(count);
|
||||
_items.Clear();
|
||||
_items.AddRange(toKeep);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = _items.Count; i < count; i++)
|
||||
{
|
||||
var newItem = new TMATSectionNumbered<T>();
|
||||
_items.Add(newItem);
|
||||
if (_number > 0)
|
||||
{
|
||||
newItem.Number = _number;;
|
||||
}
|
||||
|
||||
newItem.Identifier = _attributeIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user