ReSharper: -GenesisCore
This commit is contained in:
@@ -7,26 +7,42 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
/// <summary>
|
||||
/// Check the positioning of the streaming LED to validate the quality of the communication line
|
||||
/// </summary>
|
||||
public class GenesisMeterStreamingQuality : GenesisMeter
|
||||
{
|
||||
/// <summary>
|
||||
/// Backup of last quality
|
||||
/// </summary>
|
||||
public QualityResult LastQualityResult;
|
||||
private StreamingDecoder sd;
|
||||
|
||||
private StreamingDecoder _sd;
|
||||
/// <summary>
|
||||
/// Quality check is active
|
||||
/// </summary>
|
||||
public Boolean IsRunning;
|
||||
private DateTimeOffset? _startTime;
|
||||
private DateTimeOffset? _stopTime;
|
||||
private List<String> _collectedRecords;
|
||||
private int? TillDecodedCount = null;
|
||||
public void StartStreamingQualityCheck(int? tillDecodedCount = null)
|
||||
|
||||
private Int32? _tillDecodedCount;
|
||||
/// <summary>
|
||||
/// Kick off the streaming quality check.
|
||||
/// </summary>
|
||||
/// <param name="tillDecodedCount"></param>
|
||||
/// <exception cref="ApplicationException"></exception>
|
||||
public void StartStreamingQualityCheck(Int32? tillDecodedCount = null)
|
||||
{
|
||||
|
||||
if (IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TillDecodedCount = tillDecodedCount;
|
||||
if (TillDecodedCount.HasValue)
|
||||
_tillDecodedCount = tillDecodedCount;
|
||||
if (_tillDecodedCount.HasValue)
|
||||
{
|
||||
sd = new StreamingDecoder(false);
|
||||
_sd = new StreamingDecoder(false);
|
||||
}
|
||||
if (StreamingPort == null || !(StreamingPort is LedSerialPort))
|
||||
{
|
||||
@@ -36,7 +52,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
_stopTime = null;
|
||||
_collectedRecords = new List<String>();
|
||||
|
||||
SyncStreamingBuffer(SyncMarkRecord.FlushBuffer);
|
||||
SyncStreamingBuffer(SyncMarkRecord.DecodeEveryPackage);
|
||||
((LedSerialPort)StreamingPort).OnRawRecordReceived += GenesisMeterStreamingQuality_OnRawRecordReceived;
|
||||
_startTime = DateTimeOffset.UtcNow;
|
||||
@@ -47,21 +62,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
private void GenesisMeterStreamingQuality_OnRawRecordReceived(Object sender, BasePortDataEventArgs e)
|
||||
{
|
||||
_collectedRecords.Add(e.GetData().ToString());
|
||||
if (TillDecodedCount.HasValue)
|
||||
if (_tillDecodedCount.HasValue)
|
||||
{
|
||||
if (sd.DecodeMsg(e.GetData().ToString()))
|
||||
if (_sd.DecodeMsg(e.GetData().ToString()))
|
||||
{
|
||||
TillDecodedCount = TillDecodedCount.Value - 1;
|
||||
if (TillDecodedCount <= 0)
|
||||
_tillDecodedCount = _tillDecodedCount.Value - 1;
|
||||
if (_tillDecodedCount <= 0)
|
||||
{
|
||||
IsRunning = false;
|
||||
LastQualityResult = StopStreamingQualityCheck(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the streaming check.
|
||||
/// </summary>
|
||||
/// <param name="sampleRateHz"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ApplicationException"></exception>
|
||||
public QualityResult StopStreamingQualityCheck(Int32 sampleRateHz)
|
||||
{
|
||||
_stopTime = DateTimeOffset.UtcNow;
|
||||
@@ -79,24 +100,56 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
((LedSerialPort)StreamingPort).OnRawRecordReceived -= GenesisMeterStreamingQuality_OnRawRecordReceived;
|
||||
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
||||
IsRunning = false;
|
||||
return new QualityResult(_collectedRecords, _stopTime.Value - _startTime.Value, sampleRateHz);
|
||||
if (_stopTime != null && _startTime != null)
|
||||
return new QualityResult(_collectedRecords, _stopTime.Value - _startTime.Value, sampleRateHz);
|
||||
return new QualityResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class QualityResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of records received (read line for LED message)
|
||||
/// </summary>
|
||||
public readonly Int32 TotalLinesCount;
|
||||
/// <summary>
|
||||
/// Total records decoded
|
||||
/// </summary>
|
||||
public readonly Int32 TotalDecodedCount;
|
||||
/// <summary>
|
||||
/// Total errors
|
||||
/// </summary>
|
||||
public readonly Int32 TotalTransportErrorCount;
|
||||
/// <summary>
|
||||
/// Validated without errors
|
||||
/// </summary>
|
||||
public readonly Int32 TotalValidationWithoutErrorsCount;
|
||||
/// <summary>
|
||||
/// Expected lines
|
||||
/// </summary>
|
||||
public readonly Int32 ExpectedLinesCount;
|
||||
/// <summary>
|
||||
/// Time
|
||||
/// </summary>
|
||||
public readonly TimeSpan TotalTime;
|
||||
/// <summary>
|
||||
/// Error counter
|
||||
/// </summary>
|
||||
public readonly Dictionary<UInt16, Int32> ErrorOccurredCounter;
|
||||
|
||||
/// <summary>
|
||||
/// The real result of quality check
|
||||
/// </summary>
|
||||
/// <param name="collectedRecords"></param>
|
||||
/// <param name="ts"></param>
|
||||
/// <param name="sampleRateHz"></param>
|
||||
public QualityResult(List<String> collectedRecords, TimeSpan ts, Int32 sampleRateHz)
|
||||
{
|
||||
TotalLinesCount = collectedRecords.Count;
|
||||
TotalTime = ts;
|
||||
ExpectedLinesCount = (Int32)(Math.Round( ts.TotalSeconds * sampleRateHz, 0));
|
||||
ExpectedLinesCount = (Int32)(Math.Round(ts.TotalSeconds * sampleRateHz, 0));
|
||||
ErrorOccurredCounter = new Dictionary<UInt16, Int32>();
|
||||
foreach (var rawText in collectedRecords)
|
||||
{
|
||||
@@ -140,6 +193,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The quality result as dummy zero
|
||||
/// </summary>
|
||||
public QualityResult()
|
||||
{
|
||||
TotalLinesCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user