init
This commit is contained in:
399
DataPRO/SensorDB/TSF/TOMChannelInformationSection.cs
Normal file
399
DataPRO/SensorDB/TSF/TOMChannelInformationSection.cs
Normal file
@@ -0,0 +1,399 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.SensorDB.TSF
|
||||
{
|
||||
/// <summary>
|
||||
/// helper class for TOM Channel Information section of the TSF
|
||||
/// </summary>
|
||||
public class TSFTOMChannelInformationSection
|
||||
{
|
||||
private const string START_SECTION_HEADER = "---- Start TOM Channel Information ----";
|
||||
private const string TOM_SQUIBFIRE_CHANNELS_HEADER = "---- TOM Squib Fire Channels ----";
|
||||
private const string TOM_SQUIBFIRE_COLUMNS_HEADER = "rack,module,chan,descrip,id,type,current,delay,durationON,duration,OhmLow,OhmHigh";
|
||||
private const string TOM_DIGITALCHANNELS_HEADER = "---- TOM Digital Channels ----";
|
||||
private const string TOM_DIGITALCHANNELS_COLUMNS = "rack,module,chan,type,delay,durationON,duration";
|
||||
private const string END_SECTION_HEADER = "---- End TOM Channel Information ----";
|
||||
|
||||
/// <summary>
|
||||
/// squib fire entries in the section
|
||||
/// </summary>
|
||||
private List<TSFSquibFireEntry> _squibFireEntries = new List<TSFSquibFireEntry>();
|
||||
public TSFSquibFireEntry[] SquibFireEntries
|
||||
{
|
||||
get { return _squibFireEntries.ToArray(); }
|
||||
set { _squibFireEntries = new List<TSFSquibFireEntry>(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// digital output channels in the section
|
||||
/// </summary>
|
||||
private List<TSFTOMDigitalOutputChannel> _digitalChannelEntries = new List<TSFTOMDigitalOutputChannel>();
|
||||
public TSFTOMDigitalOutputChannel[] DigitalChannelEntries
|
||||
{
|
||||
get { return _digitalChannelEntries.ToArray(); }
|
||||
set { _digitalChannelEntries = new List<TSFTOMDigitalOutputChannel>(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads the section a TSF file
|
||||
/// assumes currentline is the start of the section
|
||||
/// </summary>
|
||||
/// <param name="lines"></param>
|
||||
/// <param name="currentLine"></param>
|
||||
/// <param name="errors"></param>
|
||||
public void ReadFrom(List<string> lines, ref int currentLine, ref List<ReadTSFError> errors)
|
||||
{
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string startSection = lines[currentLine++];
|
||||
if (startSection != START_SECTION_HEADER)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_TOMCHANNEL_INVALID_SECTIONSTART, currentLine, startSection));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string squibFireChannelsHeader = lines[currentLine++];
|
||||
if (squibFireChannelsHeader != TOM_SQUIBFIRE_CHANNELS_HEADER)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_TOMCHANNEL_INVALID_SQUIBFIREHEADER, currentLine, squibFireChannelsHeader));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string columnsHeader = lines[currentLine++];
|
||||
if (false == columnsHeader.Contains(TOM_SQUIBFIRE_COLUMNS_HEADER))
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIRECHANNELS_INVALID_COLUMNSHEADER, currentLine, columnsHeader));
|
||||
return;
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
List<TSFSquibFireEntry> squibFireEntries = new List<TSFSquibFireEntry>();
|
||||
|
||||
while (!done)
|
||||
{
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string line = lines[currentLine++];
|
||||
|
||||
if (!line.Contains("TOM Digital Channels"))
|
||||
{
|
||||
string[] tokens = line.Split(new char[] { ',' });
|
||||
|
||||
TSFSquibFireEntry squib = new TSFSquibFireEntry();
|
||||
|
||||
for (int iCurField = 0; iCurField < tokens.Length; iCurField++)
|
||||
{
|
||||
TSFSquibFireEntry.Fields field = (TSFSquibFireEntry.Fields)iCurField;
|
||||
string s = tokens[iCurField];
|
||||
switch (field)
|
||||
{
|
||||
case TSFSquibFireEntry.Fields.chan:
|
||||
try { squib.Chan = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_CHAN, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.current:
|
||||
try { squib.Current = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_CURRENT, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.delay:
|
||||
try { squib.Delay = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_DELAY, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.descrip:
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) { s = "Squib"; }
|
||||
squib.Description = s;
|
||||
}
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.duration:
|
||||
try { squib.Duration = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_DURATION, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.durationON:
|
||||
try
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "0":
|
||||
case "F":
|
||||
case "N": squib.DurationOn = false; break;
|
||||
|
||||
case "1":
|
||||
case "T":
|
||||
case "Y": squib.DurationOn = true; break;
|
||||
|
||||
default:
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_DURATIONON, currentLine, s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_DURATIONON, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.id: squib.Id = s; break;
|
||||
case TSFSquibFireEntry.Fields.ISOcode: squib.ISOcode = s; break;
|
||||
case TSFSquibFireEntry.Fields.module:
|
||||
try { squib.Module = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_MODULE, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.OhmHigh:
|
||||
try { squib.OhmHigh = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_OHMHIGH, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.OhmLow:
|
||||
try { squib.OhmLow = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_INVALID_OHMLOW, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.rack:
|
||||
try { squib.Rack = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_RACK, currentLine, s)); }
|
||||
break;
|
||||
case TSFSquibFireEntry.Fields.type:
|
||||
try { squib.Type = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_SQUIBFIREENTRY_TYPE, currentLine, s)); }
|
||||
break;
|
||||
default: throw new NotSupportedException("TSFFile::ReadTSF unsupported squib field: " + field.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
squibFireEntries.Add(squib);
|
||||
// Some code from TDC and HLAPI
|
||||
// doesn't seem to be needed for datapro, but preserved here
|
||||
/*
|
||||
// IF THIS IS A NEW MODULE THEN RESET THE TOM CHANNEL COUNTER
|
||||
if(r!=tomr || m!=tomm)
|
||||
{
|
||||
tomc=0;
|
||||
}
|
||||
tomr=r;
|
||||
tomm=m;
|
||||
|
||||
|
||||
// SET ALL TOM DATA CHANNEL DEFAULTS
|
||||
for(k=0;k<2;k++)
|
||||
{
|
||||
static char firetype[32];
|
||||
|
||||
tomc = (c-1)*2+k+1;
|
||||
TOMDataChannel++;
|
||||
Sensor_DataChan[r][m][tomc]=TOMDataChannel;
|
||||
|
||||
// DETERMINE FIRE TYPE
|
||||
FillBytes(firetype, 0, sizeof(firetype), 0);
|
||||
if (TOM_Squib_FireType[r][m][c]==1)
|
||||
{
|
||||
strcpy(firetype, "DC Cap Discharge");
|
||||
}
|
||||
if (TOM_Squib_FireType[r][m][c]==2)
|
||||
{
|
||||
strcpy(firetype, "DC Constant Current");
|
||||
}
|
||||
if (TOM_Squib_FireType[r][m][c]==3)
|
||||
{
|
||||
strcpy(firetype, "AC Cap Discharge");
|
||||
}
|
||||
|
||||
FillBytes(Sensor_ChanDescription[r][m][tomc], 0, sizeof(Sensor_ChanDescription[r][m][tomc]), 0);
|
||||
FillBytes(Sensor_EngUnit[r][m][tomc], 0, sizeof(Sensor_EngUnit[r][m][tomc]), 0);
|
||||
if(k==0)
|
||||
{
|
||||
// DESCRIPTION AND ENG UNIT
|
||||
if(TOM_Recording==0)
|
||||
{
|
||||
Fmt(Sensor_ChanDescription[r][m][tomc],"%s<%s - Fire Voltage (%s)", TOM_Squib_Description[r][m][c], firetype);
|
||||
strcpy(Sensor_EngUnit[r][m][tomc], ( 0 == stricmp (CustomerName, "gm daewoo") ) ? "V" : "Volts");
|
||||
}
|
||||
else
|
||||
{
|
||||
Fmt(Sensor_ChanDescription[r][m][tomc],"%s<%s - Initiation Pulse (%s)", TOM_Squib_Description[r][m][c], firetype);
|
||||
strcpy(Sensor_EngUnit[r][m][tomc], "Initiation");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// DESCRIPTION AND ENG UNIT
|
||||
Fmt(Sensor_ChanDescription[r][m][tomc],"%s<%s - Fire Current (%s)", TOM_Squib_Description[r][m][c], firetype);
|
||||
strcpy(Sensor_EngUnit[r][m][tomc], ( 0 == stricmp (CustomerName, "gm daewoo") ) ? "A" : "Amps" );
|
||||
}
|
||||
|
||||
// ISO CODE
|
||||
if(k==0)
|
||||
{
|
||||
FillBytes(Sensor_ISOCode[r][m][tomc], 0, sizeof(Sensor_ISOCode[r][m][tomc]), 0);
|
||||
strcpy(Sensor_ISOCode[r][m][tomc], TOM_ISOCode[r][m][c]);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBytes(Sensor_ISOCode[r][m][tomc], 0, sizeof(Sensor_ISOCode[r][m][tomc]), 0);
|
||||
CopyBytes (Sensor_ISOCode[r][m][tomc], 0, TOM_ISOCode[r][m][c], 0, 12);
|
||||
strcat(Sensor_ISOCode[r][m][tomc], "CU");
|
||||
FillBytes(dummy, 0, sizeof(dummy), 0);
|
||||
CopyBytes (dummy, 0, TOM_ISOCode[r][m][c], 14, 2);
|
||||
strcat(Sensor_ISOCode[r][m][tomc], dummy);
|
||||
}
|
||||
|
||||
Sensor_Sensitivity[r][m][tomc]=1.0;
|
||||
Sensor_Gain[r][m][tomc]=1.0;
|
||||
if(SampleRate>8000.)
|
||||
{
|
||||
Sensor_Filter[r][m][tomc]=1650;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sensor_Filter[r][m][tomc]= (int)floor(SampleRate/5.);
|
||||
}
|
||||
Sensor_InvertData[r][m][tomc]=0;
|
||||
Sensor_ZeroRef[r][m][tomc]=1;
|
||||
Sensor_DesiredMaxRange[r][m][tomc]=20.0;
|
||||
Sensor_SNRatio[r][m][tomc]=80.0;
|
||||
}
|
||||
|
||||
if(n!=14)
|
||||
{
|
||||
ReadError=3;
|
||||
}*/
|
||||
}
|
||||
else { done = true; }
|
||||
}
|
||||
SquibFireEntries = squibFireEntries.ToArray();
|
||||
|
||||
// READ TOM DIGITAL CHANNELS
|
||||
List<TSFTOMDigitalOutputChannel> digitalChannels = new List<TSFTOMDigitalOutputChannel>();
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string digitalColumns = lines[currentLine++];
|
||||
if (digitalColumns != TOM_DIGITALCHANNELS_COLUMNS)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_TOMCHANNEL_INVALID_DIGITALCOLUMNSHEADER, currentLine, digitalColumns));
|
||||
return;
|
||||
}
|
||||
done = false;
|
||||
while (!done)
|
||||
{
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
|
||||
}
|
||||
string line = lines[currentLine++];
|
||||
if (!line.Contains("End TOM Channel Information"))
|
||||
{
|
||||
string[] tokens = line.Split(new char[] { ',' });
|
||||
|
||||
TSFTOMDigitalOutputChannel digital = new TSFTOMDigitalOutputChannel();
|
||||
|
||||
for (int iCurField = 0; iCurField < tokens.Length; iCurField++)
|
||||
{
|
||||
string s = tokens[iCurField];
|
||||
TSFTOMDigitalOutputChannel.Fields field = (TSFTOMDigitalOutputChannel.Fields)iCurField;
|
||||
switch (field)
|
||||
{
|
||||
case TSFTOMDigitalOutputChannel.Fields.chan:
|
||||
try { digital.Chan = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_CHAN, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.delay:
|
||||
try { digital.Delay = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_DELAY, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.duration:
|
||||
try { digital.Duration = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_DURATION, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.durationON:
|
||||
try
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "0":
|
||||
case "N":
|
||||
case "F":
|
||||
digital.DurationOn = false; break;
|
||||
|
||||
|
||||
case "1":
|
||||
case "T":
|
||||
case "Y":
|
||||
digital.DurationOn = true; break;
|
||||
|
||||
default:
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_DURATIONON, currentLine, s));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_DURATIONON, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.module:
|
||||
try { digital.Module = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_MODULE, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.rack:
|
||||
try { digital.Rack = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_RACK, currentLine, s)); }
|
||||
break;
|
||||
case TSFTOMDigitalOutputChannel.Fields.type:
|
||||
try
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "0": digital.Type = TSFTOMDigitalOutputChannel.DigitalOutputTypes.NONE; break;
|
||||
case "1":
|
||||
case "5VLH":
|
||||
digital.Type = TSFTOMDigitalOutputChannel.DigitalOutputTypes.FiveVLH; break;
|
||||
|
||||
case "2":
|
||||
case "5VHL":
|
||||
digital.Type = TSFTOMDigitalOutputChannel.DigitalOutputTypes.FiveVHL; break;
|
||||
|
||||
case "3":
|
||||
case "CCNO":
|
||||
digital.Type = TSFTOMDigitalOutputChannel.DigitalOutputTypes.CCNO; break;
|
||||
|
||||
case "4":
|
||||
case "CCNC":
|
||||
digital.Type = TSFTOMDigitalOutputChannel.DigitalOutputTypes.CCNC; break;
|
||||
|
||||
default:
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_TYPE, currentLine, s));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIGITALCHANNEL_INVALID_TYPE, currentLine, s)); }
|
||||
break;
|
||||
default: throw new NotSupportedException("TSFFile::ReadTSF unknown digital channel field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
digitalChannels.Add(digital);
|
||||
}
|
||||
else { done = true; }
|
||||
}
|
||||
DigitalChannelEntries = digitalChannels.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user