Skip to content

Commit

Permalink
rust: check time source for MsgGpsTime
Browse files Browse the repository at this point in the history
  • Loading branch information
notoriaga committed Nov 13, 2023
1 parent 28a1089 commit a2aded3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions generator/sbpg/targets/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions rust/sbp/src/messages/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,12 @@ pub mod msg_gps_time {

#[cfg(feature = "swiftnav")]
fn gps_time(&self) -> Option<std::result::Result<time::MessageTime, time::GpsTimeError>> {
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() {
Expand Down Expand Up @@ -2044,6 +2050,12 @@ pub mod msg_gps_time_dep_a {

#[cfg(feature = "swiftnav")]
fn gps_time(&self) -> Option<std::result::Result<time::MessageTime, time::GpsTimeError>> {
if !matches!(
self.time_source(),

Check failure on line 2054 in rust/sbp/src/messages/navigation.rs

View workflow job for this annotation

GitHub Actions / Format and lint

no method named `time_source` found for reference `&messages::navigation::msg_gps_time_dep_a::MsgGpsTimeDepA` in the current scope
Ok(TimeSource::GnssSolution) | Ok(TimeSource::Propagated)

Check failure on line 2055 in rust/sbp/src/messages/navigation.rs

View workflow job for this annotation

GitHub Actions / Format and lint

failed to resolve: use of undeclared type `TimeSource`

Check failure on line 2055 in rust/sbp/src/messages/navigation.rs

View workflow job for this annotation

GitHub Actions / Format and lint

failed to resolve: use of undeclared type `TimeSource`
) {
return None;
}
let tow_s = (self.tow as f64) / 1000.0;
#[allow(clippy::useless_conversion)]
let wn: i16 = match self.wn.try_into() {
Expand Down

0 comments on commit a2aded3

Please sign in to comment.