GTB: - FwUpdate: - communication error check

This commit is contained in:
Thomas Wiedebusch
2024-04-25 15:33:48 +02:00
parent 04dddd475a
commit da1bac1989
3 changed files with 47 additions and 35 deletions
@@ -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>
@@ -348,7 +348,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2024-Apr-23" author="Thomas Wiedebusch">
/// - Removed MeterAppState.Unknown.
/// </remarks>
public void CompareAllMeterAndFileApps()
/// <remarks date="2024-Apr-25" author="Thomas Wiedebusch">
/// - Optional display code update.
/// </remarks>
public void CompareAllMeterAndFileApps(Boolean updateDisplayCode = false)
{
if (_genesisMeter == null || FileApps == null)
{
@@ -360,24 +363,33 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
CompareMeterAppWithFileApp(meterApp);
}
//remind the login status to logout if not logged in here
var wasLoggedOn = _genesisMeter.IsLoggedOn;
_genesisMeter.ReLogin();
//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.MeterAppNotRequired)
? DisplayCodes.FwUpToDate
: DisplayCodes.FwUpdateFailed, false);
if (!wasLoggedOn) _genesisMeter.Logout();
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(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>
@@ -391,7 +403,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// - 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
/// - Return if communication error without change of meter app status
/// </remarks>
public void CompareMeterAppWithFileApp(MeterApplications meterApp)
{
@@ -717,7 +729,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
}
_remainingFileAppsParts.Clear();
_fwUpdateState = FwUpdateState.UpdateFailed;
if (_stopUpdateProcess)
_fwUpdateState = FwUpdateState.UpdateFailed;
}
}
@@ -928,7 +941,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
_actualOperation = "";
//update file information
CompareAllMeterAndFileApps();
CompareAllMeterAndFileApps(true);
//logout/login/auto-login
ReestablishMeterFileSystem();
@@ -993,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)
@@ -1716,7 +1733,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
_backupPcbId = _pcbId;
RemindDownloadedFileApps();
CompareAllMeterAndFileApps();
CompareAllMeterAndFileApps(true);
return returnValue;
}
@@ -1829,7 +1846,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;
@@ -1952,7 +1969,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
}
_updatedMeterApps.Clear();
CompareAllMeterAndFileApps();
CompareAllMeterAndFileApps(true);
return true;
}