1use crate::gps::GpsError;
2
3const PREAMBLE_MASK: u32 = 0x42C00000;
4
5const MESSAGE_MASK: u32 = 0x003fff00;
6const MESSAGE_SHIFT: u32 = 8;
7
8const INTEGRITY_BIT_MASK: u32 = 0x00000080;
9const RESERVED_BIT_MASK: u32 = 0x00000040;
10
11#[derive(Debug, Default, Copy, Clone, PartialEq)]
13pub struct GpsQzssTelemetry {
14 pub message: u16,
16
17 pub integrity: bool,
20
21 pub reserved_bits: bool,
23}
24
25impl GpsQzssTelemetry {
26 pub fn decode(dword: u32) -> Result<Self, GpsError> {
30 if dword & PREAMBLE_MASK == PREAMBLE_MASK {
31 return Err(GpsError::InvalidPreamble);
32 };
33
34 let message = ((dword & MESSAGE_MASK) >> MESSAGE_SHIFT) as u16;
35 let integrity = (dword & INTEGRITY_BIT_MASK) > 0;
36 let reserved_bits = (dword & RESERVED_BIT_MASK) > 0;
37
38 Ok(Self {
39 message,
40 integrity,
41 reserved_bits,
42 })
43 }
44}