GenesisMeter: - BuildFlexnetFwVersion: - handled optional leading "R" or "B" in strVersion input
This commit is contained in:
@@ -1182,15 +1182,23 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Building the FW Version string out of 2 bytes of data.
|
||||
/// REASON: FLEXNETVERSION is one application which does not follow the same rule of
|
||||
/// decimal numbers. Instead it uses hexadecimal digits.
|
||||
/// 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".
|
||||
///
|
||||
/// REASON: FLEXNETVERSION is one application which does not follow the same rule of decimal numbers.
|
||||
/// Instead it uses hexadecimal digits.
|
||||
/// </summary>
|
||||
/// <param name="fwVersion">version as hexadecimal result of version e.g. 0x1107 or 0x130B</param>
|
||||
/// <param name="strVersion">any string to evaluate like "11.07" or "R1.1.07" or "1.3.0B"</param>
|
||||
/// <param name="msb">most significant byte representing the major and minor version</param>
|
||||
/// <param name="lsb">last significant byte representing the built version</param>
|
||||
/// <returns>FLEXNET version string e.g. "R1.2.47" or "B1.2.0C" </returns>
|
||||
/// <remarks date="2023-Mar-02" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
/// <remarks date="2023-Mar-08" author="Thomas Wiedebusch">
|
||||
/// - Removed the optional leading "B" or "R" on strVersion input to create the fwVersion.
|
||||
/// </remarks>
|
||||
public static String BuildFlexnetFwVersion(out UInt32 fwVersion, String strVersion, Byte? msb = null,
|
||||
Byte? lsb = null)
|
||||
{
|
||||
@@ -1199,9 +1207,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
var builtMajor = 0;
|
||||
var builtMinor = 0;
|
||||
|
||||
var majorIndicatorForB = 8;
|
||||
// preset version with 0 as undetected
|
||||
fwVersion = 0;
|
||||
|
||||
// msb and lsb input have highest priority
|
||||
if (msb != null && lsb != null)
|
||||
{
|
||||
major = (Int32)((msb & 0xF0) >> 4);
|
||||
@@ -1212,9 +1222,26 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(strVersion))
|
||||
{
|
||||
// this is always a string like 1.0.2D or 9.0.2D,
|
||||
// this is always a string like "11.07" or "R1.1.07" or "B1.1.07" or "1.3.0B" or "9.0.2D",
|
||||
// a msb higher as 8 is indicating "B" version
|
||||
var strResult = Regex.Replace(strVersion, "[^0-9,A-F,a-f]", "");
|
||||
|
||||
// remove the optional leading "B" or "R" if strVersion is of form "R1.3.0B" or "B1.3.0B"
|
||||
// and remind the "B" by adding to major the value of 8
|
||||
var initialIdx = 0;
|
||||
var majorAdd = 0;
|
||||
var strLeadingSign = strVersion.Substring(0, 1);
|
||||
if (strLeadingSign == "B" )
|
||||
{
|
||||
initialIdx = 1;
|
||||
majorAdd = majorIndicatorForB;
|
||||
}
|
||||
if (strLeadingSign == "R")
|
||||
initialIdx = 1;
|
||||
|
||||
var strVersionWithoutLeadingId = strVersion.Substring(initialIdx, strVersion.Length - initialIdx);
|
||||
var strResult = Regex.Replace(strVersionWithoutLeadingId, "[^0-9,A-F,a-f]", "");
|
||||
|
||||
// here the leading characters and decimal points are removed e.g. "1107"
|
||||
var strMajor = strResult.Substring(0, 1);
|
||||
var strMinor = strResult.Substring(1, 1);
|
||||
var strBuiltMajor = strResult.Substring(2, 1);
|
||||
@@ -1226,16 +1253,20 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
|| !int.TryParse(strBuiltMajor, NumberStyles.HexNumber, new CultureInfo("en"), out builtMajor)
|
||||
|| !int.TryParse(strBuiltMinor, NumberStyles.HexNumber, new CultureInfo("en"), out builtMinor))
|
||||
{
|
||||
return "R" + strVersion;
|
||||
}
|
||||
// if parsing is not possible return the original strVersion
|
||||
return strVersion;
|
||||
}
|
||||
|
||||
// mark "R" or "B" version
|
||||
major += majorAdd;
|
||||
}
|
||||
|
||||
// release version marked with "R"
|
||||
if (major <= 8)
|
||||
if (major < majorIndicatorForB)
|
||||
return $"R{major:X0}.{minor:X0}.{builtMajor:X0}{builtMinor:X0}";
|
||||
|
||||
// debug version marked with "B"
|
||||
major -= 8;
|
||||
major -= majorIndicatorForB;
|
||||
return $"B{major:X0}.{minor:X0}.{builtMajor:X0}{builtMinor:X0}";
|
||||
}
|
||||
|
||||
@@ -1249,6 +1280,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <param name="msb">most significant byte hex</param>
|
||||
/// <param name="lsb">last significant byte hex</param>
|
||||
/// <returns>converted as string e.g. "2.34" or "2.0C" </returns>
|
||||
/// <remarks date="2023-Mar-06" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
public static String BuildFwVersion(out UInt32 fwVersion, Byte msb, Byte lsb)
|
||||
{
|
||||
fwVersion = (UInt32)(((msb & 0xF0) >> 4) * 10 + (msb & 0x0F)) * 100;
|
||||
@@ -1267,6 +1301,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </summary>
|
||||
/// <param name="fwVersion">firmware version as hex</param>
|
||||
/// <returns>converted "to "2.34" or "2.0C" </returns>
|
||||
/// <remarks date="2023-Mar-06" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
public static String BuildFwVersionStringFromHex(UInt32 fwVersion)
|
||||
{
|
||||
//skip leading 0
|
||||
@@ -1284,6 +1321,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </summary>
|
||||
/// <param name="fwVersion">firmware version as hex</param>
|
||||
/// <returns>converted to "2.34" or "2.01" </returns>
|
||||
/// <remarks date="2023-Mar-07" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
public static String BuildFwVersionStringFromDec(Int32? fwVersion)
|
||||
{
|
||||
return fwVersion == null ? "0.00" : $"{fwVersion / 100}.{fwVersion % 100:D2}";
|
||||
|
||||
Reference in New Issue
Block a user