aboutsummaryrefslogtreecommitdiff
path: root/src/structs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/structs.rs')
-rw-r--r--src/structs.rs50
1 files changed, 33 insertions, 17 deletions
diff --git a/src/structs.rs b/src/structs.rs
index fe5e89a37..bce9ab9ff 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -1,3 +1,19 @@
1macro_rules! impl_bytes {
2 ($t:ident) => {
3 impl $t {
4 pub const SIZE: usize = core::mem::size_of::<Self>();
5
6 pub fn to_bytes(&self) -> [u8; Self::SIZE] {
7 unsafe { core::mem::transmute(*self) }
8 }
9
10 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self {
11 unsafe { core::mem::transmute(*bytes) }
12 }
13 }
14 };
15}
16
1#[derive(Clone, Copy)] 17#[derive(Clone, Copy)]
2#[repr(C)] 18#[repr(C)]
3pub struct SdpcmHeader { 19pub struct SdpcmHeader {
@@ -18,6 +34,7 @@ pub struct SdpcmHeader {
18 /// Reserved 34 /// Reserved
19 pub reserved: [u8; 2], 35 pub reserved: [u8; 2],
20} 36}
37impl_bytes!(SdpcmHeader);
21 38
22#[derive(Clone, Copy)] 39#[derive(Clone, Copy)]
23#[repr(C)] 40#[repr(C)]
@@ -29,6 +46,7 @@ pub struct CdcHeader {
29 pub id: u16, 46 pub id: u16,
30 pub status: u32, 47 pub status: u32,
31} 48}
49impl_bytes!(CdcHeader);
32 50
33#[derive(Clone, Copy)] 51#[derive(Clone, Copy)]
34#[repr(C)] 52#[repr(C)]
@@ -40,32 +58,30 @@ pub struct BdcHeader {
40 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers. 58 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers.
41 pub data_offset: u8, 59 pub data_offset: u8,
42} 60}
61impl_bytes!(BdcHeader);
43 62
44#[derive(Clone, Copy)] 63#[derive(Clone, Copy)]
45#[repr(C)] 64#[repr(C)]
46pub struct DownloadHeader { 65pub struct DownloadHeader {
47 pub flag: u16, 66 pub flag: u16, //
48 pub dload_type: u16, 67 pub dload_type: u16,
49 pub len: u32, 68 pub len: u32,
50 pub crc: u32, 69 pub crc: u32,
51} 70}
71impl_bytes!(DownloadHeader);
52 72
53macro_rules! impl_bytes { 73pub const DOWNLOAD_FLAG_NO_CRC: u16 = 0x0001;
54 ($t:ident) => { 74pub const DOWNLOAD_FLAG_BEGIN: u16 = 0x0002;
55 impl $t { 75pub const DOWNLOAD_FLAG_END: u16 = 0x0004;
56 pub const SIZE: usize = core::mem::size_of::<Self>(); 76pub const DOWNLOAD_FLAG_HANDLER_VER: u16 = 0x1000;
57 77
58 pub fn to_bytes(&self) -> [u8; Self::SIZE] { 78pub const DOWNLOAD_TYPE_CLM: u16 = 2;
59 unsafe { core::mem::transmute(*self) }
60 }
61 79
62 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self { 80#[derive(Clone, Copy)]
63 unsafe { core::mem::transmute(*bytes) } 81#[repr(C)]
64 } 82pub struct CountryInfo {
65 } 83 pub country_abbrev: [u8; 4],
66 }; 84 pub rev: i32,
85 pub country_code: [u8; 4],
67} 86}
68impl_bytes!(SdpcmHeader); 87impl_bytes!(CountryInfo);
69impl_bytes!(CdcHeader);
70impl_bytes!(BdcHeader);
71impl_bytes!(DownloadHeader);