namespace ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport; public static class AbStatusCodes { /// Maps a CIP general status (and optional extended status words) to an . /// The CIP general status byte. /// The extended status words, if any. /// The mapped status. public static AbStatus FromCip(byte general, ReadOnlySpan extended) => general switch { 0x00 or 0x0B => AbStatus.Ok, 0x04 or 0x05 or 0x16 => AbStatus.NotFound, 0x06 => AbStatus.Partial, 0x08 => AbStatus.Unsupported, 0x0A => AbStatus.OutOfBounds, 0x0C or 0x10 => AbStatus.DeviceStateConflict, 0x0E or 0x0F => AbStatus.NotAllowed, 0x13 => AbStatus.TooSmall, 0x15 => AbStatus.TooLarge, 0xFF when extended.Length > 0 && extended[0] == 0x2105 => AbStatus.OutOfBounds, 0xFF when extended.Length > 0 && extended[0] == 0x2107 => AbStatus.TypeMismatch, _ => AbStatus.BadReply, }; /// Maps a PCCC status byte (and optional extended status) to an . /// The PCCC STS byte. /// The extended status byte, when present. /// The mapped status. public static AbStatus FromPccc(byte sts, byte? extSts) => sts switch { 0x00 => AbStatus.Ok, 0x10 => AbStatus.Unsupported, 0x20 => AbStatus.NotFound, 0x30 => AbStatus.NotAllowed, 0x40 or 0x50 => AbStatus.DeviceStateConflict, 0xF0 when extSts is 0x06 or 0x07 => AbStatus.NotFound, _ => AbStatus.BadReply, }; }