Skip to main content

gnss_protos/gps/
how.rs

1use crate::gps::GpsError;
2
3const TOW_MASK: u32 = 0x3fffE000;
4const TOW_SHIFT: u32 = 13;
5
6const ALERT_MASK: u32 = 0x00001000;
7const AS_MASK: u32 = 0x00000800;
8
9const FRAMEID_MASK: u32 = 0x00000700;
10const FRAMEID_SHIFT: u32 = 8;
11
12use crate::gps::GpsQzssFrameId;
13
14#[cfg(doc)]
15use crate::gps::GpsQzssTelemetry;
16
17/// [GpsQzssHow] marks the beginning of each frame, following [GpsQzssTelemetry]
18#[derive(Debug, Default, Copy, Clone, PartialEq)]
19/// [GpsHowWord]
20pub struct GpsQzssHow {
21    /// TOW (in seconds)
22    pub tow: u32,
23
24    /// When alert is asserted, the SV URA may be worse than indicated in subframe 1
25    /// and user shall use this SV at their own risk.
26    pub alert: bool,
27
28    /// A-S mode is ON in that SV
29    pub anti_spoofing: bool,
30
31    /// Following Frame ID (to decode following data words)
32    pub frame_id: GpsQzssFrameId,
33}
34
35impl GpsQzssHow {
36    pub fn ephemeris1() -> Self {
37        Self {
38            tow: 0,
39            alert: false,
40            anti_spoofing: false,
41            frame_id: GpsQzssFrameId::Ephemeris1,
42        }
43    }
44
45    pub fn ephemeris2() -> Self {
46        Self {
47            tow: 0,
48            alert: false,
49            anti_spoofing: false,
50            frame_id: GpsQzssFrameId::Ephemeris2,
51        }
52    }
53
54    pub fn ephemeris3() -> Self {
55        Self {
56            tow: 0,
57            alert: false,
58            anti_spoofing: false,
59            frame_id: GpsQzssFrameId::Ephemeris3,
60        }
61    }
62
63    pub(crate) fn decode(dword: u32) -> Result<Self, GpsError> {
64        let tow = ((dword & TOW_MASK) >> TOW_SHIFT) as u32;
65        let frame_id = GpsQzssFrameId::decode(((dword & FRAMEID_MASK) >> FRAMEID_SHIFT) as u8)?;
66        let alert = (dword & ALERT_MASK) > 0;
67        let anti_spoofing = (dword & AS_MASK) > 0;
68
69        Ok(Self {
70            alert,
71            frame_id,
72            anti_spoofing,
73            tow: tow * 6,
74        })
75    }
76}