GenesisMeter: - Avoid multiple assignment of identical register even for legacy without version information

This commit is contained in:
Thomas Wiedebusch
2023-12-11 10:59:31 +01:00
parent 43953671fc
commit 9e4749348e
@@ -369,6 +369,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
#region state machine and states
/// <summary>
/// Order number under which this meter has to be produced
/// </summary>
public Int32 OrderNumber;
/// <summary>
/// Radio address
/// </summary>
public Int64 RadioAddress;
/// <summary>
/// do not use it to set ProcessStatus
/// if you want to change ProcessStatus of this genesis use <see cref="ProcessStatus" />
@@ -1316,15 +1326,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <remarks date="2023-Nov-27" author="Thomas Wiedebusch">
/// - Remind installed FW version of FLEXNETVERSION for StoreAllConfigurations.
/// </remarks>
/// <remarks date="2023-Dec-08" author="Thomas Wiedebusch">
/// - Avoid doubled or tripled registers in register dictionary as the configuration.json may overlap
/// <remarks date="2023-Dec-08..11" author="Thomas Wiedebusch">
/// - Avoid multiple assignment of identical register in dictionary as the configuration.json may overlap
/// on some versions. If one register has been added, this passed the test and is valid for this FW.
/// It has to be avoided to have the register multiple times as it may cause unpredictable
/// assignments of values to one and reading and compare from another which doesn't have a value!
/// It has to be avoided to have the register multiple times as it may cause unpredictable assignments
/// of values to one and reading and compare from another which doesn't have a value!
/// </remarks>
private void ReadMeterFirmwareAndAssignRegisters()
{
//avoid overwriting of list if this already exits
// Avoid overwriting of list if this already exits
if (MeterAppListVersion.Any())
{
_logger.Warn($"Slot:{Slot} - Trying to override meter dictionary. Skip read out FW");
@@ -1394,7 +1404,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
ReadRegister(Register.System.MetrologyUpgradePermission));
//read core revision
var coreRegisterRead = RegisterConverter.ConvertTo<String>(ReadRegister(Register.System.CoreRevision, 16));
var coreRegisterRead = RegisterConverter.ConvertTo<String>(ReadRegister(Register.System.CoreRevision));
CoreRevision = null;
if (!string.IsNullOrEmpty(coreRegisterRead))
{
@@ -1443,26 +1453,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
{
var currentGroup = MeterAppListVersion.First(f => f.AppId == registerToCheck.Key.AppAddress);
if (!registerToCheck.Key.RegisterDetail.Version.First.HasValue &&
!registerToCheck.Key.RegisterDetail.Version.Last.HasValue)
{
//TODO legacy to collect not clear specified registers
registerToCheck.Key.IsAvailable = true;
_configRegister.MeterRegisterDic.TryAdd(registerToCheck.Key, null);
if (registerToCheck.Key?.RegisterDetail?.Version == null)
continue;
}
if (registerToCheck.Key.RegisterDetail.Version.Last != null &&
registerToCheck.Key.RegisterDetail.Version.First != null &&
registerToCheck.Key.RegisterDetail.Version.First.Value <= currentGroup.Version &&
registerToCheck.Key.RegisterDetail.Version.Last.Value >= currentGroup.Version)
if (// Legacy registers may not have an version assigned
(!registerToCheck.Key.RegisterDetail.Version.First.HasValue &&
!registerToCheck.Key.RegisterDetail.Version.Last.HasValue) ||
// Normal version assignment with first and last value
(registerToCheck.Key.RegisterDetail.Version.Last != null &&
registerToCheck.Key.RegisterDetail.Version.First != null &&
registerToCheck.Key.RegisterDetail.Version.First.Value <= currentGroup.Version &&
registerToCheck.Key.RegisterDetail.Version.Last.Value >= currentGroup.Version))
{
registerToCheck.Key.IsAvailable = true;
// Avoid doubled or tripled registers in dictionary if one has passed the test
if (_configRegister.MeterRegisterDic.Any(reg => reg.Key.GetIdent().Equals(registerToCheck.Key.GetIdent())))
// Avoid multiple assignment of identical register in dictionary if one has passed the test
if (_configRegister.MeterRegisterDic.Any(reg =>
reg.Key.GetIdent().Equals(registerToCheck.Key.GetIdent())))
continue;
_configRegister.MeterRegisterDic.TryAdd(registerToCheck.Key, null);
registerToCheck.Key.IsAvailable = true;
}
}
foreach (var checkMinRegister in Register.GetMinRequiredRegisters())
{
if (_configRegister.MeterRegisterDic.All(a => a.Key.GetIdent() != checkMinRegister))
@@ -1481,8 +1492,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
catch (Exception ex)
{
_logger.Warn(ex, $"Slot:{Slot} - Not able to set minimum list of registers. check json file for {checkMinRegister} ");
_logger.Warn(ex.Message, $"Slot:{Slot} - Unable to set minimum list of registers. Check json file for {checkMinRegister} ");
}
}
}
@@ -2210,7 +2220,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
a.Key.RegisterName.ToLower() == "storeconfiguration" ||
a.Key.RegisterName.ToLower() == "storecalibration"))
{
if (!a.Key.IsAvailable) continue;
if (!a.Key.IsAvailable)
continue;
// retries for each register access
var retriesLeft = 2;
@@ -2240,10 +2251,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
a.Key.RegisterName.ToLower() == "storeconfiguration" ||
a.Key.RegisterName.ToLower() == "storecalibration"))
{
if (!a.Key.IsAvailable) continue;
if (!a.Key.IsAvailable)
continue;
// For R1.2.x the read back is corrected
if ( InstalledFwVersion < 1200 && (a.Key.AppName == "SENSUSRADIO" || a.Key.AppName == "NA2WALARMS"))
if (InstalledFwVersion < 1200 && (a.Key.AppName == "SENSUSRADIO" || a.Key.AppName == "NA2WALARMS"))
{
continue;
}