From 9b9dcd1cf3e234a9d6a0b51d8c278c3048a5de75 Mon Sep 17 00:00:00 2001 From: Steven Meyer Date: Tue, 14 Nov 2023 10:29:07 -0800 Subject: [PATCH] rust: check more messages for time validity (#1376) # Description Same as https://github.com/swift-nav/libsbp/pull/1375 but accounts for the other 3 time messages and msg_odometry @swift-nav/devinfra # API compatibility Does this change introduce a API compatibility risk? ## API compatibility plan If the above is "Yes", please detail the compatibility (or migration) plan: # JIRA Reference https://swift-nav.atlassian.net/browse/BOARD-XXXX --- generator/sbpg/targets/rust.py | 20 ++++++++++++++------ rust/sbp/src/messages/navigation.rs | 17 +++++++++++++---- rust/sbp/src/messages/vehicle.rs | 3 +++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/generator/sbpg/targets/rust.py b/generator/sbpg/targets/rust.py index d12b7a383f..44c73102be 100644 --- a/generator/sbpg/targets/rust.py +++ b/generator/sbpg/targets/rust.py @@ -59,12 +59,13 @@ 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)) { +CHECK_FLAGS = """ +if self.time_source().ok()? == TimeSource::None { return None; } -""".strip() + GPS_TIME, +""" + +CUSTOM_GPS_TIME_MSGS = { "MSG_IMU_RAW": """ const IMU_RAW_TIME_STATUS_MASK: u32 = (1 << 30) | (1 << 31); if self.tow & IMU_RAW_TIME_STATUS_MASK != 0 { @@ -223,10 +224,13 @@ def gen_body(): tow = True elif f.identifier == "wn": wn = True + res = "" + if msg.has_timesource: + res = CHECK_FLAGS if tow and wn: - return GPS_TIME + return res + GPS_TIME elif tow: - return GPS_TIME_ONLY_TOW + return res + GPS_TIME_ONLY_TOW else: return None @@ -361,11 +365,15 @@ def __init__(self, msg, package, package_specs): self.is_real_message = msg.is_real_message self.fields = [] self.has_bitfield = False + self.has_timesource = False for f in msg.fields: field = FieldItem(msg, package_specs, f) self.fields.append(field) if len(field.bitfield) > 0: self.has_bitfield = True + for b in field.bitfield: + if b["type_name"] == "TimeSource": + self.has_timesource = True self.gps_time_fn = gps_time_fn(self) self.friendly_name = msg.friendly_name diff --git a/rust/sbp/src/messages/navigation.rs b/rust/sbp/src/messages/navigation.rs index a744c90b98..5cc00ca1c4 100644 --- a/rust/sbp/src/messages/navigation.rs +++ b/rust/sbp/src/messages/navigation.rs @@ -1888,10 +1888,7 @@ pub mod msg_gps_time { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { - if !matches!( - self.time_source(), - Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated) - ) { + if self.time_source().ok()? == TimeSource::None { return None; } let tow_s = (self.tow as f64) / 1000.0; @@ -2200,6 +2197,9 @@ pub mod msg_gps_time_gnss { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if self.time_source().ok()? == TimeSource::None { + return None; + } let tow_s = (self.tow as f64) / 1000.0; #[allow(clippy::useless_conversion)] let wn: i16 = match self.wn.try_into() { @@ -2469,6 +2469,9 @@ pub mod msg_pose_relative { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if self.time_source().ok()? == TimeSource::None { + return None; + } let tow_s = (self.tow as f64) / 1000.0; let gps_time = match time::GpsTime::new(0, tow_s) { Ok(gps_time) => gps_time.tow(), @@ -7223,6 +7226,9 @@ pub mod msg_utc_time { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if self.time_source().ok()? == TimeSource::None { + return None; + } let tow_s = (self.tow as f64) / 1000.0; let gps_time = match time::GpsTime::new(0, tow_s) { Ok(gps_time) => gps_time.tow(), @@ -7478,6 +7484,9 @@ pub mod msg_utc_time_gnss { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if self.time_source().ok()? == TimeSource::None { + return None; + } let tow_s = (self.tow as f64) / 1000.0; let gps_time = match time::GpsTime::new(0, tow_s) { Ok(gps_time) => gps_time.tow(), diff --git a/rust/sbp/src/messages/vehicle.rs b/rust/sbp/src/messages/vehicle.rs index a034f62f49..4018707d93 100644 --- a/rust/sbp/src/messages/vehicle.rs +++ b/rust/sbp/src/messages/vehicle.rs @@ -128,6 +128,9 @@ pub mod msg_odometry { #[cfg(feature = "swiftnav")] fn gps_time(&self) -> Option> { + if self.time_source().ok()? == TimeSource::None { + return None; + } let tow_s = (self.tow as f64) / 1000.0; let gps_time = match time::GpsTime::new(0, tow_s) { Ok(gps_time) => gps_time.tow(),