Skip to content

Commit

Permalink
rust: check more messages for time validity (#1376)
Browse files Browse the repository at this point in the history
# Description

Same as #1375 but accounts for
the other 3 time messages and msg_odometry

@swift-nav/devinfra

<!-- Changes proposed in this PR -->

# API compatibility

Does this change introduce a API compatibility risk?

<!-- Provide a short explanation why or why not -->

## API compatibility plan

If the above is "Yes", please detail the compatibility (or migration)
plan:

<!-- Provide a short explanation plan here -->

# JIRA Reference

https://swift-nav.atlassian.net/browse/BOARD-XXXX
  • Loading branch information
notoriaga authored Nov 14, 2023
1 parent 12f7c44 commit 9b9dcd1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
20 changes: 14 additions & 6 deletions generator/sbpg/targets/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions rust/sbp/src/messages/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,10 +1888,7 @@ 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)
) {
if self.time_source().ok()? == TimeSource::None {
return None;
}
let tow_s = (self.tow as f64) / 1000.0;
Expand Down Expand Up @@ -2200,6 +2197,9 @@ pub mod msg_gps_time_gnss {

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

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

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

#[cfg(feature = "swiftnav")]
fn gps_time(&self) -> Option<std::result::Result<time::MessageTime, time::GpsTimeError>> {
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(),
Expand Down
3 changes: 3 additions & 0 deletions rust/sbp/src/messages/vehicle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ pub mod msg_odometry {

#[cfg(feature = "swiftnav")]
fn gps_time(&self) -> Option<std::result::Result<time::MessageTime, time::GpsTimeError>> {
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(),
Expand Down

0 comments on commit 9b9dcd1

Please sign in to comment.