1use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[repr(u8)]
11pub enum CommandCode {
12 WriteFlash = 0x01,
14 ReadFlash = 0x02,
16 GetVersion = 0x03,
18 BootFirmware = 0x04,
20 SetBaudRate = 0x06,
22 VerifyFirmware = 0x08,
24 BootBootloader = 0x09,
26 GetRunPhase = 0x0C,
28 GetSerialNumber = 0x10,
30 SingleTagInventory = 0x21,
32 SynchronousInventory = 0x22,
34 WriteTagEpc = 0x23,
36 WriteTagData = 0x24,
38 LockTag = 0x25,
40 KillTag = 0x26,
42 ReadTagData = 0x28,
44 GetTagBuffer = 0x29,
46 GetAntennaPorts = 0x61,
48 GetCurrentTagProtocol = 0x63,
50 GetFrequencyHopping = 0x65,
52 GetGpi = 0x66,
54 GetCurrentRegion = 0x67,
56 GetReaderConfiguration = 0x6A,
58 GetProtocolConfiguration = 0x6B,
60 GetAvailableRegions = 0x71,
62 GetCurrentTemperature = 0x72,
64 SetAntennaPorts = 0x91,
66 SetCurrentTagProtocol = 0x93,
68 SetFrequencyHopping = 0x95,
70 SetGpo = 0x96,
72 SetCurrentRegion = 0x97,
74 SetReaderConfiguration = 0x9A,
76 SetProtocolConfiguration = 0x9B,
78 AsynchronousInventory = 0xAA,
80}
81
82impl CommandCode {
83 pub const fn as_u8(self) -> u8 {
85 self as u8
86 }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq)]
91#[repr(u8)]
92pub enum RegionCode {
93 NorthAmerica = 0x01,
95 China1 = 0x06,
97 Europe = 0x08,
99 China2 = 0x0A,
101 FullFrequencyBand = 0xFF,
103}
104
105impl RegionCode {
106 pub const fn from_u8(raw: u8) -> Option<Self> {
108 match raw {
109 0x01 => Some(Self::NorthAmerica),
110 0x06 => Some(Self::China1),
111 0x08 => Some(Self::Europe),
112 0x0A => Some(Self::China2),
113 0xFF => Some(Self::FullFrequencyBand),
114 _ => None,
115 }
116 }
117
118 pub const fn as_u8(self) -> u8 {
120 self as u8
121 }
122}
123
124impl From<RegionCode> for u8 {
125 fn from(value: RegionCode) -> Self {
126 value as u8
127 }
128}
129
130impl fmt::Display for RegionCode {
131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132 let name = match self {
133 Self::NorthAmerica => "North America",
134 Self::China1 => "China 1",
135 Self::Europe => "Europe",
136 Self::China2 => "China 2",
137 Self::FullFrequencyBand => "Full Frequency Band",
138 };
139 f.write_str(name)
140 }
141}
142
143#[derive(Debug, Clone, Copy, PartialEq, Eq)]
145#[repr(u8)]
146pub enum AntennaPortsOption {
147 AccessPair = 0x00,
149 InventoryPairs = 0x02,
151 Power = 0x03,
153 PowerAndSettling = 0x04,
155 ConnectionStates = 0x05,
157}
158
159impl AntennaPortsOption {
160 pub const fn from_u8(raw: u8) -> Option<Self> {
162 match raw {
163 0x00 => Some(Self::AccessPair),
164 0x02 => Some(Self::InventoryPairs),
165 0x03 => Some(Self::Power),
166 0x04 => Some(Self::PowerAndSettling),
167 0x05 => Some(Self::ConnectionStates),
168 _ => None,
169 }
170 }
171
172 pub const fn as_u8(self) -> u8 {
174 self as u8
175 }
176}
177
178impl From<AntennaPortsOption> for u8 {
179 fn from(value: AntennaPortsOption) -> Self {
180 value as u8
181 }
182}
183
184#[derive(Debug, Clone, Copy, PartialEq, Eq)]
186#[repr(u16)]
187pub enum StatusCode {
188 Success = 0x0000,
190 DataLengthMismatch = 0x0100,
192 UnavailableCommand = 0x0101,
194 UnavailableParameter = 0x0105,
196 UnavailableBaudRate = 0x010A,
198 UnavailableRegion = 0x010B,
200 AppFirmwareCrcError = 0x0200,
202 FlashWriteFailed = 0x0302,
204 NoTagFound = 0x0400,
206 ProtocolUnavailable = 0x0402,
208 GeneralTagError = 0x040A,
210 ReadLengthOutOfLimit = 0x040B,
212 UnavailableKillPassword = 0x040C,
214 Gen2ProtocolError = 0x0420,
216 MemoryOverrunBadPc = 0x0423,
218 MemoryLocked = 0x0424,
220 InsufficientPower = 0x042B,
222 NonSpecificError = 0x042F,
224 UnknownTagError = 0x0430,
226 UnavailableFrequency = 0x0500,
228 TemperatureOverrun = 0x0504,
230 HighReturnLoss = 0x0505,
232 UnknownSeriousError = 0x7F00,
234 InitTimerFlashGpioError = 0xFF01,
236 OemInitFailed = 0xFF02,
238 CommandInterfaceInitFailed = 0xFF03,
240 MacRegisterRwInitFailed = 0xFF04,
242 MacRegisterInitFailed = 0xFF05,
244 R2000Arm7InterfaceInitFailed = 0xFF06,
246 R2000Arm7DetectFailed1 = 0xFF07,
248 R2000Arm7DetectFailed2 = 0xFF08,
250 GpioConfigError = 0xFF09,
252 R2000RegisterInitFailed = 0xFF0A,
254 EpcProtocolInitFailed = 0xFF0B,
256 OemMacMappingInitFailed = 0xFF0C,
258 SerialInitFailed = 0xFF0D,
260 AppMainHandlerInterfaceError = 0xFF0E,
262}
263
264impl StatusCode {
265 pub const fn from_u16(raw: u16) -> Option<Self> {
267 match raw {
268 0x0000 => Some(Self::Success),
269 0x0100 => Some(Self::DataLengthMismatch),
270 0x0101 => Some(Self::UnavailableCommand),
271 0x0105 => Some(Self::UnavailableParameter),
272 0x010A => Some(Self::UnavailableBaudRate),
273 0x010B => Some(Self::UnavailableRegion),
274 0x0200 => Some(Self::AppFirmwareCrcError),
275 0x0302 => Some(Self::FlashWriteFailed),
276 0x0400 => Some(Self::NoTagFound),
277 0x0402 => Some(Self::ProtocolUnavailable),
278 0x040A => Some(Self::GeneralTagError),
279 0x040B => Some(Self::ReadLengthOutOfLimit),
280 0x040C => Some(Self::UnavailableKillPassword),
281 0x0420 => Some(Self::Gen2ProtocolError),
282 0x0423 => Some(Self::MemoryOverrunBadPc),
283 0x0424 => Some(Self::MemoryLocked),
284 0x042B => Some(Self::InsufficientPower),
285 0x042F => Some(Self::NonSpecificError),
286 0x0430 => Some(Self::UnknownTagError),
287 0x0500 => Some(Self::UnavailableFrequency),
288 0x0504 => Some(Self::TemperatureOverrun),
289 0x0505 => Some(Self::HighReturnLoss),
290 0x7F00 => Some(Self::UnknownSeriousError),
291 0xFF01 => Some(Self::InitTimerFlashGpioError),
292 0xFF02 => Some(Self::OemInitFailed),
293 0xFF03 => Some(Self::CommandInterfaceInitFailed),
294 0xFF04 => Some(Self::MacRegisterRwInitFailed),
295 0xFF05 => Some(Self::MacRegisterInitFailed),
296 0xFF06 => Some(Self::R2000Arm7InterfaceInitFailed),
297 0xFF07 => Some(Self::R2000Arm7DetectFailed1),
298 0xFF08 => Some(Self::R2000Arm7DetectFailed2),
299 0xFF09 => Some(Self::GpioConfigError),
300 0xFF0A => Some(Self::R2000RegisterInitFailed),
301 0xFF0B => Some(Self::EpcProtocolInitFailed),
302 0xFF0C => Some(Self::OemMacMappingInitFailed),
303 0xFF0D => Some(Self::SerialInitFailed),
304 0xFF0E => Some(Self::AppMainHandlerInterfaceError),
305 _ => None,
306 }
307 }
308}