use bitflags::bitflags;
use core::fmt;
#[cfg(feature = "serde")]
use super::SerializeUbxPacketFields;
#[cfg(feature = "serde")]
use crate::serde::ser::SerializeMap;
use crate::{error::ParserError, GnssFixType, UbxPacketMeta};
use ublox_derive::{ubx_extend, ubx_extend_bitflags, ubx_packet_recv};
#[ubx_packet_recv]
#[ubx(class = 1, id = 3, fixed_payload_len = 16)]
struct NavStatus {
itow: u32,
#[ubx(map_type = GnssFixType)]
fix_type: u8,
#[ubx(map_type = NavStatusFlags)]
flags: u8,
#[ubx(map_type = FixStatusInfo)]
fix_stat: u8,
#[ubx(map_type = NavStatusFlags2)]
flags2: u8,
time_to_first_fix: u32,
uptime_ms: u32,
}
#[ubx_extend_bitflags]
#[ubx(from, rest_reserved)]
bitflags! {
#[derive(Debug)]
pub struct NavStatusFlags: u8 {
const GPS_FIX_OK = 1;
const DIFF_SOLN = 2;
const WKN_SET = 4;
const TOW_SET = 8;
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct FixStatusInfo(u8);
impl FixStatusInfo {
pub const fn has_pr_prr_correction(self) -> bool {
(self.0 & 1) == 1
}
pub fn map_matching(self) -> MapMatchingStatus {
let bits = (self.0 >> 6) & 3;
match bits {
0 => MapMatchingStatus::None,
1 => MapMatchingStatus::Valid,
2 => MapMatchingStatus::Used,
3 => MapMatchingStatus::Dr,
_ => unreachable!("MapMatching Status value not supported by protocol specification"),
}
}
pub const fn from(x: u8) -> Self {
Self(x)
}
}
impl fmt::Debug for FixStatusInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FixStatusInfo")
.field("has_pr_prr_correction", &self.has_pr_prr_correction())
.field("map_matching", &self.map_matching())
.finish()
}
}
#[ubx_extend]
#[ubx(from, rest_reserved)]
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
enum NavStatusFlags2 {
Acquisition = 0,
Tracking = 1,
PowerOptimizedTracking = 2,
Inactive = 3,
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum MapMatchingStatus {
None = 0,
Valid = 1,
Used = 2,
Dr = 3,
}