common/Hardware/WaterMeter/Genesis/Protocols/RequestProtocol/RequestRecord.cs
2026-04-23 17:50:07 +02:00

114 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
{
/// <summary>
/// Holds request commands with detail parameters to see processing state
/// </summary>
public class RequestRecord
{
/// <summary>
/// Indicates the base command <see cref="Commands" />
/// </summary>
public readonly Byte ResponseCommand;
/// <summary>
/// the register the command refers to.
/// needed to set Register dictionary to link response with dictionary key
/// </summary>
public readonly RegisterDefinition Register;
/// <summary>
/// Command acknowledged
/// </summary>
public RequestAcknowledgeState Acknowledge = RequestAcknowledgeState.Unsent;
/// <summary>
/// Retry counter
/// </summary>
public Int32 RetryCtr = 0;
/// <summary>
/// Wakeup-message retry counter
/// </summary>
public Int32 WakeupMessageRetryCtr = 0;
/// <summary>
/// indicates error base on <see cref="RequestRecord"/>
/// </summary>
public Byte ResponseErrorBase = 0xFF;
/// <summary>
/// indicates error reason on <see cref="RequestRecord"/>
/// </summary>
public Byte ResponseErrorReason = 0xFF;
/// <summary>
/// Combined error code of base and reason
/// </summary>
public UInt16 ResponseErrorCode = 0xFFFF;
/// <summary>
/// Chunk position of error on multiple read/write access
/// </summary>
public UInt16 ResponseErrorPosition = 0;
/// <summary>
/// Data containing the request protocol
/// </summary>
public readonly List<Byte> RequestProtocolData;
/// <summary>
/// Encoded with transmit protocol, ready to stream to port as is
/// </summary>
public List<Byte> EncodedRequestData { get; }
/// <summary>
/// Extracted payload of response
/// </summary>
public List<Byte> ResponsePayload;
/// <summary>
/// Extracted payload of response
/// </summary>
public readonly Int32 ResponseTimeoutMs;
/// <summary>
/// avoid logging for e.g. password
/// </summary>
public readonly Boolean HideDataInLog;
/// <summary>
/// error mask to skip retries for functional errors <see cref="ResponseErrorCode"/>
/// </summary>
public readonly UInt16 SkipRetryErrorCode;
/// <summary>
/// Ctor for an base command <see cref="Commands" />
/// </summary>
/// <param name="command"><see cref="Commands" /> as an byte</param>
/// <param name="requestProtocolData">Request protocol data for logging</param>
/// <param name="encodedRequestData"> Ready to send data encoded with transmit protocol retries</param>
/// <param name="responseTimeoutMs">Timeout for response</param>
/// <param name="register"><see cref="RegisterDefinition"/> to do command with</param>
/// <param name="hideDataInLog">hiding data in log file to avoid spying of passwords</param>
/// <param name="skipRetryErrorCode">error mask to skip retries <see cref="ResponseErrorCode"/></param>
public RequestRecord(Byte command, List<Byte> requestProtocolData = null, List<Byte> encodedRequestData = null,
Int32 responseTimeoutMs = 100, RegisterDefinition register = null, Boolean hideDataInLog = false,
UInt16 skipRetryErrorCode = CommunicationConfig.SkipRetryErrorCode)
{
ResponseCommand = (Byte)(command + 1);
Register = register;
RequestProtocolData = requestProtocolData;
EncodedRequestData = encodedRequestData;
ResponseTimeoutMs = responseTimeoutMs;
HideDataInLog = hideDataInLog;
SkipRetryErrorCode = skipRetryErrorCode;
}
}
}