Skip to content

Commit 3f933a2

Browse files
authored
[IOTE-6][IOTE-326] Add weeks behavior flag to MSG_GNSS_TIME_OFFSET (#1405)
# Description @swift-nav/devinfra Adding a new flag to the reserved `flags` field in the `MSG_GNSS_TIME_OFFSET` message to flag if the timestamp is affected by local timestamp rollover or not. For more information, see https://swift-nav.atlassian.net/wiki/spaces/~622a65696a4c4c0070b2567a/pages/3060662918/Amazon+INS+timestamp+issue+way+forward#Conclusion-and-decision. # API compatibility Does this change introduce a API compatibility risk? No, this has been a reserved field so should not be incompatible with current implementations of the protocol. ## API compatibility plan # JIRA Reference https://swift-nav.atlassian.net/browse/IOTE-325
1 parent 0da32d5 commit 3f933a2

File tree

11 files changed

+109
-9
lines changed

11 files changed

+109
-9
lines changed

c/include/libsbp/legacy/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ typedef struct SBP_ATTR_PACKED SBP_DEPRECATED {
210210
s32 milliseconds; /**< Milliseconds portion of the time offset [ms] */
211211
s16 microseconds; /**< Microseconds portion of the time offset [microseconds]
212212
*/
213-
u8 flags; /**< Status flags (reserved) */
213+
u8 flags; /**< Status flags */
214214
} msg_gnss_time_offset_t;
215215

216216
/** Local time at detection of PPS pulse

c/include/libsbp/system/MSG_GNSS_TIME_OFFSET.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef struct {
6161
s16 microseconds;
6262

6363
/**
64-
* Status flags (reserved)
64+
* Status flags
6565
*/
6666
u8 flags;
6767
} sbp_msg_gnss_time_offset_t;

c/include/libsbp/system_macros.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,38 @@
856856
#define SBP_MSG_INS_UPDATES_ENCODED_LEN 10u
857857

858858
#define SBP_MSG_GNSS_TIME_OFFSET 0xFF07
859+
#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK (0x7fu)
860+
#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT (1u)
861+
#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_GET(flags) \
862+
((u8)((u8)((flags) >> SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT) & \
863+
SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK))
864+
#define SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SET(flags, val) \
865+
do { \
866+
(flags) = (u8)( \
867+
(flags & (~(SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK \
868+
<< SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT))) | \
869+
(((val) & (SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_MASK)) \
870+
<< (SBP_GNSS_TIME_OFFSET_RESERVED_SET_TO_ZERO_SHIFT))); \
871+
} while (0)
872+
873+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK (0x1u)
874+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT (0u)
875+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_GET(flags) \
876+
((u8)((u8)((flags) >> SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT) & \
877+
SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK))
878+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SET(flags, val) \
879+
do { \
880+
(flags) = \
881+
(u8)((flags & (~(SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK \
882+
<< SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT))) | \
883+
(((val) & (SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_MASK)) \
884+
<< (SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_SHIFT))); \
885+
} while (0)
886+
887+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_NOT_AFFECTED_ON_LOCAL_TIMESTAMP_ROLLOVER \
888+
(0)
889+
#define SBP_GNSS_TIME_OFFSET_WEEKS_BEHAVIOR_INCREMENTED_ON_LOCAL_TIMESTAMP_ROLLOVER \
890+
(1)
859891
/**
860892
* Encoded length of sbp_msg_gnss_time_offset_t (V4 API) and
861893
* msg_gnss_time_offset_t (legacy API)

docs/sbp.pdf

10.8 KB
Binary file not shown.

haskell/src/SwiftNav/SBP/System.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ data MsgGnssTimeOffset = MsgGnssTimeOffset
426426
, _msgGnssTimeOffset_microseconds :: !Int16
427427
-- ^ Microseconds portion of the time offset
428428
, _msgGnssTimeOffset_flags :: !Word8
429-
-- ^ Status flags (reserved)
429+
-- ^ Status flags
430430
} deriving ( Show, Read, Eq )
431431

432432
instance Binary MsgGnssTimeOffset where

java/src/com/swiftnav/sbp/system/MsgGnssTimeOffset.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class MsgGnssTimeOffset extends SBPMessage {
4040
/** Microseconds portion of the time offset */
4141
public int microseconds;
4242

43-
/** Status flags (reserved) */
43+
/** Status flags */
4444
public int flags;
4545

4646
public MsgGnssTimeOffset(int sender) {

javascript/sbp/system.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ MsgInsUpdates.prototype.fieldSpec.push(['zerovel', 'writeUInt8', 1]);
428428
* @field weeks number (signed 16-bit int, 2 bytes) Weeks portion of the time offset
429429
* @field milliseconds number (signed 32-bit int, 4 bytes) Milliseconds portion of the time offset
430430
* @field microseconds number (signed 16-bit int, 2 bytes) Microseconds portion of the time offset
431-
* @field flags number (unsigned 8-bit int, 1 byte) Status flags (reserved)
431+
* @field flags number (unsigned 8-bit int, 1 byte) Status flags
432432
*
433433
* @param sbp An SBP object with a payload to be decoded.
434434
*/

kaitai/ksy/system.ksy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ types:
276276
type: s2
277277
- id: flags
278278
doc: |
279-
Status flags (reserved)
279+
Status flags
280280
type: u1
281281

282282
msg_pps_time:

python/sbp/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ class MsgGnssTimeOffset(SBP):
11201120
microseconds : int
11211121
Microseconds portion of the time offset
11221122
flags : int
1123-
Status flags (reserved)
1123+
Status flags
11241124
sender : int
11251125
Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).
11261126

rust/sbp/src/messages/system.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,37 @@ pub mod msg_gnss_time_offset {
401401
/// Microseconds portion of the time offset
402402
#[cfg_attr(feature = "serde", serde(rename = "microseconds"))]
403403
pub microseconds: i16,
404-
/// Status flags (reserved)
404+
/// Status flags
405405
#[cfg_attr(feature = "serde", serde(rename = "flags"))]
406406
pub flags: u8,
407407
}
408408

409+
impl MsgGnssTimeOffset {
410+
/// Gets the `reserved_set_to_zero` stored in `flags`.
411+
pub fn reserved_set_to_zero(&self) -> u8 {
412+
get_bit_range!(self.flags, u8, u8, 7, 1)
413+
}
414+
415+
/// Sets the `reserved_set_to_zero` bitrange of `flags`.
416+
pub fn set_reserved_set_to_zero(&mut self, reserved_set_to_zero: u8) {
417+
set_bit_range!(&mut self.flags, reserved_set_to_zero, u8, u8, 7, 1);
418+
}
419+
420+
/// Gets the [WeeksBehavior][self::WeeksBehavior] stored in the `flags` bitfield.
421+
///
422+
/// Returns `Ok` if the bitrange contains a known `WeeksBehavior` variant.
423+
/// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
424+
/// or because new variants of `WeeksBehavior` were added.
425+
pub fn weeks_behavior(&self) -> Result<WeeksBehavior, u8> {
426+
get_bit_range!(self.flags, u8, u8, 0, 0).try_into()
427+
}
428+
429+
/// Set the bitrange corresponding to the [WeeksBehavior][WeeksBehavior] of the `flags` bitfield.
430+
pub fn set_weeks_behavior(&mut self, weeks_behavior: WeeksBehavior) {
431+
set_bit_range!(&mut self.flags, weeks_behavior, u8, u8, 0, 0);
432+
}
433+
}
434+
409435
impl ConcreteMessage for MsgGnssTimeOffset {
410436
const MESSAGE_TYPE: u16 = 65287;
411437
const MESSAGE_NAME: &'static str = "MSG_GNSS_TIME_OFFSET";
@@ -478,6 +504,40 @@ pub mod msg_gnss_time_offset {
478504
}
479505
}
480506
}
507+
508+
/// Weeks behavior
509+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
510+
pub enum WeeksBehavior {
511+
/// Not affected on local timestamp rollover
512+
NotAffectedOnLocalTimestampRollover = 0,
513+
514+
/// Incremented on local timestamp rollover
515+
IncrementedOnLocalTimestampRollover = 1,
516+
}
517+
518+
impl std::fmt::Display for WeeksBehavior {
519+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
520+
match self {
521+
WeeksBehavior::NotAffectedOnLocalTimestampRollover => {
522+
f.write_str("Not affected on local timestamp rollover")
523+
}
524+
WeeksBehavior::IncrementedOnLocalTimestampRollover => {
525+
f.write_str("Incremented on local timestamp rollover")
526+
}
527+
}
528+
}
529+
}
530+
531+
impl TryFrom<u8> for WeeksBehavior {
532+
type Error = u8;
533+
fn try_from(i: u8) -> Result<Self, u8> {
534+
match i {
535+
0 => Ok(WeeksBehavior::NotAffectedOnLocalTimestampRollover),
536+
1 => Ok(WeeksBehavior::IncrementedOnLocalTimestampRollover),
537+
i => Err(i),
538+
}
539+
}
540+
}
481541
}
482542

483543
pub mod msg_group_meta {

0 commit comments

Comments
 (0)