80 lines
3.9 KiB
C#
80 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DTS.SensorDB.TSF
|
|
{
|
|
/// <summary>
|
|
/// handles the sampling information section of the TSF
|
|
/// can contain rate(Hz),pretrigtime(sec),posttrigtime(sec),AdjAAfilter(Hz),postcaltime(sec)
|
|
/// </summary>
|
|
public class TSFSamplingInformationSection
|
|
{
|
|
private const string START_SECTION_HEADER = "---- Start Sampling Information ----";
|
|
private const string COLUMN_HEADER = "rate(Hz),pretrigtime(sec),posttrigtime(sec),AdjAAfilter(Hz),postcaltime(sec)";
|
|
private const string END_SECTION_HEADER = "---- End Sampling Information ----";
|
|
|
|
private double _sampleRateHz;
|
|
public double SampleRateHz { get { return _sampleRateHz; } set { _sampleRateHz = value; } }
|
|
|
|
private double _preTriggerSeconds;
|
|
/// <summary>
|
|
/// pre trigger seconds (always positive)
|
|
/// </summary>
|
|
public double PreTriggerSeconds { get { return _preTriggerSeconds; } set { _preTriggerSeconds = value; } }
|
|
|
|
private double _postTriggerSeconds;
|
|
/// <summary>
|
|
/// post trigger seconds (always positive)
|
|
/// </summary>
|
|
public double PostTriggerSeconds { get { return _postTriggerSeconds; } set { _postTriggerSeconds = value; } }
|
|
|
|
private double _aaf;
|
|
public double AAF { get { return _aaf; } set { _aaf = value; } }
|
|
|
|
private double _postCalTimeSeconds;
|
|
public double PostCalTimeSeconds { get { return _postCalTimeSeconds; } set { _postCalTimeSeconds = value; } }
|
|
|
|
public TSFSamplingInformationSection(List<string> lines, ref int currentLine)
|
|
{
|
|
if (currentLine == lines.Count) { throw new System.IO.EndOfStreamException(); }
|
|
string startSection = lines[currentLine++];
|
|
if (startSection != START_SECTION_HEADER) { throw new System.IO.InvalidDataException(startSection); }
|
|
|
|
if (currentLine == lines.Count) { throw new System.IO.EndOfStreamException(); }
|
|
string columnHeader = lines[currentLine++];
|
|
if (columnHeader != COLUMN_HEADER) { throw new System.IO.InvalidDataException(columnHeader); }
|
|
|
|
// READ IN SAMPLING VALUES
|
|
if (currentLine == lines.Count) { throw new System.IO.EndOfStreamException(); }
|
|
string[] tokens = lines[currentLine++].Split(new string[] { "," }, StringSplitOptions.None);
|
|
|
|
if (tokens.Length < 5) { throw new System.IO.InvalidDataException(lines[currentLine - 1]); }
|
|
|
|
try { SampleRateHz = double.Parse(tokens[0], System.Globalization.CultureInfo.InvariantCulture); }
|
|
catch (System.Exception) { throw new System.IO.InvalidDataException(tokens[0]); }
|
|
|
|
try { PreTriggerSeconds = double.Parse(tokens[1], System.Globalization.CultureInfo.InvariantCulture); }
|
|
catch (System.Exception) { throw new System.IO.InvalidDataException(tokens[1]); }
|
|
|
|
try { PostTriggerSeconds = double.Parse(tokens[2], System.Globalization.CultureInfo.InvariantCulture); }
|
|
catch (System.Exception) { throw new System.IO.InvalidDataException(tokens[2]); }
|
|
|
|
try { AAF = double.Parse(tokens[3], System.Globalization.CultureInfo.InvariantCulture); }
|
|
catch (System.Exception) { throw new System.IO.InvalidDataException(tokens[3]); }
|
|
|
|
// IF PRETRIGTIME IS >0 THEN THIS IS PRE VER. 6.4A AND NEEDS TO BE CONVERTED TO A NEGATIVE NUMBER
|
|
PreTriggerSeconds = System.Math.Abs(PreTriggerSeconds);
|
|
PostTriggerSeconds = System.Math.Abs(PostTriggerSeconds);
|
|
|
|
if (currentLine == lines.Count) { throw new System.IO.EndOfStreamException(); }
|
|
string endSection = lines[currentLine++];
|
|
if (endSection != END_SECTION_HEADER)
|
|
{
|
|
throw new System.IO.InvalidDataException(endSection);
|
|
}
|
|
}
|
|
}
|
|
}
|