use crate::gps::GpsError;
const PREAMBLE_MASK: u32 = 0x42C00000;
const MESSAGE_MASK: u32 = 0x003fff00;
const MESSAGE_SHIFT: u32 = 8;
const INTEGRITY_BIT_MASK: u32 = 0x00000080;
const RESERVED_BIT_MASK: u32 = 0x00000040;
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct GpsQzssTelemetry {
pub message: u16,
pub integrity: bool,
pub reserved_bits: bool,
}
impl GpsQzssTelemetry {
pub fn decode(dword: u32) -> Result<Self, GpsError> {
if dword & PREAMBLE_MASK == PREAMBLE_MASK {
return Err(GpsError::InvalidPreamble);
};
let message = ((dword & MESSAGE_MASK) >> MESSAGE_SHIFT) as u16;
let integrity = (dword & INTEGRITY_BIT_MASK) > 0;
let reserved_bits = (dword & RESERVED_BIT_MASK) > 0;
Ok(Self {
message,
integrity,
reserved_bits,
})
}
}