ReSharper: -GenesisCore
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
|||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
public ProcessConfig(String file)
|
public ProcessConfig(String file)
|
||||||
{
|
{
|
||||||
// chack for AppRoaming
|
// check for AppRoaming
|
||||||
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
||||||
|
|
||||||
if (!File.Exists(configFile))
|
if (!File.Exists(configFile))
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
|
||||||
@@ -62,208 +61,218 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//extract information of every application
|
//extract information of every application
|
||||||
foreach (var currentApplication in applicationGroups)
|
if (applicationGroups != null)
|
||||||
{
|
foreach (var currentApplication in applicationGroups)
|
||||||
var o = (JObject)currentApplication.Value;
|
|
||||||
var application = new ApplicationDefinition();
|
|
||||||
Byte applicationAddress = 0;
|
|
||||||
|
|
||||||
foreach (var groupProp in o)
|
|
||||||
{
|
{
|
||||||
try
|
var o = (JObject)currentApplication.Value;
|
||||||
|
var application = new ApplicationDefinition();
|
||||||
|
Byte applicationAddress = 0;
|
||||||
|
|
||||||
|
foreach (var groupProp in o)
|
||||||
{
|
{
|
||||||
if (groupProp.Key == "id")
|
try
|
||||||
{
|
{
|
||||||
applicationAddress = groupProp.Value.Value<Byte>();
|
if (groupProp.Key == "id")
|
||||||
application.AppName = currentApplication.Key;
|
|
||||||
application.AppId = applicationAddress;
|
|
||||||
ConfigApplicationDefinitions.Add(application);
|
|
||||||
}
|
|
||||||
else if (groupProp.Key == "registers")
|
|
||||||
{
|
|
||||||
foreach (var registers in groupProp.Value)
|
|
||||||
{
|
{
|
||||||
var register = ((JProperty)registers);
|
applicationAddress = groupProp.Value.Value<Byte>();
|
||||||
|
application.AppName = currentApplication.Key;
|
||||||
try
|
application.AppId = applicationAddress;
|
||||||
|
ConfigApplicationDefinitions.Add(application);
|
||||||
|
}
|
||||||
|
else if (groupProp.Key == "registers")
|
||||||
|
{
|
||||||
|
foreach (var registers in groupProp.Value)
|
||||||
{
|
{
|
||||||
foreach (var registerJ in register.Value)
|
var register = (JProperty)registers;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
JProperty reg = ((JProperty)registerJ);
|
foreach (var registerJ in register.Value)
|
||||||
|
|
||||||
Byte? registerAddress = null;
|
|
||||||
if (reg.Name == "id")
|
|
||||||
{
|
{
|
||||||
registerAddress = (Byte)reg.Value;
|
var reg = (JProperty)registerJ;
|
||||||
}
|
|
||||||
|
|
||||||
if (reg.Name == "details")
|
Byte? registerAddress = null;
|
||||||
{
|
if (reg.Name == "id")
|
||||||
|
|
||||||
var details = ((JArray)reg.Value);
|
|
||||||
|
|
||||||
foreach (var jdetail in details.Children())
|
|
||||||
{
|
{
|
||||||
var actualRegister = new RegisterDefinition();
|
registerAddress = (Byte)reg.Value;
|
||||||
var idTag = reg.Parent.First(f => ((JProperty)f).Name == "id");
|
}
|
||||||
var id = (Byte)(JProperty)idTag;//.Value<int>();
|
|
||||||
|
|
||||||
if (registerAddress.HasValue)
|
if (reg.Name == "details")
|
||||||
{
|
{
|
||||||
throw new Exception("invalid json cast");
|
var details = ((JArray)reg.Value);
|
||||||
}
|
|
||||||
actualRegister.RegAddressInApp = id;
|
|
||||||
actualRegister.AppName = currentApplication.Key;
|
|
||||||
actualRegister.AppAddress = applicationAddress;
|
|
||||||
actualRegister.RegisterDetail = new RegisterDetail();
|
|
||||||
actualRegister.RegisterName = register.Name;
|
|
||||||
var detailO = (JObject)jdetail;
|
|
||||||
JProperty detail;
|
|
||||||
detail = detailO.Property("privilege");
|
|
||||||
if (detail.Name == "privilege")
|
|
||||||
{
|
|
||||||
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();
|
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>();
|
||||||
|
|
||||||
switch (detail.Value.ToString().ToLower())
|
if (registerAddress.HasValue)
|
||||||
{
|
{
|
||||||
case "bool_t":
|
throw new Exception("invalid json cast");
|
||||||
actualRegister.DataType = typeof(Boolean);
|
|
||||||
break;
|
|
||||||
case "rpc":
|
|
||||||
actualRegister.DataType = typeof(Rpc);
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
actualRegister.DataType = typeof(String);
|
|
||||||
break;
|
|
||||||
case "uint32_t":
|
|
||||||
actualRegister.DataType = typeof(UInt32);
|
|
||||||
break;
|
|
||||||
case "time_t":
|
|
||||||
actualRegister.DataType = typeof(TimeT);
|
|
||||||
break;
|
|
||||||
case "status_t":
|
|
||||||
actualRegister.DataType = typeof(StatusT);
|
|
||||||
break;
|
|
||||||
case "uint16_t":
|
|
||||||
actualRegister.DataType = typeof(UInt16);
|
|
||||||
break;
|
|
||||||
case "uint8_t":
|
|
||||||
actualRegister.DataType = typeof(byte);
|
|
||||||
break;
|
|
||||||
case "enum8":
|
|
||||||
actualRegister.DataType = typeof(Enum8);
|
|
||||||
break;
|
|
||||||
case "uint64_t":
|
|
||||||
actualRegister.DataType = typeof(UInt64);
|
|
||||||
break;
|
|
||||||
case "uint96_t":
|
|
||||||
actualRegister.DataType = typeof(UInt96);
|
|
||||||
break;
|
|
||||||
case "int8_t":
|
|
||||||
actualRegister.DataType = typeof(sbyte);
|
|
||||||
break;
|
|
||||||
case "int32_t":
|
|
||||||
actualRegister.DataType = typeof(Int32);
|
|
||||||
break;
|
|
||||||
case "int64_t":
|
|
||||||
actualRegister.DataType = typeof(Int64);
|
|
||||||
break;
|
|
||||||
case "int16_t":
|
|
||||||
actualRegister.DataType = typeof(Int16);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
actualRegister.RegAddressInApp = id;
|
||||||
detail = detailO.Property("description");
|
actualRegister.AppName = currentApplication.Key;
|
||||||
if (detail.Name == "description")
|
actualRegister.AppAddress = applicationAddress;
|
||||||
{
|
actualRegister.RegisterDetail = new RegisterDetail();
|
||||||
actualRegister.RegisterDetail.Description = detail.Value.ToString();
|
actualRegister.RegisterName = register.Name;
|
||||||
}
|
var detailO = (JObject)jdetail;
|
||||||
detail = detailO.Property("version");
|
JProperty detail;
|
||||||
if (detail.Name == "version")
|
detail = detailO.Property("privilege");
|
||||||
{
|
if (detail.Name == "privilege")
|
||||||
actualRegister.RegisterDetail.Version = JsonConvert.DeserializeObject<FwVersion>(detail.Value.ToString());
|
|
||||||
}
|
|
||||||
detail = detailO.Property("values");
|
|
||||||
if (detail != null && detail.Name == "values")
|
|
||||||
{
|
|
||||||
foreach (var dValues in detail.Children().First())
|
|
||||||
{
|
{
|
||||||
switch (((JProperty)dValues).Name)
|
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();
|
||||||
|
|
||||||
|
switch (detail.Value.ToString().ToLower())
|
||||||
{
|
{
|
||||||
case "default":
|
case "bool_t":
|
||||||
actualRegister.Default = (Int64)((JProperty)dValues).Value;
|
actualRegister.DataType = typeof(Boolean);
|
||||||
break;
|
break;
|
||||||
case "maximum":
|
case "rpc":
|
||||||
actualRegister.Maximum = (Int64)((JProperty)dValues).Value;
|
actualRegister.DataType = typeof(Rpc);
|
||||||
break;
|
break;
|
||||||
case "minimum":
|
case "string":
|
||||||
actualRegister.Minimum = (Int64)((JProperty)dValues).Value;
|
actualRegister.DataType = typeof(String);
|
||||||
|
break;
|
||||||
|
case "uint32_t":
|
||||||
|
actualRegister.DataType = typeof(UInt32);
|
||||||
|
break;
|
||||||
|
case "time_t":
|
||||||
|
actualRegister.DataType = typeof(TimeT);
|
||||||
|
break;
|
||||||
|
case "status_t":
|
||||||
|
actualRegister.DataType = typeof(StatusT);
|
||||||
|
break;
|
||||||
|
case "uint16_t":
|
||||||
|
actualRegister.DataType = typeof(UInt16);
|
||||||
|
break;
|
||||||
|
case "uint8_t":
|
||||||
|
actualRegister.DataType = typeof(byte);
|
||||||
|
break;
|
||||||
|
case "enum8":
|
||||||
|
actualRegister.DataType = typeof(Enum8);
|
||||||
|
break;
|
||||||
|
case "uint64_t":
|
||||||
|
actualRegister.DataType = typeof(UInt64);
|
||||||
|
break;
|
||||||
|
case "uint96_t":
|
||||||
|
actualRegister.DataType = typeof(UInt96);
|
||||||
|
break;
|
||||||
|
case "int8_t":
|
||||||
|
actualRegister.DataType = typeof(sbyte);
|
||||||
|
break;
|
||||||
|
case "int32_t":
|
||||||
|
actualRegister.DataType = typeof(Int32);
|
||||||
|
break;
|
||||||
|
case "int64_t":
|
||||||
|
actualRegister.DataType = typeof(Int64);
|
||||||
|
break;
|
||||||
|
case "int16_t":
|
||||||
|
actualRegister.DataType = typeof(Int16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
detail = detailO.Property(StaticType.StaticTypeFieldIdentifier);
|
detail = detailO.Property("description");
|
||||||
if (detail != null && detail.Name == StaticType.StaticTypeFieldIdentifier)
|
if (detail.Name == "description")
|
||||||
{
|
{
|
||||||
actualRegister.RestoreCapability = new StaticType(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());
|
||||||
|
}
|
||||||
|
|
||||||
|
detail = detailO.Property("values");
|
||||||
|
if (detail != null && detail.Name == "values")
|
||||||
|
{
|
||||||
|
foreach (var dValues in detail.Children().First())
|
||||||
|
{
|
||||||
|
switch (((JProperty)dValues).Name)
|
||||||
|
{
|
||||||
|
case "default":
|
||||||
|
actualRegister.Default =
|
||||||
|
(Int64)((JProperty)dValues).Value;
|
||||||
|
break;
|
||||||
|
case "maximum":
|
||||||
|
actualRegister.Maximum =
|
||||||
|
(Int64)((JProperty)dValues).Value;
|
||||||
|
break;
|
||||||
|
case "minimum":
|
||||||
|
actualRegister.Minimum =
|
||||||
|
(Int64)((JProperty)dValues).Value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
detail = detailO.Property(StaticType.StaticTypeFieldIdentifier);
|
||||||
|
if (detail != null && detail.Name ==
|
||||||
|
StaticType.StaticTypeFieldIdentifier)
|
||||||
|
{
|
||||||
|
actualRegister.RestoreCapability =
|
||||||
|
new StaticType(detail.Value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigRegistersDefinitions.Add(actualRegister);
|
||||||
}
|
}
|
||||||
ConfigRegistersDefinitions.Add(actualRegister);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception )
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
//todo log ex
|
||||||
//todo log ex
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception )
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
//todo log ex
|
||||||
//todo log ex
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception )
|
||||||
{
|
{
|
||||||
|
// ignored
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////tofile
|
////tofile
|
||||||
var sb = new StringBuilder();
|
var listOfRegisters = new List<RegisterDefinition>();
|
||||||
var lsitOfRegisters = new List<RegisterDefinition>();
|
|
||||||
foreach (var item in ConfigRegistersDefinitions)
|
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());
|
var oldItem = listOfRegisters.First(a => a.GetIdent() == reg.GetIdent());
|
||||||
if (oldItem.RegisterDetail.Version.Last < Reg.RegisterDetail.Version.Last)
|
if (oldItem.RegisterDetail.Version.Last < reg.RegisterDetail.Version.Last)
|
||||||
{
|
{
|
||||||
lsitOfRegisters.Remove(oldItem);
|
listOfRegisters.Remove(oldItem);
|
||||||
lsitOfRegisters.Add(Reg);
|
listOfRegisters.Add(reg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lsitOfRegisters.Add(Reg);
|
listOfRegisters.Add(reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#region create a file for my american friends
|
//#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();
|
public static readonly LvlConverter Singleton = new LvlConverter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Settings
|
||||||
|
/// </summary>
|
||||||
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||||
|
|||||||
@@ -7,26 +7,42 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
|||||||
|
|
||||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
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
|
public class GenesisMeterStreamingQuality : GenesisMeter
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Backup of last quality
|
||||||
|
/// </summary>
|
||||||
public QualityResult LastQualityResult;
|
public QualityResult LastQualityResult;
|
||||||
private StreamingDecoder sd;
|
|
||||||
|
private StreamingDecoder _sd;
|
||||||
|
/// <summary>
|
||||||
|
/// Quality check is active
|
||||||
|
/// </summary>
|
||||||
public Boolean IsRunning;
|
public Boolean IsRunning;
|
||||||
private DateTimeOffset? _startTime;
|
private DateTimeOffset? _startTime;
|
||||||
private DateTimeOffset? _stopTime;
|
private DateTimeOffset? _stopTime;
|
||||||
private List<String> _collectedRecords;
|
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)
|
if (IsRunning)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TillDecodedCount = tillDecodedCount;
|
_tillDecodedCount = tillDecodedCount;
|
||||||
if (TillDecodedCount.HasValue)
|
if (_tillDecodedCount.HasValue)
|
||||||
{
|
{
|
||||||
sd = new StreamingDecoder(false);
|
_sd = new StreamingDecoder(false);
|
||||||
}
|
}
|
||||||
if (StreamingPort == null || !(StreamingPort is LedSerialPort))
|
if (StreamingPort == null || !(StreamingPort is LedSerialPort))
|
||||||
{
|
{
|
||||||
@@ -36,7 +52,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
_stopTime = null;
|
_stopTime = null;
|
||||||
_collectedRecords = new List<String>();
|
_collectedRecords = new List<String>();
|
||||||
|
|
||||||
SyncStreamingBuffer(SyncMarkRecord.FlushBuffer);
|
|
||||||
SyncStreamingBuffer(SyncMarkRecord.DecodeEveryPackage);
|
SyncStreamingBuffer(SyncMarkRecord.DecodeEveryPackage);
|
||||||
((LedSerialPort)StreamingPort).OnRawRecordReceived += GenesisMeterStreamingQuality_OnRawRecordReceived;
|
((LedSerialPort)StreamingPort).OnRawRecordReceived += GenesisMeterStreamingQuality_OnRawRecordReceived;
|
||||||
_startTime = DateTimeOffset.UtcNow;
|
_startTime = DateTimeOffset.UtcNow;
|
||||||
@@ -47,21 +62,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
private void GenesisMeterStreamingQuality_OnRawRecordReceived(Object sender, BasePortDataEventArgs e)
|
private void GenesisMeterStreamingQuality_OnRawRecordReceived(Object sender, BasePortDataEventArgs e)
|
||||||
{
|
{
|
||||||
_collectedRecords.Add(e.GetData().ToString());
|
_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;
|
_tillDecodedCount = _tillDecodedCount.Value - 1;
|
||||||
if (TillDecodedCount <= 0)
|
if (_tillDecodedCount <= 0)
|
||||||
{
|
{
|
||||||
IsRunning = false;
|
IsRunning = false;
|
||||||
LastQualityResult = StopStreamingQualityCheck(10);
|
LastQualityResult = StopStreamingQualityCheck(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stop the streaming check.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sampleRateHz"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ApplicationException"></exception>
|
||||||
public QualityResult StopStreamingQualityCheck(Int32 sampleRateHz)
|
public QualityResult StopStreamingQualityCheck(Int32 sampleRateHz)
|
||||||
{
|
{
|
||||||
_stopTime = DateTimeOffset.UtcNow;
|
_stopTime = DateTimeOffset.UtcNow;
|
||||||
@@ -79,24 +100,56 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
((LedSerialPort)StreamingPort).OnRawRecordReceived -= GenesisMeterStreamingQuality_OnRawRecordReceived;
|
((LedSerialPort)StreamingPort).OnRawRecordReceived -= GenesisMeterStreamingQuality_OnRawRecordReceived;
|
||||||
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
||||||
IsRunning = false;
|
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
|
public class QualityResult
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Number of records received (read line for LED message)
|
||||||
|
/// </summary>
|
||||||
public readonly Int32 TotalLinesCount;
|
public readonly Int32 TotalLinesCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Total records decoded
|
||||||
|
/// </summary>
|
||||||
public readonly Int32 TotalDecodedCount;
|
public readonly Int32 TotalDecodedCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Total errors
|
||||||
|
/// </summary>
|
||||||
public readonly Int32 TotalTransportErrorCount;
|
public readonly Int32 TotalTransportErrorCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Validated without errors
|
||||||
|
/// </summary>
|
||||||
public readonly Int32 TotalValidationWithoutErrorsCount;
|
public readonly Int32 TotalValidationWithoutErrorsCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Expected lines
|
||||||
|
/// </summary>
|
||||||
public readonly Int32 ExpectedLinesCount;
|
public readonly Int32 ExpectedLinesCount;
|
||||||
|
/// <summary>
|
||||||
|
/// Time
|
||||||
|
/// </summary>
|
||||||
public readonly TimeSpan TotalTime;
|
public readonly TimeSpan TotalTime;
|
||||||
|
/// <summary>
|
||||||
|
/// Error counter
|
||||||
|
/// </summary>
|
||||||
public readonly Dictionary<UInt16, Int32> ErrorOccurredCounter;
|
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)
|
public QualityResult(List<String> collectedRecords, TimeSpan ts, Int32 sampleRateHz)
|
||||||
{
|
{
|
||||||
TotalLinesCount = collectedRecords.Count;
|
TotalLinesCount = collectedRecords.Count;
|
||||||
TotalTime = ts;
|
TotalTime = ts;
|
||||||
ExpectedLinesCount = (Int32)(Math.Round( ts.TotalSeconds * sampleRateHz, 0));
|
ExpectedLinesCount = (Int32)(Math.Round(ts.TotalSeconds * sampleRateHz, 0));
|
||||||
ErrorOccurredCounter = new Dictionary<UInt16, Int32>();
|
ErrorOccurredCounter = new Dictionary<UInt16, Int32>();
|
||||||
foreach (var rawText in collectedRecords)
|
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()
|
public QualityResult()
|
||||||
{
|
{
|
||||||
TotalLinesCount = 0;
|
TotalLinesCount = 0;
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
/// All channels required to process
|
/// All channels required to process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Boolean AllChannelsRequired = true;
|
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);
|
displayStateString = ByteStyler.ToString(displayState);
|
||||||
if (displayStateString != "00-00-00-00")
|
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("GENESISFLOW_DisplayPow10", (new Byte[] { 0x00, 0x00, 0x00, 0xFA }).Reverse().ToArray());
|
||||||
WriteRegister(Register.Genesisflow.StoreCalibration, 1, true);
|
WriteRegister(Register.Genesisflow.StoreCalibration, 1);
|
||||||
WriteRegister(Register.Genesisflow.StoreConfiguration, 1, true);
|
WriteRegister(Register.Genesisflow.StoreConfiguration, 1);
|
||||||
|
|
||||||
|
|
||||||
//}
|
//}
|
||||||
@@ -233,15 +238,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
if (_listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsRunning)
|
if (_listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsRunning)
|
||||||
|| _listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsCompleted))
|
|| _listOfIMeasurement.All(m => m.MeasurementState == MeasurementStates.IsCompleted))
|
||||||
{
|
{
|
||||||
if (QualityWatchMode)
|
SyncStreamingBuffer(QualityWatchMode
|
||||||
{
|
? SyncMarkRecord.DecodeIntermediateQuality
|
||||||
SyncStreamingBuffer(SyncMarkRecord.DecodeIntermediateQuality);
|
: SyncMarkRecord.SkipDecoding);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -263,35 +262,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
if (onlyChannelNr.HasValue)
|
if (onlyChannelNr.HasValue)
|
||||||
{
|
{
|
||||||
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
||||||
if (measurement == null)
|
|
||||||
{
|
|
||||||
return MeasurementStates.NotStarted;
|
|
||||||
}
|
|
||||||
|
|
||||||
return measurement.GetMeasurementState();
|
return measurement.GetMeasurementState();
|
||||||
}
|
}
|
||||||
return _listOfIMeasurement.Min(m => m.MeasurementState);
|
return _listOfIMeasurement.Min(m => m.MeasurementState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
|
public Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
|
||||||
{
|
{
|
||||||
_logger.Trace($"Slot:{Slot} - Get measurement state");
|
_logger.Trace($"Slot:{Slot} - Get measurement state");
|
||||||
if (!_listOfIMeasurement.Any())
|
if (!_listOfIMeasurement.Any())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool? ret = null;
|
Boolean? ret = null;
|
||||||
foreach (var item in _listOfIMeasurement)
|
foreach (var item in _listOfIMeasurement)
|
||||||
{
|
{
|
||||||
if (!onlyChannelNr.HasValue || item.GetChannel() == onlyChannelNr.Value)
|
if (!onlyChannelNr.HasValue || item.GetChannel() == onlyChannelNr.Value)
|
||||||
{
|
{
|
||||||
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
var measurement = _listOfIMeasurement.First(f => onlyChannelNr != null && f.GetChannel() == onlyChannelNr.Value);
|
||||||
if (measurement != null &&
|
if ((measurement.MeasurementState == MeasurementStates.IsRunning
|
||||||
(measurement.MeasurementState == MeasurementStates.IsRunning
|
|| measurement.MeasurementState == MeasurementStates.IsWaitingForIntermediateData))
|
||||||
|| measurement.MeasurementState == MeasurementStates.IsWaitingForIntermediateData))
|
|
||||||
{
|
{
|
||||||
measurement.RequestIntermediateRecord();
|
measurement.RequestIntermediateRecord();
|
||||||
if (!ret.HasValue)
|
if (!ret.HasValue)
|
||||||
@@ -307,8 +298,5 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
}
|
}
|
||||||
return ret.HasValue ? ret.Value : false;
|
return ret.HasValue ? ret.Value : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null );
|
MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null );
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request for intermediate measurement state.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="onlyChannelNr"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// set up calibration parameter (calibration factor to default) and set meter into calibration mode
|
/// set up calibration parameter (calibration factor to default) and set meter into calibration mode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
5ed75d99ee45ff67821090f1b3dbb001dd9e4fe3
|
1a3d4919c9c702245832d925951f2b7cb72fc333
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
0d85a5b3a7561b41163c20e5dc7713bcd0d65555
|
f64d563def603c89cafafa61a3219ba97e1e344c
|
||||||
|
|||||||
Reference in New Issue
Block a user