diff --git a/c/include/libsbp/legacy/system.h b/c/include/libsbp/legacy/system.h index b5b3de63c2..56e6353768 100644 --- a/c/include/libsbp/legacy/system.h +++ b/c/include/libsbp/legacy/system.h @@ -210,7 +210,7 @@ typedef struct SBP_ATTR_PACKED SBP_DEPRECATED { s32 milliseconds; /**< Milliseconds portion of the time offset [ms] */ s16 microseconds; /**< Microseconds portion of the time offset [microseconds] */ - u8 flags; /**< Status flags (reserved) */ + u8 flags; /**< Status flags */ } msg_gnss_time_offset_t; /** Local time at detection of PPS pulse diff --git a/c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h b/c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h index 8c5e6261ba..5d0cd2d373 100644 --- a/c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h +++ b/c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h @@ -61,7 +61,7 @@ typedef struct { s16 microseconds; /** - * Status flags (reserved) + * Status flags */ u8 flags; } sbp_msg_gnss_time_offset_t; diff --git a/c/include/libsbp/system_macros.h b/c/include/libsbp/system_macros.h index 780df5e619..413d6091b0 100644 --- a/c/include/libsbp/system_macros.h +++ b/c/include/libsbp/system_macros.h @@ -856,6 +856,38 @@ #define SBP_MSG_INS_UPDATES_ENCODED_LEN 10u #define SBP_MSG_GNSS_TIME_OFFSET 0xFF07 +#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK (0x7fu) +#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT (1u) +#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_GET(flags) \ + ((u8)((u8)((flags) >> SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT) & \ + SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK)) +#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SET(flags, val) \ + do { \ + (flags) = (u8)( \ + (flags & (~(SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK \ + << SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT))) | \ + (((val) & (SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK)) \ + << (SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT))); \ + } while (0) + +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK (0x1u) +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT (0u) +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_GET(flags) \ + ((u8)((u8)((flags) >> SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT) & \ + SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK)) +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SET(flags, val) \ + do { \ + (flags) = \ + (u8)((flags & (~(SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK \ + << SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT))) | \ + (((val) & (SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK)) \ + << (SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT))); \ + } while (0) + +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_NOT_AFFECTED_BY_LOCAL_TIMESTAMP_WEEK_ROLLOVER \ + (0) +#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_INCREMENTED_ON_LOCAL_TIMESTAMP_WEEK_ROLLOVER \ + (1) /** * Encoded length of sbp_msg_gnss_time_offset_t (V4 API) and * msg_gnss_time_offset_t (legacy API) diff --git a/docs/sbp.pdf b/docs/sbp.pdf index 293b4029f6..0993c5b79a 100644 Binary files a/docs/sbp.pdf and b/docs/sbp.pdf differ diff --git a/haskell/src/SwiftNav/SBP/System.hs b/haskell/src/SwiftNav/SBP/System.hs index 72b765551c..f976e64b4a 100644 --- a/haskell/src/SwiftNav/SBP/System.hs +++ b/haskell/src/SwiftNav/SBP/System.hs @@ -426,7 +426,7 @@ data MsgGnssTimeOffset = MsgGnssTimeOffset , _msgGnssTimeOffset_microseconds :: !Int16 -- ^ Microseconds portion of the time offset , _msgGnssTimeOffset_flags :: !Word8 - -- ^ Status flags (reserved) + -- ^ Status flags } deriving ( Show, Read, Eq ) instance Binary MsgGnssTimeOffset where diff --git a/java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java b/java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java index 90161e9f0b..71e8addcd3 100644 --- a/java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java +++ b/java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java @@ -40,7 +40,7 @@ public class MsgGnssTimeOffset extends SBPMessage { /** Microseconds portion of the time offset */ public int microseconds; - /** Status flags (reserved) */ + /** Status flags */ public int flags; public MsgGnssTimeOffset(int sender) { diff --git a/javascript/sbp/system.js b/javascript/sbp/system.js index fba08ae504..c453dbabaa 100644 --- a/javascript/sbp/system.js +++ b/javascript/sbp/system.js @@ -428,7 +428,7 @@ MsgInsUpdates.prototype.fieldSpec.push(['zerovel', 'writeUInt8', 1]); * @field weeks number (signed 16-bit int, 2 bytes) Weeks portion of the time offset * @field milliseconds number (signed 32-bit int, 4 bytes) Milliseconds portion of the time offset * @field microseconds number (signed 16-bit int, 2 bytes) Microseconds portion of the time offset - * @field flags number (unsigned 8-bit int, 1 byte) Status flags (reserved) + * @field flags number (unsigned 8-bit int, 1 byte) Status flags * * @param sbp An SBP object with a payload to be decoded. */ diff --git a/kaitai/ksy/sbp.ksy b/kaitai/ksy/sbp.ksy index 35e8bddca2..ee6d7bd444 100644 --- a/kaitai/ksy/sbp.ksy +++ b/kaitai/ksy/sbp.ksy @@ -8,7 +8,7 @@ # EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. # -# Kaitai Struct definition file for Swift Binary Protocol 5.0.6-alpha +# Kaitai Struct definition file for Swift Binary Protocol 5.0.7-alpha # # Automatically generated with generate.py. Do not hand edit! diff --git a/kaitai/ksy/system.ksy b/kaitai/ksy/system.ksy index 7ece243c86..3653c346a1 100644 --- a/kaitai/ksy/system.ksy +++ b/kaitai/ksy/system.ksy @@ -276,7 +276,7 @@ types: type: s2 - id: flags doc: | - Status flags (reserved) + Status flags type: u1 msg_pps_time: diff --git a/python/sbp/system.py b/python/sbp/system.py index 4a095bf28c..fe22b2412f 100644 --- a/python/sbp/system.py +++ b/python/sbp/system.py @@ -1120,7 +1120,7 @@ class MsgGnssTimeOffset(SBP): microseconds : int Microseconds portion of the time offset flags : int - Status flags (reserved) + Status flags sender : int Optional sender ID, defaults to SENDER_ID (see sbp/msg.py). diff --git a/rust/sbp/src/messages/system.rs b/rust/sbp/src/messages/system.rs index 47ea29c93a..d557de3e2c 100644 --- a/rust/sbp/src/messages/system.rs +++ b/rust/sbp/src/messages/system.rs @@ -401,11 +401,37 @@ pub mod msg_gnss_time_offset { /// Microseconds portion of the time offset #[cfg_attr(feature = "serde", serde(rename = "microseconds"))] pub microseconds: i16, - /// Status flags (reserved) + /// Status flags #[cfg_attr(feature = "serde", serde(rename = "flags"))] pub flags: u8, } + impl MsgGnssTimeOffset { + /// Gets the `reserved_set_to_zero` stored in `flags`. + pub fn reserved_set_to_zero(&self) -> u8 { + get_bit_range!(self.flags, u8, u8, 7, 1) + } + + /// Sets the `reserved_set_to_zero` bitrange of `flags`. + pub fn set_reserved_set_to_zero(&mut self, reserved_set_to_zero: u8) { + set_bit_range!(&mut self.flags, reserved_set_to_zero, u8, u8, 7, 1); + } + + /// Gets the [WeeksBehavior][self::WeeksBehavior] stored in the `flags` bitfield. + /// + /// Returns `Ok` if the bitrange contains a known `WeeksBehavior` variant. + /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message, + /// or because new variants of `WeeksBehavior` were added. + pub fn weeks_behavior(&self) -> Result { + get_bit_range!(self.flags, u8, u8, 0, 0).try_into() + } + + /// Set the bitrange corresponding to the [WeeksBehavior][WeeksBehavior] of the `flags` bitfield. + pub fn set_weeks_behavior(&mut self, weeks_behavior: WeeksBehavior) { + set_bit_range!(&mut self.flags, weeks_behavior, u8, u8, 0, 0); + } + } + impl ConcreteMessage for MsgGnssTimeOffset { const MESSAGE_TYPE: u16 = 65287; const MESSAGE_NAME: &'static str = "MSG_GNSS_TIME_OFFSET"; @@ -478,6 +504,40 @@ pub mod msg_gnss_time_offset { } } } + + /// Weeks behavior + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] + pub enum WeeksBehavior { + /// Not affected by local timestamp week rollover + NotAffectedByLocalTimestampWeekRollover = 0, + + /// Incremented on local timestamp week rollover + IncrementedOnLocalTimestampWeekRollover = 1, + } + + impl std::fmt::Display for WeeksBehavior { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + WeeksBehavior::NotAffectedByLocalTimestampWeekRollover => { + f.write_str("Not affected by local timestamp week rollover") + } + WeeksBehavior::IncrementedOnLocalTimestampWeekRollover => { + f.write_str("Incremented on local timestamp week rollover") + } + } + } + } + + impl TryFrom for WeeksBehavior { + type Error = u8; + fn try_from(i: u8) -> Result { + match i { + 0 => Ok(WeeksBehavior::NotAffectedByLocalTimestampWeekRollover), + 1 => Ok(WeeksBehavior::IncrementedOnLocalTimestampWeekRollover), + i => Err(i), + } + } + } } pub mod msg_group_meta { diff --git a/spec/yaml/swiftnav/sbp/system.yaml b/spec/yaml/swiftnav/sbp/system.yaml index 3171abb1e4..eb1f70c30c 100644 --- a/spec/yaml/swiftnav/sbp/system.yaml +++ b/spec/yaml/swiftnav/sbp/system.yaml @@ -443,7 +443,15 @@ definitions: desc: Microseconds portion of the time offset - flags: type: u8 - desc: Status flags (reserved) + desc: Status flags + fields: + - 1-7: + desc: Reserved, set to zero + - 0: + desc: Weeks behavior + values: + - 0: Not affected by local timestamp week rollover + - 1: Incremented on local timestamp week rollover - MSG_PPS_TIME: id: 0xFF08