RegisterConverter: - Removed SizeOf

This commit is contained in:
Thomas Wiedebusch 2025-10-13 10:50:12 +02:00
parent 24d25d0261
commit 61c3583a95
6 changed files with 95 additions and 93 deletions

View File

@ -171,7 +171,7 @@
</site>
<site name="MeterProcessState(2)" id="4">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\REPO\lab\la_operations\laa_production\Common\Service\MeterProcessState" />
<virtualDirectory path="/" physicalPath="D:\Projekte\SENSUS_GitLab\LAA_PRODUCTION\Common\Service\MeterProcessState" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:50075:localhost" />

View File

@ -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.
/// </remarks>
private void BuildRegisterList(String configurationJson)
public void BuildRegisterList(String configurationJson)
{
IDictionary<String, AppSection> sections;

View File

@ -140,6 +140,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
private ILogger _loggerRawData;
/// <summary>
/// Optional request to use the offline passwords
/// </summary>
public Boolean UseOfflinePasswords;
/// <summary>
/// Process configuration
/// </summary>
@ -1211,6 +1216,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <remarks date="2023-Feb-28" author="T.Wiedebusch">
/// - Used <see cref="MeterPwdHandlerDb.GetPasswordFromDb"/>
/// </remarks>
/// <remarks date="2025-Oct-10" author="T.Wiedebusch">
/// - Optional the offline passwords will be used.
/// </remarks>
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
/// <remarks date="2024-May-17" author="Thomas Wiedebusch">
/// - Changed sensitive information from "*****" to SHA256.
/// </remarks>
/// <remarks date="2025-Oct-13" author="Thomas Wiedebusch">
/// - Date size directly from register object.
/// </remarks>
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;

View File

@ -1671,6 +1671,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <remarks date="2025-Apr-07" author="Thomas Wiedebusch">
/// - CancellationToken.
/// </remarks>
/// <remarks date="2025-Oct-13" author="Thomas Wiedebusch">
/// - Date size directly from register object.
/// </remarks>
private Boolean ReadRegistersSet(ref List<RecoveryRegisterItem> 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)

View File

@ -255,23 +255,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
return converted;
}
/// <summary>
/// Get size of type
/// </summary>
/// <param name="registerDefinition"></param>
/// <returns>size in bytes</returns>
/// <remarks date="2023-Sep-05" author="Thomas Wiedebusch">
/// - Init.
/// </remarks>
/// <remarks date="2025-Oct-09" author="Thomas Wiedebusch">
/// - Build the size in the 'GenesisConfigReader.cs'/>
/// </remarks>
public static Int32 SizeOf(RegisterDefinition registerDefinition)
{
return registerDefinition.DataSize;
}
/// <summary>
/// Build the result of the array as text.
/// </summary>
@ -333,7 +316,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
}
if (type == typeof(ByteArray) || type == typeof(Byte[]))
{
//return ByteArrayToValue<Byte[]>(rawByteArray).ToString();
return "";
}
if (type == typeof(SByte))

View File

@ -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)