CUST: - new data types uint48_t, uint72_t,..

This commit is contained in:
Thomas Wiedebusch
2025-06-05 17:20:15 +02:00
parent 0d195026e1
commit bc667ae07b
8 changed files with 241 additions and 26 deletions
@@ -1,4 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
namespace Xylem.ServiceFwUpdate.Ui.FwUpdateLoader
@@ -6,12 +8,19 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateLoader
[Serializable]
static class Program
{
private static Mutex _mutex;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName;
_mutex = new Mutex(true, assemblyName, out var isNotRunning);
if (!isNotRunning)
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmFwUpdateLoader());
@@ -72,7 +72,6 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
private DateTimeOffset _startTime;
private Boolean _resetTimeMeasurement;
private Boolean _stopRequest;
private readonly ILogger _logger;
@@ -244,6 +243,10 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
private readonly System.Threading.Timer _tmrProgressUpdate;
private const Int32 TimerInterval_ms = 200;
// cancellation token
private CancellationTokenSource _cancellationTokenSource;
private CancellationToken _cancellationToken;
#endregion --------------------------------------- Variables --------------------------------------------------
#region ------------------------------------------ State Machine ----------------------------------------------
@@ -342,10 +345,16 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2024-May-16" author="Thomas Wiedebusch">
/// - Force stop on stop request.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void FwUpdateSwStateMachine()
{
while (!_processToken.IsCancellationRequested)
{
if (_cancellationTokenSource.IsCancellationRequested)
_processState = ProcessState.Stop;
if (_lastProcessState == _processState)
{
Thread.Sleep(1);
@@ -356,8 +365,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
try
{
_lastProcessState = _processState;
if (_stopRequest)
_processState = ProcessState.Stop;
switch (_processState)
{
case ProcessState.Init:
@@ -750,6 +758,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Culture info fixed to English.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
public FrmServiceFwUpdateSw()
{
_logger = NLogHelper.CreateOrGetLogger("ServiceFwUpdateSw");
@@ -765,6 +776,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
InitializeComponent();
_cultureInfo = Thread.CurrentThread.CurrentCulture;
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
radioBtnEnglishLanguage.Checked = true;
if (_cultureInfo.IetfLanguageTag == "de-DE")
{
@@ -806,8 +820,21 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2022-Mai-10" author="Thomas Wiedebusch">
/// - Release display removed.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void DisposeGenesis()
{
//// Wait for cancellation
//if (_cancellationToken.IsCancellationRequested)
//{
// Thread.Sleep(500);
// // Reset the cancellation request
// _cancellationTokenSource?.Dispose();
// _cancellationTokenSource = new CancellationTokenSource();
// _cancellationToken = _cancellationTokenSource.Token;
//}
_currentGenesis?.Logout();
// Batch removal disposes the meter!
_meterBatch?.RemoveAllMeters();
@@ -931,8 +958,12 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2022-Mai-10" author="Thomas Wiedebusch">
/// - Release display removed.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void FrmFwUpdate_FormClosing(Object sender, FormClosingEventArgs e)
{
_cancellationTokenSource?.Dispose();
_frmHistory?.Close();
_processToken?.Cancel();
@@ -1840,7 +1871,6 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
{
// restart for new device
_afterUpdateConnect = false;
_stopRequest = false;
if (_resetTimeMeasurement)
{
_startTime = DateTimeOffset.UtcNow;
@@ -1880,10 +1910,12 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Nov-27" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void BtnStop_Click(Object sender, EventArgs e)
{
_processState = ProcessState.Stop;
_stopRequest = true;
_cancellationTokenSource?.Cancel();
}
/// <summary>
@@ -1903,7 +1935,6 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
_registerRestorer == null)
return;
_stopRequest = false;
_startTime = DateTimeOffset.UtcNow;
_resetTimeMeasurement = false;
_processState = ProcessState.ReadInfoEraseRestoreFiles;
@@ -2507,10 +2538,13 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2023-Nov-15" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private ProcessState GetNextProcessState(ProcessState invokerProcessState,
IReadOnlyList<ProcessState> processSateSequence)
{
if (_stopRequest)
if (_cancellationToken.IsCancellationRequested)
return ProcessState.Stop;
// The last entry is an end of list marker
for (var c = 0; c < processSateSequence.Count - 1; c++)
@@ -2957,7 +2991,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// - If LUT restore generates an error all processes have to be stopped as the meter is NOT functional.
/// </remarks>
/// <remarks date="2024-Apr-24" author="Thomas Wiedebusch">
/// - COmmunication error on app detection.
/// - Communication error on app detection.
/// </remarks>
private void ErrorProcesses()
{
@@ -3181,6 +3215,12 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// - Enable [Connect] and [Port Scan],
/// - _processState to idle.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - Removed registerRestorer.StopRegisterAccess.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void StopProcesses()
{
InfoProcessFailed(null, Resources.StrUserStop);
@@ -3192,10 +3232,19 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
_serialPortScanner.StopPortScan = true;
if (_meterFwUpdate != null)
_meterFwUpdate.StopUpdateProcess = true;
if (_registerRestorer != null)
_registerRestorer.StopRegisterAccess = true;
if (_meterFile != null)
_meterFile.StopProcess = true;
// Wait for cancellation
if (_cancellationToken.IsCancellationRequested)
{
Thread.Sleep(500);
// Reset the cancellation request
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
}
MessageBoxShow(Resources.StrUserStop, "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
// take the invoker of the error state to generate the message and / or popup window
@@ -3312,6 +3361,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-12" author="Thomas Wiedebusch">
/// - Changed port scanner call using state responses after execution.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void Reboot(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -3331,7 +3383,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
var processExec = new ProcessExec();
processExec.NewProcess(InitReboot, null, ExecReboot, FinalizeReboot, _cultureInfo,
exitProcessStateObjects);
exitProcessStateObjects, _cancellationToken);
}
/// <summary>
@@ -3447,6 +3499,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-12" author="Thomas Wiedebusch">
/// - Changed port scanner call using state responses after execution.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void PortScanner(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -3460,7 +3515,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
var processExec = new ProcessExec();
processExec.NewProcess(InitPortScanner, null, ExecPortScanner, FinalizePortScanner, _cultureInfo,
exitProcessStateObjects);
exitProcessStateObjects, _cancellationToken);
}
/// <summary>
@@ -3582,6 +3637,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-12" author="Thomas Wiedebusch">
/// - Changed port scanner call using state responses after execution.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void Connect(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -3594,7 +3652,8 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
exitProcessStateObjects[2] = breakExitState;
var processExec = new ProcessExec();
processExec.NewProcess(InitConnect, null, ExecConnect, FinalizeConnect, _cultureInfo, exitProcessStateObjects);
processExec.NewProcess(InitConnect, null, ExecConnect, FinalizeConnect, _cultureInfo,
exitProcessStateObjects, _cancellationToken);
}
/// <summary>
@@ -4055,6 +4114,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-12" author="Thomas Wiedebusch">
/// - Changed port scanner call using state responses after execution.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void ReadRegisters(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -4074,7 +4136,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
var processExec = new ProcessExec();
processExec.NewProcess(InitReadRegister, null, ExecReadRegister, FinalReadRegisters,
_cultureInfo, exitProcessStateObjects);
_cultureInfo, exitProcessStateObjects, _cancellationToken);
}
/// <summary>
@@ -4109,6 +4171,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// - Status unknown implemented,
/// - activity message moved from InitReadRegister()
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private StatusReturn ExecReadRegister()
{
Boolean retVal;
@@ -4117,7 +4182,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
case ProcessState.InitialReadRegisters:
SetOverallProgressDisplayOn(Resources.StrRegisterReadoutActive);
InfoProcessActive(lblRegisterReadout, Resources.StrRegisterReadoutActive);
retVal = _registerRestorer.InitialReadRegisters();
retVal = _registerRestorer.InitialReadRegisters(_cancellationToken);
break;
case ProcessState.FinalReadRegisters:
@@ -4125,7 +4190,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
{
SetOverallProgressDisplayOn(Resources.StrRegisterReadoutActive);
InfoProcessActive(lblRegisterReadout, Resources.StrRegisterReadoutActive);
retVal = _registerRestorer.FinalReadRegisters();
retVal = _registerRestorer.FinalReadRegisters(_cancellationToken);
}
else
{
@@ -4138,7 +4203,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
{
SetOverallProgressDisplayOn(Resources.StrRegisterReadoutActive);
InfoProcessActive(lblRegisterReadout, Resources.StrRegisterCompareActive);
retVal = _registerRestorer.CompareRegisters();
retVal = _registerRestorer.CompareRegisters(_cancellationToken);
}
else
{
@@ -4149,7 +4214,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
default:
SetOverallProgressDisplayOn(Resources.StrRegisterReadoutActive);
InfoProcessActive(lblRegisterReadout, Resources.StrRegisterReadoutActive);
retVal = _registerRestorer.ReadRegisters();
retVal = _registerRestorer.ReadRegisters(_cancellationToken);
break;
}
return retVal ? StatusReturn.Okay : StatusReturn.Failed;
@@ -4762,6 +4827,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-17" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void RegisterRecovery(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -4781,7 +4849,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
var processExec = new ProcessExec();
processExec.NewProcess(InitRegisterRecovery, null, ExecRegisterRecovery, FinalizeRegisterRecovery,
_cultureInfo, exitProcessStateObjects);
_cultureInfo, exitProcessStateObjects, _cancellationToken);
}
/// <summary>
@@ -4820,6 +4888,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2024-Jun-25" author="Thomas Wiedebusch">
/// - Moved process messages from InitRegisterRecovery().
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private StatusReturn ExecRegisterRecovery()
{
var retVal = StatusReturn.Okay;
@@ -4835,7 +4906,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
InfoProcessActive(lblRegisterRestore, Resources.StrRegisterAccessActive);
//set the process bars
SetOverallProgressDisplayOn(Resources.StrRegisterAccessActive);
retVal = _registerRestorer.WriteRegisters(device.RecoveryRegisters);
retVal = _registerRestorer.WriteRegisters(device.RecoveryRegisters, _cancellationToken);
break;
}
@@ -4924,6 +4995,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2020-Dec-12" author="Thomas Wiedebusch">
/// - Changed port scanner call using state responses after execution.
/// </remarks>
/// <remarks date="2025-Jun-05" author="Thomas Wiedebusch">
/// - _cancellationToken.
/// </remarks>
private void FwUpdate(ProcessState successExitState, ProcessState errorExitState = ProcessState.Error,
ProcessState breakExitState = ProcessState.Stop)
{
@@ -4944,7 +5018,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
var processExec = new ProcessExec();
processExec.NewProcess(InitFwUpdate, null, ExecFwUpdate, FinalizeFwUpdate, _cultureInfo,
exitProcessStateObjects);
exitProcessStateObjects, _cancellationToken);
}
/// <summary>