From 61c3583a95cdca274497f005e68797f7591e44bd Mon Sep 17 00:00:00 2001 From: Thomas Wiedebusch Date: Mon, 13 Oct 2025 10:50:12 +0200 Subject: [PATCH] RegisterConverter: - Removed SizeOf --- .../.vs/Common/config/applicationhost.config | 2 +- .../GenesisCore/GenesisConfigReader.cs | 2 +- .../Genesis/GenesisCore/GenesisMeter.cs | 19 ++- .../Genesis/GenesisCore/RegisterRestorer.cs | 5 +- .../Genesis/Registers/RegisterConverter.cs | 18 --- .../ProductionProcesses/ProcessController.cs | 142 +++++++++--------- 6 files changed, 95 insertions(+), 93 deletions(-) diff --git a/Common/.vs/Common/config/applicationhost.config b/Common/.vs/Common/config/applicationhost.config index 5616ab8b..8f2db308 100644 --- a/Common/.vs/Common/config/applicationhost.config +++ b/Common/.vs/Common/config/applicationhost.config @@ -171,7 +171,7 @@ - + diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisConfigReader.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisConfigReader.cs index b05bd0eb..4cef69f8 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisConfigReader.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisConfigReader.cs @@ -87,7 +87,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore /// - Data size introduced including the new 'ByteArray' type and size to get rid of new defined 'uintxx_t' /// data types. /// - private void BuildRegisterList(String configurationJson) + public void BuildRegisterList(String configurationJson) { IDictionary sections; diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs index 9e0b8517..a5498a09 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs @@ -140,6 +140,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore private ILogger _loggerRawData; + /// + /// Optional request to use the offline passwords + /// + public Boolean UseOfflinePasswords; + /// /// Process configuration /// @@ -1211,6 +1216,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore /// /// - Used /// + /// + /// - Optional the offline passwords will be used. + /// private String GetPassword() { // without PCB ID it is not possible to login, @@ -1229,14 +1237,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore } // on unknown password try to get it from DB - if (MeterPwdHandlerDb.GetPasswordFromDb(PcbId, out var password)) + if (MeterPwdHandlerDb.GetPasswordFromDb(PcbId, out var password) && !UseOfflinePasswords) { Logger.Info($"Slot:{Slot} - Got password from GenesisPasswordService, " + $"URL({ServiceUrls.GenesisGetPasswordServiceUrl() + PcbId})"); } else { - Logger.Info($"Slot:{Slot} - Cannot get password from GenesisPasswordService, " + + if (!UseOfflinePasswords) + Logger.Info($"Slot:{Slot} - Cannot get password from GenesisPasswordService, " + $"URL({ServiceUrls.GenesisGetPasswordServiceUrl() + PcbId}))"); // try to read the password from an offline password file var offlinePwdPathName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @@ -2386,6 +2395,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore /// /// - Changed sensitive information from "*****" to SHA256. /// + /// + /// - Date size directly from register object. + /// public virtual Byte[] ReadRegister(String regName, Int32? expectedLength = null, UInt16 skipRetryErrorCode = CommunicationConfig.SkipRetryErrorCode) { @@ -2394,14 +2406,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore { var regDef = ConfigRegister.GetRegisterDefinitionByName(regName); ConfigRegister.Set(regDef, null); - //_logger.Info($"Slot:{Slot} - Read register({regDef.GetIdent()})"); var hideDataInLog = regDef.RegisterName.Contains("EncryptionKey"); // setup length based on data type if (!expectedLength.HasValue) { - expectedLength = RegisterConverter.SizeOf(regDef); + expectedLength = regDef.DataSize; } var dataLengthPreset = expectedLength.Value; diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/RegisterRestorer.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/RegisterRestorer.cs index d7e5a6de..7cf28d83 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/RegisterRestorer.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/RegisterRestorer.cs @@ -1671,6 +1671,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore /// /// - CancellationToken. /// + /// + /// - Date size directly from register object. + /// private Boolean ReadRegistersSet(ref List registers, CancellationToken cancellationToken) { if (_currentGenesis == null) @@ -1706,7 +1709,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore try { - var rawRegister = _currentGenesis.ReadRegister(regName, RegisterConverter.SizeOf(regDef)); + var rawRegister = _currentGenesis.ReadRegister(regName, regDef.DataSize); try { if (register != null && rawRegister != null) diff --git a/Common/Hardware/WaterMeter/Genesis/Registers/RegisterConverter.cs b/Common/Hardware/WaterMeter/Genesis/Registers/RegisterConverter.cs index cc49b719..95d6c65c 100644 --- a/Common/Hardware/WaterMeter/Genesis/Registers/RegisterConverter.cs +++ b/Common/Hardware/WaterMeter/Genesis/Registers/RegisterConverter.cs @@ -255,23 +255,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers return converted; } - /// - /// Get size of type - /// - /// - /// size in bytes - /// - /// - Init. - /// - /// - /// - Build the size in the 'GenesisConfigReader.cs'/> - /// - public static Int32 SizeOf(RegisterDefinition registerDefinition) - { - return registerDefinition.DataSize; - - } - /// /// Build the result of the array as text. /// @@ -333,7 +316,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers } if (type == typeof(ByteArray) || type == typeof(Byte[])) { - //return ByteArrayToValue(rawByteArray).ToString(); return ""; } if (type == typeof(SByte)) diff --git a/Common/Production/ProductionUiCordonel/ProductionProcesses/ProcessController.cs b/Common/Production/ProductionUiCordonel/ProductionProcesses/ProcessController.cs index 64d76e62..be4f394d 100644 --- a/Common/Production/ProductionUiCordonel/ProductionProcesses/ProcessController.cs +++ b/Common/Production/ProductionUiCordonel/ProductionProcesses/ProcessController.cs @@ -335,79 +335,85 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses // Signal state change to logger OnStateMachineStateChanged?.Invoke(this, new ProcessStateArgs(_stateMachineState)); - - // Check if state is the first in the list of production processes to reset cancellationToken and - // calculate the over all process steps to feed the progress bars. - var startProcessState = _processStateDef.GetStateOfFirstProcess(); - if (startProcessState == _stateMachineState) + + if (_processStateDef != null) { - // Kill all processes at start - KillProcesses(); - // Avoid immediately cancellation for first process of the process chain - ResetCancellationToken(); - // Set up the counter for maximum overall process progress bar in GUI - CalcAndPushMaxOverAllProcessSteps(); - } - - // Get the processStateStruct of this new required stateMachineState - var processStateStruct = _processStateDef.GetProcessStateStructOfState(_stateMachineState); - - switch (_stateMachineState) - { - case ProcessState.Idle: - break; - - case ProcessState.CheckNewMeter: - // Detection of Cordonel has to be completed before assigning next state. It has to be checked if - // the meter changed to clear all collected contents of previous run. To UPDATE ALL INFORMATION after - // new meter assignment the "DetectCordonel" has to be repeated to return here "Old Meter" and then - // enter the "ConnectCordonel"! - if (processStateStruct.NextStateOnSuccess != null) - { - _stateMachineState = CheckForNewMeter() ? (ProcessState)processStateStruct.NextStateOnSuccess : - processStateStruct.ErrorExitState; - } - else - { - _stateMachineState = ProcessState.Error; - } - break; - - case ProcessState.RepeatFailedTests: - _stateMachineState = RepeatFailedTests(); - break; - - case ProcessState.AbortTest: - AbortProcesses(); - _stateMachineState = ProcessState.Idle; - break; - - case ProcessState.Stop: + // Check if state is the first in the list of production processes to reset cancellationToken and + // calculate the over all process steps to feed the progress bars. + var startProcessState = _processStateDef.GetStateOfFirstProcess(); + if (startProcessState == _stateMachineState) + { + // Kill all processes at start KillProcesses(); - _stateMachineState = ProcessState.Idle; - break; + // Avoid immediately cancellation for first process of the process chain + ResetCancellationToken(); + // Set up the counter for maximum overall process progress bar in GUI + CalcAndPushMaxOverAllProcessSteps(); + } - case ProcessState.Error: - // Common error handling routine - ProcessErrorHandler(_stateChangeRequestProcess); - // Start the error handler with its user feedback request. It has to be started - // always even if the abortion of all processes is required! The error handler - // will change the exit state based on the user input. - StartProcess(processStateStruct); - break; + // Get the processStateStruct of this new required stateMachineState + var processStateStruct = _processStateDef.GetProcessStateStructOfState(_stateMachineState); - case ProcessState.StateListDelimiter: - _stateMachineState = ProcessState.Idle; - break; + switch (_stateMachineState) + { + case ProcessState.Idle: + break; - default: - // This is the call to the processes for a specific test - StartProcess(processStateStruct); - if (processStateStruct.KickOffParallelState != null) - { - _stateMachineState = (ProcessState)processStateStruct.KickOffParallelState; - } - break; + case ProcessState.CheckNewMeter: + // Detection of Cordonel has to be completed before assigning next state. It has to be checked if + // the meter changed to clear all collected contents of previous run. To UPDATE ALL INFORMATION after + // new meter assignment the "DetectCordonel" has to be repeated to return here "Old Meter" and then + // enter the "ConnectCordonel"! + if (processStateStruct.NextStateOnSuccess != null) + { + _stateMachineState = CheckForNewMeter() + ? (ProcessState)processStateStruct.NextStateOnSuccess + : processStateStruct.ErrorExitState; + } + else + { + _stateMachineState = ProcessState.Error; + } + + break; + + case ProcessState.RepeatFailedTests: + _stateMachineState = RepeatFailedTests(); + break; + + case ProcessState.AbortTest: + AbortProcesses(); + _stateMachineState = ProcessState.Idle; + break; + + case ProcessState.Stop: + KillProcesses(); + _stateMachineState = ProcessState.Idle; + break; + + case ProcessState.Error: + // Common error handling routine + ProcessErrorHandler(_stateChangeRequestProcess); + // Start the error handler with its user feedback request. It has to be started + // always even if the abortion of all processes is required! The error handler + // will change the exit state based on the user input. + StartProcess(processStateStruct); + break; + + case ProcessState.StateListDelimiter: + _stateMachineState = ProcessState.Idle; + break; + + default: + // This is the call to the processes for a specific test + StartProcess(processStateStruct); + if (processStateStruct.KickOffParallelState != null) + { + _stateMachineState = (ProcessState)processStateStruct.KickOffParallelState; + } + + break; + } } } catch (ThreadAbortException ex)