using ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport;
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip;
///
/// Maps transport values to OPC UA StatusCodes through the table shared with AbLegacy
/// (): timeout, not-found, not-allowed, out-of-bounds, unsupported, type-mismatch
/// and device-state-conflict get their specific codes; the remaining transport errors fold into
/// BadCommunicationError. (The raw CIP general-status mapper that used to live here had no callers — the
/// transports surface an , not the status byte — and was removed.)
///
public static class AbCipStatusMapper
{
public const uint Good = 0u;
public const uint GoodMoreData = 0x00A60000u;
public const uint BadInternalError = 0x80020000u;
public const uint BadNodeIdUnknown = 0x80340000u;
public const uint BadNotReadable = 0x803A0000u;
public const uint BadNotWritable = 0x803B0000u;
public const uint BadOutOfRange = 0x803C0000u;
public const uint BadNotSupported = 0x803D0000u;
public const uint BadDeviceFailure = 0x808B0000u;
public const uint BadCommunicationError = 0x80050000u;
public const uint BadTimeout = 0x800A0000u;
public const uint BadTypeMismatch = 0x80740000u;
public const uint BadConfigurationError = 0x80890000u;
///
/// Map a transport status code to an OPC UA StatusCode. The integer is
/// , i.e. the underlying value of .
///
/// The as an integer.
/// The mapped OPC UA StatusCode value.
public static uint MapStatus(int status) => MapStatus((AbStatus)status);
///
/// Map an to an OPC UA StatusCode. Timeout, not-found, not-allowed and
/// out-of-bounds get their specific codes; the remaining transport errors fold into
/// .
///
/// The transport status.
/// The mapped OPC UA StatusCode value.
public static uint MapStatus(AbStatus status) => AbOpcUaStatusMap.MapStatus(status);
///
/// Status for an exception thrown while creating / reading a tag: a transport exception maps
/// through its (so a tag the controller does not have reads
/// , not a comms error); anything else is
/// .
///
/// The exception.
/// The OPC UA status code.
public static uint MapException(Exception ex) =>
AbOpcUaStatusMap.MapException(ex);
///
/// Status for a READ the controller refused: as , except that a
/// answer to a read is (the shared table's
/// BadNotWritable describes a refused write).
///
/// The refusal status.
/// The OPC UA status code.
public static uint MapReadStatus(AbStatus status) =>
status == AbStatus.NotAllowed ? BadNotReadable : MapStatus(status);
}