Decimal numbers in OptoData logfiles use commas instead of dots, Delta time fixed, test start/end labels added.

This commit is contained in:
Milan Hanajik 2015-12-17 12:29:39 +01:00
parent bcae594b3f
commit 58a2be10aa
3 changed files with 58 additions and 31 deletions

4
.gitignore vendored
View File

@ -1,11 +1,11 @@
TestBenchFramework/bin/
TestBenchFramework/obj/
Config/bin/
Config/obj/
Results/bin/
Results/obj/
ResultsBrowser/bin/
ResultsBrowser/obj/
TestBenchFramework/bin/
TestBenchFramework/obj/
TBFSetup/Debug/
TBFSetup/Release/
Doc/

View File

@ -6,11 +6,19 @@ namespace TBF.BenchControl.WaterMeters.iPerl
public class OptoTelegramRaw
{
public static readonly int Length = 42;
private static CultureInfo culture;
///
/// Strobed value
///
public static decimal TestStartTimestampDec;
///
/// Stored values
///
public OptoTelegramFlags flags;
public OptoTelegramFlags Flags;
public DateTime DateTime; /// From PC
public int Counter;
@ -38,26 +46,31 @@ namespace TBF.BenchControl.WaterMeters.iPerl
public decimal TimestampDec() { return (decimal)Timestamp / (decimal)8192; }
public double RefFlow() { return 0; }
public double VolumeDelta(double scalingFactor, OptoTelegramRaw previous) { return (previous == null) ? 0 : Volume(scalingFactor) - previous.Volume(scalingFactor); }
public decimal TimeDelta(OptoTelegramRaw previous) { return (previous == null) ? 0 : TimestampDec() - previous.TimestampDec(); }
public decimal TimeDelta() { return TimestampDec() - TestStartTimestampDec; }
public string Label()
{
if (flags == OptoTelegramFlags.OK_TestStart) return "#### start test ####";
else if (flags == OptoTelegramFlags.OK_TestEnd) return "#### end of test ####";
if (Flags == OptoTelegramFlags.OK_TestStart) return "#### start test ####";
else if (Flags == OptoTelegramFlags.OK_TestEnd) return "#### end of test ####";
else return string.Empty;
}
static OptoTelegramRaw()
{
culture = CultureInfo.CreateSpecificCulture("DE"); /// This is to use comma as decimal number separator
}
public OptoTelegramRaw()
{
}
public string ToString(double scalingFactor, OptoTelegramRaw previous)
{
if (flags == OptoTelegramFlags.SyncError)
if (Flags == OptoTelegramFlags.SyncError)
{
return "Sychronization error";
}
else if (flags == OptoTelegramFlags.InvalidTelegram)
else if (Flags == OptoTelegramFlags.InvalidTelegram)
{
return "Invalid telegram";
}
@ -76,16 +89,16 @@ namespace TBF.BenchControl.WaterMeters.iPerl
Impedance.ToString("X4"),
Timestamp.ToString("X8"),
CheckSum.ToString("X2"),
EMF().ToString("F4"),
MagneticField().ToString("F0"),
Flow(scalingFactor).ToString("F2"),
Volume(scalingFactor).ToString("F4"),
FlipTime().ToString("F0"),
TimestampDec().ToString("F4"),
RefFlow().ToString("F2"),
VolumeDelta(scalingFactor, previous).ToString("F4"),
TimeDelta(previous).ToString("F3"),
scalingFactor.ToString("F1"),
EMF().ToString("F4", culture),
MagneticField().ToString("F0", culture),
Flow(scalingFactor).ToString("F2", culture),
Volume(scalingFactor).ToString("F4", culture),
FlipTime().ToString("F0", culture),
TimestampDec().ToString("F4", culture),
RefFlow().ToString("F2", culture),
VolumeDelta(scalingFactor, previous).ToString("F4", culture),
TimeDelta().ToString("F3", culture),
scalingFactor.ToString("F1", culture),
Label());
}
}
@ -160,7 +173,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
public void SetFlags(OptoTelegramFlags flags)
{
this.flags = flags;
this.Flags = flags;
}
}
}

View File

@ -237,6 +237,9 @@ namespace TBF.BenchControl.WaterMeters.iPerl
double timestampSecEnd2;
double timestampSecEnd3;
private int telegramIx;
public int TestStartTelegramIx;
public int TestEndTelegramIx;
private Boxes.IntBox pulses;
private Boxes.IntBox refPulses;
@ -442,6 +445,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
{
/// Reset opto data
optoDataCount = 0;
TestStartTelegramIx = 0;
TestEndTelegramIx = 0;
/// File name is: PCB_AA_BB_HH_MI_SS..txt
string wmPosition = Name.Substring(5);
@ -482,34 +487,40 @@ namespace TBF.BenchControl.WaterMeters.iPerl
/// Take the test start sample
VolumeLtrStart = volumeLtr;
TimestampSecStart = timestampSec;
TestStartTelegramIx = telegramIx;
}
/// Shift data in pipelines
VolumeLtrEnd = volumeLtrEnd3;
//volumeLtrEnd6 = volumeLtrEnd5;
//volumeLtrEnd5 = volumeLtrEnd4;
//volumeLtrEnd4 = volumeLtrEnd3;
volumeLtrEnd3 = volumeLtrEnd2;
volumeLtrEnd2 = volumeLtrEnd1;
volumeLtrEnd1 = volumeLtr;
TimestampSecEnd = timestampSecEnd3;
//timestampSecEnd6 = timestampSecEnd5;
//timestampSecEnd5 = timestampSecEnd4;
//timestampSecEnd4 = timestampSecEnd3;
timestampSecEnd3 = timestampSecEnd2;
timestampSecEnd2 = timestampSecEnd1;
timestampSecEnd1 = timestampSec;
TestEndTelegramIx = telegramIx - 3;
return Event.ReadRegisterDone;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
StopParsingOptoSerialPort();
if (TestStartTelegramIx > 0 && TestStartTelegramIx < optoData.Length && optoData[TestStartTelegramIx].Flags == OptoTelegramFlags.OK)
{
optoData[TestStartTelegramIx].Flags = OptoTelegramFlags.OK_TestStart;
OptoTelegramRaw.TestStartTimestampDec = optoData[TestStartTelegramIx].TimestampDec();
}
if (TestEndTelegramIx > 0 && TestEndTelegramIx < optoData.Length && optoData[TestEndTelegramIx].Flags == OptoTelegramFlags.OK)
{
optoData[TestEndTelegramIx].Flags = OptoTelegramFlags.OK_TestEnd;
}
StopParsingOptoSerialPort();
SaveOptoData();
}
@ -617,8 +628,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
// CR+LF found and (pos >= OptoTelegramRaw.Length - 2)
else if (optoData[optoDataCount].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), optoDataCount))
{
OptoTelegramRreceived(optoData[optoDataCount++], synchronized2);
synchronized2 = synchronized;
OptoTelegramRreceived(optoDataCount++, synchronized2);
synchronized2 = synchronized;
allRcvd = allRcvd.Substring(pos + 2);
}
else
@ -660,8 +671,11 @@ namespace TBF.BenchControl.WaterMeters.iPerl
}
void OptoTelegramRreceived(OptoTelegramRaw optoTelegram, bool async)
void OptoTelegramRreceived(int currentIx, bool async)
{
OptoTelegramRaw optoTelegram = optoData[currentIx];
telegramIx = currentIx;
Int32 uncorrectedRawVolume = 0;
if (!lastVolumeRawValid)
{