ReSharper: -GenesisCore
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
||||
/// <param name="file"></param>
|
||||
public ProcessConfig(String file)
|
||||
{
|
||||
// chack for AppRoaming
|
||||
// check for AppRoaming
|
||||
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
||||
|
||||
if (!File.Exists(configFile))
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
|
||||
@@ -62,6 +61,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
try
|
||||
{
|
||||
//extract information of every application
|
||||
if (applicationGroups != null)
|
||||
foreach (var currentApplication in applicationGroups)
|
||||
{
|
||||
var o = (JObject)currentApplication.Value;
|
||||
@@ -83,13 +83,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
foreach (var registers in groupProp.Value)
|
||||
{
|
||||
var register = ((JProperty)registers);
|
||||
var register = (JProperty)registers;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var registerJ in register.Value)
|
||||
{
|
||||
JProperty reg = ((JProperty)registerJ);
|
||||
var reg = (JProperty)registerJ;
|
||||
|
||||
Byte? registerAddress = null;
|
||||
if (reg.Name == "id")
|
||||
@@ -99,19 +99,19 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
|
||||
if (reg.Name == "details")
|
||||
{
|
||||
|
||||
var details = ((JArray)reg.Value);
|
||||
|
||||
foreach (var jdetail in details.Children())
|
||||
{
|
||||
var actualRegister = new RegisterDefinition();
|
||||
var idTag = reg.Parent.First(f => ((JProperty)f).Name == "id");
|
||||
var id = (Byte)(JProperty)idTag;//.Value<int>();
|
||||
var id = (Byte)(JProperty)idTag; //.Value<int>();
|
||||
|
||||
if (registerAddress.HasValue)
|
||||
{
|
||||
throw new Exception("invalid json cast");
|
||||
}
|
||||
|
||||
actualRegister.RegAddressInApp = id;
|
||||
actualRegister.AppName = currentApplication.Key;
|
||||
actualRegister.AppAddress = applicationAddress;
|
||||
@@ -122,13 +122,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
detail = detailO.Property("privilege");
|
||||
if (detail.Name == "privilege")
|
||||
{
|
||||
actualRegister.RegisterDetail.Privilege = JsonConvert.DeserializeObject<Privilege>(detail.Value.ToString(), Settings);
|
||||
actualRegister.RegisterDetail.Privilege =
|
||||
JsonConvert.DeserializeObject<Privilege>(
|
||||
detail.Value.ToString(), Settings);
|
||||
}
|
||||
|
||||
detail = detailO.Property("type");
|
||||
if (detail.Name == "type")
|
||||
{
|
||||
|
||||
actualRegister.DataType = typeof(String);// detail.Value.ToString();
|
||||
actualRegister.DataType =
|
||||
typeof(String); // detail.Value.ToString();
|
||||
|
||||
switch (detail.Value.ToString().ToLower())
|
||||
{
|
||||
@@ -178,18 +181,23 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
actualRegister.DataType = typeof(Int16);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
detail = detailO.Property("description");
|
||||
if (detail.Name == "description")
|
||||
{
|
||||
actualRegister.RegisterDetail.Description = detail.Value.ToString();
|
||||
actualRegister.RegisterDetail.Description =
|
||||
detail.Value.ToString();
|
||||
}
|
||||
|
||||
detail = detailO.Property("version");
|
||||
if (detail.Name == "version")
|
||||
{
|
||||
actualRegister.RegisterDetail.Version = JsonConvert.DeserializeObject<FwVersion>(detail.Value.ToString());
|
||||
actualRegister.RegisterDetail.Version =
|
||||
JsonConvert.DeserializeObject<FwVersion>(
|
||||
detail.Value.ToString());
|
||||
}
|
||||
|
||||
detail = detailO.Property("values");
|
||||
if (detail != null && detail.Name == "values")
|
||||
{
|
||||
@@ -198,72 +206,73 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
switch (((JProperty)dValues).Name)
|
||||
{
|
||||
case "default":
|
||||
actualRegister.Default = (Int64)((JProperty)dValues).Value;
|
||||
actualRegister.Default =
|
||||
(Int64)((JProperty)dValues).Value;
|
||||
break;
|
||||
case "maximum":
|
||||
actualRegister.Maximum = (Int64)((JProperty)dValues).Value;
|
||||
actualRegister.Maximum =
|
||||
(Int64)((JProperty)dValues).Value;
|
||||
break;
|
||||
case "minimum":
|
||||
actualRegister.Minimum = (Int64)((JProperty)dValues).Value;
|
||||
actualRegister.Minimum =
|
||||
(Int64)((JProperty)dValues).Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
detail = detailO.Property(StaticType.StaticTypeFieldIdentifier);
|
||||
if (detail != null && detail.Name == StaticType.StaticTypeFieldIdentifier)
|
||||
if (detail != null && detail.Name ==
|
||||
StaticType.StaticTypeFieldIdentifier)
|
||||
{
|
||||
actualRegister.RestoreCapability = new StaticType(detail.Value.ToString());
|
||||
actualRegister.RestoreCapability =
|
||||
new StaticType(detail.Value.ToString());
|
||||
}
|
||||
|
||||
ConfigRegistersDefinitions.Add(actualRegister);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception )
|
||||
{
|
||||
//todo log ex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception )
|
||||
{
|
||||
//todo log ex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception )
|
||||
{
|
||||
|
||||
|
||||
// ignored
|
||||
}
|
||||
|
||||
|
||||
////tofile
|
||||
var sb = new StringBuilder();
|
||||
var lsitOfRegisters = new List<RegisterDefinition>();
|
||||
var listOfRegisters = new List<RegisterDefinition>();
|
||||
foreach (var item in ConfigRegistersDefinitions)
|
||||
{
|
||||
if (item is RegisterDefinition Reg)
|
||||
if (item is RegisterDefinition reg)
|
||||
{
|
||||
if (lsitOfRegisters.Any(a => a.GetIdent() == Reg.GetIdent()))
|
||||
if (listOfRegisters.Any(a => a.GetIdent() == reg.GetIdent()))
|
||||
{
|
||||
var oldItem = lsitOfRegisters.First(a => a.GetIdent() == Reg.GetIdent());
|
||||
if (oldItem.RegisterDetail.Version.Last < Reg.RegisterDetail.Version.Last)
|
||||
var oldItem = listOfRegisters.First(a => a.GetIdent() == reg.GetIdent());
|
||||
if (oldItem.RegisterDetail.Version.Last < reg.RegisterDetail.Version.Last)
|
||||
{
|
||||
lsitOfRegisters.Remove(oldItem);
|
||||
lsitOfRegisters.Add(Reg);
|
||||
listOfRegisters.Remove(oldItem);
|
||||
listOfRegisters.Add(reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lsitOfRegisters.Add(Reg);
|
||||
listOfRegisters.Add(reg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//#region create a file for my american friends
|
||||
@@ -439,6 +448,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
public static readonly LvlConverter Singleton = new LvlConverter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settings
|
||||
/// </summary>
|
||||
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||
|
||||
@@ -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,12 +62,12 @@ 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);
|
||||
@@ -62,6 +77,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
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;
|
||||
|
||||
@@ -23,7 +23,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// All channels required to process
|
||||
/// </summary>
|
||||
public Boolean AllChannelsRequired = true;
|
||||
private const bool QualityWatchMode = false;
|
||||
|
||||
/// <summary>
|
||||
/// Quality watch mode can be used to decode intermediate records and check
|
||||
/// for actual quality of the measurements.
|
||||
/// </summary>
|
||||
public Boolean QualityWatchMode;
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +74,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
displayStateString = ByteStyler.ToString(displayState);
|
||||
if (displayStateString != "00-00-00-00")
|
||||
{
|
||||
WriteRegister(Register.Genesisflow.TriggerActive, 1, true);
|
||||
WriteRegister(Register.Genesisflow.TriggerActive, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -79,9 +84,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
|
||||
|
||||
WriteRegister("GENESISFLOW_DisplayPow10", (new Byte[] { 0x00, 0x00, 0x00, 0xFA }).Reverse().ToArray(), true, false);
|
||||
WriteRegister(Register.Genesisflow.StoreCalibration, 1, true);
|
||||
WriteRegister(Register.Genesisflow.StoreConfiguration, 1, true);
|
||||
WriteRegister("GENESISFLOW_DisplayPow10", (new Byte[] { 0x00, 0x00, 0x00, 0xFA }).Reverse().ToArray());
|
||||
WriteRegister(Register.Genesisflow.StoreCalibration, 1);
|
||||
WriteRegister(Register.Genesisflow.StoreConfiguration, 1);
|
||||
|
||||
|
||||
//}
|
||||
@@ -233,15 +238,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
if (_listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsRunning)
|
||||
|| _listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsCompleted))
|
||||
{
|
||||
if (QualityWatchMode)
|
||||
{
|
||||
SyncStreamingBuffer(SyncMarkRecord.DecodeIntermediateQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
||||
}
|
||||
|
||||
SyncStreamingBuffer(QualityWatchMode
|
||||
? SyncMarkRecord.DecodeIntermediateQuality
|
||||
: SyncMarkRecord.SkipDecoding);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -263,34 +262,26 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
if (onlyChannelNr.HasValue)
|
||||
{
|
||||
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
||||
if (measurement == null)
|
||||
{
|
||||
return MeasurementStates.NotStarted;
|
||||
}
|
||||
|
||||
return measurement.GetMeasurementState();
|
||||
}
|
||||
return _listOfIMeasurement.Min(m => m.MeasurementState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
|
||||
public Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
|
||||
{
|
||||
_logger.Trace($"Slot:{Slot} - Get measurement state");
|
||||
if (!_listOfIMeasurement.Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool? ret = null;
|
||||
Boolean? ret = null;
|
||||
foreach (var item in _listOfIMeasurement)
|
||||
{
|
||||
if (!onlyChannelNr.HasValue || item.GetChannel() == onlyChannelNr.Value)
|
||||
{
|
||||
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
||||
if (measurement != null &&
|
||||
(measurement.MeasurementState == MeasurementStates.IsRunning
|
||||
var measurement = _listOfIMeasurement.First(f => onlyChannelNr != null && f.GetChannel() == onlyChannelNr.Value);
|
||||
if ((measurement.MeasurementState == MeasurementStates.IsRunning
|
||||
|| measurement.MeasurementState == MeasurementStates.IsWaitingForIntermediateData))
|
||||
{
|
||||
measurement.RequestIntermediateRecord();
|
||||
@@ -307,8 +298,5 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
return ret.HasValue ? ret.Value : false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,13 @@ namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore
|
||||
/// <returns></returns>
|
||||
MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null );
|
||||
|
||||
/// <summary>
|
||||
/// Request for intermediate measurement state.
|
||||
/// </summary>
|
||||
/// <param name="onlyChannelNr"></param>
|
||||
/// <returns></returns>
|
||||
Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null);
|
||||
|
||||
/// <summary>
|
||||
/// set up calibration parameter (calibration factor to default) and set meter into calibration mode
|
||||
/// </summary>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
5ed75d99ee45ff67821090f1b3dbb001dd9e4fe3
|
||||
1a3d4919c9c702245832d925951f2b7cb72fc333
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0d85a5b3a7561b41163c20e5dc7713bcd0d65555
|
||||
f64d563def603c89cafafa61a3219ba97e1e344c
|
||||
|
||||
Reference in New Issue
Block a user