iPerlHead : FLow filtering by FIRFilterFlow() corrected, ver. 2.18.1109
This commit is contained in:
@@ -2,17 +2,12 @@
|
|||||||
/// Copyright (c) 2015-2018 Sensus Slovensko a.s.
|
/// Copyright (c) 2015-2018 Sensus Slovensko a.s.
|
||||||
///
|
///
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Threading;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using Config.Entities;
|
using Config.Entities;
|
||||||
using TBF.BenchControl;
|
|
||||||
using TBF.BenchControl.Generic;
|
using TBF.BenchControl.Generic;
|
||||||
using TBF.BenchControl.Output;
|
using TBF.BenchControl.Output;
|
||||||
using TBF.Resources;
|
|
||||||
|
|
||||||
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||||
{
|
{
|
||||||
@@ -25,9 +20,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
|
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
|
||||||
|
|
||||||
|
|
||||||
const int MaxOptoDataCount = 40000;
|
public const int MaxOptoDataCount = 40000;
|
||||||
const int StartOptoDataCount = MaxOptoDataCount / 2;
|
public const int StartOptoDataCount = MaxOptoDataCount / 2;
|
||||||
const int EndOptoDataCount = MaxOptoDataCount - StartOptoDataCount;
|
public const int EndOptoDataCount = MaxOptoDataCount - StartOptoDataCount;
|
||||||
|
|
||||||
|
|
||||||
readonly IperlHeadCfg iperlHeadCfg;
|
readonly IperlHeadCfg iperlHeadCfg;
|
||||||
@@ -631,17 +626,21 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
OptoTelegramRaw.TestStartTimestampDec = optoData[TestStartTelegramIx].TimestampDec();
|
OptoTelegramRaw.TestStartTimestampDec = optoData[TestStartTelegramIx].TimestampDec();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((TestEndTelegramIx > 0) && (TestEndTelegramIx < MaxOptoDataCount) && (optoData[TestEndTelegramIx].Flags == OptoTelegramFlags.OK))
|
if (optoData[OptoTelegramRaw.BufferIdx(TestEndTelegramIx)].Flags == OptoTelegramFlags.OK)
|
||||||
{
|
{
|
||||||
optoData[TestEndTelegramIx].Flags = OptoTelegramFlags.OK_TestEnd;
|
optoData[OptoTelegramRaw.BufferIdx(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();
|
StopParsingOptoSerialPort();
|
||||||
OptoTelegramRaw.FIRFilterFlow(optoData, Math.Min(optoDataCount, MaxOptoDataCount));
|
if (optoDataCount <= MaxOptoDataCount)
|
||||||
|
{
|
||||||
|
OptoTelegramRaw.FIRFilterFlow(optoData, 0, optoDataCount - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OptoTelegramRaw.FIRFilterFlow(optoData, 0, StartOptoDataCount - 1);
|
||||||
|
OptoTelegramRaw.FIRFilterFlow(optoData, (optoDataCount - EndOptoDataCount), optoDataCount - 1);
|
||||||
|
}
|
||||||
SaveOptoData();
|
SaveOptoData();
|
||||||
|
|
||||||
if (TestStartTelegramIx == 0 || optoDataCount < 100)
|
if (TestStartTelegramIx == 0 || optoDataCount < 100)
|
||||||
@@ -698,11 +697,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
optoLogFile.WriteLine(" ...");
|
optoLogFile.WriteLine(" ...");
|
||||||
|
|
||||||
/// Second part of the buffer is an overflowed circular buffer
|
/// Second part of the buffer is an overflowed circular buffer
|
||||||
optoLogFile.WriteLine(optoData[(optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].ToString(scalFact, null));
|
optoLogFile.WriteLine(optoData[OptoTelegramRaw.BufferIdx(optoDataCount)].ToString(scalFact, null));
|
||||||
for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++)
|
for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++)
|
||||||
{
|
{
|
||||||
optoLogFile.WriteLine(optoData[(i - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount]
|
optoLogFile.WriteLine(optoData[OptoTelegramRaw.BufferIdx(i)]
|
||||||
.ToString(scalFact, optoData[(i - 1 - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount]));
|
.ToString(scalFact, optoData[OptoTelegramRaw.BufferIdx(i - 1)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,7 +790,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
/// CR+LF found
|
/// CR+LF found
|
||||||
if (optoState == OptoState.Read)
|
if (optoState == OptoState.Read)
|
||||||
{
|
{
|
||||||
int bufferIx = (optoDataCount < MaxOptoDataCount) ? optoDataCount : ((optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount);
|
int bufferIx = OptoTelegramRaw.BufferIdx(optoDataCount);
|
||||||
|
|
||||||
if (pos < OptoTelegramRaw.Length - 2)
|
if (pos < OptoTelegramRaw.Length - 2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -259,8 +259,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
/// 7 ...
|
/// 7 ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="optoData">array of OptoTelegramRaw objects</param>
|
/// <param name="optoData">array of OptoTelegramRaw objects</param>
|
||||||
/// <param name="optoDataCount">number of objects to process</param>
|
/// <param name="from">Index of the first optoData item to process</param>
|
||||||
public static void FIRFilterFlow(OptoTelegramRaw[] optoData, int optoDataCount)
|
/// <param name="to">Index of the last optoData item to process</param>
|
||||||
|
public static void FIRFilterFlow(OptoTelegramRaw[] optoData, int from, int to)
|
||||||
{
|
{
|
||||||
float[] kernel = new float[] { 0.1f, 0.2f, 0.4f, 0.2f, 0.1f };
|
float[] kernel = new float[] { 0.1f, 0.2f, 0.4f, 0.2f, 0.1f };
|
||||||
int kSize = kernel.Length;
|
int kSize = kernel.Length;
|
||||||
@@ -268,29 +269,52 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
|
|
||||||
float[] filtered = new float[kSize];
|
float[] filtered = new float[kSize];
|
||||||
|
|
||||||
for (int i = 0; i < optoDataCount; i++)
|
for (int i = from; i <= to; i++)
|
||||||
{
|
{
|
||||||
int k = i - kSize;
|
if ((i < from + kSize2) || (i > to - kSize2))
|
||||||
if (k >= 0) optoData[k].RefFlow = filtered[i % kSize];
|
|
||||||
|
|
||||||
if (i < kSize2 || i >= optoDataCount - kSize2)
|
|
||||||
{
|
{
|
||||||
filtered[i % kSize] = optoData[i].RefFlow;
|
/// Beginning or end of optoData buffer => Just copy data (=do not filter)
|
||||||
|
filtered[i % kSize] = optoData[BufferIdx(i)].RefFlow;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float weoightedSum = 0;
|
/// Make a convolution of optoData and the kernel
|
||||||
|
float weightedSum = 0;
|
||||||
for (int j = -kSize2; j <= kSize2; j++)
|
for (int j = -kSize2; j <= kSize2; j++)
|
||||||
weoightedSum += optoData[i + j].RefFlow * kernel[j + kSize2];
|
weightedSum += optoData[BufferIdx(i + j)].RefFlow * kernel[j + kSize2];
|
||||||
|
|
||||||
filtered[i % kSize] = weoightedSum;
|
filtered[i % kSize] = weightedSum;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (int k = optoDataCount - kSize; k < optoDataCount; k++)
|
if (i >= from + kSize)
|
||||||
|
{
|
||||||
|
/// filtered[] buffer full => copy filtered data to optoData
|
||||||
|
optoData[BufferIdx(i - kSize)].RefFlow = filtered[i % kSize];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = to - kSize + 1; i <= to; i++)
|
||||||
{
|
{
|
||||||
if (k >= 0) optoData[k].RefFlow = filtered[k % kSize];
|
if (i >= 0) optoData[BufferIdx(i)].RefFlow = filtered[i % kSize];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get index to optoData buffer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">Original unwrapped index</param>
|
||||||
|
/// <returns>Index to the buffer</returns>
|
||||||
|
public static int BufferIdx(int index)
|
||||||
|
{
|
||||||
|
if (index < IperlHead.MaxOptoDataCount)
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return IperlHead.StartOptoDataCount + (index - IperlHead.MaxOptoDataCount) % IperlHead.EndOptoDataCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("2.18.1108.0")]
|
[assembly: AssemblyVersion("2.18.1109.0")]
|
||||||
[assembly: AssemblyFileVersion("2.18.1108.0")]
|
[assembly: AssemblyFileVersion("2.18.1109.0")]
|
||||||
|
|||||||
Reference in New Issue
Block a user