Common: - configuration.json compatibility test and messages

This commit is contained in:
Thomas Wiedebusch
2025-08-07 16:39:12 +02:00
parent 3f53efa965
commit 1efe5400a6
17 changed files with 335 additions and 72 deletions
@@ -31,6 +31,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications
/// </summary>
public Int32? AppVersion;
/// <summary>
/// Max supported version of configuration.json for region EMEA.
/// </summary>
public String InterfaceMaxEmeaVersion;
/// <summary>
/// Max supported version of configuration.json for region NA.
/// </summary>
public String InterfaceMaxNaVersion;
/// <summary>
/// Get application name
/// </summary>
@@ -1,4 +1,6 @@
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
using System.Linq;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
{
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@@ -60,6 +62,15 @@
/// <param name="configurationJson"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
/// <remarks date="2025-Aug-05" author="Thomas Wiedebusch">
/// - AppId from Byte to UInt16 including typecast for Byte[] return. To external, it will be used as Byte
/// as before this change. But being able to parse the configuration.json with OPTICALINTERFACE using the
/// AppId 256, which exceeds the byte range as this isn't a real application, but will be used to identify
/// the interface (configuration.json) version.
/// </remarks>
/// <remarks date="2025-Aug-07" author="Thomas Wiedebusch">
/// - Extract the max supported versions for EMEA and NA to check the supported FW.
/// </remarks>
public void BuildRegisterList(String configurationJson)
{
IDictionary<String, AppSection> sections;
@@ -80,13 +91,34 @@
var appId = sectionKVP.Value.Id;
var appName = sectionKVP.Key;
var appVersion = sectionKVP.Value.Version.Last;
if (appName.Equals("OPTICALINTERFACE"))
{
var builds = sectionKVP.Value.Builds;
var emeaBuilds = builds["emea"];
var naBuilds = builds["na"];
String maxSupportedEmeaVersion = "";
String maxSupportedNaVersion = "";
if (emeaBuilds.Count > 0)
maxSupportedEmeaVersion = emeaBuilds[emeaBuilds.Count - 1].FW;
if (naBuilds.Count > 0)
maxSupportedNaVersion = naBuilds[naBuilds.Count - 1].FW;
ConfigApplicationDefinitions.Add(new ApplicationDefinition
{
AppId = appId,
AppName = appName,
AppVersion = appVersion,
InterfaceMaxEmeaVersion = maxSupportedEmeaVersion,
InterfaceMaxNaVersion = maxSupportedNaVersion
});
continue;
}
ConfigApplicationDefinitions.Add(new ApplicationDefinition
{
AppId = appId,
AppName = appName,
AppVersion = appVersion
});
AppVersion = appVersion,
});
var section = sectionKVP.Value;
@@ -125,7 +157,7 @@
AppName = appName,
DataType = GetType(detail.Type),
Default = values?.Default is Int64 d ? d : default(Int64?),
IsAvailable = default(Boolean),
IsAvailable = false,
Maximum = values?.Maximum is Int64 max ? max : default(Int64?),
Minimum = values?.Minimum is Int64 min ? min : default(Int64?),
RegAddressInApp = regId,
@@ -229,11 +229,26 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
/// <inheritdoc />
public String InterfaceVersion {
public String InterfaceVersion
{
protected set;
get;
} = "?";
/// <inheritdoc />
public String InterfaceMaxFwVersion
{
protected set;
get;
}
/// <inheritdoc />
public Boolean InterfaceSupportsFwVersion
{
protected set;
get;
}
/// <inheritdoc />
public String Region
{
@@ -241,7 +256,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
/// <inheritdoc />
public String MeterLength {
public String MeterLength
{
set;
get;
} = "?";
@@ -1287,7 +1303,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <summary>
/// Building the FW Version string and the hexadecimal version out of 2 bytes of data or from an
/// input string like "11.07" or "R1.1.07" or "B1.1.07" or "1.3.0B" or "9.0.2D".
/// input string like "1107", "11.07", "R1.1.07", "B1.1.07", "1.3.0B" or "9.0.2D".
///
/// REASON: FLEXNETVERSION is one application which does not follow the same rule of decimal numbers.
/// Instead, it uses hexadecimal digits.
@@ -1649,6 +1665,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
InstalledFwVersion = 0;
MeterAppListVersion.Clear();
CheckRegionSizeLutCrc();
UInt32 interfaceMaxEmeaVersion = 0;
UInt32 interfaceMaxNaVersion = 0;
// Get all existing applications from meter register dictionary
foreach (var meterApp in ConfigApplications.OrderBy(o => o.AppId))
{
@@ -1657,8 +1678,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
{
// Build the interface id for information of compatibility from FW to configuration.json
InterfaceVersion = BuildFwVersionStringFromDec(meterApp.AppVersion);
// Build the max supported versions for EMEA and NA to check the supported FW
if (Region.Equals("EMEA"))
InterfaceMaxFwVersion = BuildFlexnetFwVersion(out interfaceMaxEmeaVersion,
meterApp.InterfaceMaxEmeaVersion);
if (Region.Equals("NA"))
InterfaceMaxFwVersion = BuildFlexnetFwVersion(out interfaceMaxNaVersion,
meterApp.InterfaceMaxNaVersion);
continue;
}
UInt32 readFwVersion = 0;
UInt16 readFwCrc = 0;
var isInstalled = false;
@@ -1677,7 +1706,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
if (meterApp.AppName.Equals("FLEXNETVERSION"))
{
// msb and lsb are swapped during communication
FwVersion = BuildFlexnetFwVersion(out readFwVersion, null, readFwVersionBytes[1],
FwVersion = BuildFlexnetFwVersion(out readFwVersion, null, readFwVersionBytes[1],
readFwVersionBytes[0]);
versionString = FwVersion;
InstalledFwVersion = readFwVersion;
@@ -1724,8 +1753,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
});
}
CheckRegionSizeLutCrc();
//read metrology upgrade permission
MetrologyUpgradePermission = RegisterConverter.ByteArrayToValue<Byte>(
ReadRegister(Register.System.MetrologyUpgradePermission));
@@ -1789,6 +1816,20 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
Logger.Info($"Slot:{Slot} - Meter size: {MeterSize}");
Logger.Info($"Slot:{Slot} - Upgrade permission: {MetrologyUpgradePermission:X2}");
Logger.Info($"Slot:{Slot} - Interface (configuration.json) version: {InterfaceVersion}");
if (InstalledFwVersion != null &&
((Region.Equals("EMEA") && interfaceMaxEmeaVersion >= InstalledFwVersion) ||
(Region.Equals("NA") && interfaceMaxNaVersion >= InstalledFwVersion)))
{
InterfaceSupportsFwVersion = true;
Logger.Info($"Slot:{Slot} - Interface supports FW version: {FwVersion}");
}
else
{
InterfaceSupportsFwVersion = false;
Logger.Warn($"Slot:{Slot} - Interface does not support FW version! Installed FW version: {FwVersion}, " +
$"Interface supports max FW version: {InterfaceMaxFwVersion}");
}
// initial list of ALL registers defined in configuration.json
var tempConfigRegisters = ConfigRegister.MeterRegisterDic.ToList();
@@ -2745,7 +2786,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
private void PostRegisterRead(RegisterDefinition reg, Byte[] value)
{
var avoidLoggingRegisterNameList = Register.GetAvoidLogRegisters();
if (Configuration.UseRegisterWatchService && avoidLoggingRegisterNameList.All(regName => regName != reg.GetIdent()))
{
try
@@ -95,13 +95,30 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
/// <summary>
/// This is the version Id of the interface "configuration.json".
/// This is the version of the interface "configuration.json".
/// </summary>
String InterfaceVersion
{
get;
}
/// <summary>
/// This is the max supported firmware version of the interface "configuration.json".
/// It is the max version for a specific region.
/// </summary>
String InterfaceMaxFwVersion
{
get;
}
/// <summary>
/// This FW version is supported by the interface "configuration.json".
/// </summary>
Boolean InterfaceSupportsFwVersion
{
get;
}
/// <summary>
/// Length of the meter.
/// </summary>
@@ -447,6 +447,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.MockGenesis
/// <remarks date="2025-Jun-19" author="Thomas Wiedebusch">
/// - Avoid overwriting of list combined with valid register dictionary.
/// </remarks>
/// <remarks date="2025-Aug-07" author="Thomas Wiedebusch">
/// - Check interface compatibility.
/// </remarks>
protected override void ReadMeterFirmwareAndAssignRegisters()
{
// Avoid overwriting of list if this already exits
@@ -470,9 +473,26 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.MockGenesis
return;
}
UInt32 interfaceMaxEmeaVersion = 0;
UInt32 interfaceMaxNaVersion = 0;
var strInterfaceMaxEmeaVersion = "";
var strInterfaceMaxNaVersion = "";
//Get all existing applications from meter register dictionary
foreach (var meterApp in ConfigApplications.OrderBy(o => o.AppId))
{
if (meterApp.AppName.Equals("OPTICALINTERFACE"))
{
// Build the interface id for information of compatibility from FW to configuration.json
InterfaceVersion = BuildFwVersionStringFromDec(meterApp.AppVersion);
// Build the max supported versions for EMEA and NA to check the supported FW
strInterfaceMaxEmeaVersion = BuildFlexnetFwVersion(out interfaceMaxEmeaVersion,
meterApp.InterfaceMaxEmeaVersion);
strInterfaceMaxNaVersion = BuildFlexnetFwVersion(out interfaceMaxNaVersion,
meterApp.InterfaceMaxNaVersion);
continue;
}
// Take all listed config apps even if not installed
var app = new MeterApplications
{
@@ -530,6 +550,28 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.MockGenesis
Region = "EMEA";
}
}
// Assign the max supported FW version of the interface depending on the region
if (Region.Equals("EMEA"))
InterfaceMaxFwVersion = strInterfaceMaxEmeaVersion;
if (Region.Equals("NA"))
InterfaceMaxFwVersion = strInterfaceMaxNaVersion;
// Check if the interface supports the FW
if (InstalledFwVersion != null &&
((Region.Equals("EMEA") && interfaceMaxEmeaVersion >= InstalledFwVersion) ||
(Region.Equals("NA") && interfaceMaxNaVersion >= InstalledFwVersion)))
{
InterfaceSupportsFwVersion = true;
Logger.Info($"Slot:{Slot} - Interface supports FW version: {FwVersion}");
}
else
{
InterfaceSupportsFwVersion = false;
Logger.Warn($"Slot:{Slot} - Interface does not support FW version! Installed FW version: {FwVersion}, " +
$"Interface supports max FW version: {InterfaceMaxFwVersion}");
}
}
catch (Exception ex)
{