From a2aded3bcdb29451df735ac6298320dd6771c02b Mon Sep 17 00:00:00 2001 From: notoriaga Date: Mon, 13 Nov 2023 09:49:22 -0800 Subject: [PATCH] rust: check time source for MsgGpsTime --- generator/sbpg/targets/rust.py | 10 ++++++++++ rust/sbp/src/messages/navigation.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/generator/sbpg/targets/rust.py b/generator/sbpg/targets/rust.py index 3a23861d47..5b09a98126 100644 --- a/generator/sbpg/targets/rust.py +++ b/generator/sbpg/targets/rust.py @@ -60,6 +60,16 @@ BASE_TIME_MSGS = ["MSG_OBS", "MSG_OSR", "MSG_SSR"] CUSTOM_GPS_TIME_MSGS = { + "MSG_GPS_TIME": """ +if !matches!(self.time_source(), Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated)) { + return None; +} +""".strip() + GPS_TIME, + "MSG_GPS_TIME_DEP_A": """ +if !matches!(self.time_source(), Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated)) { + return None; +} +""".strip() + GPS_TIME, "MSG_IMU_RAW": """ const IMU_RAW_TIME_STATUS_MASK: u32 = (1 << 30) | (1 << 31); if self.tow & IMU_RAW_TIME_STATUS_MASK != 0 { diff --git a/rust/sbp/src/messages/navigation.rs b/rust/sbp/src/messages/navigation.rs index 62b805e224..2096a75a8e 100644 --- a/rust/sbp/src/messages/navigation.rs +++ b/rust/sbp/src/messages/navigation.rs @@ -1888,6 +1888,12 @@ pub mod msg_gps_time { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if !matches!( + self.time_source(), + Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated) + ) { + return None; + } let tow_s = (self.tow as f64) / 1000.0; #[allow(clippy::useless_conversion)] let wn: i16 = match self.wn.try_into() { @@ -2044,6 +2050,12 @@ pub mod msg_gps_time_dep_a { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if !matches!( + self.time_source(), + Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated) + ) { + return None; + } let tow_s = (self.tow as f64) / 1000.0; #[allow(clippy::useless_conversion)] let wn: i16 = match self.wn.try_into() {