Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOTE-6][IOTE-326] Add weeks behavior flag to MSG_GNSS_TIME_OFFSET #1405

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c/include/libsbp/legacy/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
s16 microseconds;

/**
* Status flags (reserved)
* Status flags
*/
u8 flags;
} sbp_msg_gnss_time_offset_t;
Expand Down
32 changes: 32 additions & 0 deletions c/include/libsbp/system_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ON_LOCAL_TIMESTAMP_ROLLOVER \
(0)
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_INCREMENTED_ON_LOCAL_TIMESTAMP_ROLLOVER \
sokhealy marked this conversation as resolved.
Show resolved Hide resolved
(1)
/**
* Encoded length of sbp_msg_gnss_time_offset_t (V4 API) and
* msg_gnss_time_offset_t (legacy API)
Expand Down
Binary file modified docs/sbp.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion haskell/src/SwiftNav/SBP/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion javascript/sbp/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion kaitai/ksy/system.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ types:
type: s2
- id: flags
doc: |
Status flags (reserved)
Status flags
type: u1

msg_pps_time:
Expand Down
2 changes: 1 addition & 1 deletion python/sbp/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
62 changes: 61 additions & 1 deletion rust/sbp/src/messages/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeeksBehavior, u8> {
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";
Expand Down Expand Up @@ -478,6 +504,40 @@ pub mod msg_gnss_time_offset {
}
}
}

/// Weeks behavior
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum WeeksBehavior {
/// Not affected on local timestamp rollover
NotAffectedOnLocalTimestampRollover = 0,

/// Incremented on local timestamp rollover
IncrementedOnLocalTimestampRollover = 1,
}

impl std::fmt::Display for WeeksBehavior {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WeeksBehavior::NotAffectedOnLocalTimestampRollover => {
f.write_str("Not affected on local timestamp rollover")
}
WeeksBehavior::IncrementedOnLocalTimestampRollover => {
f.write_str("Incremented on local timestamp rollover")
}
}
}
}

impl TryFrom<u8> for WeeksBehavior {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(WeeksBehavior::NotAffectedOnLocalTimestampRollover),
1 => Ok(WeeksBehavior::IncrementedOnLocalTimestampRollover),
i => Err(i),
}
}
}
}

pub mod msg_group_meta {
Expand Down
10 changes: 9 additions & 1 deletion spec/yaml/swiftnav/sbp/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 on local timestamp rollover
- 1: Incremented on local timestamp rollover
sokhealy marked this conversation as resolved.
Show resolved Hide resolved

- MSG_PPS_TIME:
id: 0xFF08
Expand Down
Loading