swift-nav/libsbp

Cannot access `GPSTime` inside `BaseTime`

Closed this issue ยท 4 comments

Hello,
I am trying to extract a timestamp from each SBPMessage that contains one (Rust).

I found the function gps_time() by enabling the feature swiftnav:

    // frame: &Sbp
    if let Some(Ok(msg_time)) = sbp::messages::SbpMessage::gps_time(frame) {
        let _tow = match msg_time {
            MessageTime::Rover(RoverTime::Tow(rover_tow)) => rover_tow,
            MessageTime::Rover(RoverTime::GpsTime(gps_time)) => gps_time.tow(),
            MessageTime::Base(BaseTime(gps_time)) => gps_time.tow()
        };
    }

However BaseTime is a struct that contains gps_time as a private field:
https://github.com/swift-nav/libsbp/blob/d122b3b82e048e8a313967332ad97ebf05cc80c3/rust/sbp/src/time.rs#LL92C1-L92C1
So I can't access it.

Is this a bug or am I not supposed to do things this way?

Thanks,
Marco

Not sure what exactly your use-case is but there is a function that converts Iterator<Item = Sbp> to Iterator<Item = Sbp, Option<Result<GpsTime, GpsTimeError>>> (also works with Iterator<Item = Result<Sbp>>) -

fn with_rover_time<T>(self) -> swiftnav_impl::RoverTimeIter<Self>

It's not showing up in the docs because it requires the swiftnav feature (which enables some integrations with https://github.com/swift-nav/swiftnav-rs) and I guess we aren't building the docs with all features enabled.

It might not be want you want because it excludes BaseTime messages, but it takes care of tracking the week number for you which is nice. Either way we have a fix for this on the way ๐Ÿ˜„

Thank you!

I will patch locally waiting for the fix.

Release v4.14.1 with this fix has been cut (and now available on crates.io).

Thank you so much!