GTB 2.2.2:

FwUpdate can upload entire 0\\config file
This commit is contained in:
Thomas Wiedebusch
2022-04-26 16:32:15 +02:00
parent 7a197a6793
commit e8ec68dee1
18 changed files with 487 additions and 202 deletions
@@ -2061,6 +2061,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// - Corrected logic to enter write and read loop,
/// - Removed SENSUSRADIO from read check as it returns NULL on read of StoreConfiguration.
/// </remarks>
/// <remarks date="2022-Apr-26" author="Thomas Wiedebusch">
/// - After write store configuration extended sleep.
/// </remarks>
public Boolean StoreAllConfigurations()
{
var overallResult = true;
@@ -2074,6 +2077,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
while (retryLeft > 0 && !done)
{
Thread.Sleep(100);
var result = WriteRegister(a.Key.GetIdent(), 1);
if (!result)
{
@@ -2085,7 +2089,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
continue;
}
Thread.Sleep(100);
// Wait for storing
Thread.Sleep(500);
if (a.Key.AppName == "SENSUSRADIO")
{
done = true;
@@ -2105,8 +2110,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
done = true;
Thread.Sleep(100);
}
}
@@ -16884,16 +16884,16 @@
"details": [
{
"type": "uint32_t",
"privilege": {
"lvl1": "RW",
"lvl2": "RW",
"lvl3": "RW",
"lvl4": "RW",
"lvl5": "RW",
"lvl6": "RW",
"lvl7": "RW",
"lvl8": "RW"
},
"privilege": {
"lvl1": "RW",
"lvl2": "RW",
"lvl3": "RW",
"lvl4": "RW",
"lvl5": "RW",
"lvl6": "RW",
"lvl7": "RW",
"lvl8": "RW"
},
"description": "Lorem Ipsum",
"version": {
"first": 2,
@@ -8,58 +8,66 @@
/// <summary>
/// FW Update State Idle
/// </summary>
Idle = 0,
Idle,
/// <summary>
/// FW update single step failed
/// </summary>
StepFailed = 1,
StepFailed,
/// <summary>
/// FW update entire process failed
/// </summary>
UpdateFailed = 2,
UpdateFailed,
/// <summary>
/// Start initial FW update
/// </summary>
StartInitial = 3,
StartInitial,
/// <summary>
/// Repeat FW update
/// </summary>
RepeatFwUpdate = 4,
RepeatFwUpdate,
/// <summary>
/// Upload (partial-) update files
/// </summary>
UploadFileApps = 5,
UploadFileApps,
/// <summary>
/// Download (partial-) update files
/// </summary>
DownloadFileApps = 6,
DownloadFileApps,
/// <summary>
/// Compare (partial-) update files
/// </summary>
CompareFileApps = 7,
CompareFileApps,
/// <summary>
/// Download upgrade control file
/// </summary>
DownloadUpgradeControlFile = 8,
DownloadUpgradeControlFile,
/// <summary>
/// Build upgrade control file
/// </summary>
BuildUpgradeControlFile = 9,
BuildUpgradeControlFile,
/// <summary>
/// Build Update Files
/// </summary>
BuildFileApps = 10,
BuildFileApps,
/// <summary>
/// Trigger Upgrade
/// </summary>
TriggerUpgrade = 11,
TriggerUpgrade,
/// <summary>
/// Erase update file
/// </summary>
EraseUpdateFile = 12,
EraseUpdateFile,
/// <summary>
/// Prepare update, read registers for restorer and store configuration
/// </summary>
PrepareUpdate,
/// <summary>
/// Read configuration file from meter
/// </summary>
UploadConfigFile,
/// <summary>
/// Delimiter for list
/// </summary>
FwUpdateStateListDelimiter = 13
FwUpdateStateListDelimiter
}
}
@@ -20,44 +20,50 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Consts
static FwUpdateStateInfo()
{
StateInfos = new FwUpdateStateText[(Int32)FwUpdateState.FwUpdateStateListDelimiter];
StateInfos[0].State = FwUpdateState.Idle;
StateInfos[0].Message = Resources.StrFwUpdateStateIdle;
StateInfos[(Int32)FwUpdateState.Idle].State = FwUpdateState.Idle;
StateInfos[(Int32)FwUpdateState.Idle].Message = Resources.StrFwUpdateStateIdle;
StateInfos[1].State = FwUpdateState.StepFailed;
StateInfos[1].Message = Resources.StrFwUpdateStateStepFailed;
StateInfos[(Int32)FwUpdateState.StepFailed].State = FwUpdateState.StepFailed;
StateInfos[(Int32)FwUpdateState.StepFailed].Message = Resources.StrFwUpdateStateStepFailed;
StateInfos[2].State = FwUpdateState.UpdateFailed;
StateInfos[2].Message = Resources.StrFwUpdateStateUpdateFailed;
StateInfos[(Int32)FwUpdateState.UpdateFailed].State = FwUpdateState.UpdateFailed;
StateInfos[(Int32)FwUpdateState.UpdateFailed].Message = Resources.StrFwUpdateStateUpdateFailed;
StateInfos[3].State = FwUpdateState.StartInitial;
StateInfos[3].Message = Resources.StrFwUpdateStateStartInitial;
StateInfos[(Int32)FwUpdateState.StartInitial].State = FwUpdateState.StartInitial;
StateInfos[(Int32)FwUpdateState.StartInitial].Message = Resources.StrFwUpdateStateStartInitial;
StateInfos[4].State = FwUpdateState.RepeatFwUpdate;
StateInfos[4].Message = Resources.StrFwUpdateStateRepeatFwUpdate;
StateInfos[(Int32)FwUpdateState.RepeatFwUpdate].State = FwUpdateState.RepeatFwUpdate;
StateInfos[(Int32)FwUpdateState.RepeatFwUpdate].Message = Resources.StrFwUpdateStateRepeatFwUpdate;
StateInfos[5].State = FwUpdateState.UploadFileApps;
StateInfos[5].Message = Resources.StrFwUpdateStateUploadFileApps;
StateInfos[(Int32)FwUpdateState.UploadFileApps].State = FwUpdateState.UploadFileApps;
StateInfos[(Int32)FwUpdateState.UploadFileApps].Message = Resources.StrFwUpdateStateUploadFileApps;
StateInfos[6].State = FwUpdateState.DownloadFileApps;
StateInfos[6].Message = Resources.StrFwUpdateStateDownloadFileApps;
StateInfos[(Int32)FwUpdateState.DownloadFileApps].State = FwUpdateState.DownloadFileApps;
StateInfos[(Int32)FwUpdateState.DownloadFileApps].Message = Resources.StrFwUpdateStateDownloadFileApps;
StateInfos[7].State = FwUpdateState.CompareFileApps;
StateInfos[7].Message = Resources.StrFwUpdateStateCompareFileApps;
StateInfos[(Int32)FwUpdateState.CompareFileApps].State = FwUpdateState.CompareFileApps;
StateInfos[(Int32)FwUpdateState.CompareFileApps].Message = Resources.StrFwUpdateStateCompareFileApps;
StateInfos[8].State = FwUpdateState.DownloadUpgradeControlFile;
StateInfos[8].Message = Resources.StrFwUpdateStateDownloadUpgradeControlFile;
StateInfos[(Int32)FwUpdateState.DownloadUpgradeControlFile].State = FwUpdateState.DownloadUpgradeControlFile;
StateInfos[(Int32)FwUpdateState.DownloadUpgradeControlFile].Message = Resources.StrFwUpdateStateDownloadUpgradeControlFile;
StateInfos[9].State = FwUpdateState.BuildUpgradeControlFile;
StateInfos[9].Message = Resources.StrFwUpdateStateBuildUpgradeControlFile;
StateInfos[(Int32)FwUpdateState.BuildUpgradeControlFile].State = FwUpdateState.BuildUpgradeControlFile;
StateInfos[(Int32)FwUpdateState.BuildUpgradeControlFile].Message = Resources.StrFwUpdateStateBuildUpgradeControlFile;
StateInfos[10].State = FwUpdateState.BuildFileApps;
StateInfos[10].Message = Resources.StrFwUpdateStateBuildFileApps;
StateInfos[(Int32)FwUpdateState.BuildFileApps].State = FwUpdateState.BuildFileApps;
StateInfos[(Int32)FwUpdateState.BuildFileApps].Message = Resources.StrFwUpdateStateBuildFileApps;
StateInfos[11].State = FwUpdateState.TriggerUpgrade;
StateInfos[11].Message = Resources.StrFwUpdateStateTriggerUpgrade;
StateInfos[(Int32)FwUpdateState.TriggerUpgrade].State = FwUpdateState.TriggerUpgrade;
StateInfos[(Int32)FwUpdateState.TriggerUpgrade].Message = Resources.StrFwUpdateStateTriggerUpgrade;
StateInfos[12].State = FwUpdateState.EraseUpdateFile;
StateInfos[12].Message = Resources.StrFwUpdateStateEraseUpdateFile;
StateInfos[(Int32)FwUpdateState.EraseUpdateFile].State = FwUpdateState.EraseUpdateFile;
StateInfos[(Int32)FwUpdateState.EraseUpdateFile].Message = Resources.StrFwUpdateStateEraseUpdateFile;
StateInfos[(Int32)FwUpdateState.PrepareUpdate].State = FwUpdateState.PrepareUpdate;
StateInfos[(Int32)FwUpdateState.PrepareUpdate].Message = Resources.StrFwUpdateStatePrepareUpdate;
StateInfos[(Int32)FwUpdateState.UploadConfigFile].State = FwUpdateState.UploadConfigFile;
StateInfos[(Int32)FwUpdateState.UploadConfigFile].Message = Resources.StrUploadConfigFile;
}
/// <summary>
@@ -67,7 +73,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Consts
public static String GetTextFromState(FwUpdateState state)
{
return (from stateInfo in StateInfos
where stateInfo.State == state select stateInfo.Message).FirstOrDefault();
where stateInfo.State == state
select stateInfo.Message).FirstOrDefault();
}
/// <summary>
/// Get the state of the text
@@ -76,7 +83,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Consts
public static FwUpdateState GetStateFromText(String text)
{
return (from stateInfo in StateInfos
where stateInfo.Message == text select stateInfo.State).FirstOrDefault();
where stateInfo.Message == text
select stateInfo.State).FirstOrDefault();
}
}
}
@@ -102,6 +102,7 @@
<Compile Include="Consts\FwUpdateState.cs" />
<Compile Include="Consts\FwUpdateStateInfo.cs" />
<Compile Include="Consts\FwUpdateStateText.cs" />
<Compile Include="MeterConfigFile.cs" />
<Compile Include="MeterLutFile.cs" />
<Compile Include="MeterFileRestore.cs" />
<Compile Include="MeterFilesEraseRestore.cs" />
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using Logic.ProductionToProductMapper.Cordonel;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
/// <summary>
/// File for meter configuration
/// </summary>
public class MeterConfigFile
{
/// <summary>
/// Data length
/// </summary>
public UInt32 DataLength;
/// <summary>
/// Binary file content
/// </summary>
public List<Byte> BinData = new List<Byte>();
}
}
@@ -25,11 +25,17 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
#region Variables
// Look up table file
public MeterConfigFile ConfigFile;
/// <summary>
/// Port scan result event for message dispatcher to caller
/// </summary>
public event EventHandler<ProcessExecEventArgs> OnProcessUpdate;
//disk and name of config file
private const String StrConfigMeterFileName = "0\\config";
//name for upgrade control file
private const String StrUpgradeCtrlFileName = "1\\upgrade";
@@ -94,11 +100,17 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <summary>
/// Core revision minimum as double for comparison
/// </summary>
public Double? CoreRevisionMinimum { get; private set; }
public Double? CoreRevisionMinimum
{
get; private set;
}
/// <summary>
/// Core revision maximum as double for comparison
/// </summary>
public Double? CoreRevisionMaximum { get; private set; }
public Double? CoreRevisionMaximum
{
get; private set;
}
//reminder for the core minimum requirement as string
private String _strCoreRevisionMinimum;
@@ -161,6 +173,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// </summary>
public Boolean SingleFilePartsRetryEnable = true;
/// <summary>
/// Store configuration in advance to the update
/// </summary>
public Boolean StoreConfigEnable = true;
/// <summary>
/// Enable partial file writes from first failed part to the end
/// </summary>
@@ -701,6 +718,59 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
}
}
/// <summary>
/// Upload the config file from meter
/// </summary>
/// <returns></returns>
/// <remarks date="2022-Apr-26" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public Boolean UploadConfigFile()
{
//counters for actual process information
var retryCtr = 0;
ConfigFile = new MeterConfigFile();
_processedBytesCtr = 0;
_overallBytesCtr = 6;
_meterFile = new MeterFile(_genesisMeter);
if (_meterFile != null)
{
_meterFile.OnProcessUpdate += ProcessUpdate_Event;
}
_genesisMeter?.ReLogin();
_genesisMeter?.SetProcessState(DisplayCodes.FwUpdateActive, false);
if (_genesisMeter == null || !_genesisMeter.IsLoggedOn || _meterFile == null)
return false;
var returnValue = true;
//write LUT files and retry if not successful
do
{
_actualOperation = Resources.StrUploadConfigFile;
// logout and re-login to clear all ongoing processes and clear the Genesis buffers
ReestablishMeterFileSystem();
if (!_meterFile.ReadMeterFile(StrConfigMeterFileName, out ConfigFile.BinData, 5000))
{
returnValue = false;
}
if (!returnValue)
{
ReestablishMeterFileSystem();
}
} while (!returnValue && retryCtr++ < FileWriteRetries && !StopUpdateProcess);
_meterFile.OnProcessUpdate -= ProcessUpdate_Event;
return !StopUpdateProcess && returnValue;
}
/// <summary>
/// Update meter firmware
/// </summary>
@@ -960,10 +1030,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2022-Apr-21" author="Thomas Wiedebusch">
/// - Store all configurations before the update.
/// </remarks>
/// <remarks date="2022-Apr-26" author="Thomas Wiedebusch">
/// - Message for actual operation,
/// - PrepareUpdate state introduced.
/// </remarks>
public Boolean UpdatePreparation()
{
_actualOperation = "";
_fwUpdateState = FwUpdateState.Idle;
_actualOperation = Resources.StrFwUpdateStatePrepareUpdate;
_fwUpdateState = FwUpdateState.PrepareUpdate;
_processedBytesCtr = 0;
_overallBytesCtr = 6;
_meterFile = new MeterFile(_genesisMeter);
if (_meterFile != null)
@@ -990,10 +1066,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
var writeBackValue = _genesisMeter.ReadRegister(item.Key);
_registersAfterUpdate.Add(item.Key, writeBackValue);
_genesisMeter.WriteRegister(item.Key, item.Value);
_processedBytesCtr++;
}
//store all configuration parameters
if (!_genesisMeter.StoreAllConfigurations()) return false;
if (StoreConfigEnable)
{
//store all configuration parameters
_actualOperation = Resources.StrStoreConfigurations;
if (!_genesisMeter.StoreAllConfigurations())
return false;
}
//remove the update stop action
StopUpdateProcess = false;
@@ -1075,6 +1157,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2022-Mar-04" author="Thomas Wiedebusch">
/// - Introduced lock for repeated execution of state machine
/// </remarks>
/// <remarks date="2022-Apr-26" author="Thomas Wiedebusch">
/// - Prepare update added,
/// - Upload config file added.
/// </remarks>
private void FwUpdateStateMachine()
{
if (_fwBackupUpdateState == _fwUpdateState)
@@ -1090,6 +1176,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
case FwUpdateState.Idle:
break;
case FwUpdateState.UploadConfigFile:
_fwUpdateState = UploadConfigFile()
? FwUpdateState.Idle
: FwUpdateState.StepFailed;
break;
case FwUpdateState.StartInitial:
_updateProcedureRetryCtr = 0;
_fwUpdateState = FwUpdateState.BuildFileApps;
@@ -1164,6 +1256,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
case FwUpdateState.UploadFileApps:
break;
case FwUpdateState.PrepareUpdate:
break;
case FwUpdateState.CompareFileApps:
break;
@@ -1290,7 +1385,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2022-Apr-22" author="Thomas Wiedebusch">
/// - Corrected return value (was constantly true).
/// </remarks>
private Boolean ValidateLoadedFiles()
private Boolean ValidateLoadedFiles()
{
var returnValue = true;
@@ -901,7 +901,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
_genesisMeter.TransmitProtocol.SetResponseTimeout(1000);
var returnValue = true;
//write LUT files and retry if not successful
//verify LUT files and retry if not successful
do
{
var filesToUpload = new[] { StrLutMeterFileName, StrLutBackupMeterFileName };
@@ -123,6 +123,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Prepare update.
/// </summary>
public static string StrFwUpdateStatePrepareUpdate {
get {
return ResourceManager.GetString("StrFwUpdateStatePrepareUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Repeat FW Update.
/// </summary>
@@ -222,6 +231,24 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Store configurations.
/// </summary>
public static string StrStoreConfigurations {
get {
return ResourceManager.GetString("StrStoreConfigurations", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Upload configuration file.
/// </summary>
public static string StrUploadConfigFile {
get {
return ResourceManager.GetString("StrUploadConfigFile", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Waiting.....
/// </summary>
@@ -174,4 +174,13 @@
<data name="StrProcessDownload" xml:space="preserve">
<value>Einspielen </value>
</data>
<data name="StrFwUpdateStatePrepareUpdate" xml:space="preserve">
<value>Update Vorbereitung</value>
</data>
<data name="StrStoreConfigurations" xml:space="preserve">
<value>Sichere Einstellungen</value>
</data>
<data name="StrUploadConfigFile" xml:space="preserve">
<value>Lade Einstellungen</value>
</data>
</root>
@@ -174,4 +174,13 @@
<data name="StrProcessDownload" xml:space="preserve">
<value>Download</value>
</data>
<data name="StrFwUpdateStatePrepareUpdate" xml:space="preserve">
<value>Prepare update</value>
</data>
<data name="StrStoreConfigurations" xml:space="preserve">
<value>Store configurations</value>
</data>
<data name="StrUploadConfigFile" xml:space="preserve">
<value>Upload configuration file</value>
</data>
</root>