1use crate::consts::RDM_MAX_PARAMETER_DATA_LENGTH;
2
3pub type DataPack = heapless::Vec<u8, RDM_MAX_PARAMETER_DATA_LENGTH>;
4
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8#[repr(u8)]
9pub enum ResponseType {
10 ResponseTypeAck = 0x00,
12 ResponseTypeAckTimer = 0x01,
14 ResponseTypeNackReason = 0x02,
16 ResponseTypeAckOverflow = 0x03,
18}
19
20impl TryFrom<u8> for ResponseType {
21 type Error = ();
22
23 fn try_from(value: u8) -> Result<Self, ()> {
24 Ok(match value {
25 0x00 => Self::ResponseTypeAck,
26 0x01 => Self::ResponseTypeAckTimer,
27 0x02 => Self::ResponseTypeNackReason,
28 0x03 => Self::ResponseTypeAckOverflow,
29 _ => {
30 return Err(());
31 },
32 })
33 }
34}
35
36#[derive(Copy, Clone, Debug, Eq, PartialEq)]
37#[cfg_attr(feature = "defmt", derive(defmt::Format))]
38#[repr(u16)]
39pub enum NackReason {
40 UnknownPid = 0x0000,
41 FormatError = 0x0001,
42 HardwareFault = 0x0002,
43 ProxyReject = 0x0003,
44 WriteProtect = 0x0004,
45 UnsupportedCommandClass = 0x0005,
46 DataOutOfRange = 0x0006,
47 BufferFull = 0x0007,
48 PacketSizeUnsupported = 0x0008,
49 SubDeviceOutOfRange = 0x0009,
50 ProxyBufferFull = 0x000A,
51}
52
53impl NackReason {
54 pub fn serialize(&self) -> DataPack {
55 DataPack::from_slice(&(*self as u16).to_be_bytes()).unwrap()
56 }
57}
58
59impl TryFrom<u16> for NackReason {
60 type Error = ();
61
62 fn try_from(value: u16) -> Result<Self, ()> {
63 match value {
64 0x0000 => Ok(Self::UnknownPid),
65 0x0001 => Ok(Self::FormatError),
66 0x0002 => Ok(Self::HardwareFault),
67 0x0003 => Ok(Self::ProxyReject),
68 0x0004 => Ok(Self::WriteProtect),
69 0x0005 => Ok(Self::UnsupportedCommandClass),
70 0x0006 => Ok(Self::DataOutOfRange),
71 0x0007 => Ok(Self::BufferFull),
72 0x0008 => Ok(Self::PacketSizeUnsupported),
73 0x0009 => Ok(Self::SubDeviceOutOfRange),
74 0x000A => Ok(Self::ProxyBufferFull),
75 _ => Err(()),
76 }
77 }
78}