diff options
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/structs.rs b/src/structs.rs index 060c2b060..7a7c25b26 100644 --- a/src/structs.rs +++ b/src/structs.rs | |||
| @@ -67,7 +67,41 @@ impl_bytes!(BcdHeader); | |||
| 67 | #[derive(Clone, Copy)] | 67 | #[derive(Clone, Copy)] |
| 68 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 68 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 69 | #[repr(C)] | 69 | #[repr(C)] |
| 70 | pub struct EthernetHeader { | ||
| 71 | pub destination_mac: [u8; 6], | ||
| 72 | pub source_mac: [u8; 6], | ||
| 73 | pub ether_type: u16, | ||
| 74 | } | ||
| 75 | |||
| 76 | impl EthernetHeader { | ||
| 77 | pub fn byteswap(&mut self) { | ||
| 78 | self.ether_type = self.ether_type.to_be(); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | #[derive(Clone, Copy)] | ||
| 83 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 84 | #[repr(C)] | ||
| 70 | pub struct EventHeader { | 85 | pub struct EventHeader { |
| 86 | pub subtype: u16, | ||
| 87 | pub length: u16, | ||
| 88 | pub version: u8, | ||
| 89 | pub oui: [u8; 3], | ||
| 90 | pub user_subtype: u16, | ||
| 91 | } | ||
| 92 | |||
| 93 | impl EventHeader { | ||
| 94 | pub fn byteswap(&mut self) { | ||
| 95 | self.subtype = self.subtype.to_be(); | ||
| 96 | self.length = self.length.to_be(); | ||
| 97 | self.user_subtype = self.user_subtype.to_be(); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | #[derive(Clone, Copy)] | ||
| 102 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 103 | #[repr(C)] | ||
| 104 | pub struct EventMessage { | ||
| 71 | /// version | 105 | /// version |
| 72 | pub version: u16, | 106 | pub version: u16, |
| 73 | /// see flags below | 107 | /// see flags below |
| @@ -91,9 +125,9 @@ pub struct EventHeader { | |||
| 91 | /// source bsscfg index | 125 | /// source bsscfg index |
| 92 | pub bsscfgidx: u8, | 126 | pub bsscfgidx: u8, |
| 93 | } | 127 | } |
| 94 | impl_bytes!(EventHeader); | 128 | impl_bytes!(EventMessage); |
| 95 | 129 | ||
| 96 | impl EventHeader { | 130 | impl EventMessage { |
| 97 | pub fn byteswap(&mut self) { | 131 | pub fn byteswap(&mut self) { |
| 98 | self.version = self.version.to_be(); | 132 | self.version = self.version.to_be(); |
| 99 | self.flags = self.flags.to_be(); | 133 | self.flags = self.flags.to_be(); |
| @@ -106,6 +140,24 @@ impl EventHeader { | |||
| 106 | } | 140 | } |
| 107 | 141 | ||
| 108 | #[derive(Clone, Copy)] | 142 | #[derive(Clone, Copy)] |
| 143 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 144 | #[repr(C)] | ||
| 145 | pub struct EventPacket { | ||
| 146 | pub eth: EthernetHeader, | ||
| 147 | pub hdr: EventHeader, | ||
| 148 | pub msg: EventMessage, | ||
| 149 | } | ||
| 150 | impl_bytes!(EventPacket); | ||
| 151 | |||
| 152 | impl EventPacket { | ||
| 153 | pub fn byteswap(&mut self) { | ||
| 154 | self.eth.byteswap(); | ||
| 155 | self.hdr.byteswap(); | ||
| 156 | self.msg.byteswap(); | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | #[derive(Clone, Copy)] | ||
| 109 | #[repr(C)] | 161 | #[repr(C)] |
| 110 | pub struct DownloadHeader { | 162 | pub struct DownloadHeader { |
| 111 | pub flag: u16, // | 163 | pub flag: u16, // |
