iPerlHead : Support for very long tests exceeding optodata buffer size, ver. 2.18.1099
This commit is contained in:
@@ -24,6 +24,12 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead));
|
||||
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
|
||||
|
||||
|
||||
const int MaxOptoDataCount = 40000;
|
||||
const int StartOptoDataCount = MaxOptoDataCount / 2;
|
||||
const int EndOptoDataCount = MaxOptoDataCount - StartOptoDataCount;
|
||||
|
||||
|
||||
readonly IperlHeadCfg iperlHeadCfg;
|
||||
|
||||
public int RfidComPortNr { get { return iperlHeadCfg.RfidComPortNr; } }
|
||||
@@ -371,7 +377,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
|
||||
|
||||
OptoTelegramRaw[] optoData;
|
||||
const int MaxOptoDataCount = 40000;
|
||||
int optoDataCount;
|
||||
string optoDataLogFileName;
|
||||
///
|
||||
@@ -621,16 +626,20 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (TestStartTelegramIx > 0 && TestStartTelegramIx < optoData.Length && optoData[TestStartTelegramIx].Flags == OptoTelegramFlags.OK)
|
||||
if ((TestStartTelegramIx > 0) && (TestStartTelegramIx < StartOptoDataCount) && (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)
|
||||
if ((TestEndTelegramIx > 0) && (TestEndTelegramIx < MaxOptoDataCount) && (optoData[TestEndTelegramIx].Flags == OptoTelegramFlags.OK))
|
||||
{
|
||||
optoData[TestEndTelegramIx].Flags = OptoTelegramFlags.OK_TestEnd;
|
||||
}
|
||||
else if ((TestEndTelegramIx >= MaxOptoDataCount) && optoData[(TestEndTelegramIx - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].Flags == OptoTelegramFlags.OK)
|
||||
{
|
||||
optoData[(TestEndTelegramIx - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].Flags = OptoTelegramFlags.OK_TestEnd;
|
||||
}
|
||||
|
||||
StopParsingOptoSerialPort();
|
||||
OptoTelegramRaw.FIRFilterFlow(optoData, optoDataCount);
|
||||
@@ -646,7 +655,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Save opto data to a file.
|
||||
/// </summary>
|
||||
void SaveOptoData()
|
||||
{
|
||||
string directory = string.Format("C:\\TBF\\ProcessData\\{0}\\{1}\\{2}\\",
|
||||
@@ -662,8 +673,36 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
|
||||
using (TextWriter optoLogFile = new StreamWriter(fullFileName))
|
||||
{
|
||||
if (optoDataCount <= MaxOptoDataCount)
|
||||
{
|
||||
/// Telegrams are stored continuously, save them.
|
||||
optoLogFile.WriteLine(optoData[0].ToString(scalFact, null));
|
||||
for (int i = 1; i < optoDataCount; i++) optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1]));
|
||||
for (int i = 1; i < optoDataCount; i++)
|
||||
{
|
||||
optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1]));
|
||||
}
|
||||
}
|
||||
else /// if (optoDataCount > MaxOptoDataCount)
|
||||
{
|
||||
/// Buffer overflow
|
||||
/// First part of the buffer is saved as is
|
||||
optoLogFile.WriteLine(optoData[0].ToString(scalFact, null));
|
||||
for (int i = 1; i < StartOptoDataCount; i++)
|
||||
{
|
||||
optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1]));
|
||||
}
|
||||
|
||||
optoLogFile.WriteLine(" ...");
|
||||
|
||||
/// Second part of the buffer is an overflowed circular buffer
|
||||
optoLogFile.WriteLine(optoData[(optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].ToString(scalFact, null));
|
||||
for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++)
|
||||
{
|
||||
optoLogFile.WriteLine(optoData[(i - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount]
|
||||
.ToString(scalFact, optoData[(i - 1 - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount]));
|
||||
}
|
||||
}
|
||||
|
||||
optoLogFile.Close();
|
||||
}
|
||||
}
|
||||
@@ -743,35 +782,39 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
}
|
||||
else
|
||||
{
|
||||
// CR+LF found
|
||||
/// CR+LF found
|
||||
if (optoState == OptoState.Read)
|
||||
{
|
||||
int bufferIx = (optoDataCount < MaxOptoDataCount) ? optoDataCount : ((optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount);
|
||||
|
||||
if (pos < OptoTelegramRaw.Length - 2)
|
||||
{
|
||||
/// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
if (synchronized)
|
||||
{
|
||||
optoData[optoDataCount].Counter = optoDataCount;
|
||||
optoData[optoDataCount++].SetFlags(OptoTelegramFlags.SyncError);
|
||||
optoData[bufferIx].Counter = optoDataCount;
|
||||
optoData[bufferIx].SetFlags(OptoTelegramFlags.SyncError);
|
||||
}
|
||||
synchronized = true;
|
||||
}
|
||||
else if (optoData[optoDataCount].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), optoDataCount, ref volumeRawExtLast, ref timestampExtLast))
|
||||
else if (optoData[bufferIx].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2), optoDataCount, ref volumeRawExtLast, ref timestampExtLast))
|
||||
{
|
||||
/// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) && the telegram is OK
|
||||
flowDirectionDetection.WriteToFifo(volumeRawExtLast, timestampExtLast);
|
||||
OptoTelegramRreceived(optoDataCount++, synchronized2, volumeRawExtLast, timestampExtLast);
|
||||
OptoTelegramRreceived(optoDataCount, synchronized2, volumeRawExtLast, timestampExtLast);
|
||||
synchronized2 = synchronized;
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// CR+LF was found && (pos >= OptoTelegramRaw.Length - 2) but the telgram was not OK
|
||||
optoData[optoDataCount].Counter = optoDataCount;
|
||||
optoData[bufferIx].Counter = optoDataCount;
|
||||
optoDataCount++;
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
}
|
||||
|
||||
optoDataCount++;
|
||||
}
|
||||
else /// optoState == OptoState.Flush
|
||||
{
|
||||
|
||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.1098.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.1098.0")]
|
||||
[assembly: AssemblyVersion("2.18.1099.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.1099.0")]
|
||||
|
||||
Reference in New Issue
Block a user