use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum CommandCode {
WriteFlash = 0x01,
ReadFlash = 0x02,
GetVersion = 0x03,
BootFirmware = 0x04,
SetBaudRate = 0x06,
VerifyFirmware = 0x08,
BootBootloader = 0x09,
GetRunPhase = 0x0C,
GetSerialNumber = 0x10,
SingleTagInventory = 0x21,
SynchronousInventory = 0x22,
WriteTagEpc = 0x23,
WriteTagData = 0x24,
LockTag = 0x25,
KillTag = 0x26,
ReadTagData = 0x28,
GetTagBuffer = 0x29,
GetAntennaPorts = 0x61,
GetCurrentTagProtocol = 0x63,
GetFrequencyHopping = 0x65,
GetGpi = 0x66,
GetCurrentRegion = 0x67,
GetReaderConfiguration = 0x6A,
GetProtocolConfiguration = 0x6B,
GetAvailableRegions = 0x71,
GetCurrentTemperature = 0x72,
SetAntennaPorts = 0x91,
SetCurrentTagProtocol = 0x93,
SetFrequencyHopping = 0x95,
SetGpo = 0x96,
SetCurrentRegion = 0x97,
SetReaderConfiguration = 0x9A,
SetProtocolConfiguration = 0x9B,
AsynchronousInventory = 0xAA,
}
impl CommandCode {
pub const fn as_u8(self) -> u8 {
self as u8
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum RegionCode {
NorthAmerica = 0x01,
China1 = 0x06,
Europe = 0x08,
China2 = 0x0A,
FullFrequencyBand = 0xFF,
}
impl RegionCode {
pub const fn from_u8(raw: u8) -> Option<Self> {
match raw {
0x01 => Some(Self::NorthAmerica),
0x06 => Some(Self::China1),
0x08 => Some(Self::Europe),
0x0A => Some(Self::China2),
0xFF => Some(Self::FullFrequencyBand),
_ => None,
}
}
pub const fn as_u8(self) -> u8 {
self as u8
}
}
impl From<RegionCode> for u8 {
fn from(value: RegionCode) -> Self {
value as u8
}
}
impl fmt::Display for RegionCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
Self::NorthAmerica => "North America",
Self::China1 => "China 1",
Self::Europe => "Europe",
Self::China2 => "China 2",
Self::FullFrequencyBand => "Full Frequency Band",
};
f.write_str(name)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum AntennaPortsOption {
AccessPair = 0x00,
InventoryPairs = 0x02,
Power = 0x03,
PowerAndSettling = 0x04,
ConnectionStates = 0x05,
}
impl AntennaPortsOption {
pub const fn from_u8(raw: u8) -> Option<Self> {
match raw {
0x00 => Some(Self::AccessPair),
0x02 => Some(Self::InventoryPairs),
0x03 => Some(Self::Power),
0x04 => Some(Self::PowerAndSettling),
0x05 => Some(Self::ConnectionStates),
_ => None,
}
}
pub const fn as_u8(self) -> u8 {
self as u8
}
}
impl From<AntennaPortsOption> for u8 {
fn from(value: AntennaPortsOption) -> Self {
value as u8
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)]
pub enum StatusCode {
Success = 0x0000,
DataLengthMismatch = 0x0100,
UnavailableCommand = 0x0101,
UnavailableParameter = 0x0105,
UnavailableBaudRate = 0x010A,
UnavailableRegion = 0x010B,
AppFirmwareCrcError = 0x0200,
FlashWriteFailed = 0x0302,
NoTagFound = 0x0400,
ProtocolUnavailable = 0x0402,
GeneralTagError = 0x040A,
ReadLengthOutOfLimit = 0x040B,
UnavailableKillPassword = 0x040C,
Gen2ProtocolError = 0x0420,
MemoryOverrunBadPc = 0x0423,
MemoryLocked = 0x0424,
InsufficientPower = 0x042B,
NonSpecificError = 0x042F,
UnknownTagError = 0x0430,
UnavailableFrequency = 0x0500,
TemperatureOverrun = 0x0504,
HighReturnLoss = 0x0505,
UnknownSeriousError = 0x7F00,
InitTimerFlashGpioError = 0xFF01,
OemInitFailed = 0xFF02,
CommandInterfaceInitFailed = 0xFF03,
MacRegisterRwInitFailed = 0xFF04,
MacRegisterInitFailed = 0xFF05,
R2000Arm7InterfaceInitFailed = 0xFF06,
R2000Arm7DetectFailed1 = 0xFF07,
R2000Arm7DetectFailed2 = 0xFF08,
GpioConfigError = 0xFF09,
R2000RegisterInitFailed = 0xFF0A,
EpcProtocolInitFailed = 0xFF0B,
OemMacMappingInitFailed = 0xFF0C,
SerialInitFailed = 0xFF0D,
AppMainHandlerInterfaceError = 0xFF0E,
}
impl StatusCode {
pub const fn from_u16(raw: u16) -> Option<Self> {
match raw {
0x0000 => Some(Self::Success),
0x0100 => Some(Self::DataLengthMismatch),
0x0101 => Some(Self::UnavailableCommand),
0x0105 => Some(Self::UnavailableParameter),
0x010A => Some(Self::UnavailableBaudRate),
0x010B => Some(Self::UnavailableRegion),
0x0200 => Some(Self::AppFirmwareCrcError),
0x0302 => Some(Self::FlashWriteFailed),
0x0400 => Some(Self::NoTagFound),
0x0402 => Some(Self::ProtocolUnavailable),
0x040A => Some(Self::GeneralTagError),
0x040B => Some(Self::ReadLengthOutOfLimit),
0x040C => Some(Self::UnavailableKillPassword),
0x0420 => Some(Self::Gen2ProtocolError),
0x0423 => Some(Self::MemoryOverrunBadPc),
0x0424 => Some(Self::MemoryLocked),
0x042B => Some(Self::InsufficientPower),
0x042F => Some(Self::NonSpecificError),
0x0430 => Some(Self::UnknownTagError),
0x0500 => Some(Self::UnavailableFrequency),
0x0504 => Some(Self::TemperatureOverrun),
0x0505 => Some(Self::HighReturnLoss),
0x7F00 => Some(Self::UnknownSeriousError),
0xFF01 => Some(Self::InitTimerFlashGpioError),
0xFF02 => Some(Self::OemInitFailed),
0xFF03 => Some(Self::CommandInterfaceInitFailed),
0xFF04 => Some(Self::MacRegisterRwInitFailed),
0xFF05 => Some(Self::MacRegisterInitFailed),
0xFF06 => Some(Self::R2000Arm7InterfaceInitFailed),
0xFF07 => Some(Self::R2000Arm7DetectFailed1),
0xFF08 => Some(Self::R2000Arm7DetectFailed2),
0xFF09 => Some(Self::GpioConfigError),
0xFF0A => Some(Self::R2000RegisterInitFailed),
0xFF0B => Some(Self::EpcProtocolInitFailed),
0xFF0C => Some(Self::OemMacMappingInitFailed),
0xFF0D => Some(Self::SerialInitFailed),
0xFF0E => Some(Self::AppMainHandlerInterfaceError),
_ => None,
}
}
}