GenesisMeter: - communication error marks application as undetected to avoid accidentally FW update

This commit is contained in:
Thomas Wiedebusch
2024-04-23 15:53:34 +02:00
parent 2c80a547fb
commit a523d70cc8
20 changed files with 260 additions and 134 deletions
@@ -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>
@@ -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>
@@ -176,6 +176,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
@@ -1401,6 +1406,11 @@ 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>
private void ReadMeterFirmwareAndAssignRegisters()
{
// Avoid overwriting of list if this already exits
@@ -1414,13 +1424,14 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
InstalledFwVersion = 0;
//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);
@@ -1435,7 +1446,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
//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;
InstalledFwVersion = readFwVersion;
@@ -1444,24 +1455,35 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
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,
});
}
@@ -1509,6 +1531,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}");
}
@@ -2008,13 +2033,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:
@@ -2411,14 +2443,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);
@@ -345,6 +345,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2019-Jul-02" author="Thomas Wiedebusch">
/// - Removed genesis meter has to be logged in
/// </remarks>
/// <remarks date="2024-Apr-23" author="Thomas Wiedebusch">
/// - Removed MeterAppState.Unknown.
/// </remarks>
public void CompareAllMeterAndFileApps()
{
if (_genesisMeter == null || FileApps == null)
@@ -362,7 +365,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
//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)
f.Status == MeterAppState.MeterAppNotRequired )
? DisplayCodes.FwUpToDate
: DisplayCodes.FwUpdateFailed, false);
_genesisMeter.Logout();
@@ -372,7 +375,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
//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)
f.Status == MeterAppState.MeterAppNotRequired )
? DisplayCodes.FwUpToDate
: DisplayCodes.FwUpdateFailed, false);
}
@@ -396,25 +399,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 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 +508,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>
@@ -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)
@@ -637,10 +641,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
return cRecord;
}
else
{
return cRecord;
}
return cRecord;
}
}
@@ -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