init
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.SensorDB.TSF
|
||||
{
|
||||
/// <summary>
|
||||
/// the G5 Digital Input Channels section of the TSF
|
||||
/// </summary>
|
||||
public class TSFG5DigitalInputSection
|
||||
{
|
||||
private const string SECTION_START_HEADER = "---- G5 Digital Input Channels Begin ----";
|
||||
private const string COLUMN_HEADER = "datachan,rack,mod,chan,descrip,ISOCode,scale,invert";
|
||||
private const string SECTION_END_HEADER = "---- G5 Digital Input Channels End ----";
|
||||
|
||||
private List<G5DigtalInputChannelTSFEntry> _digitalInputChannels = new List<G5DigtalInputChannelTSFEntry>();
|
||||
public G5DigtalInputChannelTSFEntry[] DigitalInputChannels
|
||||
{
|
||||
get { return _digitalInputChannels.ToArray(); }
|
||||
set { _digitalInputChannels = new List<G5DigtalInputChannelTSFEntry>(value); }
|
||||
}
|
||||
|
||||
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 sectionStart = lines[currentLine++];
|
||||
if (sectionStart != SECTION_START_HEADER)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.G5DIGITALINPUTSECTION_START_INVALID_HEADER, currentLine, sectionStart));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLine == lines.Count)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
|
||||
return;
|
||||
}
|
||||
string columnHeader = lines[currentLine++];
|
||||
if (columnHeader != COLUMN_HEADER)
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.G5DIGITALINPUTSECTION_COLUMN_INVALID_HEADER, currentLine, columnHeader));
|
||||
return;
|
||||
}
|
||||
|
||||
List<G5DigtalInputChannelTSFEntry> g5DigitalInputChannels = new List<G5DigtalInputChannelTSFEntry>();
|
||||
bool 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("G5 Digital Input Channels End"))
|
||||
{
|
||||
G5DigtalInputChannelTSFEntry ichan = new G5DigtalInputChannelTSFEntry();
|
||||
string[] tokens = line.Split(new char[] { ',' });
|
||||
for (int iCurField = 0; iCurField < tokens.Length; iCurField++)
|
||||
{
|
||||
string s = tokens[iCurField];
|
||||
G5DigtalInputChannelTSFEntry.Fields field = (G5DigtalInputChannelTSFEntry.Fields)iCurField;
|
||||
switch (field)
|
||||
{
|
||||
case G5DigtalInputChannelTSFEntry.Fields.chan:
|
||||
try { ichan.Chan = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_CHAN, currentLine, s)); }
|
||||
break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.datachan:
|
||||
try { ichan.DataChan = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_DATACHAN, currentLine, s)); }
|
||||
break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.descrip: ichan.Descripton = s; break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.invert:
|
||||
try
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "0":
|
||||
case "F":
|
||||
case "N":
|
||||
ichan.Invert = false; break;
|
||||
|
||||
case "1":
|
||||
case "T":
|
||||
case "Y":
|
||||
ichan.Invert = true; break;
|
||||
|
||||
default:
|
||||
{
|
||||
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_INVERT, currentLine, s));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_INVERT, currentLine, s)); }
|
||||
break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.ISOCode: ichan.ISOCode = s; break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.mod:
|
||||
try { ichan.Module = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_MODULE, currentLine, s)); }
|
||||
break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.rack:
|
||||
try { ichan.Rack = Convert.ToInt32(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_RACK, currentLine, s)); }
|
||||
break;
|
||||
case G5DigtalInputChannelTSFEntry.Fields.scale:
|
||||
try { ichan.Scale = Convert.ToDouble(s); }
|
||||
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_G5DIGITALCHANNEL_INVALID_SCALE, currentLine, s)); }
|
||||
break;
|
||||
default: throw new NotSupportedException("TSFFile::ReadTSF invalid G5DigitalInput field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
g5DigitalInputChannels.Add(ichan);
|
||||
}
|
||||
else { done = true; }
|
||||
}
|
||||
DigitalInputChannels = g5DigitalInputChannels.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user