CUST: - FwUpdateSw prepared for LUT readout, UNFINISHED

This commit is contained in:
Thomas Wiedebusch 2023-11-08 12:56:29 +01:00
parent c145398e6d
commit df9e868386
9 changed files with 168 additions and 16 deletions

View File

@ -9,11 +9,28 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// </summary>
public class MeterLutFile
{
/// <summary>
/// Disk number and name name of meter LUT file
/// </summary>
public const String StrLutMeterFileName = "1\\mettbl";
/// <summary>
/// Disk number and name of meter LUT file
/// </summary>
public const String StrLutBackupMeterFileName = "1\\mettbl_b";
/// <summary>
/// File name of the file on PC
/// </summary>
public String LutPcFileName;
/// <summary>
/// Ctor file applications
/// </summary>
public MeterLutFile()
{
}
/// <summary>
/// Ctor file applications
/// </summary>

View File

@ -31,12 +31,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
//error mask for unsuccessfully written LUT CRC
private const UInt32 LutCrcErrorMask = 0x8000000;
//disk and name of lookup file
private const String StrLutMeterFileName = "1\\mettbl";
//disk and name of lookup file
private const String StrLutBackupMeterFileName = "1\\mettbl_b";
// identifier for Genesis lookup table
private const String StrLutFileId = "GEN_LUT\0";
private const Int32 IndexLutFileId = 0;
@ -455,8 +449,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
case LutUpdateState.StartInitial:
_updateProcedureRetryCtr = 0;
_lutUpdateState = LutUpdateState.DownloadLutFile;
//_lutUpdateState = LutUpdateState.EraseLutFile;
break;
case LutUpdateState.EraseLutFile:
@ -757,7 +749,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
var filesToErase = new[] {
//"1\\upg00", "1\\upg01", "1\\upg04","1\\upg08","1\\upg09","1\\upg12","1\\upg14","1\\upg15",
StrLutMeterFileName, StrLutBackupMeterFileName };
MeterLutFile.StrLutMeterFileName, MeterLutFile.StrLutBackupMeterFileName };
// read all files which are already installed
_actualOperation = "Catalogue installed meter files drive 1";
@ -821,7 +813,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
//write LUT files and retry if not successful
do
{
var filesToDownload = new[] { StrLutMeterFileName, StrLutBackupMeterFileName };
var filesToDownload = new[] { MeterLutFile.StrLutMeterFileName, MeterLutFile.StrLutBackupMeterFileName };
foreach (var fileToDownload in filesToDownload)
{
@ -910,7 +902,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
//verify LUT files and retry if not successful
do
{
var filesToUpload = new[] { StrLutMeterFileName, StrLutBackupMeterFileName };
var filesToUpload = new[] { MeterLutFile.StrLutMeterFileName, MeterLutFile.StrLutBackupMeterFileName };
foreach (var fileToUpload in filesToUpload)
{

View File

@ -116,6 +116,11 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw.Const
/// </summary>
RestorePasswordFile,
/// <summary>
/// Restore tho look up table
/// </summary>
RestoreLut,
/// <summary>
/// Firmware update
/// </summary>

View File

@ -7,6 +7,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Windows.Forms;
@ -52,6 +53,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
private GenesisMeter _currentGenesis;
private readonly MeterBatch _meterBatch;
private Byte[] _hashedSafePwdFile;
private Byte[] _lutFileBinary;
private String _passwordLvl8;
private String _skeletonKey;
@ -255,6 +257,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2023-Oct-27" author="Thomas Wiedebusch">
/// - Release meter to normal operation after error state.
/// </remarks>
/// <remarks date="2023-Nov-08" author="Thomas Wiedebusch">
/// - LUT restore.
/// </remarks>
private void FwUpdateSwStateMachine()
{
while (!_processToken.IsCancellationRequested)
@ -354,8 +359,8 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
case ProcessState.FinalConnect:
DisposeGenesis();
// remind, that the final login with the Level 8 password has to be forced to validate
// the password file
// REMIND: The final login with the Level 8 password has to be forced to validate
// the password file, the skeletonKey is NOT allowed
_finalLoginAfterUpdate = true;
Connect(ProcessState.RestoreMeterFiles);
break;
@ -376,7 +381,11 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
break;
case ProcessState.RestorePasswordFile:
RestorePasswordFile(ProcessState.FirmwareUpdateSuccess);
RestorePasswordFile(ProcessState.RestoreLut);
break;
case ProcessState.RestoreLut:
RestoreLut(ProcessState.FirmwareUpdateSuccess);
break;
case ProcessState.FirmwareUpdateSuccess:
@ -1685,8 +1694,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// - Reworked with new information from Joerg Lachenmayer:
/// 1. Write 0xff,
/// 2. logout,
/// 3. login
/// 4. read if not 0x01.
/// 3. Wait 1000 ms,
/// 4. login
/// 5. read if not 0x01.
/// </remarks>
/// <remarks date="2023-Mar-07" author="Thomas Wiedebusch">
/// - Handle SystemState 0 = OFF
@ -3056,6 +3066,8 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
_hashedSafePwdFile = new Byte[MeterPwdDb.PwdFileLength];
_hashedSafePwdFile = device.PwdContainer.EncryptedPasswordFile;
// extract the LUT
_lutFile = new MeterLutFile(
_genesisInUpdateList = true;
break;
}
@ -3806,6 +3818,87 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
SetOverallProgressDisplayOff();
}
/// <summary>
/// Reads the LUT and restores it if different from given LUT in FwUpdateSafe.
/// </summary>
/// <param name="successExitState"></param>
/// <param name="errorExitState"></param>
/// <remarks date="2023-Nov-07" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void RestoreLut(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error)
{
// remind the invoker being able to generate error messages based on the last state
_invokerProcessState = _processState;
// if meter LUT CRC is not set and the meter files do not report the LUT, the meter does not have an installed LUT
if ((string.IsNullOrEmpty(_currentGenesis.LutCrc) ||
_currentGenesis.LutCrc.Equals(Constants.StrUnknown)) &&
_readMeterFiles != null && _readMeterFiles.Any( f => f.Contains(MeterLutFile.StrLutMeterFileName)))
{
// if the safe contains a LUT file, the installation of it has failed or it got lost during update
if (_lutFileBinary != null)
{
LogErrorText(Resources.StrLutFileNotInstalled);
_processState = errorExitState;
return;
}
// this FW version does not require a LUT file
LogText(Resources.StrLutFileNotNeeded);
_processState = successExitState;
return;
}
// if the LUT is not in the safe it cannot be restored but can be logged
// read and log the LUT
//if (!_passwordFileIsCorrupted)
//{
// InfoProcessSuccess(lblPasswordFileCheck, Resources.StrPasswordFileValid);
// _processState = successExitState;
// return;
//}
//InfoProcessActive(lblPasswordFileCheck, Resources.StrPasswordFileRestoreActive);
//// try to install password, first get the password file from device info
//var pwdFileObject = new MeterPwdFile(_currentGenesis);
//if (_hashedSafePwdFile != null &&
// pwdFileObject.CheckHashedPwdFile(_hashedSafePwdFile , _skeletonKey, _passwordLvl8))
//{
// SetControlsCommunicationActive();
// _currentGenesis?.ReLogin();
// if (pwdFileObject.UnlockEraseWriteMeterPwdFile())
// {
// if (pwdFileObject.WriteAndVerifyMeterPwdFile(_hashedSafePwdFile) &&
// ReadLogAndCompareMeterPwdFile())
// {
// // a reconnect will check for proper installed password file and check the Level 8 pwd.
// _processState = ProcessState.FinalConnect;
// _passwordFileIsCorrupted = false;
// InfoProcessSuccess(lblPasswordFileCheck, Resources.StrPasswordFileRestoreSucceeded);
// }
// else
// {
// InfoProcessFailed(lblPasswordFileCheck, Resources.StrPasswordFileRestoreFailed);
// _processState = errorExitState;
// }
// }
// _currentGenesis?.Logout();
//}
//// the password file is NOT in the password container
//else
//{
// InfoProcessFailed(lblPasswordFileCheck, Resources.StrPasswordFileFromSafeInvalid);
// _processState = errorExitState;
//}
// change first the process state, otherwise the timer may switch the bar on again
SetOverallProgressDisplayOff();
}
#endregion --------------------------------------- File Access ------------------------------------------------
#region ------------------------------------------ Register Recovery -----------------------------------------

View File

@ -583,6 +583,33 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to ERROR: LUT is required but not installed!.
/// </summary>
internal static string StrLutFileNotInstalled {
get {
return ResourceManager.GetString("StrLutFileNotInstalled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to LUT not required for this FW..
/// </summary>
internal static string StrLutFileNotNeeded {
get {
return ResourceManager.GetString("StrLutFileNotNeeded", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to LUT successfully validated..
/// </summary>
internal static string StrLutFileValidatedSuccessfully {
get {
return ResourceManager.GetString("StrLutFileValidatedSuccessfully", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not installed.
/// </summary>

View File

@ -607,4 +607,13 @@
<data name="StrPasswordFileFromSafeInvalid" xml:space="preserve">
<value>FEHLER: Paßwortdatei vom FW Update Safe ist ungültig!</value>
</data>
<data name="StrLutFileNotInstalled" xml:space="preserve">
<value>FEHLER: LUT wird benötigt und ist nicht installiert!</value>
</data>
<data name="StrLutFileNotNeeded" xml:space="preserve">
<value>LUT wird für diese FW nicht benötigt.</value>
</data>
<data name="StrLutFileValidatedSuccessfully" xml:space="preserve">
<value>LUT erfolgreich überprüft.</value>
</data>
</root>

View File

@ -607,4 +607,13 @@
<data name="StrPasswordFileFromSafeInvalid" xml:space="preserve">
<value>ERROR: Password file from FW update safe is invalid!</value>
</data>
<data name="StrLutFileNotInstalled" xml:space="preserve">
<value>ERROR: LUT is required but not installed!</value>
</data>
<data name="StrLutFileNotNeeded" xml:space="preserve">
<value>LUT not required for this FW.</value>
</data>
<data name="StrLutFileValidatedSuccessfully" xml:space="preserve">
<value>LUT successfully validated.</value>
</data>
</root>