From da47a66e7791053a7c3ad9cf6cd175f78beeea3d Mon Sep 17 00:00:00 2001 From: Rodrigo Reichert Date: Wed, 27 Apr 2022 13:29:33 +1000 Subject: [PATCH 1/3] Add new specs --- spec/yaml/swiftnav/sbp/system.yaml | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/spec/yaml/swiftnav/sbp/system.yaml b/spec/yaml/swiftnav/sbp/system.yaml index 98e8e5d942..5cb40b98a5 100644 --- a/spec/yaml/swiftnav/sbp/system.yaml +++ b/spec/yaml/swiftnav/sbp/system.yaml @@ -216,6 +216,84 @@ definitions: fill: SubSystemReport desc: Reported status of individual subsystems + - StatusJournalItem: + short_desc: Sub-system Status report + embedded_type: true + desc: > + Report the general and specific state of a sub-system. If the generic + state is reported as initializing, the specific state should be ignored. + fields: + - uptime: + type: u32 + desc: Milliseconds since system startup + - component: + type: u16 + desc: Identity of reporting subsystem + fields: + - 0-15: + desc: Subsystem + values: + - 0: Primary GNSS Antenna + - 1: Measurement Engine + - 2: Corrections Client + - 3: Differential GNSS Engine + - 4: CAN + - 5: Wheel Odometry + - 6: Sensor Fusion Engine + - generic: + type: u8 + desc: Generic form status report + fields: + - 0-7: + desc: Generic + values: + - 0: OK/Nominal + - 1: Initializing + - 2: Unknown + - 3: Degraded + - 4: Unusable + - specific: + type: u8 + desc: Subsystem specific status code + + - MSG_STATUS_JOURNAL: + id: 0xFFFD + short_desc: Status report journal + desc: > + The status journal message contains past status reports (see MSG_STATUS_REPORT) + and functions as a error/event storage for telemetry purposes. + fields: + - reporting_system: + type: u16 + desc: Identity of reporting system + fields: + - 0-15: + desc: System + values: + - 0: Starling + - 1: Precision GNSS Module (PGM) + - sbp_version: + type: u16 + desc: SBP protocol version + fields: + - 8-16: + desc: SBP major protocol version number + - 0-7: + desc: SBP minor protocol version number + - n_status_reports: + type: u32 + desc: Total number of status reports sent since system startup + - packet_index: + type: u8 + desc: Index of this packet in the status journal + - n_packets: + type: u8 + desc: Number of packets in this status journal + - journal: + type: array + fill: StatusJournalItem + desc: Status journal + - MSG_INS_STATUS: id: 0xFF03 short_desc: Inertial Navigation System status message From 94982e707bc6b0d877a5f64fdcb0991d4bb890f5 Mon Sep 17 00:00:00 2001 From: Rodrigo Reichert Date: Wed, 27 Apr 2022 14:09:47 +1000 Subject: [PATCH 2/3] generate C code --- c/include/libsbp/cpp/message_traits.h | 35 +++ c/include/libsbp/legacy/cpp/message_traits.h | 6 + c/include/libsbp/legacy/system.h | 30 +++ c/include/libsbp/sbp_msg_type.h | 1 + c/include/libsbp/system_macros.h | 105 ++++++++ c/include/libsbp/v4/sbp_msg.h | 11 + c/include/libsbp/v4/system.h | 2 + .../libsbp/v4/system/MSG_STATUS_JOURNAL.h | 217 +++++++++++++++++ .../libsbp/v4/system/StatusJournalItem.h | 175 ++++++++++++++ c/include/libsbp/version.h | 2 +- c/src/include/libsbp/internal/v4/system.h | 40 +++ c/src/v4/system.c | 227 ++++++++++++++++++ 12 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h create mode 100644 c/include/libsbp/v4/system/StatusJournalItem.h diff --git a/c/include/libsbp/cpp/message_traits.h b/c/include/libsbp/cpp/message_traits.h index 62eea87ec3..9d61f6f7db 100644 --- a/c/include/libsbp/cpp/message_traits.h +++ b/c/include/libsbp/cpp/message_traits.h @@ -6019,6 +6019,41 @@ struct MessageTraits { } }; +template <> +struct MessageTraits { + static constexpr sbp_msg_type_t id = SbpMsgStatusJournal; + static const sbp_msg_status_journal_t &get(const sbp_msg_t &msg) { + return msg.status_journal; + } + static sbp_msg_status_journal_t &get(sbp_msg_t &msg) { + return msg.status_journal; + } + static void to_sbp_msg(const sbp_msg_status_journal_t &msg, + sbp_msg_t *sbp_msg) { + sbp_msg->status_journal = msg; + } + static sbp_msg_t to_sbp_msg(const sbp_msg_status_journal_t &msg) { + sbp_msg_t sbp_msg; + sbp_msg.status_journal = msg; + return sbp_msg; + } + static s8 send(sbp_state_t *state, u16 sender_id, + const sbp_msg_status_journal_t &msg, sbp_write_fn_t write) { + return sbp_msg_status_journal_send(state, sender_id, &msg, write); + } + static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_msg_status_journal_t &msg) { + return sbp_msg_status_journal_encode(buf, len, n_written, &msg); + } + static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read, + sbp_msg_status_journal_t *msg) { + return sbp_msg_status_journal_decode(buf, len, n_read, msg); + } + static size_t encoded_len(const sbp_msg_status_journal_t &msg) { + return sbp_msg_status_journal_encoded_len(&msg); + } +}; + template <> struct MessageTraits { static constexpr sbp_msg_type_t id = SbpMsgStatusReport; diff --git a/c/include/libsbp/legacy/cpp/message_traits.h b/c/include/libsbp/legacy/cpp/message_traits.h index 59d5d21fb6..96bc1dfbe4 100644 --- a/c/include/libsbp/legacy/cpp/message_traits.h +++ b/c/include/libsbp/legacy/cpp/message_traits.h @@ -1200,6 +1200,12 @@ struct MessageTraits { }; +template<> +struct MessageTraits { + static constexpr u16 id = 65533; +}; + + template<> struct MessageTraits { static constexpr u16 id = 65534; diff --git a/c/include/libsbp/legacy/system.h b/c/include/libsbp/legacy/system.h index a3b80da461..f8eed89397 100644 --- a/c/include/libsbp/legacy/system.h +++ b/c/include/libsbp/legacy/system.h @@ -106,6 +106,36 @@ typedef struct SBP_ATTR_PACKED { subsystems */ } msg_status_report_t; +/** Sub-system Status report + * + * Report the general and specific state of a sub-system. If the generic + * state is reported as initializing, the specific state should be ignored. + */ + +typedef struct SBP_ATTR_PACKED { + u32 uptime; /**< Milliseconds since system startup */ + u16 component; /**< Identity of reporting subsystem */ + u8 generic; /**< Generic form status report */ + u8 specific; /**< Subsystem specific status code */ +} status_journal_item_t; + +/** Status report journal + * + * The status journal message contains past status reports (see + * MSG_STATUS_REPORT) and functions as a error/event storage for telemetry + * purposes. + */ + +typedef struct SBP_ATTR_PACKED { + u16 reporting_system; /**< Identity of reporting system */ + u16 sbp_version; /**< SBP protocol version */ + u32 n_status_reports; /**< Total number of status reports sent since + system startup */ + u8 packet_index; /**< Index of this packet in the status journal */ + u8 n_packets; /**< Number of packets in this status journal */ + status_journal_item_t journal[0]; /**< Status journal */ +} msg_status_journal_t; + /** Inertial Navigation System status message * * The INS status message describes the state of the operation and diff --git a/c/include/libsbp/sbp_msg_type.h b/c/include/libsbp/sbp_msg_type.h index e593f639f6..3d941f6098 100644 --- a/c/include/libsbp/sbp_msg_type.h +++ b/c/include/libsbp/sbp_msg_type.h @@ -221,6 +221,7 @@ typedef enum { SbpMsgSsrStecCorrection = SBP_MSG_SSR_STEC_CORRECTION, SbpMsgSsrTileDefinition = SBP_MSG_SSR_TILE_DEFINITION, SbpMsgStartup = SBP_MSG_STARTUP, + SbpMsgStatusJournal = SBP_MSG_STATUS_JOURNAL, SbpMsgStatusReport = SBP_MSG_STATUS_REPORT, SbpMsgStmFlashLockSector = SBP_MSG_STM_FLASH_LOCK_SECTOR, SbpMsgStmFlashUnlockSector = SBP_MSG_STM_FLASH_UNLOCK_SECTOR, diff --git a/c/include/libsbp/system_macros.h b/c/include/libsbp/system_macros.h index 8121fe768d..e5e78b63a3 100644 --- a/c/include/libsbp/system_macros.h +++ b/c/include/libsbp/system_macros.h @@ -297,6 +297,111 @@ */ #define SBP_MSG_STATUS_REPORT_ENCODED_OVERHEAD 12u +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK (0xffff) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT (0u) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_GET(flags) \ + ((u16)(((flags) >> SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT) & \ + SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK)) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SET(flags, val) \ + do { \ + (flags) = \ + (u16)((flags) | (((val) & (SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK)) \ + << (SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT))); \ + } while (0) + +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_PRIMARY_GNSS_ANTENNA (0) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_MEASUREMENT_ENGINE (1) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_CORRECTIONS_CLIENT (2) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_DIFFERENTIAL_GNSS_ENGINE (3) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_CAN (4) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_WHEEL_ODOMETRY (5) +#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SENSOR_FUSION_ENGINE (6) +#define SBP_STATUSJOURNALITEM_GENERIC_MASK (0xff) +#define SBP_STATUSJOURNALITEM_GENERIC_SHIFT (0u) +#define SBP_STATUSJOURNALITEM_GENERIC_GET(flags) \ + ((u8)(((flags) >> SBP_STATUSJOURNALITEM_GENERIC_SHIFT) & \ + SBP_STATUSJOURNALITEM_GENERIC_MASK)) +#define SBP_STATUSJOURNALITEM_GENERIC_SET(flags, val) \ + do { \ + (flags) = (u8)((flags) | (((val) & (SBP_STATUSJOURNALITEM_GENERIC_MASK)) \ + << (SBP_STATUSJOURNALITEM_GENERIC_SHIFT))); \ + } while (0) + +#define SBP_STATUSJOURNALITEM_GENERIC_OKNOMINAL (0) +#define SBP_STATUSJOURNALITEM_GENERIC_INITIALIZING (1) +#define SBP_STATUSJOURNALITEM_GENERIC_UNKNOWN (2) +#define SBP_STATUSJOURNALITEM_GENERIC_DEGRADED (3) +#define SBP_STATUSJOURNALITEM_GENERIC_UNUSABLE (4) +/** + * Encoded length of sbp_status_journal_item_t (V4 API) and + * status_journal_item_t (legacy API) + */ +#define SBP_STATUS_JOURNAL_ITEM_ENCODED_LEN 8u + +#define SBP_MSG_STATUS_JOURNAL 0xFFFD +#define SBP_STATUS_JOURNAL_SYSTEM_MASK (0xffff) +#define SBP_STATUS_JOURNAL_SYSTEM_SHIFT (0u) +#define SBP_STATUS_JOURNAL_SYSTEM_GET(flags) \ + ((u16)(((flags) >> SBP_STATUS_JOURNAL_SYSTEM_SHIFT) & \ + SBP_STATUS_JOURNAL_SYSTEM_MASK)) +#define SBP_STATUS_JOURNAL_SYSTEM_SET(flags, val) \ + do { \ + (flags) = (u16)((flags) | (((val) & (SBP_STATUS_JOURNAL_SYSTEM_MASK)) \ + << (SBP_STATUS_JOURNAL_SYSTEM_SHIFT))); \ + } while (0) + +#define SBP_STATUS_JOURNAL_SYSTEM_STARLING (0) +#define SBP_STATUS_JOURNAL_SYSTEM_PRECISION_GNSS_MODULE (1) +#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_MASK (0x1ff) +#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_SHIFT (8u) +#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_GET(flags) \ + ((u16)(((flags) >> \ + SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_SHIFT) & \ + SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_MASK)) +#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_SET(flags, val) \ + do { \ + (flags) = (u16)( \ + (flags) | \ + (((val) & (SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_MASK)) \ + << (SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_SHIFT))); \ + } while (0) + +#define SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_MASK (0xff) +#define SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_SHIFT (0u) +#define SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_GET(flags) \ + ((u16)(((flags) >> \ + SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_SHIFT) & \ + SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_MASK)) +#define SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_SET(flags, val) \ + do { \ + (flags) = (u16)( \ + (flags) | \ + (((val) & (SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_MASK)) \ + << (SBP_STATUS_JOURNAL_SBP_MINOR_PROTOCOL_VERSION_NUMBER_SHIFT))); \ + } while (0) + +/** + * The maximum number of items that can be stored in + * sbp_msg_status_journal_t::journal (V4 API) or msg_status_journal_t::journal + * (legacy API) before the maximum SBP message size is exceeded + */ +#define SBP_MSG_STATUS_JOURNAL_JOURNAL_MAX 30u + +/** + * Encoded length of sbp_msg_status_journal_t (V4 API) and + * msg_status_journal_t (legacy API) + * + * This type is not fixed size and an instance of this message may be longer + * than the value indicated by this symbol. Users of the V4 API should call + * #sbp_msg_status_journal_encoded_len to determine the actual size of an + * instance of this message. Users of the legacy API are required to track the + * encoded message length when interacting with the legacy type. + * + * See the documentation for libsbp for more details regarding the message + * structure and its variable length component(s) + */ +#define SBP_MSG_STATUS_JOURNAL_ENCODED_OVERHEAD 10u + #define SBP_MSG_INS_STATUS 0xFF03 #define SBP_INS_STATUS_INS_TYPE_MASK (0x7) #define SBP_INS_STATUS_INS_TYPE_SHIFT (29u) diff --git a/c/include/libsbp/v4/sbp_msg.h b/c/include/libsbp/v4/sbp_msg.h index ab682df342..9959cfdc83 100644 --- a/c/include/libsbp/v4/sbp_msg.h +++ b/c/include/libsbp/v4/sbp_msg.h @@ -227,6 +227,7 @@ typedef union { sbp_msg_ssr_stec_correction_t ssr_stec_correction; sbp_msg_ssr_tile_definition_t ssr_tile_definition; sbp_msg_startup_t startup; + sbp_msg_status_journal_t status_journal; sbp_msg_status_report_t status_report; sbp_msg_stm_flash_lock_sector_t stm_flash_lock_sector; sbp_msg_stm_flash_unlock_sector_t stm_flash_unlock_sector; @@ -740,6 +741,9 @@ static inline s8 sbp_message_encode(uint8_t *buf, uint8_t len, &msg->ssr_tile_definition); case SbpMsgStartup: return sbp_msg_startup_encode(buf, len, n_written, &msg->startup); + case SbpMsgStatusJournal: + return sbp_msg_status_journal_encode(buf, len, n_written, + &msg->status_journal); case SbpMsgStatusReport: return sbp_msg_status_report_encode(buf, len, n_written, &msg->status_report); @@ -1307,6 +1311,9 @@ static inline s8 sbp_message_decode(const uint8_t *buf, uint8_t len, &msg->ssr_tile_definition); case SbpMsgStartup: return sbp_msg_startup_decode(buf, len, n_read, &msg->startup); + case SbpMsgStatusJournal: + return sbp_msg_status_journal_decode(buf, len, n_read, + &msg->status_journal); case SbpMsgStatusReport: return sbp_msg_status_report_decode(buf, len, n_read, &msg->status_report); @@ -1782,6 +1789,8 @@ static inline size_t sbp_message_encoded_len(sbp_msg_type_t msg_type, return sbp_msg_ssr_tile_definition_encoded_len(&msg->ssr_tile_definition); case SbpMsgStartup: return sbp_msg_startup_encoded_len(&msg->startup); + case SbpMsgStatusJournal: + return sbp_msg_status_journal_encoded_len(&msg->status_journal); case SbpMsgStatusReport: return sbp_msg_status_report_encoded_len(&msg->status_report); case SbpMsgStmFlashLockSector: @@ -2305,6 +2314,8 @@ static inline int sbp_message_cmp(sbp_msg_type_t msg_type, const sbp_msg_t *a, &b->ssr_tile_definition); case SbpMsgStartup: return sbp_msg_startup_cmp(&a->startup, &b->startup); + case SbpMsgStatusJournal: + return sbp_msg_status_journal_cmp(&a->status_journal, &b->status_journal); case SbpMsgStatusReport: return sbp_msg_status_report_cmp(&a->status_report, &b->status_report); case SbpMsgStmFlashLockSector: diff --git a/c/include/libsbp/v4/system.h b/c/include/libsbp/v4/system.h index 95ce17055f..58777cba97 100644 --- a/c/include/libsbp/v4/system.h +++ b/c/include/libsbp/v4/system.h @@ -28,7 +28,9 @@ #include #include #include +#include #include +#include #include #endif /* LIBSBP_V4_SYSTEM_MESSAGES_H */ diff --git a/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h b/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h new file mode 100644 index 0000000000..0513149d26 --- /dev/null +++ b/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +/***************************************************************************** + * Automatically generated from yaml/swiftnav/sbp/system.yaml + * with generate.py. Please do not hand edit! + *****************************************************************************/ + +#ifndef LIBSBP_V4_SYSTEM_MSG_STATUS_JOURNAL_H +#define LIBSBP_V4_SYSTEM_MSG_STATUS_JOURNAL_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * + * SBP_MSG_STATUS_JOURNAL + * + *****************************************************************************/ +/** Status report journal + * + * The status journal message contains past status reports (see + * MSG_STATUS_REPORT) and functions as a error/event storage for telemetry + * purposes. + */ +typedef struct { + /** + * Identity of reporting system + */ + u16 reporting_system; + + /** + * SBP protocol version + */ + u16 sbp_version; + + /** + * Total number of status reports sent since system startup + */ + u32 n_status_reports; + + /** + * Index of this packet in the status journal + */ + u8 packet_index; + + /** + * Number of packets in this status journal + */ + u8 n_packets; + + /** + * Status journal + */ + sbp_status_journal_item_t journal[SBP_MSG_STATUS_JOURNAL_JOURNAL_MAX]; + /** + * Number of elements in journal + * + * When sending a message fill in this field with the number elements set in + * journal before calling an appropriate libsbp send function + * + * When receiving a message query this field for the number of elements in + * journal. The value of any elements beyond the index specified in this field + * is undefined + */ + u8 n_journal; +} sbp_msg_status_journal_t; + +/** + * Get encoded size of an instance of sbp_msg_status_journal_t + * + * @param msg sbp_msg_status_journal_t instance + * @return Length of on-wire representation + */ +static inline size_t sbp_msg_status_journal_encoded_len( + const sbp_msg_status_journal_t *msg) { + return SBP_MSG_STATUS_JOURNAL_ENCODED_OVERHEAD + + (msg->n_journal * SBP_STATUS_JOURNAL_ITEM_ENCODED_LEN); +} + +/** + * Encode an instance of sbp_msg_status_journal_t to wire representation + * + * This function encodes the given instance in to the user provided buffer. The + * buffer provided to this function must be large enough to store the encoded + * message otherwise it will return SBP_ENCODE_ERROR without writing anything to + * the buffer. + * + * Specify the length of the destination buffer in the \p len parameter. If + * non-null the number of bytes written to the buffer will be returned in \p + * n_written. + * + * @param buf Destination buffer + * @param len Length of \p buf + * @param n_written If not null, on success will be set to the number of bytes + * written to \p buf + * @param msg Instance of sbp_msg_status_journal_t to encode + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 +sbp_msg_status_journal_encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_msg_status_journal_t *msg); + +/** + * Decode an instance of sbp_msg_status_journal_t from wire representation + * + * This function decodes the wire representation of a sbp_msg_status_journal_t + * message to the given instance. The caller must specify the length of the + * buffer in the \p len parameter. If non-null the number of bytes read from the + * buffer will be returned in \p n_read. + * + * @param buf Wire representation of the sbp_msg_status_journal_t instance + * @param len Length of \p buf + * @param n_read If not null, on success will be set to the number of bytes read + * from \p buf + * @param msg Destination + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 sbp_msg_status_journal_decode(const uint8_t *buf, uint8_t len, + uint8_t *n_read, + sbp_msg_status_journal_t *msg); +/** + * Send an instance of sbp_msg_status_journal_t with the given write function + * + * An equivalent of #sbp_message_send which operates specifically on + * sbp_msg_status_journal_t + * + * The given message will be encoded to wire representation and passed in to the + * given write function callback. The write callback will be called several + * times for each invocation of this function. + * + * @param s SBP state + * @param sender_id SBP sender id + * @param msg Message to send + * @param write Write function + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 sbp_msg_status_journal_send(sbp_state_t *s, u16 sender_id, + const sbp_msg_status_journal_t *msg, + sbp_write_fn_t write); + +/** + * Compare two instances of sbp_msg_status_journal_t + * + * The two instances will be compared and a value returned consistent with the + * return codes of comparison functions from the C standard library + * + * 0 will be returned if \p a and \p b are considered equal + * A value less than 0 will be returned if \p a is considered to be less than \p + * b A value greater than 0 will be returned if \p b is considered to be greater + * than \p b + * + * @param a sbp_msg_status_journal_t instance + * @param b sbp_msg_status_journal_t instance + * @return 0, <0, >0 + */ +SBP_EXPORT int sbp_msg_status_journal_cmp(const sbp_msg_status_journal_t *a, + const sbp_msg_status_journal_t *b); + +#ifdef __cplusplus +} + +static inline bool operator==(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) == 0; +} + +static inline bool operator!=(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) != 0; +} + +static inline bool operator<(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) < 0; +} + +static inline bool operator<=(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) <= 0; +} + +static inline bool operator>(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) > 0; +} + +static inline bool operator>=(const sbp_msg_status_journal_t &lhs, + const sbp_msg_status_journal_t &rhs) { + return sbp_msg_status_journal_cmp(&lhs, &rhs) >= 0; +} + +#endif // ifdef __cplusplus + +#endif /* LIBSBP_V4_SYSTEM_MSG_STATUS_JOURNAL_H */ diff --git a/c/include/libsbp/v4/system/StatusJournalItem.h b/c/include/libsbp/v4/system/StatusJournalItem.h new file mode 100644 index 0000000000..049c4df3fc --- /dev/null +++ b/c/include/libsbp/v4/system/StatusJournalItem.h @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +/***************************************************************************** + * Automatically generated from yaml/swiftnav/sbp/system.yaml + * with generate.py. Please do not hand edit! + *****************************************************************************/ + +#ifndef LIBSBP_V4_SYSTEM_STATUSJOURNALITEM_H +#define LIBSBP_V4_SYSTEM_STATUSJOURNALITEM_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * + * SBP_STATUSJOURNALITEM + * + *****************************************************************************/ +/** Sub-system Status report + * + * Report the general and specific state of a sub-system. If the generic state + * is reported as initializing, the specific state should be ignored. + */ +typedef struct { + /** + * Milliseconds since system startup + */ + u32 uptime; + + /** + * Identity of reporting subsystem + */ + u16 component; + + /** + * Generic form status report + */ + u8 generic; + + /** + * Subsystem specific status code + */ + u8 specific; +} sbp_status_journal_item_t; + +/** + * Get encoded size of an instance of sbp_status_journal_item_t + * + * @param msg sbp_status_journal_item_t instance + * @return Length of on-wire representation + */ +static inline size_t sbp_status_journal_item_encoded_len( + const sbp_status_journal_item_t *msg) { + (void)msg; + return SBP_STATUS_JOURNAL_ITEM_ENCODED_LEN; +} + +/** + * Encode an instance of sbp_status_journal_item_t to wire representation + * + * This function encodes the given instance in to the user provided buffer. The + * buffer provided to this function must be large enough to store the encoded + * message otherwise it will return SBP_ENCODE_ERROR without writing anything to + * the buffer. + * + * Specify the length of the destination buffer in the \p len parameter. If + * non-null the number of bytes written to the buffer will be returned in \p + * n_written. + * + * @param buf Destination buffer + * @param len Length of \p buf + * @param n_written If not null, on success will be set to the number of bytes + * written to \p buf + * @param msg Instance of sbp_status_journal_item_t to encode + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 +sbp_status_journal_item_encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_status_journal_item_t *msg); + +/** + * Decode an instance of sbp_status_journal_item_t from wire representation + * + * This function decodes the wire representation of a sbp_status_journal_item_t + * message to the given instance. The caller must specify the length of the + * buffer in the \p len parameter. If non-null the number of bytes read from the + * buffer will be returned in \p n_read. + * + * @param buf Wire representation of the sbp_status_journal_item_t instance + * @param len Length of \p buf + * @param n_read If not null, on success will be set to the number of bytes read + * from \p buf + * @param msg Destination + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 sbp_status_journal_item_decode(const uint8_t *buf, uint8_t len, + uint8_t *n_read, + sbp_status_journal_item_t *msg); + +/** + * Compare two instances of sbp_status_journal_item_t + * + * The two instances will be compared and a value returned consistent with the + * return codes of comparison functions from the C standard library + * + * 0 will be returned if \p a and \p b are considered equal + * A value less than 0 will be returned if \p a is considered to be less than \p + * b A value greater than 0 will be returned if \p b is considered to be greater + * than \p b + * + * @param a sbp_status_journal_item_t instance + * @param b sbp_status_journal_item_t instance + * @return 0, <0, >0 + */ +SBP_EXPORT int sbp_status_journal_item_cmp(const sbp_status_journal_item_t *a, + const sbp_status_journal_item_t *b); + +#ifdef __cplusplus +} + +static inline bool operator==(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) == 0; +} + +static inline bool operator!=(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) != 0; +} + +static inline bool operator<(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) < 0; +} + +static inline bool operator<=(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) <= 0; +} + +static inline bool operator>(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) > 0; +} + +static inline bool operator>=(const sbp_status_journal_item_t &lhs, + const sbp_status_journal_item_t &rhs) { + return sbp_status_journal_item_cmp(&lhs, &rhs) >= 0; +} + +#endif // ifdef __cplusplus + +#endif /* LIBSBP_V4_SYSTEM_STATUSJOURNALITEM_H */ diff --git a/c/include/libsbp/version.h b/c/include/libsbp/version.h index 91a9fea6ae..2ddc171b88 100644 --- a/c/include/libsbp/version.h +++ b/c/include/libsbp/version.h @@ -28,7 +28,7 @@ #define SBP_PATCH_VERSION 5 /** Full SBP version string. */ -#define SBP_VERSION "4.1.5" +#define SBP_VERSION "4.1.6-alpha" /** \} */ diff --git a/c/src/include/libsbp/internal/v4/system.h b/c/src/include/libsbp/internal/v4/system.h index 5239d195f6..7f0ee4abfc 100644 --- a/c/src/include/libsbp/internal/v4/system.h +++ b/c/src/include/libsbp/internal/v4/system.h @@ -127,6 +127,46 @@ bool sbp_msg_status_report_encode_internal(sbp_encode_ctx_t *ctx, bool sbp_msg_status_report_decode_internal(sbp_decode_ctx_t *ctx, sbp_msg_status_report_t *msg); +/** + * Internal function to encode an SBP type to a buffer + * + * @param ctx Encode context + * @param msg SBP type instance + * @return true on success, false otherwise + */ +bool sbp_status_journal_item_encode_internal( + sbp_encode_ctx_t *ctx, const sbp_status_journal_item_t *msg); + +/** + * Internal function to decode an SBP type from a buffer + * + * @param ctx Decode context + * @param msg SBP type instance + * @return true on success, false otherwise + */ +bool sbp_status_journal_item_decode_internal(sbp_decode_ctx_t *ctx, + sbp_status_journal_item_t *msg); + +/** + * Internal function to encode an SBP type to a buffer + * + * @param ctx Encode context + * @param msg SBP type instance + * @return true on success, false otherwise + */ +bool sbp_msg_status_journal_encode_internal( + sbp_encode_ctx_t *ctx, const sbp_msg_status_journal_t *msg); + +/** + * Internal function to decode an SBP type from a buffer + * + * @param ctx Decode context + * @param msg SBP type instance + * @return true on success, false otherwise + */ +bool sbp_msg_status_journal_decode_internal(sbp_decode_ctx_t *ctx, + sbp_msg_status_journal_t *msg); + /** * Internal function to encode an SBP type to a buffer * diff --git a/c/src/v4/system.c b/c/src/v4/system.c index dc01480993..6cd53318a1 100644 --- a/c/src/v4/system.c +++ b/c/src/v4/system.c @@ -582,6 +582,233 @@ int sbp_msg_status_report_cmp(const sbp_msg_status_report_t *a, return ret; } +bool sbp_status_journal_item_encode_internal( + sbp_encode_ctx_t *ctx, const sbp_status_journal_item_t *msg) { + if (!sbp_u32_encode(ctx, &msg->uptime)) { + return false; + } + if (!sbp_u16_encode(ctx, &msg->component)) { + return false; + } + if (!sbp_u8_encode(ctx, &msg->generic)) { + return false; + } + if (!sbp_u8_encode(ctx, &msg->specific)) { + return false; + } + return true; +} + +s8 sbp_status_journal_item_encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_status_journal_item_t *msg) { + sbp_encode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_status_journal_item_encode_internal(&ctx, msg)) { + return SBP_ENCODE_ERROR; + } + if (n_written != NULL) { + *n_written = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +bool sbp_status_journal_item_decode_internal(sbp_decode_ctx_t *ctx, + sbp_status_journal_item_t *msg) { + if (!sbp_u32_decode(ctx, &msg->uptime)) { + return false; + } + if (!sbp_u16_decode(ctx, &msg->component)) { + return false; + } + if (!sbp_u8_decode(ctx, &msg->generic)) { + return false; + } + if (!sbp_u8_decode(ctx, &msg->specific)) { + return false; + } + return true; +} + +s8 sbp_status_journal_item_decode(const uint8_t *buf, uint8_t len, + uint8_t *n_read, + sbp_status_journal_item_t *msg) { + sbp_decode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_status_journal_item_decode_internal(&ctx, msg)) { + return SBP_DECODE_ERROR; + } + if (n_read != NULL) { + *n_read = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +int sbp_status_journal_item_cmp(const sbp_status_journal_item_t *a, + const sbp_status_journal_item_t *b) { + int ret = 0; + + ret = sbp_u32_cmp(&a->uptime, &b->uptime); + if (ret != 0) { + return ret; + } + + ret = sbp_u16_cmp(&a->component, &b->component); + if (ret != 0) { + return ret; + } + + ret = sbp_u8_cmp(&a->generic, &b->generic); + if (ret != 0) { + return ret; + } + + ret = sbp_u8_cmp(&a->specific, &b->specific); + if (ret != 0) { + return ret; + } + return ret; +} + +bool sbp_msg_status_journal_encode_internal( + sbp_encode_ctx_t *ctx, const sbp_msg_status_journal_t *msg) { + if (!sbp_u16_encode(ctx, &msg->reporting_system)) { + return false; + } + if (!sbp_u16_encode(ctx, &msg->sbp_version)) { + return false; + } + if (!sbp_u32_encode(ctx, &msg->n_status_reports)) { + return false; + } + if (!sbp_u8_encode(ctx, &msg->packet_index)) { + return false; + } + if (!sbp_u8_encode(ctx, &msg->n_packets)) { + return false; + } + for (size_t i = 0; i < msg->n_journal; i++) { + if (!sbp_status_journal_item_encode_internal(ctx, &msg->journal[i])) { + return false; + } + } + return true; +} + +s8 sbp_msg_status_journal_encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_msg_status_journal_t *msg) { + sbp_encode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_msg_status_journal_encode_internal(&ctx, msg)) { + return SBP_ENCODE_ERROR; + } + if (n_written != NULL) { + *n_written = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +bool sbp_msg_status_journal_decode_internal(sbp_decode_ctx_t *ctx, + sbp_msg_status_journal_t *msg) { + if (!sbp_u16_decode(ctx, &msg->reporting_system)) { + return false; + } + if (!sbp_u16_decode(ctx, &msg->sbp_version)) { + return false; + } + if (!sbp_u32_decode(ctx, &msg->n_status_reports)) { + return false; + } + if (!sbp_u8_decode(ctx, &msg->packet_index)) { + return false; + } + if (!sbp_u8_decode(ctx, &msg->n_packets)) { + return false; + } + msg->n_journal = (uint8_t)((ctx->buf_len - ctx->offset) / + SBP_STATUS_JOURNAL_ITEM_ENCODED_LEN); + for (uint8_t i = 0; i < msg->n_journal; i++) { + if (!sbp_status_journal_item_decode_internal(ctx, &msg->journal[i])) { + return false; + } + } + return true; +} + +s8 sbp_msg_status_journal_decode(const uint8_t *buf, uint8_t len, + uint8_t *n_read, + sbp_msg_status_journal_t *msg) { + sbp_decode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_msg_status_journal_decode_internal(&ctx, msg)) { + return SBP_DECODE_ERROR; + } + if (n_read != NULL) { + *n_read = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +s8 sbp_msg_status_journal_send(sbp_state_t *s, u16 sender_id, + const sbp_msg_status_journal_t *msg, + sbp_write_fn_t write) { + uint8_t payload[SBP_MAX_PAYLOAD_LEN]; + uint8_t payload_len; + s8 ret = sbp_msg_status_journal_encode(payload, sizeof(payload), &payload_len, + msg); + if (ret != SBP_OK) { + return ret; + } + return sbp_payload_send(s, SBP_MSG_STATUS_JOURNAL, sender_id, payload_len, + payload, write); +} + +int sbp_msg_status_journal_cmp(const sbp_msg_status_journal_t *a, + const sbp_msg_status_journal_t *b) { + int ret = 0; + + ret = sbp_u16_cmp(&a->reporting_system, &b->reporting_system); + if (ret != 0) { + return ret; + } + + ret = sbp_u16_cmp(&a->sbp_version, &b->sbp_version); + if (ret != 0) { + return ret; + } + + ret = sbp_u32_cmp(&a->n_status_reports, &b->n_status_reports); + if (ret != 0) { + return ret; + } + + ret = sbp_u8_cmp(&a->packet_index, &b->packet_index); + if (ret != 0) { + return ret; + } + + ret = sbp_u8_cmp(&a->n_packets, &b->n_packets); + if (ret != 0) { + return ret; + } + + ret = sbp_u8_cmp(&a->n_journal, &b->n_journal); + for (uint8_t i = 0; ret == 0 && i < a->n_journal; i++) { + ret = sbp_status_journal_item_cmp(&a->journal[i], &b->journal[i]); + } + if (ret != 0) { + return ret; + } + return ret; +} + bool sbp_msg_ins_status_encode_internal(sbp_encode_ctx_t *ctx, const sbp_msg_ins_status_t *msg) { if (!sbp_u32_encode(ctx, &msg->flags)) { From 1804266f74274b3057fed1fc2846b71d40ea5ba8 Mon Sep 17 00:00:00 2001 From: Rodrigo Reichert Date: Mon, 2 May 2022 11:00:24 +1000 Subject: [PATCH 3/3] update --- c/include/libsbp/legacy/system.h | 27 ++-- c/include/libsbp/system_macros.h | 39 +----- .../libsbp/v4/system/MSG_STATUS_JOURNAL.h | 13 +- .../libsbp/v4/system/StatusJournalItem.h | 23 +--- c/src/v4/system.c | 51 ++------ spec/yaml/swiftnav/sbp/system.yaml | 119 +++++++----------- 6 files changed, 83 insertions(+), 189 deletions(-) diff --git a/c/include/libsbp/legacy/system.h b/c/include/libsbp/legacy/system.h index f8eed89397..4f15339ae3 100644 --- a/c/include/libsbp/legacy/system.h +++ b/c/include/libsbp/legacy/system.h @@ -106,17 +106,16 @@ typedef struct SBP_ATTR_PACKED { subsystems */ } msg_status_report_t; -/** Sub-system Status report +/** Subsystem Status report * - * Report the general and specific state of a sub-system. If the generic - * state is reported as initializing, the specific state should be ignored. + * Reports the uptime and the state of a subsystem via generic and specific + * status codes. If the generic state is reported as initializing, the + * specific state should be ignored. */ typedef struct SBP_ATTR_PACKED { - u32 uptime; /**< Milliseconds since system startup */ - u16 component; /**< Identity of reporting subsystem */ - u8 generic; /**< Generic form status report */ - u8 specific; /**< Subsystem specific status code */ + u32 uptime; /**< Milliseconds since system startup */ + sub_system_report_t report; } status_journal_item_t; /** Status report journal @@ -127,12 +126,14 @@ typedef struct SBP_ATTR_PACKED { */ typedef struct SBP_ATTR_PACKED { - u16 reporting_system; /**< Identity of reporting system */ - u16 sbp_version; /**< SBP protocol version */ - u32 n_status_reports; /**< Total number of status reports sent since - system startup */ - u8 packet_index; /**< Index of this packet in the status journal */ - u8 n_packets; /**< Number of packets in this status journal */ + u16 reporting_system; /**< Identity of reporting system */ + u16 sbp_version; /**< SBP protocol version */ + u32 total_status_reports; /**< Total number of status reports sent since + system startup */ + u8 sequence_descriptor; /**< Index and number of messages in this + sequence. First nibble is the size of the + sequence (n), second nibble is the zero- + indexed counter (ith packet of n) */ status_journal_item_t journal[0]; /**< Status journal */ } msg_status_journal_t; diff --git a/c/include/libsbp/system_macros.h b/c/include/libsbp/system_macros.h index e5e78b63a3..61214be794 100644 --- a/c/include/libsbp/system_macros.h +++ b/c/include/libsbp/system_macros.h @@ -297,41 +297,6 @@ */ #define SBP_MSG_STATUS_REPORT_ENCODED_OVERHEAD 12u -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK (0xffff) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT (0u) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_GET(flags) \ - ((u16)(((flags) >> SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT) & \ - SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK)) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SET(flags, val) \ - do { \ - (flags) = \ - (u16)((flags) | (((val) & (SBP_STATUSJOURNALITEM_SUBSYSTEM_MASK)) \ - << (SBP_STATUSJOURNALITEM_SUBSYSTEM_SHIFT))); \ - } while (0) - -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_PRIMARY_GNSS_ANTENNA (0) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_MEASUREMENT_ENGINE (1) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_CORRECTIONS_CLIENT (2) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_DIFFERENTIAL_GNSS_ENGINE (3) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_CAN (4) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_WHEEL_ODOMETRY (5) -#define SBP_STATUSJOURNALITEM_SUBSYSTEM_SENSOR_FUSION_ENGINE (6) -#define SBP_STATUSJOURNALITEM_GENERIC_MASK (0xff) -#define SBP_STATUSJOURNALITEM_GENERIC_SHIFT (0u) -#define SBP_STATUSJOURNALITEM_GENERIC_GET(flags) \ - ((u8)(((flags) >> SBP_STATUSJOURNALITEM_GENERIC_SHIFT) & \ - SBP_STATUSJOURNALITEM_GENERIC_MASK)) -#define SBP_STATUSJOURNALITEM_GENERIC_SET(flags, val) \ - do { \ - (flags) = (u8)((flags) | (((val) & (SBP_STATUSJOURNALITEM_GENERIC_MASK)) \ - << (SBP_STATUSJOURNALITEM_GENERIC_SHIFT))); \ - } while (0) - -#define SBP_STATUSJOURNALITEM_GENERIC_OKNOMINAL (0) -#define SBP_STATUSJOURNALITEM_GENERIC_INITIALIZING (1) -#define SBP_STATUSJOURNALITEM_GENERIC_UNKNOWN (2) -#define SBP_STATUSJOURNALITEM_GENERIC_DEGRADED (3) -#define SBP_STATUSJOURNALITEM_GENERIC_UNUSABLE (4) /** * Encoded length of sbp_status_journal_item_t (V4 API) and * status_journal_item_t (legacy API) @@ -352,7 +317,7 @@ #define SBP_STATUS_JOURNAL_SYSTEM_STARLING (0) #define SBP_STATUS_JOURNAL_SYSTEM_PRECISION_GNSS_MODULE (1) -#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_MASK (0x1ff) +#define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_MASK (0xff) #define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_SHIFT (8u) #define SBP_STATUS_JOURNAL_SBP_MAJOR_PROTOCOL_VERSION_NUMBER_GET(flags) \ ((u16)(((flags) >> \ @@ -400,7 +365,7 @@ * See the documentation for libsbp for more details regarding the message * structure and its variable length component(s) */ -#define SBP_MSG_STATUS_JOURNAL_ENCODED_OVERHEAD 10u +#define SBP_MSG_STATUS_JOURNAL_ENCODED_OVERHEAD 9u #define SBP_MSG_INS_STATUS 0xFF03 #define SBP_INS_STATUS_INS_TYPE_MASK (0x7) diff --git a/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h b/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h index 0513149d26..2786052eaa 100644 --- a/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h +++ b/c/include/libsbp/v4/system/MSG_STATUS_JOURNAL.h @@ -59,17 +59,14 @@ typedef struct { /** * Total number of status reports sent since system startup */ - u32 n_status_reports; + u32 total_status_reports; /** - * Index of this packet in the status journal + * Index and number of messages in this sequence. First nibble is the size of + * the sequence (n), second nibble is the zero-indexed counter (ith packet of + * n) */ - u8 packet_index; - - /** - * Number of packets in this status journal - */ - u8 n_packets; + u8 sequence_descriptor; /** * Status journal diff --git a/c/include/libsbp/v4/system/StatusJournalItem.h b/c/include/libsbp/v4/system/StatusJournalItem.h index 049c4df3fc..b55550215a 100644 --- a/c/include/libsbp/v4/system/StatusJournalItem.h +++ b/c/include/libsbp/v4/system/StatusJournalItem.h @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -38,10 +39,11 @@ extern "C" { * SBP_STATUSJOURNALITEM * *****************************************************************************/ -/** Sub-system Status report +/** Subsystem Status report * - * Report the general and specific state of a sub-system. If the generic state - * is reported as initializing, the specific state should be ignored. + * Reports the uptime and the state of a subsystem via generic and specific + * status codes. If the generic state is reported as initializing, the specific + * state should be ignored. */ typedef struct { /** @@ -49,20 +51,7 @@ typedef struct { */ u32 uptime; - /** - * Identity of reporting subsystem - */ - u16 component; - - /** - * Generic form status report - */ - u8 generic; - - /** - * Subsystem specific status code - */ - u8 specific; + sbp_sub_system_report_t report; } sbp_status_journal_item_t; /** diff --git a/c/src/v4/system.c b/c/src/v4/system.c index 6cd53318a1..c007f3cd40 100644 --- a/c/src/v4/system.c +++ b/c/src/v4/system.c @@ -587,13 +587,7 @@ bool sbp_status_journal_item_encode_internal( if (!sbp_u32_encode(ctx, &msg->uptime)) { return false; } - if (!sbp_u16_encode(ctx, &msg->component)) { - return false; - } - if (!sbp_u8_encode(ctx, &msg->generic)) { - return false; - } - if (!sbp_u8_encode(ctx, &msg->specific)) { + if (!sbp_sub_system_report_encode_internal(ctx, &msg->report)) { return false; } return true; @@ -619,13 +613,7 @@ bool sbp_status_journal_item_decode_internal(sbp_decode_ctx_t *ctx, if (!sbp_u32_decode(ctx, &msg->uptime)) { return false; } - if (!sbp_u16_decode(ctx, &msg->component)) { - return false; - } - if (!sbp_u8_decode(ctx, &msg->generic)) { - return false; - } - if (!sbp_u8_decode(ctx, &msg->specific)) { + if (!sbp_sub_system_report_decode_internal(ctx, &msg->report)) { return false; } return true; @@ -656,17 +644,7 @@ int sbp_status_journal_item_cmp(const sbp_status_journal_item_t *a, return ret; } - ret = sbp_u16_cmp(&a->component, &b->component); - if (ret != 0) { - return ret; - } - - ret = sbp_u8_cmp(&a->generic, &b->generic); - if (ret != 0) { - return ret; - } - - ret = sbp_u8_cmp(&a->specific, &b->specific); + ret = sbp_sub_system_report_cmp(&a->report, &b->report); if (ret != 0) { return ret; } @@ -681,13 +659,10 @@ bool sbp_msg_status_journal_encode_internal( if (!sbp_u16_encode(ctx, &msg->sbp_version)) { return false; } - if (!sbp_u32_encode(ctx, &msg->n_status_reports)) { + if (!sbp_u32_encode(ctx, &msg->total_status_reports)) { return false; } - if (!sbp_u8_encode(ctx, &msg->packet_index)) { - return false; - } - if (!sbp_u8_encode(ctx, &msg->n_packets)) { + if (!sbp_u8_encode(ctx, &msg->sequence_descriptor)) { return false; } for (size_t i = 0; i < msg->n_journal; i++) { @@ -721,13 +696,10 @@ bool sbp_msg_status_journal_decode_internal(sbp_decode_ctx_t *ctx, if (!sbp_u16_decode(ctx, &msg->sbp_version)) { return false; } - if (!sbp_u32_decode(ctx, &msg->n_status_reports)) { - return false; - } - if (!sbp_u8_decode(ctx, &msg->packet_index)) { + if (!sbp_u32_decode(ctx, &msg->total_status_reports)) { return false; } - if (!sbp_u8_decode(ctx, &msg->n_packets)) { + if (!sbp_u8_decode(ctx, &msg->sequence_descriptor)) { return false; } msg->n_journal = (uint8_t)((ctx->buf_len - ctx->offset) / @@ -784,17 +756,12 @@ int sbp_msg_status_journal_cmp(const sbp_msg_status_journal_t *a, return ret; } - ret = sbp_u32_cmp(&a->n_status_reports, &b->n_status_reports); - if (ret != 0) { - return ret; - } - - ret = sbp_u8_cmp(&a->packet_index, &b->packet_index); + ret = sbp_u32_cmp(&a->total_status_reports, &b->total_status_reports); if (ret != 0) { return ret; } - ret = sbp_u8_cmp(&a->n_packets, &b->n_packets); + ret = sbp_u8_cmp(&a->sequence_descriptor, &b->sequence_descriptor); if (ret != 0) { return ret; } diff --git a/spec/yaml/swiftnav/sbp/system.yaml b/spec/yaml/swiftnav/sbp/system.yaml index 5cb40b98a5..d400898261 100644 --- a/spec/yaml/swiftnav/sbp/system.yaml +++ b/spec/yaml/swiftnav/sbp/system.yaml @@ -217,82 +217,57 @@ definitions: desc: Reported status of individual subsystems - StatusJournalItem: - short_desc: Sub-system Status report - embedded_type: true - desc: > - Report the general and specific state of a sub-system. If the generic - state is reported as initializing, the specific state should be ignored. - fields: - - uptime: - type: u32 - desc: Milliseconds since system startup - - component: - type: u16 - desc: Identity of reporting subsystem - fields: - - 0-15: - desc: Subsystem - values: - - 0: Primary GNSS Antenna - - 1: Measurement Engine - - 2: Corrections Client - - 3: Differential GNSS Engine - - 4: CAN - - 5: Wheel Odometry - - 6: Sensor Fusion Engine - - generic: - type: u8 - desc: Generic form status report - fields: - - 0-7: - desc: Generic - values: - - 0: OK/Nominal - - 1: Initializing - - 2: Unknown - - 3: Degraded - - 4: Unusable - - specific: - type: u8 - desc: Subsystem specific status code + short_desc: Subsystem Status report + embedded_type: true + desc: > + Reports the uptime and the state of a subsystem via generic and specific + status codes. If the generic state is reported as initializing, the + specific state should be ignored. + fields: + - uptime: + type: u32 + desc: Milliseconds since system startup + - report: + type: SubSystemReport - MSG_STATUS_JOURNAL: - id: 0xFFFD - short_desc: Status report journal - desc: > - The status journal message contains past status reports (see MSG_STATUS_REPORT) - and functions as a error/event storage for telemetry purposes. - fields: - - reporting_system: - type: u16 - desc: Identity of reporting system - fields: - - 0-15: + id: 0xFFFD + short_desc: Status report journal + desc: > + The status journal message contains past status reports (see + MSG_STATUS_REPORT) and functions as a error/event storage for telemetry + purposes. + fields: + - reporting_system: + type: u16 + desc: Identity of reporting system + fields: + - 0-15: desc: System values: - - 0: Starling - - 1: Precision GNSS Module (PGM) - - sbp_version: - type: u16 - desc: SBP protocol version - fields: - - 8-16: - desc: SBP major protocol version number - - 0-7: - desc: SBP minor protocol version number - - n_status_reports: - type: u32 - desc: Total number of status reports sent since system startup - - packet_index: - type: u8 - desc: Index of this packet in the status journal - - n_packets: - type: u8 - desc: Number of packets in this status journal - - journal: - type: array - fill: StatusJournalItem - desc: Status journal + - 0: Starling + - 1: Precision GNSS Module (PGM) + - sbp_version: + type: u16 + desc: SBP protocol version + fields: + - 8-15: + desc: SBP major protocol version number + - 0-7: + desc: SBP minor protocol version number + - total_status_reports: + type: u32 + desc: Total number of status reports sent since system startup + - sequence_descriptor: + type: u8 + desc: > + Index and number of messages in this sequence. First nibble is + the size of the sequence (n), second nibble is the zero-indexed + counter (ith packet of n) + - journal: + type: array + fill: StatusJournalItem + desc: Status journal - MSG_INS_STATUS: id: 0xFF03