Files
lmxopcua/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Heidenhain/HeidenhainStatus.cs
T
Joseph Doherty 4cee05c2f8 feat(heidenhain): R_RI runtime-info parity with pyLSV2 — state names, refusal codes, timer/unit docs
Compared every R_RI decoder we use (22-28, 30-34, 51) byte-for-byte with pyLSV2 (MIT,
97a3d691) and ran the captured iTNC 530 replies through pyLSV2 itself: no decode
disagreement, so no published value changes.

- Additive read-only String leaves Status/ExecutionStateName, Status/ProgramStateName and
  Tool/AxisName (pyLSV2 ExecState / PgmState / decode_tool_info names; out-of-table code =
  "Unknown"). They ride the raw leaf's feature, so no extra wire read; raw Int32 leaves unchanged.
- Refusals: 52/72 -> BadOutOfRange, 58 -> BadTimeout, 56 -> BadInvalidState, 57 (outside the
  alarm walk) -> BadNoData. IsStable and the 57-only alarm-walk end are unchanged.
  Lsv2RefusalCodes names every code (pyLSV2 LSV2StatusCode) in exception/log/probe text.
- Timers 30-34 documented as uint32be seconds (lifetime counters) per pyLSV2, hardware-unproven;
  TimersEnabled stays false. Axis/tool units: none on the wire, none assumed.
- Lsv2ReadOnlyPolicy untouched (pinned by a test); R_RI 20/21 left out.

Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
2026-11-12 23:55:34 -05:00

92 lines
4.6 KiB
C#

namespace ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
/// <summary>
/// The OPC UA status codes this driver publishes (canonical <c>Opc.Ua.StatusCodes</c> numerics, pinned by
/// <c>HeidenhainStatusTests</c>), with the reference's failure interpretation.
/// </summary>
public static class HeidenhainStatus
{
public const uint Good = 0u;
/// <summary>Transport lost — every remote leaf, immediately.</summary>
public const uint BadNoCommunication = 0x80310000u;
/// <summary>Refusal 22/24, disabled feature, or a feature absent from the reply (8-byte tool geometry).</summary>
public const uint BadNotSupported = 0x803D0000u;
/// <summary>Refusal 23/49.</summary>
public const uint BadUserAccessDenied = 0x801F0000u;
/// <summary>Malformed complete record.</summary>
public const uint BadDecodingError = 0x80070000u;
/// <summary>Binding type mismatch.</summary>
public const uint BadTypeMismatch = 0x80740000u;
/// <summary>Out-of-region binding, or alarm-list overflow.</summary>
public const uint BadOutOfRange = 0x803C0000u;
/// <summary>Any other controller refusal (retried next poll).</summary>
public const uint BadUnexpectedError = 0x80010000u;
/// <summary>
/// An optional-role (DNC/DATA) credential cannot be used — unresolvable reference, or a password the login
/// payload cannot carry (NUL, non-Latin-1, too long). Degrades only the reads that need that role.
/// </summary>
public const uint BadConfigurationError = 0x80890000u;
/// <summary>A RawPath this driver has no authored tag for.</summary>
public const uint BadNodeIdUnknown = 0x80340000u;
/// <summary>Authored but not yet acquired.</summary>
public const uint BadWaitingForInitialData = 0x80320000u;
/// <summary>Refusal 58 (<c>T_ER_ACCESS_TIMEOUT</c>): the control timed out reaching the data (retried).</summary>
public const uint BadTimeout = 0x800A0000u;
/// <summary>Refusal 56 (<c>T_ER_OPERATING_MODE</c>): not allowed in the control's current mode (retried).</summary>
public const uint BadInvalidState = 0x80AF0000u;
/// <summary>Refusal 57 (<c>T_ER_NO_NEXT_ERROR</c>) outside the alarm walk, which consumes it as "end of list".</summary>
public const uint BadNoData = 0x809B0000u;
/// <summary>
/// Maps a controller refusal code to a value status. Code names per pyLSV2 (MIT)
/// <c>const.py:LSV2StatusCode</c> (<see cref="Lsv2.Lsv2RefusalCodes"/>): 22 UNKNOWN_TELE / 24 WRONG_PARA ⇒
/// unsupported; 23 NO_PRIV / 49 NO_LOGIN ⇒ access denied; 52 BAD_MEMADR / 72 OUT_OF_RANGE ⇒ out of range;
/// 58 ACCESS_TIMEOUT ⇒ timeout; 56 OPERATING_MODE ⇒ invalid state; 57 NO_NEXT_ERROR ⇒ no data; anything else
/// unexpected. Only the first two are <see cref="IsStable"/> (suppressed for the session) — every other code is
/// retried on the next poll, exactly as before the specific mapping.
/// </summary>
/// <param name="code">The refusal code.</param>
/// <returns>The status.</returns>
public static uint FromRefusal(int code) => code switch
{
Lsv2.Lsv2RefusalCodes.UnknownTelegram or Lsv2.Lsv2RefusalCodes.WrongParameter => BadNotSupported,
Lsv2.Lsv2RefusalCodes.NoPrivilege or Lsv2.Lsv2RefusalCodes.NoLogin => BadUserAccessDenied,
Lsv2.Lsv2RefusalCodes.BadMemoryAddress or Lsv2.Lsv2RefusalCodes.OutOfRange => BadOutOfRange,
Lsv2.Lsv2RefusalCodes.AccessTimeout => BadTimeout,
Lsv2.Lsv2RefusalCodes.OperatingMode => BadInvalidState,
Lsv2.Lsv2RefusalCodes.NoNextError => BadNoData,
_ => BadUnexpectedError,
};
/// <summary>True for the stable refusals that may be suppressed for the rest of a session.</summary>
/// <param name="status">The status.</param>
/// <returns>Whether it is stable.</returns>
public static bool IsStable(uint status) => status is BadNotSupported or BadUserAccessDenied or BadConfigurationError;
/// <summary>The capability state for a failure status.</summary>
/// <param name="status">The status.</param>
/// <returns>The state string.</returns>
public static string State(uint status) => status switch
{
BadUserAccessDenied => HeidenhainCatalog.States.AccessDenied,
BadNotSupported => HeidenhainCatalog.States.Unsupported,
BadDecodingError or BadTypeMismatch or BadOutOfRange => HeidenhainCatalog.States.InvalidData,
BadNoCommunication => HeidenhainCatalog.States.CommunicationLost,
BadConfigurationError => HeidenhainCatalog.States.ConfigurationError,
_ => HeidenhainCatalog.States.Unknown,
};
}