merge
This commit is contained in:
@@ -63,6 +63,14 @@
|
||||
/// </summary>
|
||||
Unknown,
|
||||
/// <summary>
|
||||
/// Meter application detected but not checked
|
||||
/// </summary>
|
||||
MeterAppInstalledUnchecked,
|
||||
/// <summary>
|
||||
/// Meter application is not required
|
||||
/// </summary>
|
||||
MeterAppNotRequired,
|
||||
/// <summary>
|
||||
/// Delimiter for list
|
||||
/// </summary>
|
||||
MeterAppStateListDelimiter
|
||||
|
||||
@@ -20,47 +20,54 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Const
|
||||
public MeterAppStateInfo()
|
||||
{
|
||||
_stateInfos = new MeterAppStateText[(Int32)MeterAppState.MeterAppStateListDelimiter];
|
||||
_stateInfos[0].State = MeterAppState.MeterAppNotInstalled;
|
||||
_stateInfos[0].Message = Resources.StrMeterAppNotInstalled;
|
||||
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppNotInstalled].State = MeterAppState.MeterAppNotInstalled;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppNotInstalled].Message = Resources.StrMeterAppNotInstalled;
|
||||
|
||||
_stateInfos[1].State = MeterAppState.MeterAppUpToDate;
|
||||
_stateInfos[1].Message = Resources.StrMeterAppUpToDate;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppNotRequired].State = MeterAppState.MeterAppNotRequired;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppNotRequired].Message = Resources.StrMeterAppNotRequired;
|
||||
|
||||
_stateInfos[2].State = MeterAppState.MeterAppInstallationRequired;
|
||||
_stateInfos[2].Message = Resources.StrMeterAppInstallationRequired;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppUpToDate].State = MeterAppState.MeterAppUpToDate;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppUpToDate].Message = Resources.StrMeterAppUpToDate;
|
||||
|
||||
_stateInfos[3].State = MeterAppState.MeterAppVersionOutdated;
|
||||
_stateInfos[3].Message = Resources.StrMeterAppVersionOutdated;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppInstallationRequired].State = MeterAppState.MeterAppInstallationRequired;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppInstallationRequired].Message = Resources.StrMeterAppInstallationRequired;
|
||||
|
||||
_stateInfos[4].State = MeterAppState.InvalidCrc;
|
||||
_stateInfos[4].Message = Resources.StrInvalidCrc;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppVersionOutdated].State = MeterAppState.MeterAppVersionOutdated;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppVersionOutdated].Message = Resources.StrMeterAppVersionOutdated;
|
||||
|
||||
_stateInfos[5].State = MeterAppState.MeterAppErasureRequired;
|
||||
_stateInfos[5].Message = Resources.StrMeterAppErasureRequired;
|
||||
_stateInfos[(Int32)MeterAppState.InvalidCrc].State = MeterAppState.InvalidCrc;
|
||||
_stateInfos[(Int32)MeterAppState.InvalidCrc].Message = Resources.StrInvalidCrc;
|
||||
|
||||
_stateInfos[6].State = MeterAppState.MeterAppDownloadSucceeded;
|
||||
_stateInfos[6].Message = Resources.StrMeterAppDownloadSucceeded;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppErasureRequired].State = MeterAppState.MeterAppErasureRequired;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppErasureRequired].Message = Resources.StrMeterAppErasureRequired;
|
||||
|
||||
_stateInfos[7].State = MeterAppState.MeterAppDownloadSuspicious;
|
||||
_stateInfos[7].Message = Resources.StrMeterAppDownloadSuspicious;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadSucceeded].State = MeterAppState.MeterAppDownloadSucceeded;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadSucceeded].Message = Resources.StrMeterAppDownloadSucceeded;
|
||||
|
||||
_stateInfos[8].State = MeterAppState.MeterAppSuccessfulErased;
|
||||
_stateInfos[8].Message = Resources.StrMeterAppSuccessfulErased;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadSuspicious].State = MeterAppState.MeterAppDownloadSuspicious;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadSuspicious].Message = Resources.StrMeterAppDownloadSuspicious;
|
||||
|
||||
_stateInfos[9].State = MeterAppState.MeterAppSuccessfulUpdated;
|
||||
_stateInfos[9].Message = Resources.StrMeterAppSuccessfulUpdated;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppSuccessfulErased].State = MeterAppState.MeterAppSuccessfulErased;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppSuccessfulErased].Message = Resources.StrMeterAppSuccessfulErased;
|
||||
|
||||
_stateInfos[10].State = MeterAppState.MeterAppDownloadFailed;
|
||||
_stateInfos[10].Message = Resources.StrMeterAppDownloadFailed;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppSuccessfulUpdated].State = MeterAppState.MeterAppSuccessfulUpdated;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppSuccessfulUpdated].Message = Resources.StrMeterAppSuccessfulUpdated;
|
||||
|
||||
_stateInfos[11].State = MeterAppState.MeterAppDownloadActive;
|
||||
_stateInfos[11].Message = Resources.StrMeterAppDownloadActive;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadFailed].State = MeterAppState.MeterAppDownloadFailed;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadFailed].Message = Resources.StrMeterAppDownloadFailed;
|
||||
|
||||
_stateInfos[12].State = MeterAppState.FileAppInvalid;
|
||||
_stateInfos[12].Message = Resources.StrFileAppInvalid;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadActive].State = MeterAppState.MeterAppDownloadActive;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppDownloadActive].Message = Resources.StrMeterAppDownloadActive;
|
||||
|
||||
_stateInfos[13].State = MeterAppState.Unknown;
|
||||
_stateInfos[13].Message = "";
|
||||
_stateInfos[(Int32)MeterAppState.FileAppInvalid].State = MeterAppState.FileAppInvalid;
|
||||
_stateInfos[(Int32)MeterAppState.FileAppInvalid].Message = Resources.StrFileAppInvalid;
|
||||
|
||||
_stateInfos[(Int32)MeterAppState.Unknown].State = MeterAppState.Unknown;
|
||||
_stateInfos[(Int32)MeterAppState.Unknown].Message = Resources.StrMeterAppStateUnknown;
|
||||
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppInstalledUnchecked].State = MeterAppState.MeterAppInstalledUnchecked;
|
||||
_stateInfos[(Int32)MeterAppState.MeterAppInstalledUnchecked].Message = Resources.StrMeterAppDetected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+29
-2
@@ -78,6 +78,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Installed.
|
||||
/// </summary>
|
||||
public static string StrMeterAppDetected {
|
||||
get {
|
||||
return ResourceManager.GetString("StrMeterAppDetected", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to DOWNLOAD....
|
||||
/// </summary>
|
||||
@@ -133,7 +142,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Application not required.
|
||||
/// Looks up a localized string similar to Not installed.
|
||||
/// </summary>
|
||||
public static string StrMeterAppNotInstalled {
|
||||
get {
|
||||
@@ -141,6 +150,24 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Not required.
|
||||
/// </summary>
|
||||
public static string StrMeterAppNotRequired {
|
||||
get {
|
||||
return ResourceManager.GetString("StrMeterAppNotRequired", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Installation state unknown.
|
||||
/// </summary>
|
||||
public static string StrMeterAppStateUnknown {
|
||||
get {
|
||||
return ResourceManager.GetString("StrMeterAppStateUnknown", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Erasure succeeded.
|
||||
/// </summary>
|
||||
@@ -160,7 +187,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Up To Date.
|
||||
/// Looks up a localized string similar to Okay.
|
||||
/// </summary>
|
||||
public static string StrMeterAppUpToDate {
|
||||
get {
|
||||
|
||||
@@ -118,16 +118,16 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="StrMeterAppNotInstalled" xml:space="preserve">
|
||||
<value>Anwendung nicht erforderlich</value>
|
||||
<value>Nicht installiert</value>
|
||||
</data>
|
||||
<data name="StrMeterAppUpToDate" xml:space="preserve">
|
||||
<value>Version ist aktuell</value>
|
||||
<value>Okay</value>
|
||||
</data>
|
||||
<data name="StrMeterAppInstallationRequired" xml:space="preserve">
|
||||
<value>Installation notwendig</value>
|
||||
</data>
|
||||
<data name="StrMeterAppVersionOutdated" xml:space="preserve">
|
||||
<value>Version ist unterschiedlich</value>
|
||||
<value>Update erforderlich</value>
|
||||
</data>
|
||||
<data name="StrInvalidCrc" xml:space="preserve">
|
||||
<value>Prüfsummenfehler (CRC)</value>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="StrFileAppInvalid" xml:space="preserve">
|
||||
<value>Ungültige Aktualisierungsdatei</value>
|
||||
</data>
|
||||
<data name="StrMeterAppDetected" xml:space="preserve">
|
||||
<value>Installiert</value>
|
||||
</data>
|
||||
<data name="StrMeterAppStateUnknown" xml:space="preserve">
|
||||
<value>Installationszustand unbekannt</value>
|
||||
</data>
|
||||
<data name="StrMeterAppNotRequired" xml:space="preserve">
|
||||
<value>Nicht eforderlich</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -118,10 +118,10 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="StrMeterAppNotInstalled" xml:space="preserve">
|
||||
<value>Application not required</value>
|
||||
<value>Not installed</value>
|
||||
</data>
|
||||
<data name="StrMeterAppUpToDate" xml:space="preserve">
|
||||
<value>Up To Date</value>
|
||||
<value>Okay</value>
|
||||
</data>
|
||||
<data name="StrMeterAppInstallationRequired" xml:space="preserve">
|
||||
<value>Installation required</value>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="StrFileAppInvalid" xml:space="preserve">
|
||||
<value>INVALID UPDATE FILE</value>
|
||||
</data>
|
||||
<data name="StrMeterAppDetected" xml:space="preserve">
|
||||
<value>Installed</value>
|
||||
</data>
|
||||
<data name="StrMeterAppStateUnknown" xml:space="preserve">
|
||||
<value>Installation state unknown</value>
|
||||
</data>
|
||||
<data name="StrMeterAppNotRequired" xml:space="preserve">
|
||||
<value>Not required</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -219,6 +219,7 @@
|
||||
<Compile Include="..\..\..\..\.shared\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="PowerCorrection.cs" />
|
||||
<Compile Include="Consts\ErrorState.cs" />
|
||||
<Compile Include="Consts\LedMode.cs" />
|
||||
<Compile Include="GenesisMeter.cs" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -10,6 +11,7 @@ using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Authentication;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Timers;
|
||||
using NLog;
|
||||
@@ -176,6 +178,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </summary>
|
||||
private String _password;
|
||||
|
||||
/// <summary>
|
||||
/// reminder for last communication acknowledge code to detect communication errors
|
||||
/// </summary>
|
||||
private RequestAcknowledgeState _acknowledgeCode;
|
||||
|
||||
/// <summary>
|
||||
/// default false only enabled by <see cref="EnableAutoLogon"/>
|
||||
/// when it is true, the meter will enforce the login when session is gone or access is denied
|
||||
@@ -1174,32 +1181,98 @@ 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. After the conversion of this
|
||||
/// number to a pure Uint32, needed for comparison of file versions in configuration.json,
|
||||
/// the hexadecimal outline will be lost and the comparison with the rowproduct.txt fails.
|
||||
/// FW-update needs this information to validate a tested package!
|
||||
/// 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>
|
||||
public static String BuildFlexnetFwVersion(out UInt32 fwVersion, String strVersion, Byte? msb = null,
|
||||
Byte? lsb = null)
|
||||
{
|
||||
var major = 0;
|
||||
var minor = 0;
|
||||
var builtMajor = 0;
|
||||
var builtMinor = 0;
|
||||
|
||||
// preset version with 0 as undetected
|
||||
fwVersion = 0;
|
||||
|
||||
if (msb != null && lsb != null)
|
||||
{
|
||||
major = (Int32)((msb & 0xF0) >> 4);
|
||||
minor = (Int32)(msb & 0x0F);
|
||||
builtMajor = (Int32)((lsb & 0xF0) >> 4);
|
||||
builtMinor = (Int32)(lsb & 0x0F);
|
||||
fwVersion = (UInt32)((msb << 8) + lsb);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(strVersion))
|
||||
{
|
||||
// this is always a string like 1.0.2D or 9.0.2D,
|
||||
// a msb higher as 8 is indicating "B" version
|
||||
var strResult = Regex.Replace(strVersion, "[^0-9,A-F,a-f]", "");
|
||||
var strMajor = strResult.Substring(0, 1);
|
||||
var strMinor = strResult.Substring(1, 1);
|
||||
var strBuiltMajor = strResult.Substring(2, 1);
|
||||
var strBuiltMinor = strResult.Substring(3, 1);
|
||||
|
||||
if (!UInt32.TryParse(strResult, NumberStyles.HexNumber, new CultureInfo("en"), out fwVersion)
|
||||
|| !Int32.TryParse(strMajor, NumberStyles.HexNumber, new CultureInfo("en"), out major)
|
||||
|| !Int32.TryParse(strMinor, NumberStyles.HexNumber, new CultureInfo("en"), out minor)
|
||||
|| !Int32.TryParse(strBuiltMajor, NumberStyles.HexNumber, new CultureInfo("en"), out builtMajor)
|
||||
|| !Int32.TryParse(strBuiltMinor, NumberStyles.HexNumber, new CultureInfo("en"), out builtMinor))
|
||||
{
|
||||
return "R" + strVersion;
|
||||
}
|
||||
}
|
||||
|
||||
// release version marked with "R"
|
||||
if (major <= 8)
|
||||
return $"R{major:X0}.{minor:X0}.{builtMajor:X0}{builtMinor:X0}";
|
||||
|
||||
// debug version marked with "B"
|
||||
major -= 8;
|
||||
return $"B{major:X0}.{minor:X0}.{builtMajor:X0}{builtMinor:X0}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Building the FW Version string out of 2 bytes of data.
|
||||
/// </summary>
|
||||
/// <param name="fwVersion">firmware version as hex</param>
|
||||
/// <param name="msb">most significant byte</param>
|
||||
/// <param name="lsb">last significant byte</param>
|
||||
/// <returns>converted "msb.lsb" as string e.g. "12.34" or "2.0C" </returns>
|
||||
public static String BuildFwVersionString(Byte msb, Byte lsb)
|
||||
/// <returns>converted "msb.lsb" as string e.g. "2.34" or "2.0C" </returns>
|
||||
public static String BuildFwVersion(out UInt32 fwVersion, Byte msb, Byte lsb)
|
||||
{
|
||||
fwVersion = (UInt32)((msb << 8) + lsb);
|
||||
//skip leading 0
|
||||
var msbPartString = (msb & 0xF0) > 0 ? $"{(msb & 0xF0) >> 4:X0}" : "";
|
||||
var msbPartString = (msb & 0xF0) > 0 ? $"{(msb & 0xF0) >> 4:X0}." : "";
|
||||
return msbPartString + $"{msb & 0x0F:X0}" + "." + $"{(lsb & 0xF0) >> 4:X1}" + $"{lsb & 0x0F:X1}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Building a version string with 2 decimals e.g. " 12.34"
|
||||
/// Building the FW Version string out of UInt32 as hexadecimal input.
|
||||
/// </summary>
|
||||
/// <remarks date="2022-Dec-02" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
/// <param name="version">the version</param>
|
||||
/// <returns>converted version to string </returns>
|
||||
public static String BuildFwVersionString(Int32? version)
|
||||
/// <param name="fwVersion">firmware version as hex</param>
|
||||
/// <returns>converted "to "2.34" or "2.0C" </returns>
|
||||
public static String BuildFwVersionStringFromHex(UInt32 fwVersion)
|
||||
{
|
||||
return version == null ? "0.00" : $@"{version / 100}.{version % 100:D2}";
|
||||
//skip leading 0
|
||||
var msbPartString = (fwVersion & 0xF000) > 0 ? $"{(fwVersion & 0xF000) >> 12:X0}." : "";
|
||||
return msbPartString + $"{(fwVersion & 0xF00) >> 8:X0}.{(fwVersion & 0x0F0) >> 4:X0}{fwVersion & 0x00F:X0}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Building the FW Version string out of Int32 as decimal input.
|
||||
/// </summary>
|
||||
/// <param name="fwVersion">firmware version as hex</param>
|
||||
/// <returns>converted to "2.34" or "2.01" </returns>
|
||||
public static String BuildFwVersionStringFromDec(Int32? fwVersion)
|
||||
{
|
||||
if (fwVersion == 0)
|
||||
return "0.00";
|
||||
return $"{fwVersion / 100}.{fwVersion % 100:D2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1208,10 +1281,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
public List<MeterApplications> MeterAppListVersion = new List<MeterApplications>();
|
||||
|
||||
/// <summary>
|
||||
/// Core revision of boot code.
|
||||
/// Core revision of boot code as hex number.
|
||||
/// </summary>
|
||||
public UInt32 CoreRevision;
|
||||
|
||||
/// <summary>
|
||||
/// Core revision of boot code as string.
|
||||
/// </summary>
|
||||
//public String CoreRevision;
|
||||
public Int32? CoreRevision;
|
||||
public String StrCoreRevision;
|
||||
|
||||
/// <summary>
|
||||
/// This is the FLEXNETVERSION version which describes the entire packet.
|
||||
@@ -1221,7 +1299,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <summary>
|
||||
/// This is the FLEXNETVERSION version which describes the entire packet.
|
||||
/// </summary>
|
||||
public UInt32 InstalledFwVersion;
|
||||
public UInt32? InstalledFwVersion;
|
||||
|
||||
/// <summary>
|
||||
/// This is the Metrology Lookup Table CRC.
|
||||
@@ -1331,7 +1409,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
foreach (var registerToCheck in tempConfigRegisters)
|
||||
{
|
||||
if (registerToCheck.Key?.RegisterDetail?.Version == null ||
|
||||
if (registerToCheck.Key?.RegisterDetail?.Version == null ||
|
||||
MeterAppListVersion.All(f => f.AppId != registerToCheck.Key.AppAddress))
|
||||
continue;
|
||||
|
||||
@@ -1413,10 +1491,19 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <remarks date="2024-Feb-22" author="Thomas Wiedebusch">
|
||||
/// - Build dictionary for debug to observe if configuration.json contains overlapping versions.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-23" author="Thomas Wiedebusch">
|
||||
/// - On missing answer mark as communication error being able to compare against not-installed. This issue
|
||||
/// was responsible to start a FW update process in the CUST as it assumes the installation was incomplete
|
||||
/// but it couldn't detect those applications due to communication issues.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-May-06" author="Thomas Wiedebusch">
|
||||
/// - BuildFlexnetFwVersion,
|
||||
/// - Calculate core revision.
|
||||
/// </remarks>
|
||||
private void ReadMeterFirmwareAndAssignRegisters()
|
||||
{
|
||||
// Avoid overwriting of list if this already exits
|
||||
if (MeterAppListVersion.Any())
|
||||
if (MeterAppListVersion.Any() && MeterAppListVersion.All(f => f.Status != MeterAppState.Unknown))
|
||||
{
|
||||
_logger.Warn($"Slot:{Slot} - Trying to override meter dictionary. Skip read out FW");
|
||||
return;
|
||||
@@ -1424,15 +1511,17 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
|
||||
// On new readout reset the installed version
|
||||
InstalledFwVersion = 0;
|
||||
MeterAppListVersion.Clear();
|
||||
|
||||
//Get all existing applications from meter register dictionary
|
||||
foreach (var appVersionToRead in _configApplications.OrderBy(o => o.AppId))
|
||||
foreach (var meterApp in _configApplications.OrderBy(o => o.AppId))
|
||||
{
|
||||
UInt32 readFwVersion = 0;
|
||||
UInt16 readFwCrc = 0;
|
||||
var isInstalled = false;
|
||||
var installationStatus = MeterAppState.MeterAppNotInstalled;
|
||||
var versionString = "";
|
||||
if (WriteRegister(Register.System.CheckFwPresence, appVersionToRead.AppId))
|
||||
if (WriteRegister(Register.System.CheckFwPresence, meterApp.AppId))
|
||||
{
|
||||
//read version, skip retries on SYSTEM 0x04-> FW nor present is a valid feedback
|
||||
var readFwVersionBytes = ReadRegister(Register.System.CheckFwPresence, 4);
|
||||
@@ -1440,40 +1529,53 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
//the FW version as UInt32 will be used for comparison with the configuration.json
|
||||
if (readFwVersionBytes != null && readFwVersionBytes.Length > 0)
|
||||
{
|
||||
readFwVersion = (UInt32)(((readFwVersionBytes[1] & 0xF0) >> 4) * 10 +
|
||||
(readFwVersionBytes[1] & 0x0F)) * 100;
|
||||
readFwVersion += (UInt32)(((readFwVersionBytes[0] & 0xF0) >> 4) * 10 +
|
||||
(readFwVersionBytes[0] & 0x0F));
|
||||
//build the version string, because e.g. FLEXNETVERSION is one application which does not
|
||||
//follow the same rule. After the upper conversion, the hexadecimal outline will be lost
|
||||
versionString = BuildFwVersionString(readFwVersionBytes[1], readFwVersionBytes[0]);
|
||||
if (appVersionToRead.AppName == "FLEXNETVERSION")
|
||||
if (meterApp.AppName == "FLEXNETVERSION")
|
||||
{
|
||||
FwVersion = versionString;
|
||||
// msb and lsb are swapped during communication
|
||||
FwVersion = BuildFlexnetFwVersion(out readFwVersion, null, readFwVersionBytes[1], readFwVersionBytes[0]);
|
||||
versionString = FwVersion;
|
||||
InstalledFwVersion = readFwVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
// msb and lsb are swapped during communication
|
||||
versionString = BuildFwVersion(out readFwVersion, readFwVersionBytes[1], readFwVersionBytes[0]);
|
||||
}
|
||||
|
||||
if (readFwVersion != 0)
|
||||
{
|
||||
isInstalled = true;
|
||||
installationStatus = MeterAppState.MeterAppInstalledUnchecked;
|
||||
//write application Id to CRC register
|
||||
if (WriteRegister(Register.System.CheckFwCrc, appVersionToRead.AppId))
|
||||
if (WriteRegister(Register.System.CheckFwCrc, meterApp.AppId))
|
||||
{
|
||||
readFwCrc = RegisterConverter.ByteArrayToValue<UInt16>(ReadRegister(Register.System.CheckFwCrc));
|
||||
}
|
||||
}
|
||||
}
|
||||
// missing answer
|
||||
else if (RequestAcknowledgeState.NoResponse == _acknowledgeCode)
|
||||
{
|
||||
installationStatus = MeterAppState.Unknown;
|
||||
}
|
||||
}
|
||||
// missing answer
|
||||
else if (RequestAcknowledgeState.NoResponse == _acknowledgeCode)
|
||||
{
|
||||
installationStatus = MeterAppState.Unknown;
|
||||
}
|
||||
|
||||
//add application always, even if this is not installed. This will be used for FW updates
|
||||
MeterAppListVersion.Add(new MeterApplications
|
||||
{
|
||||
AppId = appVersionToRead.AppId,
|
||||
AppId = meterApp.AppId,
|
||||
Version = readFwVersion,
|
||||
StrVersion = versionString,
|
||||
AppName = appVersionToRead.AppName,
|
||||
AppName = meterApp.AppName,
|
||||
Crc = readFwCrc,
|
||||
Status = isInstalled ? MeterAppState.Unknown : MeterAppState.MeterAppNotInstalled,
|
||||
Status = installationStatus,
|
||||
IsInstalled = isInstalled,
|
||||
});
|
||||
}
|
||||
@@ -1486,28 +1588,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
|
||||
//read core revision
|
||||
var coreRegisterRead = RegisterConverter.ByteArrayToValue<String>(ReadRegister(Register.System.CoreRevision, 16));
|
||||
CoreRevision = null;
|
||||
CoreRevision = 0;
|
||||
StrCoreRevision = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(coreRegisterRead))
|
||||
{
|
||||
var coreRevisionStrings = coreRegisterRead.Split('\0');
|
||||
//remove Cordonel sub-string and the blanks
|
||||
// remove Cordonel sub-string and the blanks
|
||||
var coreRevisionSubString = $"{coreRevisionStrings[0].ToLower().Replace("cordonel ", "")}";
|
||||
var coreRevisionSubStrings = coreRevisionSubString.Split('.');
|
||||
if (int.TryParse(coreRevisionSubStrings[0], out var coreRevisionMsb))
|
||||
var strResult = Regex.Replace(coreRevisionSubString, "[^0-9,A-F,a-f]", "");
|
||||
if (UInt32.TryParse(strResult, NumberStyles.HexNumber, new CultureInfo("en"), out CoreRevision))
|
||||
{
|
||||
if (int.TryParse(coreRevisionSubStrings[1], out var coreRevisionLsb))
|
||||
{
|
||||
CoreRevision = coreRevisionMsb * 100 + coreRevisionLsb;
|
||||
}
|
||||
StrCoreRevision = BuildFwVersionStringFromHex(CoreRevision);
|
||||
}
|
||||
}
|
||||
|
||||
//log application information to file
|
||||
// log application information to file
|
||||
_logger.Info($"Slot:{Slot} - PCB ID: {PcbId}");
|
||||
_logger.Info($"Slot:{Slot} - Date time (UTC): {DateTimeOffset.UtcNow}");
|
||||
if (CoreRevision != null)
|
||||
if (CoreRevision != 0)
|
||||
{
|
||||
_logger.Info($"Slot:{Slot} - System Core Revision: {BuildFwVersionString(CoreRevision)}");
|
||||
_logger.Info($"Slot:{Slot} - System Core Revision: {StrCoreRevision}");
|
||||
}
|
||||
|
||||
_logger.Info($"Slot:{Slot} - Region: {Region}");
|
||||
@@ -1521,6 +1622,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
var versionString = fm.IsInstalled
|
||||
? $"V: {fm.StrVersion} - CRC: 0x{fm.Crc:X4}" : "Not installed";
|
||||
if (fm.Status == MeterAppState.Unknown)
|
||||
versionString = "Communication error";
|
||||
|
||||
_logger.Info($"Slot:{Slot} - AppId: 0x{fm.AppId:X2} - {versionString} - AppName: {fm.AppName}");
|
||||
}
|
||||
|
||||
@@ -2020,13 +2124,20 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute request protocol and acts on response code.
|
||||
/// </summary>
|
||||
/// <remarks date="2020-Dec-19" author="Thomas Wiedebusch">
|
||||
/// - Removed throw because the throw always kicks in to
|
||||
/// the FW-Update process causing an unpredictable stop!
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-22" author="Thomas Wiedebusch">
|
||||
/// - Remind last communication acknowledge code.
|
||||
/// </remarks>
|
||||
private void RequestProtocolProcess()
|
||||
{
|
||||
switch (RequestProtocol.ProcessRecordList())
|
||||
_acknowledgeCode = RequestProtocol.ProcessRecordList();
|
||||
switch (_acknowledgeCode)
|
||||
{
|
||||
case RequestAcknowledgeState.AuthorizationRequired:
|
||||
|
||||
@@ -2359,7 +2470,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
apps.Add(new CordonelAppVersion(item.AppId, item.StrVersion, item.AppId != 15));
|
||||
}
|
||||
|
||||
apps.Add(new CordonelAppVersion(-1, BuildFwVersionString(CoreRevision), false));
|
||||
apps.Add(new CordonelAppVersion(-1, StrCoreRevision, false));
|
||||
|
||||
var url = $"{ServiceUrls.MeterProcessStateUrl()}SetCordonelProgress?PcbId={PcbId}" +
|
||||
$"&ProgressName={progressName}&version={version}";
|
||||
@@ -2423,14 +2534,14 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
try
|
||||
{
|
||||
var valuestring = "NULL";
|
||||
var valueString = "NULL";
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
valuestring = BitConverter.ToString(value);
|
||||
valueString = BitConverter.ToString(value);
|
||||
}
|
||||
|
||||
var url = $"{Configuration.RegisterWatchServiceUrl}RegisterWrite?PcbID={PcbId}&Address={BitConverter.ToString(reg.RegisterAddress)}&value={valuestring}";
|
||||
var url = $"{Configuration.RegisterWatchServiceUrl}RegisterWrite?PcbID={PcbId}&Address={BitConverter.ToString(reg.RegisterAddress)}&value={valueString}";
|
||||
|
||||
var result = LocalWebRequest.PostRequestAsync(url, 1500, string.Empty);
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
/// <summary>
|
||||
/// Power correction parameters used for overestimated power consumption on
|
||||
/// Cordonel FW update from:
|
||||
/// EMEA below R1.3.x
|
||||
/// NA below R2.0.07
|
||||
/// </summary>
|
||||
public class PowerCorrection
|
||||
{
|
||||
#region Data Base at EOL - Production
|
||||
/// <summary>
|
||||
/// Unique identification of PCB
|
||||
/// </summary>
|
||||
public String PcbId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date time UTC at EOL - Production
|
||||
/// </summary>
|
||||
public DateTime? ProductionDateTimeUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used seconds at EOL - Production
|
||||
/// </summary>
|
||||
public UInt32 ProductionTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used charge of batteries at EOL - Production
|
||||
/// </summary>
|
||||
public UInt64 ProductionTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Radio system state at EOL - Production
|
||||
/// </summary>
|
||||
public Byte? ProductionRadioSystemState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse adapter was installed during at EOL - Production
|
||||
/// </summary>
|
||||
public Boolean ProductionPulseAdapterIsInstalled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse mode during at EOL - Production
|
||||
/// </summary>
|
||||
public Byte ProductionPulseMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse sequence counter during at EOL - Production
|
||||
/// </summary>
|
||||
public Byte ProductionPulseSequenceCounter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse distribution at EOL - Production
|
||||
/// </summary>
|
||||
public Boolean ProductionPulseEvenDistribution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Detected region at EOL - Production
|
||||
/// </summary>
|
||||
public String ProductionRegion { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance readout
|
||||
|
||||
/// <summary>
|
||||
/// Detected FW version before maintenance
|
||||
/// </summary>
|
||||
public UInt32 ActualFwVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date time UTC at time of maintenance
|
||||
/// </summary>
|
||||
public DateTime? ActualDateTimeUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used seconds before maintenance
|
||||
/// </summary>
|
||||
public UInt32 ActualTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used charge of batteries before maintenance
|
||||
/// </summary>
|
||||
public UInt64 ActualTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Actual detected radio system state at maintenance
|
||||
/// </summary>
|
||||
public Byte? ActualRadioSystemState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Detection of pulse adapter installation
|
||||
/// </summary>
|
||||
public Boolean ActualPulseAdapterIsInstalled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse mode during maintenance
|
||||
/// </summary>
|
||||
public Byte ActualPulseMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse distribution during maintenance
|
||||
/// </summary>
|
||||
public Boolean ActualPulseEvenDistribution { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance calculation
|
||||
|
||||
/// <summary>
|
||||
/// FW version for the update
|
||||
/// </summary>
|
||||
public UInt32 RequiredFwVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculated pulse report length
|
||||
/// </summary>
|
||||
public UInt32 PulseReportLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used seconds after EOL and before maintenance
|
||||
/// </summary>
|
||||
public UInt32 AfterProductionTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Overestimated total used charge before maintenance
|
||||
/// </summary>
|
||||
public UInt64 OverestimatedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lowest threshold for total used charge calculated during maintenance
|
||||
/// </summary>
|
||||
public UInt64 MinimumTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Corrected total used charge during maintenance
|
||||
/// </summary>
|
||||
public UInt64 CorrectedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionFileSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionCRC { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -124,7 +124,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Reading registers after update.
|
||||
/// Looks up a localized string similar to Reading registers after maintenance.
|
||||
/// </summary>
|
||||
internal static string StrReadRegistersAfterUpdate {
|
||||
get {
|
||||
@@ -133,7 +133,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Reading registers before update.
|
||||
/// Looks up a localized string similar to Reading registers before maintenance.
|
||||
/// </summary>
|
||||
internal static string StrReadRegistersBeforeUpdate {
|
||||
get {
|
||||
|
||||
@@ -148,10 +148,10 @@
|
||||
<value>Schreibe Register</value>
|
||||
</data>
|
||||
<data name="StrReadRegistersBeforeUpdate" xml:space="preserve">
|
||||
<value>Lese Register vor dem Firmware Update</value>
|
||||
<value>Lese Register vor der Wartung</value>
|
||||
</data>
|
||||
<data name="StrReadRegistersAfterUpdate" xml:space="preserve">
|
||||
<value>Lese Register nach dem Firmware Update</value>
|
||||
<value>Lese Register nach der Wartung</value>
|
||||
</data>
|
||||
<data name="StrRegisterRecoveryExec" xml:space="preserve">
|
||||
<value>Ausführung Konfigurationswiederherstellungssequenz....</value>
|
||||
|
||||
@@ -139,10 +139,10 @@
|
||||
<value>Scan port</value>
|
||||
</data>
|
||||
<data name="StrReadRegistersAfterUpdate" xml:space="preserve">
|
||||
<value>Reading registers after update</value>
|
||||
<value>Reading registers after maintenance</value>
|
||||
</data>
|
||||
<data name="StrReadRegistersBeforeUpdate" xml:space="preserve">
|
||||
<value>Reading registers before update</value>
|
||||
<value>Reading registers before maintenance</value>
|
||||
</data>
|
||||
<data name="StrRegisterCompare" xml:space="preserve">
|
||||
<value>Compare register</value>
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<Compile Include="MeterLutUpdate.cs" />
|
||||
<Compile Include="MeterFwUpdate.cs" />
|
||||
<Compile Include="MeterFwUpdateCapability.cs" />
|
||||
<Compile Include="MeterPowerCorrectionFile.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="MeterFile.cs" />
|
||||
<Compile Include="MeterPwdFile.cs" />
|
||||
|
||||
@@ -330,9 +330,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
#region Compare
|
||||
|
||||
/// <summary>
|
||||
/// Compare file and meter applications
|
||||
/// Compare file and meter applications and update display code if required.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <param name="updateDisplayCode">true updates the display code</param>
|
||||
/// <remarks date="2019-Jun-25" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
@@ -345,7 +345,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2019-Jul-02" author="Thomas Wiedebusch">
|
||||
/// - Removed genesis meter has to be logged in
|
||||
/// </remarks>
|
||||
public void CompareAllMeterAndFileApps()
|
||||
/// <remarks date="2024-Apr-23" author="Thomas Wiedebusch">
|
||||
/// - Removed MeterAppState.Unknown.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-25" author="Thomas Wiedebusch">
|
||||
/// - Optional display code update.
|
||||
/// </remarks>
|
||||
public void CompareAllMeterAndFileApps(Boolean updateDisplayCode = false)
|
||||
{
|
||||
if (_genesisMeter == null || FileApps == null)
|
||||
{
|
||||
@@ -356,34 +362,34 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
{
|
||||
CompareMeterAppWithFileApp(meterApp);
|
||||
}
|
||||
if (!_genesisMeter.IsLoggedOn)
|
||||
|
||||
if (updateDisplayCode)
|
||||
{
|
||||
//remind the login status to logout if not logged in here
|
||||
var wasLoggedOn = _genesisMeter.IsLoggedOn;
|
||||
|
||||
_genesisMeter.ReLogin();
|
||||
var isUpToDate = _genesisMeter.MeterAppListVersion.All(
|
||||
meterApp => meterApp.Status == MeterAppState.MeterAppUpToDate ||
|
||||
meterApp.Status == MeterAppState.MeterAppNotRequired);
|
||||
//set display code to up to date if not needed to be installed or up to date
|
||||
_genesisMeter.SetProcessState(_genesisMeter.MeterAppListVersion.All(
|
||||
f => f.Status == MeterAppState.MeterAppUpToDate ||
|
||||
f.Status == MeterAppState.MeterAppNotInstalled || f.Status == MeterAppState.Unknown)
|
||||
? DisplayCodes.FwUpToDate
|
||||
: DisplayCodes.FwUpdateFailed, false);
|
||||
_genesisMeter.Logout();
|
||||
}
|
||||
else
|
||||
{
|
||||
//set display code to up to date if not needed to be installed or up to date
|
||||
_genesisMeter.SetProcessState(_genesisMeter.MeterAppListVersion.All(
|
||||
f => f.Status == MeterAppState.MeterAppUpToDate ||
|
||||
f.Status == MeterAppState.MeterAppNotInstalled || f.Status == MeterAppState.Unknown)
|
||||
? DisplayCodes.FwUpToDate
|
||||
: DisplayCodes.FwUpdateFailed, false);
|
||||
}
|
||||
|
||||
_genesisMeter.SetProcessState(isUpToDate ? DisplayCodes.FwUpToDate
|
||||
: DisplayCodes.FwUpdateFailed, false);
|
||||
|
||||
if (!wasLoggedOn)
|
||||
_genesisMeter.Logout();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare single meter application with file
|
||||
/// Check the meter app status and if this is not indicating the unknown status
|
||||
/// compare the meter app with the file app to check for required action.
|
||||
/// After comparison it marks the meter app status <see cref="MeterAppState"/> and
|
||||
/// the "Update" or "Erase" request.
|
||||
/// Preconditions:
|
||||
/// - FileApps have to be preset.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <param name="meterApp">single application for check</param>
|
||||
/// <remarks date="2019-Jun-29" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
@@ -396,25 +402,35 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2020-Dec-01" author="Thomas Wiedebusch">
|
||||
/// - Meter state unknown if file apps not loaded
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-23" author="Thomas Wiedebusch">
|
||||
/// - Return if communication error without change of meter app status
|
||||
/// </remarks>
|
||||
public void CompareMeterAppWithFileApp(MeterApplications meterApp)
|
||||
{
|
||||
meterApp.Update = false;
|
||||
meterApp.Erase = false;
|
||||
|
||||
//CASE -1: meter application is installed but files are not loaded
|
||||
if (meterApp.IsInstalled && FileApps.Count == 0)
|
||||
//CASE -3: file apps not loaded, no comparison possible, leave everything as is
|
||||
if (FileApps.Count == 0)
|
||||
{
|
||||
meterApp.Status = MeterAppState.Unknown;
|
||||
return;
|
||||
}
|
||||
|
||||
//CASE 0: meter application is not installed and update files are not loaded
|
||||
if (!meterApp.IsInstalled && FileApps.Count == 0)
|
||||
//CASE -2: meter application could not be read due to communication error
|
||||
if (meterApp.Status == MeterAppState.Unknown)
|
||||
{
|
||||
meterApp.Status = MeterAppState.MeterAppNotInstalled;
|
||||
//CASE -2.1 Installation is required but installed app is not detected due to communication error
|
||||
if (FileApps.Any(x => x.AppId == meterApp.AppId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//CASE -2.2 Installation not required as app is NOT in the fileApp list
|
||||
meterApp.Status = MeterAppState.MeterAppNotRequired;
|
||||
return;
|
||||
}
|
||||
|
||||
//compare file apps with meter apps and change meterApp.Status
|
||||
foreach (var fileApp in FileApps)
|
||||
{
|
||||
if (meterApp.AppId != fileApp.AppId)
|
||||
@@ -495,7 +511,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
}
|
||||
|
||||
//CASE 4.2: update file application not found and meter application is not installed
|
||||
meterApp.Status = MeterAppState.Unknown;
|
||||
meterApp.Status = MeterAppState.MeterAppNotRequired;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -713,7 +729,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
}
|
||||
|
||||
_remainingFileAppsParts.Clear();
|
||||
_fwUpdateState = FwUpdateState.UpdateFailed;
|
||||
if (_stopUpdateProcess)
|
||||
_fwUpdateState = FwUpdateState.UpdateFailed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,7 +941,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
_actualOperation = "";
|
||||
|
||||
//update file information
|
||||
CompareAllMeterAndFileApps();
|
||||
CompareAllMeterAndFileApps(true);
|
||||
|
||||
//logout/login/auto-login
|
||||
ReestablishMeterFileSystem();
|
||||
@@ -989,12 +1006,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2023-Jan-20" author="Thomas Wiedebusch">
|
||||
/// - Set upgrade permission for metrology to 0xFF if required (will be done by GTB).
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-25" author="Thomas Wiedebusch">
|
||||
/// - Reset retry counter.
|
||||
/// </remarks>
|
||||
public Boolean UpdatePreparation()
|
||||
{
|
||||
_actualOperation = Resources.StrFwUpdateStatePrepareUpdate;
|
||||
_fwUpdateState = FwUpdateState.PrepareUpdate;
|
||||
_processedBytesCtr = 0;
|
||||
_overallBytesCtr = 6;
|
||||
_updateProcedureRetryCtr = 0;
|
||||
|
||||
_meterFile = new MeterFile(_genesisMeter);
|
||||
if (_meterFile != null)
|
||||
@@ -1411,12 +1432,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// </remarks>
|
||||
public static UInt32 GetFileAppVersion(Byte[] binData)
|
||||
{
|
||||
return (UInt32)((binData[FileAppVersionIndex] & 0x0F)
|
||||
+ ((binData[FileAppVersionIndex] & 0xF0) >> 4) * 10
|
||||
+ (binData[FileAppVersionIndex + 1] & 0x0F) * 100
|
||||
+ ((binData[FileAppVersionIndex + 1] & 0xF0) >> 4) * 1000);
|
||||
return (UInt32)(binData[FileAppVersionIndex] + (binData[FileAppVersionIndex + 1] << 8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check the content of the binaries:
|
||||
/// - begins with "APP>",
|
||||
@@ -1432,15 +1449,29 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2019-Jun-26" author="Thomas Wiedebusch">
|
||||
/// - New file version string builder.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-May-06" author="Thomas Wiedebusch">
|
||||
/// - File version as hex number to handle .
|
||||
/// </remarks>
|
||||
private static Boolean CheckFileApp(FileApplications fileApp)
|
||||
{
|
||||
fileApp.AppId = GetFileAppAppId(fileApp.BinData.ToArray());
|
||||
fileApp.Crc = GetFileAppCrc(fileApp.BinData.ToArray());
|
||||
fileApp.Version = GetFileAppVersion(fileApp.BinData.ToArray());
|
||||
var binData = fileApp.BinData.ToArray();
|
||||
fileApp.AppId = binData[FileAppAppIdIndex];
|
||||
fileApp.Crc = (UInt16)(binData[FileAppCrcIndex] + (binData[FileAppCrcIndex + 1] << 8));
|
||||
|
||||
fileApp.StrVersion = GenesisMeter.BuildFwVersionString(fileApp.BinData[FileAppVersionIndex + 1],
|
||||
fileApp.BinData[FileAppVersionIndex]);
|
||||
var fileAppStartId = Encoding.UTF8.GetString(fileApp.BinData.ToArray(), 0, 4);
|
||||
if (fileApp.AppId == 0x18) //FLEXNETVERSION
|
||||
{
|
||||
fileApp.StrVersion = GenesisMeter.BuildFlexnetFwVersion(out fileApp.Version, null,
|
||||
binData[FileAppVersionIndex + 1],
|
||||
binData[FileAppVersionIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileApp.StrVersion = GenesisMeter.BuildFwVersion(out fileApp.Version,
|
||||
binData[FileAppVersionIndex + 1],
|
||||
binData[FileAppVersionIndex]);
|
||||
}
|
||||
|
||||
var fileAppStartId = Encoding.UTF8.GetString(binData, 0, 4);
|
||||
//check update file start identifier
|
||||
if (fileAppStartId != StrFileAppStartId)
|
||||
{
|
||||
@@ -1712,7 +1743,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
_backupPcbId = _pcbId;
|
||||
|
||||
RemindDownloadedFileApps();
|
||||
CompareAllMeterAndFileApps();
|
||||
CompareAllMeterAndFileApps(true);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -1825,7 +1856,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
private Boolean DownloadUpgradeCtrlFile()
|
||||
{
|
||||
//initiate upgrade by writing the upgrade control file
|
||||
if (_upgradeCtrlFile == "" ||
|
||||
if (_upgradeCtrlFile == "" || _meterFile == null ||
|
||||
!_meterFile.UnlockEraseWriteMeterFile(StrUpgradeCtrlFileName))
|
||||
{
|
||||
return false;
|
||||
@@ -1948,7 +1979,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
}
|
||||
|
||||
_updatedMeterApps.Clear();
|
||||
CompareAllMeterAndFileApps();
|
||||
CompareAllMeterAndFileApps(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1967,16 +1998,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
return $"0x{appId:X2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a version string like 2.02
|
||||
/// </summary>
|
||||
/// <param name="version"></param>
|
||||
/// <returns></returns>
|
||||
public static String ConvertVersionToString(Int32? version)
|
||||
{
|
||||
return version == null ? "0.00" : $"{version / 100}.{version % 100:D2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build the hexadecimal CRC string
|
||||
/// </summary>
|
||||
@@ -2046,6 +2067,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// new versions starting with 2022-11-04_NA_B122B contain a CRC16 and CRC32 identifier.
|
||||
/// - File line check modified to be immune against multiple blanks behind the field identifier.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-May-06" author="Thomas Wiedebusch">
|
||||
/// - Handle FLEXNETVERSION correctly.
|
||||
/// </remarks>
|
||||
public Boolean ValidateFileAppsWithPackageFile()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageDescriptionFile) || FileApps.Count == 0 ||
|
||||
@@ -2058,7 +2082,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
var validAppsCtr = 0;
|
||||
foreach (var fileApp in FileApps)
|
||||
{
|
||||
//find a line which contains all required information
|
||||
// convert version from 0x1107 to "11.07"
|
||||
var strVersion = fileApp.AppId == 0x18 ?
|
||||
$"{(fileApp.Version & 0xFF00) >> 8:X2}.{fileApp.Version & 0x00FF:X2}"
|
||||
: fileApp.StrVersion;
|
||||
// find a line which contains all required information
|
||||
validAppsCtr += packageFileLines.Count(line =>
|
||||
line.Contains($"{StrPackageFileAppId}") &&
|
||||
line.Contains($"{ConvertAppIdToString(fileApp.AppId)}") &&
|
||||
@@ -2066,7 +2094,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
line.Contains($"{StrPackageFileAppCrc16}")) &&
|
||||
line.Contains($"{ConvertCrcToString(fileApp.Crc)}") &&
|
||||
line.Contains($"{StrPackageFileAppVersion}") &&
|
||||
line.Contains($"{fileApp.StrVersion}"));
|
||||
line.Contains($"{strVersion}"));
|
||||
}
|
||||
|
||||
//extract the core revision fields
|
||||
@@ -2095,9 +2123,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2022-Dec-05" author="Thomas Wiedebusch">
|
||||
/// - Core revision data type changed from string ti int32?.
|
||||
/// </remarks>
|
||||
public Boolean CheckCoreRevision(Int32? coreRevision)
|
||||
public Boolean CheckCoreRevision(UInt32 coreRevision)
|
||||
{
|
||||
if (null == CoreRevisionMaximum || null == CoreRevisionMinimum || null == coreRevision ||
|
||||
if (null == CoreRevisionMaximum || null == CoreRevisionMinimum ||
|
||||
null == _packageDescriptionFile)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -65,9 +65,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2022-Dec-05" author="Thomas Wiedebusch">
|
||||
/// - Core revision data type changed from string ti int32?.
|
||||
/// </remarks>
|
||||
public static Boolean CheckCoreRevision(MeterFwUpdate meterFwUpdate, Int32? coreRevision)
|
||||
public static Boolean CheckCoreRevision(MeterFwUpdate meterFwUpdate, UInt32 coreRevision)
|
||||
{
|
||||
if (meterFwUpdate == null || coreRevision == null) return false;
|
||||
if (meterFwUpdate == null ) return false;
|
||||
return meterFwUpdate.CheckCoreRevision(coreRevision);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Power correction file stored as reminder and log to meter
|
||||
/// </summary>
|
||||
public class MeterPowerCorrectionFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Drive and name for power correction file stored on meter
|
||||
/// </summary>
|
||||
public const String StrMeterPowerCorrectionFilePathName = "1\\powcorr";
|
||||
|
||||
private const Int32 MeterPwrCorrFileLengthIndex = 0;
|
||||
private const Int32 MeterPwrCorrFileLengthSize = 2;
|
||||
private const Int32 MeterPwrCorrFileCrcIndex = MeterPwrCorrFileLengthIndex + MeterPwrCorrFileLengthSize;
|
||||
private const Int32 MeterPwrCorrFileCrcSize= 2;
|
||||
private const Int32 MeterPwrCorrFileDataIndex = MeterPwrCorrFileCrcIndex + MeterPwrCorrFileCrcSize;
|
||||
|
||||
/// <summary>
|
||||
/// Detected FW version before maintenance
|
||||
/// </summary>
|
||||
public UInt32 ActualFwVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date time UTC at time of maintenance
|
||||
/// </summary>
|
||||
public DateTime? ActualDateTimeUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used seconds before maintenance
|
||||
/// </summary>
|
||||
public UInt32 ActualTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used charge of batteries before maintenance
|
||||
/// </summary>
|
||||
public UInt64 ActualTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Actual detected radio system state at maintenance
|
||||
/// </summary>
|
||||
public Byte? ActualRadioSystemState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Detection of pulse adapter installation
|
||||
/// </summary>
|
||||
public Boolean ActualPulseAdapterIsInstalled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse mode during maintenance
|
||||
/// </summary>
|
||||
public Byte ActualPulseMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse distribution during maintenance
|
||||
/// </summary>
|
||||
public Boolean ActualPulseEvenDistribution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// FW version for the update
|
||||
/// </summary>
|
||||
public UInt32 RequiredFwVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculated pulse report length
|
||||
/// </summary>
|
||||
public UInt32 PulseReportLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total used seconds after EOL and before maintenance
|
||||
/// </summary>
|
||||
public UInt32 AfterProductionTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Overestimated total used charge before maintenance
|
||||
/// </summary>
|
||||
public UInt64 OverestimatedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lowest threshold for total used charge calculated during maintenance
|
||||
/// </summary>
|
||||
public UInt64 MinimumTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Corrected total used charge during maintenance
|
||||
/// </summary>
|
||||
public UInt64 CorrectedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionFileSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionCRC { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -18,111 +18,111 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus
|
||||
/// <summary>
|
||||
/// Data base primary key
|
||||
/// </summary>
|
||||
public Int32 Id;
|
||||
|
||||
public Int32 Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order number
|
||||
/// </summary>
|
||||
public Int32? OrderNumber;
|
||||
|
||||
public Int32? OrderNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PcbId.
|
||||
/// </summary>
|
||||
public String PcbId;
|
||||
public String PcbId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Skip radio parameter check
|
||||
/// </summary>
|
||||
public Boolean SkipRadioParametersCheck;
|
||||
public Boolean SkipRadioParametersCheck { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Override FW version. Normally the FW will be assigned to the latest released version
|
||||
/// and taken from the data base. Here special versions can be used for FW tests.
|
||||
/// null means take the current released version
|
||||
/// </summary>
|
||||
public Int32? OverrideFwCheck;
|
||||
|
||||
public Int32? OverrideFwCheck { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// override the Lut version to check the look-up-table installation as this device may be used for development.
|
||||
/// null means take the current released version
|
||||
/// </summary>
|
||||
public Int32? OverrideLutCheck;
|
||||
|
||||
public Int32? OverrideLutCheck { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Internally used to signal that production and shipping is proved and validated.
|
||||
/// </summary>
|
||||
public Boolean ProductionAccepted;
|
||||
public Boolean ProductionAccepted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date and time of production of electronics.
|
||||
/// </summary>
|
||||
public DateTime KitronProductionDate;
|
||||
public DateTime KitronProductionDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last date until production has to be finished, can be extended by special permission
|
||||
/// </summary>
|
||||
public DateTime ProductionDueDate;
|
||||
public DateTime ProductionDueDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining life time for Cordonel in years based on battery drainage.
|
||||
/// </summary>
|
||||
public Double RemainingLifeTimeYears;
|
||||
public Double RemainingLifeTimeYears { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Exceeded life time of all batteries in seconds.
|
||||
/// </summary>
|
||||
public UInt64 ExceededLifeTime_s;
|
||||
public UInt64 ExceededLifeTime_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required life time in years for assembly, is dependent on region and special permission.
|
||||
/// </summary>
|
||||
public Double RequiredLifeTimeYearsAssembly;
|
||||
public Double RequiredLifeTimeYearsAssembly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required life time in years for shipping, is dependent on region and special permission.
|
||||
/// </summary>
|
||||
public Double RequiredLifeTimeYearsShipping;
|
||||
public Double RequiredLifeTimeYearsShipping { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Battery drainage in percent.
|
||||
/// </summary>
|
||||
public Double DrainedBatteryLoadPercent;
|
||||
public Double DrainedBatteryLoadPercent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum drained Battery load in percent.
|
||||
/// </summary>
|
||||
public Double MaxDrainedBatteryLoadPercent;
|
||||
public Double MaxDrainedBatteryLoadPercent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of batteries attached to Cordonel.
|
||||
/// </summary>
|
||||
public Int32 BatteryQuantity;
|
||||
public Int32 BatteryQuantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initial capacity of one battery in mAh.
|
||||
/// </summary>
|
||||
public UInt64 InitialBatteryLoad_mAh;
|
||||
public UInt64 InitialBatteryLoad_mAh { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Drained capacity of all batteries in uAs.
|
||||
/// </summary>
|
||||
public UInt64 DrainedBatteryLoad_uAs;
|
||||
public UInt64 DrainedBatteryLoad_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Comment for approval and permissions reasons:
|
||||
/// e.g. "On customer requirement for test purposes the life time isn't of importance".
|
||||
/// </summary>
|
||||
public String ApprovalComment;
|
||||
public String ApprovalComment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of approver for special permissions.
|
||||
/// </summary>
|
||||
public String ApproverName;
|
||||
public String ApproverName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date of approval.
|
||||
/// </summary>
|
||||
public DateTime ApprovalDate;
|
||||
public DateTime ApprovalDate { get; set; }
|
||||
|
||||
public Double UNTLimit { get; internal set; } = 0;
|
||||
public Boolean UNTStatus { get; internal set; } = false;
|
||||
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
/// </summary>
|
||||
CommandNotAssigned,
|
||||
/// <summary>
|
||||
/// Acknowledge code not set, will be used initially
|
||||
/// Will be used initially as the record is not sent
|
||||
/// </summary>
|
||||
NotDecoded,
|
||||
Unsent,
|
||||
/// <summary>
|
||||
/// Response missing
|
||||
/// </summary>
|
||||
|
||||
@@ -173,6 +173,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
/// <remarks date="2022-Nov-07" author="T.Wiedebusch">
|
||||
/// - Command not assigned response for recordInProcess == null.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-22" author="T.Wiedebusch">
|
||||
/// - Initial request acknowledge state changed from NotDecoded to NoResponse.
|
||||
/// </remarks>
|
||||
public RequestAcknowledgeState ProcessRecordList()
|
||||
{
|
||||
_logger.Trace($"{_ident} Entry to ProcessRecordList, FIFO contains ({_recordsSendFifo.Count}) records");
|
||||
@@ -195,10 +198,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
if (_recordInProcess == null)
|
||||
return RequestAcknowledgeState.CommandNotAssigned;
|
||||
|
||||
//mark record as answer outstanding
|
||||
_recordInProcess.Acknowledge = RequestAcknowledgeState.NotDecoded;
|
||||
do
|
||||
{
|
||||
//mark record as answer outstanding
|
||||
_recordInProcess.Acknowledge = RequestAcknowledgeState.NoResponse;
|
||||
|
||||
_logger.Trace($"{_ident} Record({loopCounter}) - Processing");
|
||||
//log retries
|
||||
if (_recordInProcess.RetryCtr > 0)
|
||||
@@ -610,6 +614,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
/// <remarks date="2024-Apr-11 Version 2" author="T.Wiedebusch">
|
||||
/// - Rewound to version from 06.09.2023 14:44:33 before Commit 8c9d7704.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-Apr-15" author="T.Wiedebusch">
|
||||
/// - Removed useless too short comments as every string is going to be delimited by a 0 and usually won't match
|
||||
/// to a 4 byte chunk.
|
||||
/// </remarks>
|
||||
public RequestRecord CommandToMeter(Byte command, RegisterDefinition meterRegister = null,
|
||||
Byte[] payload = null, Int32? expectedLength = null, Boolean hideDataInLog = false,
|
||||
UInt16 skipRetryErrorCode = CommunicationConfig.SkipRetryErrorCode)
|
||||
@@ -617,82 +625,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
if (command == Commands.MultipleReadData && meterRegister != null && meterRegister.DataType == typeof(String))
|
||||
{
|
||||
var completeResponse = new List<Byte>();
|
||||
//TODO THW check this including the recursive call CommandToMeter
|
||||
while (true)
|
||||
{
|
||||
var cRecord = CommandToMeter(Commands.ReadData, meterRegister, payload, expectedLength,
|
||||
hideDataInLog, skipRetryErrorCode);
|
||||
var rest = ProcessRecordList();
|
||||
if (rest == RequestAcknowledgeState.Ok && cRecord != null && cRecord.ResponsePayload != null)
|
||||
if (rest == RequestAcknowledgeState.Ok && cRecord?.ResponsePayload != null)
|
||||
{
|
||||
completeResponse.AddRange(cRecord.ResponsePayload);
|
||||
if (cRecord.ResponsePayload.Contains(0))
|
||||
{
|
||||
cRecord.ResponsePayload = completeResponse;
|
||||
OnMeterRegisterUpdated?.Invoke(this,
|
||||
new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
||||
if (expectedLength.HasValue && completeResponse.Count < expectedLength.Value)
|
||||
{
|
||||
_logger.Debug("Too Short. Payload contains zero");
|
||||
}
|
||||
if (!cRecord.ResponsePayload.Contains(0)) continue;
|
||||
|
||||
return cRecord;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expectedLength.HasValue && completeResponse.Any() &&
|
||||
completeResponse.Count < expectedLength.Value)
|
||||
{
|
||||
if (rest != RequestAcknowledgeState.Ok)
|
||||
{
|
||||
_logger.Debug($"Too Short.Request Acknowledge State is {rest}");
|
||||
}
|
||||
else if (cRecord == null)
|
||||
{
|
||||
_logger.Debug("Too Short.Record is empty or null");
|
||||
}
|
||||
else if (cRecord.ResponsePayload == null)
|
||||
{
|
||||
_logger.Debug("Too Short.ResponsePayload is empty or null");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Too Short.Unkown reason");
|
||||
}
|
||||
|
||||
}
|
||||
cRecord.ResponsePayload = completeResponse;
|
||||
OnMeterRegisterUpdated?.Invoke(this,
|
||||
new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
||||
|
||||
return cRecord;
|
||||
}
|
||||
|
||||
return cRecord;
|
||||
}
|
||||
}
|
||||
//if (command == Commands.MultipleReadData && meterRegister != null && meterRegister.DataType == typeof(String))
|
||||
//{
|
||||
// var completeResponse = new List<Byte>();
|
||||
// while (!completeResponse.Contains(0) && _recordInProcess.RetryCtr <= CommunicationConfig.MaxRequestRetries)
|
||||
// {
|
||||
// var cRecord = CommandToMeter(Commands.ReadData, meterRegister, payload, 4, hideDataInLog,
|
||||
// skipRetryErrorCode);
|
||||
// var rest = ProcessRecordList();
|
||||
// if (rest == RequestAcknowledgeState.Ok && cRecord?.ResponsePayload != null)
|
||||
// {
|
||||
// completeResponse.AddRange(cRecord.ResponsePayload);
|
||||
// if (cRecord.ResponsePayload.Contains(0))
|
||||
// {
|
||||
// cRecord.ResponsePayload = completeResponse;
|
||||
// OnMeterRegisterUpdated?.Invoke(this,
|
||||
// new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
||||
// return cRecord;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (cRecord?.ResponsePayload == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//the minimum payload is one 4 byte chunk
|
||||
var chunkSize = RegisterDefinition.ChunkSize;
|
||||
if (payload == null)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
/// <summary>
|
||||
/// Command acknowledged
|
||||
/// </summary>
|
||||
public RequestAcknowledgeState Acknowledge = RequestAcknowledgeState.NoResponse;
|
||||
public RequestAcknowledgeState Acknowledge = RequestAcknowledgeState.Unsent;
|
||||
|
||||
/// <summary>
|
||||
/// Retry counter
|
||||
|
||||
@@ -9,8 +9,19 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
||||
public class TimeT
|
||||
{
|
||||
/// <summary>
|
||||
/// Seconds since 01. Jan 2000
|
||||
/// 1. Get seconds since 01. Jan 2000 00:00:00 UTC previously set by any call by
|
||||
/// <see cref="UtcNowToSecondsSince2000"/> or <see cref="UtcAnyToSecondsSince2000"/>
|
||||
/// or directly by this routine delivering the seconds e.g. read from meter,
|
||||
/// 2. Set UTC seconds to analyze the corresponding time in UTC and use the ToString to
|
||||
/// read the converted result.
|
||||
/// </summary>
|
||||
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000.
|
||||
/// </remarks>
|
||||
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||
/// - Setting of seconds and conversion to corresponding UTC sine 2000 or return seconds
|
||||
/// from set DataTimeUtc.
|
||||
/// </remarks>
|
||||
public Int32 SecondsSince2000
|
||||
{
|
||||
set
|
||||
@@ -18,25 +29,74 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
||||
var secondsToTimeSpan = TimeSpan.FromSeconds(value);
|
||||
DateTimeUtc = _fixedDateTime2000.Add(secondsToTimeSpan);
|
||||
}
|
||||
// DateTimeUtc has to be set in advance with seconds or by the call
|
||||
// of UtcNowToSecondsSince2000 or UtcAnyToSecondsSince2000
|
||||
get => UtcToSecondsSince2000();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get actual seconds (UTC now) since 01. Jan 2000 00:00:00 UTC.
|
||||
/// </summary>
|
||||
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
public Int32 UtcNowToSecondsSince2000
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTimeUtc = DateTime.UtcNow;
|
||||
var timeSince2000Utc = DateTimeUtc - _fixedDateTime2000;
|
||||
var secondsSince2000 = Convert.ToInt32(timeSince2000Utc.TotalSeconds);
|
||||
return secondsSince2000;
|
||||
return UtcToSecondsSince2000();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date and time of 01.Jan 2000 00:00:00
|
||||
/// Common routine to convert given UTC timestamp to seconds since 01. Jan 2000 00:00:00 UTC.
|
||||
/// </summary>
|
||||
private readonly DateTime _fixedDateTime2000 = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
private Int32 UtcToSecondsSince2000()
|
||||
{
|
||||
var timeSince2000Utc = DateTimeUtc - _fixedDateTime2000;
|
||||
var secondsSince2000 = Convert.ToInt32(timeSince2000Utc.TotalSeconds);
|
||||
return secondsSince2000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the seconds for a given timestamp based on 01.Jan.2000 00:00:00 UTC
|
||||
/// </summary>
|
||||
/// <param name="dateTimeUtc">time stamp dateTime for conversion</param>
|
||||
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||
/// - Optional input of dateTime to convert this to the time in UTC based on 01. Jan 2000.
|
||||
/// </remarks>
|
||||
public Int32 UtcAnyToSecondsSince2000(DateTime dateTimeUtc)
|
||||
{
|
||||
try
|
||||
{
|
||||
// limit dateTime to 01. Jan 2000 00:00:00 UTC
|
||||
DateTimeUtc = dateTimeUtc < _fixedDateTime2000 ? _fixedDateTime2000 : dateTimeUtc;
|
||||
return UtcToSecondsSince2000();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date and time of 01.Jan 2000 00:00:00 UTC
|
||||
/// </summary>
|
||||
private static readonly DateTime _fixedDateTime2000 = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Converted date and time to UTC using the FixedDateTime2000
|
||||
/// and the SecondsSince2000
|
||||
/// </summary>
|
||||
public DateTime DateTimeUtc;
|
||||
public DateTime DateTimeUtc
|
||||
{
|
||||
private set;
|
||||
get;
|
||||
} = _fixedDateTime2000;
|
||||
|
||||
/// <summary>
|
||||
/// Get string of UTC date and time universal language with 24 hours format
|
||||
|
||||
Reference in New Issue
Block a user