Skip to main content

gnss_protos/gps/
tlm.rs

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/// [GpsQzssTelemetry] marks the beginning of each frame
12#[derive(Debug, Default, Copy, Clone, PartialEq)]
13pub struct GpsQzssTelemetry {
14    /// 14-bit TLM Message
15    pub message: u16,
16
17    /// Integrity bit is asserted means the conveying signal is provided
18    /// with an enhanced level of integrity assurance.
19    pub integrity: bool,
20
21    /// Reserved bits
22    pub reserved_bits: bool,
23}
24
25impl GpsQzssTelemetry {
26    /// [GpsQzssTelemetry] decoding attempt.   
27    /// The special GPS marker must be present on the MSB for this to pass.   
28    /// When parity_check is requested, the parity check must pass as well.
29    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}