From 7ddcacac7bbfaed303dcda7d14ab29cad94fd570 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 11 Jul 2022 03:07:39 +0200 Subject: clm download, country config. --- src/structs.rs | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'src/structs.rs') 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 @@ +macro_rules! impl_bytes { + ($t:ident) => { + impl $t { + pub const SIZE: usize = core::mem::size_of::(); + + pub fn to_bytes(&self) -> [u8; Self::SIZE] { + unsafe { core::mem::transmute(*self) } + } + + pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self { + unsafe { core::mem::transmute(*bytes) } + } + } + }; +} + #[derive(Clone, Copy)] #[repr(C)] pub struct SdpcmHeader { @@ -18,6 +34,7 @@ pub struct SdpcmHeader { /// Reserved pub reserved: [u8; 2], } +impl_bytes!(SdpcmHeader); #[derive(Clone, Copy)] #[repr(C)] @@ -29,6 +46,7 @@ pub struct CdcHeader { pub id: u16, pub status: u32, } +impl_bytes!(CdcHeader); #[derive(Clone, Copy)] #[repr(C)] @@ -40,32 +58,30 @@ pub struct BdcHeader { /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers. pub data_offset: u8, } +impl_bytes!(BdcHeader); #[derive(Clone, Copy)] #[repr(C)] pub struct DownloadHeader { - pub flag: u16, + pub flag: u16, // pub dload_type: u16, pub len: u32, pub crc: u32, } +impl_bytes!(DownloadHeader); -macro_rules! impl_bytes { - ($t:ident) => { - impl $t { - pub const SIZE: usize = core::mem::size_of::(); +pub const DOWNLOAD_FLAG_NO_CRC: u16 = 0x0001; +pub const DOWNLOAD_FLAG_BEGIN: u16 = 0x0002; +pub const DOWNLOAD_FLAG_END: u16 = 0x0004; +pub const DOWNLOAD_FLAG_HANDLER_VER: u16 = 0x1000; - pub fn to_bytes(&self) -> [u8; Self::SIZE] { - unsafe { core::mem::transmute(*self) } - } +pub const DOWNLOAD_TYPE_CLM: u16 = 2; - pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self { - unsafe { core::mem::transmute(*bytes) } - } - } - }; +#[derive(Clone, Copy)] +#[repr(C)] +pub struct CountryInfo { + pub country_abbrev: [u8; 4], + pub rev: i32, + pub country_code: [u8; 4], } -impl_bytes!(SdpcmHeader); -impl_bytes!(CdcHeader); -impl_bytes!(BdcHeader); -impl_bytes!(DownloadHeader); +impl_bytes!(CountryInfo); -- cgit