diff --git a/c/include/libsbp/cpp/message_traits.h b/c/include/libsbp/cpp/message_traits.h index dbe88518b1..85a3d2d97b 100644 --- a/c/include/libsbp/cpp/message_traits.h +++ b/c/include/libsbp/cpp/message_traits.h @@ -3527,6 +3527,39 @@ struct MessageTraits { } }; +template <> +struct MessageTraits { + static constexpr sbp_msg_type_t id = SbpMsgImuComp; + static constexpr const char *name = "MSG_IMU_COMP"; + static const sbp_msg_imu_comp_t &get(const sbp_msg_t &msg) { + return msg.imu_comp; + } + static sbp_msg_imu_comp_t &get(sbp_msg_t &msg) { return msg.imu_comp; } + static void to_sbp_msg(const sbp_msg_imu_comp_t &msg, sbp_msg_t *sbp_msg) { + sbp_msg->imu_comp = msg; + } + static sbp_msg_t to_sbp_msg(const sbp_msg_imu_comp_t &msg) { + sbp_msg_t sbp_msg; + sbp_msg.imu_comp = msg; + return sbp_msg; + } + static s8 send(sbp_state_t *state, u16 sender_id, + const sbp_msg_imu_comp_t &msg, sbp_write_fn_t write) { + return sbp_msg_imu_comp_send(state, sender_id, &msg, write); + } + static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_msg_imu_comp_t &msg) { + return sbp_msg_imu_comp_encode(buf, len, n_written, &msg); + } + static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read, + sbp_msg_imu_comp_t *msg) { + return sbp_msg_imu_comp_decode(buf, len, n_read, msg); + } + static size_t encoded_len(const sbp_msg_imu_comp_t &msg) { + return sbp_msg_imu_comp_encoded_len(&msg); + } +}; + template <> struct MessageTraits { static constexpr sbp_msg_type_t id = SbpMsgImuRaw; diff --git a/c/include/libsbp/imu.h b/c/include/libsbp/imu.h index 56a867b9b4..ccb7f849a4 100644 --- a/c/include/libsbp/imu.h +++ b/c/include/libsbp/imu.h @@ -18,6 +18,7 @@ #ifndef LIBSBP_IMU_MESSAGES_H #define LIBSBP_IMU_MESSAGES_H #include +#include #include #endif /* LIBSBP_IMU_MESSAGES_H */ diff --git a/c/include/libsbp/imu/MSG_IMU_COMP.h b/c/include/libsbp/imu/MSG_IMU_COMP.h new file mode 100644 index 0000000000..7f28d160c6 --- /dev/null +++ b/c/include/libsbp/imu/MSG_IMU_COMP.h @@ -0,0 +1,214 @@ +/* + * 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 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/imu.yaml + * with generate.py. Please do not hand edit! + *****************************************************************************/ + +#ifndef LIBSBP_IMU_MSG_IMU_COMP_H +#define LIBSBP_IMU_MSG_IMU_COMP_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * + * SBP_MSG_IMU_COMP + * + *****************************************************************************/ +/** Compensated IMU data + * + * Data from the Inertial Measurement Unit, containing accelerometer and + * gyroscope readings compensated for estimated errors and constant physical + * effects. The output is valid for the center of navigation. + */ +typedef struct { + /** + * Microseconds since reference epoch [microseconds] + */ + u64 time; + + /** + * Contains the applied compensation parameters and time synchronization mode + */ + u16 flags; + + /** + * Compensated acceleration X axis [1e-2 m/s^2] + */ + s32 acc_comp_x; + + /** + * Compensated acceleration Y axis [1e-2 m/s^2] + */ + s32 acc_comp_y; + + /** + * Compensated acceleration Z axis [1e-2 m/s^2] + */ + s32 acc_comp_z; + + /** + * Compensated angular rate X axis [1e-3 deg/s] + */ + s32 gyr_comp_x; + + /** + * Compensated angular rate Y axis [1e-3 deg/s] + */ + s32 gyr_comp_y; + + /** + * Compensated angular rate Z axis [1e-3 deg/s] + */ + s32 gyr_comp_z; +} sbp_msg_imu_comp_t; + +/** + * Get encoded size of an instance of sbp_msg_imu_comp_t + * + * @param msg sbp_msg_imu_comp_t instance + * @return Length of on-wire representation + */ +static inline size_t sbp_msg_imu_comp_encoded_len( + const sbp_msg_imu_comp_t *msg) { + (void)msg; + return SBP_MSG_IMU_COMP_ENCODED_LEN; +} + +/** + * Encode an instance of sbp_msg_imu_comp_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_imu_comp_t to encode + * @return SBP_OK on success, or other libsbp error code + */ +SBP_EXPORT s8 sbp_msg_imu_comp_encode(uint8_t *buf, uint8_t len, + uint8_t *n_written, + const sbp_msg_imu_comp_t *msg); + +/** + * Decode an instance of sbp_msg_imu_comp_t from wire representation + * + * This function decodes the wire representation of a sbp_msg_imu_comp_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_imu_comp_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_imu_comp_decode(const uint8_t *buf, uint8_t len, + uint8_t *n_read, sbp_msg_imu_comp_t *msg); +/** + * Send an instance of sbp_msg_imu_comp_t with the given write function + * + * An equivalent of #sbp_message_send which operates specifically on + * sbp_msg_imu_comp_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_imu_comp_send(sbp_state_t *s, u16 sender_id, + const sbp_msg_imu_comp_t *msg, + sbp_write_fn_t write); + +/** + * Compare two instances of sbp_msg_imu_comp_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_imu_comp_t instance + * @param b sbp_msg_imu_comp_t instance + * @return 0, <0, >0 + */ +SBP_EXPORT int sbp_msg_imu_comp_cmp(const sbp_msg_imu_comp_t *a, + const sbp_msg_imu_comp_t *b); + +#ifdef __cplusplus +} + +static inline bool operator==(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) == 0; +} + +static inline bool operator!=(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) != 0; +} + +static inline bool operator<(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) < 0; +} + +static inline bool operator<=(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) <= 0; +} + +static inline bool operator>(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) > 0; +} + +static inline bool operator>=(const sbp_msg_imu_comp_t &lhs, + const sbp_msg_imu_comp_t &rhs) { + return sbp_msg_imu_comp_cmp(&lhs, &rhs) >= 0; +} + +#endif // ifdef __cplusplus + +#endif /* LIBSBP_IMU_MSG_IMU_COMP_H */ diff --git a/c/include/libsbp/imu_macros.h b/c/include/libsbp/imu_macros.h index 134fa546fe..42590ec1dd 100644 --- a/c/include/libsbp/imu_macros.h +++ b/c/include/libsbp/imu_macros.h @@ -129,4 +129,27 @@ */ #define SBP_MSG_IMU_AUX_ENCODED_LEN 4u +#define SBP_IMU_COMP_TIME_STATUS_MASK (0x3u) +#define SBP_IMU_COMP_TIME_STATUS_SHIFT (0u) +#define SBP_IMU_COMP_TIME_STATUS_GET(flags) \ + ((u16)((u16)((flags) >> SBP_IMU_COMP_TIME_STATUS_SHIFT) & \ + SBP_IMU_COMP_TIME_STATUS_MASK)) +#define SBP_IMU_COMP_TIME_STATUS_SET(flags, val) \ + do { \ + (flags) = (u16)((flags & (~(SBP_IMU_COMP_TIME_STATUS_MASK \ + << SBP_IMU_COMP_TIME_STATUS_SHIFT))) | \ + (((val) & (SBP_IMU_COMP_TIME_STATUS_MASK)) \ + << (SBP_IMU_COMP_TIME_STATUS_SHIFT))); \ + } while (0) + +#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_START_OF_CURRENT_GPS_WEEK \ + (0) +#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_TIME_OF_SYSTEM_STARTUP (1) +#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_UNKNOWN (2) +#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_LAST_PPS (3) +/** + * Encoded length of sbp_msg_imu_comp_t + */ +#define SBP_MSG_IMU_COMP_ENCODED_LEN 34u + #endif /* LIBSBP_IMU_MACROS_H */ diff --git a/c/include/libsbp/sbp_msg.h b/c/include/libsbp/sbp_msg.h index c8c510256f..754aeb8e79 100644 --- a/c/include/libsbp/sbp_msg.h +++ b/c/include/libsbp/sbp_msg.h @@ -157,6 +157,7 @@ typedef union { sbp_msg_heartbeat_t heartbeat; sbp_msg_iar_state_t iar_state; sbp_msg_imu_aux_t imu_aux; + sbp_msg_imu_comp_t imu_comp; sbp_msg_imu_raw_t imu_raw; sbp_msg_init_base_dep_t init_base_dep; sbp_msg_ins_status_t ins_status; @@ -587,6 +588,8 @@ static inline s8 sbp_message_encode(uint8_t *buf, uint8_t len, return sbp_msg_iar_state_encode(buf, len, n_written, &msg->iar_state); case SbpMsgImuAux: return sbp_msg_imu_aux_encode(buf, len, n_written, &msg->imu_aux); + case SbpMsgImuComp: + return sbp_msg_imu_comp_encode(buf, len, n_written, &msg->imu_comp); case SbpMsgImuRaw: return sbp_msg_imu_raw_encode(buf, len, n_written, &msg->imu_raw); case SbpMsgInitBaseDep: @@ -1257,6 +1260,8 @@ static inline s8 sbp_message_decode(const uint8_t *buf, uint8_t len, return sbp_msg_iar_state_decode(buf, len, n_read, &msg->iar_state); case SbpMsgImuAux: return sbp_msg_imu_aux_decode(buf, len, n_read, &msg->imu_aux); + case SbpMsgImuComp: + return sbp_msg_imu_comp_decode(buf, len, n_read, &msg->imu_comp); case SbpMsgImuRaw: return sbp_msg_imu_raw_decode(buf, len, n_read, &msg->imu_raw); case SbpMsgInitBaseDep: @@ -1861,6 +1866,8 @@ static inline size_t sbp_message_encoded_len(sbp_msg_type_t msg_type, return sbp_msg_iar_state_encoded_len(&msg->iar_state); case SbpMsgImuAux: return sbp_msg_imu_aux_encoded_len(&msg->imu_aux); + case SbpMsgImuComp: + return sbp_msg_imu_comp_encoded_len(&msg->imu_comp); case SbpMsgImuRaw: return sbp_msg_imu_raw_encoded_len(&msg->imu_raw); case SbpMsgInitBaseDep: @@ -2452,6 +2459,8 @@ static inline int sbp_message_cmp(sbp_msg_type_t msg_type, const sbp_msg_t *a, return sbp_msg_iar_state_cmp(&a->iar_state, &b->iar_state); case SbpMsgImuAux: return sbp_msg_imu_aux_cmp(&a->imu_aux, &b->imu_aux); + case SbpMsgImuComp: + return sbp_msg_imu_comp_cmp(&a->imu_comp, &b->imu_comp); case SbpMsgImuRaw: return sbp_msg_imu_raw_cmp(&a->imu_raw, &b->imu_raw); case SbpMsgInitBaseDep: diff --git a/c/include/libsbp/sbp_msg_type.h b/c/include/libsbp/sbp_msg_type.h index 906bdce08c..a098bfc013 100644 --- a/c/include/libsbp/sbp_msg_type.h +++ b/c/include/libsbp/sbp_msg_type.h @@ -148,6 +148,7 @@ typedef enum { SbpMsgHeartbeat = 0xFFFF, SbpMsgIarState = 0x0019, SbpMsgImuAux = 0x0901, + SbpMsgImuComp = 0x0905, SbpMsgImuRaw = 0x0900, SbpMsgInitBaseDep = 0x0023, SbpMsgInsStatus = 0xFF03, @@ -489,6 +490,8 @@ static inline const char *sbp_msg_type_to_string(sbp_msg_type_t msg_type) { return "MSG_IAR_STATE"; case SbpMsgImuAux: return "MSG_IMU_AUX"; + case SbpMsgImuComp: + return "MSG_IMU_COMP"; case SbpMsgImuRaw: return "MSG_IMU_RAW"; case SbpMsgInitBaseDep: diff --git a/c/src/imu.c b/c/src/imu.c index 95aeed2b82..4610a2d3b2 100644 --- a/c/src/imu.c +++ b/c/src/imu.c @@ -247,3 +247,146 @@ int sbp_msg_imu_aux_cmp(const sbp_msg_imu_aux_t *a, ret = sbp_u8_cmp(&a->imu_conf, &b->imu_conf); return ret; } + +bool sbp_msg_imu_comp_encode_internal(sbp_encode_ctx_t *ctx, + const sbp_msg_imu_comp_t *msg) { + if (!sbp_u64_encode(ctx, &msg->time)) { + return false; + } + if (!sbp_u16_encode(ctx, &msg->flags)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->acc_comp_x)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->acc_comp_y)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->acc_comp_z)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->gyr_comp_x)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->gyr_comp_y)) { + return false; + } + if (!sbp_s32_encode(ctx, &msg->gyr_comp_z)) { + return false; + } + return true; +} + +s8 sbp_msg_imu_comp_encode(uint8_t *buf, uint8_t len, uint8_t *n_written, + const sbp_msg_imu_comp_t *msg) { + sbp_encode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_msg_imu_comp_encode_internal(&ctx, msg)) { + return SBP_ENCODE_ERROR; + } + if (n_written != NULL) { + *n_written = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +bool sbp_msg_imu_comp_decode_internal(sbp_decode_ctx_t *ctx, + sbp_msg_imu_comp_t *msg) { + if (!sbp_u64_decode(ctx, &msg->time)) { + return false; + } + if (!sbp_u16_decode(ctx, &msg->flags)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->acc_comp_x)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->acc_comp_y)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->acc_comp_z)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->gyr_comp_x)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->gyr_comp_y)) { + return false; + } + if (!sbp_s32_decode(ctx, &msg->gyr_comp_z)) { + return false; + } + return true; +} + +s8 sbp_msg_imu_comp_decode(const uint8_t *buf, uint8_t len, uint8_t *n_read, + sbp_msg_imu_comp_t *msg) { + sbp_decode_ctx_t ctx; + ctx.buf = buf; + ctx.buf_len = len; + ctx.offset = 0; + if (!sbp_msg_imu_comp_decode_internal(&ctx, msg)) { + return SBP_DECODE_ERROR; + } + if (n_read != NULL) { + *n_read = (uint8_t)ctx.offset; + } + return SBP_OK; +} + +s8 sbp_msg_imu_comp_send(sbp_state_t *s, u16 sender_id, + const sbp_msg_imu_comp_t *msg, sbp_write_fn_t write) { + uint8_t payload[SBP_MAX_PAYLOAD_LEN]; + uint8_t payload_len; + s8 ret = sbp_msg_imu_comp_encode(payload, sizeof(payload), &payload_len, msg); + if (ret != SBP_OK) { + return ret; + } + return sbp_internal_forward_payload(s, SbpMsgImuComp, sender_id, payload_len, + payload, write); +} + +int sbp_msg_imu_comp_cmp(const sbp_msg_imu_comp_t *a, + const sbp_msg_imu_comp_t *b) { + int ret = 0; + + ret = sbp_u64_cmp(&a->time, &b->time); + if (ret != 0) { + return ret; + } + + ret = sbp_u16_cmp(&a->flags, &b->flags); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->acc_comp_x, &b->acc_comp_x); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->acc_comp_y, &b->acc_comp_y); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->acc_comp_z, &b->acc_comp_z); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->gyr_comp_x, &b->gyr_comp_x); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->gyr_comp_y, &b->gyr_comp_y); + if (ret != 0) { + return ret; + } + + ret = sbp_s32_cmp(&a->gyr_comp_z, &b->gyr_comp_z); + return ret; +} diff --git a/c/src/include/libsbp/internal/imu.h b/c/src/include/libsbp/internal/imu.h index 257f7ace24..6e8c5fbd77 100644 --- a/c/src/include/libsbp/internal/imu.h +++ b/c/src/include/libsbp/internal/imu.h @@ -67,6 +67,26 @@ bool sbp_msg_imu_aux_encode_internal(sbp_encode_ctx_t *ctx, bool sbp_msg_imu_aux_decode_internal(sbp_decode_ctx_t *ctx, sbp_msg_imu_aux_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_imu_comp_encode_internal(sbp_encode_ctx_t *ctx, + const sbp_msg_imu_comp_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_imu_comp_decode_internal(sbp_decode_ctx_t *ctx, + sbp_msg_imu_comp_t *msg); + #ifdef __cplusplus } #endif diff --git a/docs/sbp.pdf b/docs/sbp.pdf index 7b879fc442..5463b4b8ac 100644 Binary files a/docs/sbp.pdf and b/docs/sbp.pdf differ diff --git a/python/sbp/imu.py b/python/sbp/imu.py index be27d3c67c..4623ff5bb4 100644 --- a/python/sbp/imu.py +++ b/python/sbp/imu.py @@ -271,8 +271,141 @@ def to_json_dict(self): d.update(j) return d +SBP_MSG_IMU_COMP = 0x0905 +class MsgImuComp(SBP): + """SBP class for message MSG_IMU_COMP (0x0905). + + You can have MSG_IMU_COMP inherit its fields directly + from an inherited SBP object, or construct it inline using a dict + of its fields. + + + Data from the Inertial Measurement Unit, containing accelerometer and + gyroscope readings compensated for estimated errors and constant physical + effects. The output is valid for the center of navigation. + + Parameters + ---------- + sbp : SBP + SBP parent object to inherit from. + time : int + Microseconds since reference epoch + flags : int + Contains the applied compensation parameters and time synchronization mode + acc_comp_x : int + Compensated acceleration X axis + acc_comp_y : int + Compensated acceleration Y axis + acc_comp_z : int + Compensated acceleration Z axis + gyr_comp_x : int + Compensated angular rate X axis + gyr_comp_y : int + Compensated angular rate Y axis + gyr_comp_z : int + Compensated angular rate Z axis + sender : int + Optional sender ID, defaults to SENDER_ID (see sbp/msg.py). + + """ + _parser = construct.Struct( + 'time' / construct.Int64ul, + 'flags' / construct.Int16ul, + 'acc_comp_x' / construct.Int32sl, + 'acc_comp_y' / construct.Int32sl, + 'acc_comp_z' / construct.Int32sl, + 'gyr_comp_x' / construct.Int32sl, + 'gyr_comp_y' / construct.Int32sl, + 'gyr_comp_z' / construct.Int32sl,) + __slots__ = [ + 'time', + 'flags', + 'acc_comp_x', + 'acc_comp_y', + 'acc_comp_z', + 'gyr_comp_x', + 'gyr_comp_y', + 'gyr_comp_z', + ] + + def __init__(self, sbp=None, **kwargs): + if sbp: + super( MsgImuComp, + self).__init__(sbp.msg_type, sbp.sender, sbp.length, + sbp.payload, sbp.crc) + self.from_binary(sbp.payload) + else: + super( MsgImuComp, self).__init__() + self.msg_type = SBP_MSG_IMU_COMP + self.sender = kwargs.pop('sender', SENDER_ID) + self.time = kwargs.pop('time') + self.flags = kwargs.pop('flags') + self.acc_comp_x = kwargs.pop('acc_comp_x') + self.acc_comp_y = kwargs.pop('acc_comp_y') + self.acc_comp_z = kwargs.pop('acc_comp_z') + self.gyr_comp_x = kwargs.pop('gyr_comp_x') + self.gyr_comp_y = kwargs.pop('gyr_comp_y') + self.gyr_comp_z = kwargs.pop('gyr_comp_z') + + def __repr__(self): + return fmt_repr(self) + + @staticmethod + def from_json(s): + """Given a JSON-encoded string s, build a message object. + + """ + d = json.loads(s) + return MsgImuComp.from_json_dict(d) + + @staticmethod + def from_json_dict(d): + sbp = SBP.from_json_dict(d) + return MsgImuComp(sbp, **d) + + + def from_binary(self, d): + """Given a binary payload d, update the appropriate payload fields of + the message. + + """ + p = MsgImuComp._parser.parse(d) + for n in self.__class__.__slots__: + setattr(self, n, getattr(p, n)) + + def to_binary(self): + """Produce a framed/packed SBP message. + + """ + c = containerize(exclude_fields(self)) + self.payload = MsgImuComp._parser.build(c) + return self.pack() + + def friendly_name(self): + """Produces friendly human-readable name for this message + + """ + return "IMU COMP" + + def into_buffer(self, buf, offset): + """Produce a framed/packed SBP message into the provided buffer and offset. + + """ + self.payload = containerize(exclude_fields(self)) + self.parser = MsgImuComp._parser + self.stream_payload.reset(buf, offset) + return self.pack_into(buf, offset, self._build_payload) + + def to_json_dict(self): + self.to_binary() + d = super( MsgImuComp, self).to_json_dict() + j = walk_json_dict(exclude_fields(self)) + d.update(j) + return d + msg_classes = { 0x0900: MsgImuRaw, 0x0901: MsgImuAux, + 0x0905: MsgImuComp, } \ No newline at end of file diff --git a/python/tests/sbp/test_messages.py b/python/tests/sbp/test_messages.py index 397245d370..908b664bdf 100644 --- a/python/tests/sbp/test_messages.py +++ b/python/tests/sbp/test_messages.py @@ -20,7 +20,7 @@ PYTHON_ROOT = os.path.join(HERE, "..", "..") ROOTPATH = os.path.join(PYTHON_ROOT, "..", "spec", "tests", "yaml") -EXPECTED_MISSING_MESSAGES = 1 +EXPECTED_MISSING_MESSAGES = 2 MESSAGES_WITH_TEST_CASES = set()