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

Make integer to enum conversion explicit [SAR-261] #1098

Merged
merged 5 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions c/include/libsbp/sbp.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ extern "C" {
/** Get message payload pointer from frame */
#define SBP_FRAME_MSG_PAYLOAD(frame_ptr) (&((frame_ptr)[SBP_FRAME_OFFSET_MSG]))

/** SBP_MSG_ID to use to register frame callback for ALL messages. */
#define SBP_MSG_ALL 0

/** SBP callback function prototype definitions. */
typedef union {
sbp_msg_callback_t msg;
Expand Down
4 changes: 4 additions & 0 deletions c/include/libsbp/sbp_msg_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
extern "C" {
#endif

/** SBP_MSG_ID to use to register frame callback for ALL messages. */
#define SBP_MSG_ALL 0

typedef enum {
SbpMsgAcqResultDepA = SBP_MSG_ACQ_RESULT_DEP_A,
SbpMsgAcqResultDepB = SBP_MSG_ACQ_RESULT_DEP_B,
Expand Down Expand Up @@ -252,6 +255,7 @@ typedef enum {
SbpMsgVelNedGnss = SBP_MSG_VEL_NED_GNSS,
SbpMsgVelNed = SBP_MSG_VEL_NED,
SbpMsgWheeltick = SBP_MSG_WHEELTICK,
SbpMsgAll = SBP_MSG_ALL,
} sbp_msg_type_t;

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions c/include/libsbp/v4/sbp_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ static inline s8 sbp_message_encode(uint8_t *buf, uint8_t len,
return sbp_msg_vel_ned_encode(buf, len, n_written, &msg->vel_ned);
case SbpMsgWheeltick:
return sbp_msg_wheeltick_encode(buf, len, n_written, &msg->wheeltick);
case SbpMsgAll:
fpezzinosn marked this conversation as resolved.
Show resolved Hide resolved
break;
default:
break;
}
Expand Down Expand Up @@ -1393,6 +1395,8 @@ static inline s8 sbp_message_decode(const uint8_t *buf, uint8_t len,
return sbp_msg_vel_ned_decode(buf, len, n_read, &msg->vel_ned);
case SbpMsgWheeltick:
return sbp_msg_wheeltick_decode(buf, len, n_read, &msg->wheeltick);
case SbpMsgAll:
break;
default:
break;
}
Expand Down Expand Up @@ -1853,6 +1857,8 @@ static inline size_t sbp_message_encoded_len(sbp_msg_type_t msg_type,
return sbp_msg_vel_ned_encoded_len(&msg->vel_ned);
case SbpMsgWheeltick:
return sbp_msg_wheeltick_encoded_len(&msg->wheeltick);
case SbpMsgAll:
break;
default:
break;
}
Expand Down Expand Up @@ -2381,6 +2387,8 @@ static inline int sbp_message_cmp(sbp_msg_type_t msg_type, const sbp_msg_t *a,
return sbp_msg_vel_ned_cmp(&a->vel_ned, &b->vel_ned);
case SbpMsgWheeltick:
return sbp_msg_wheeltick_cmp(&a->wheeltick, &b->wheeltick);
case SbpMsgAll:
break;
default:
break;
}
Expand Down
14 changes: 7 additions & 7 deletions c/src/sbp.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
*
* \param s Pointer to sbp_state
* \param msg_type Message type on which to fire callback.
* SBP_MSG_ALL will fire for every message, but only
* SbpMsgAll will fire for every message, but only
* for callbacks of type SBP_FRAME_CALLBACK.
* \param cb Pointer to message callback function
* \param cb_type sbp_cb_type indicating what kind of cb is in use.
Expand Down Expand Up @@ -381,7 +381,7 @@ static s8 process_frame(sbp_state_t *s, u16 sender_id, sbp_msg_type_t msg_type,
bool unpacked_successfully = false;
for (node = s->sbp_msg_callbacks_head; node; node = node->next) {
if ((SBP_CALLBACK_FLAG(node->cb_type) & cb_mask) &&
((node->msg_type == msg_type) || (node->msg_type == SBP_MSG_ALL))) {
((node->msg_type == msg_type) || (node->msg_type == SbpMsgAll))) {
switch (node->cb_type) {
case SBP_FRAME_CALLBACK:
{
Expand Down Expand Up @@ -670,7 +670,7 @@ s8 sbp_all_message_callback_register(sbp_state_t *s,
sbp_msg_callbacks_node_t *node) {
sbp_callback_t callback;
callback.decoded = cb;
return sbp_register_callback_generic(s, SBP_MSG_ALL, callback,
return sbp_register_callback_generic(s, SbpMsgAll, callback,
SBP_DECODED_CALLBACK, context, node);
}

Expand All @@ -692,7 +692,7 @@ s8 sbp_message_process(sbp_state_t *s, u16 sender_id, sbp_msg_type_t msg_type,

s8 ret = SBP_OK_CALLBACK_UNDEFINED;
for (node = s->sbp_msg_callbacks_head; node; node = node->next) {
if (((node->msg_type == msg_type) || (node->msg_type == SBP_MSG_ALL))) {
if (((node->msg_type == msg_type) || (node->msg_type == SbpMsgAll))) {
switch (node->cb_type) {
case SBP_FRAME_CALLBACK:
case SBP_MSG_CALLBACK:
Expand Down Expand Up @@ -738,7 +738,7 @@ s8 sbp_payload_callback_register(sbp_state_t* s, u16 msg_type, sbp_msg_callback_
{
sbp_callback_t callback;
callback.msg = cb;
return sbp_register_callback_generic(s, msg_type, callback,
return sbp_register_callback_generic(s, (sbp_msg_type_t) msg_type, callback,
fpezzinosn marked this conversation as resolved.
Show resolved Hide resolved
SBP_MSG_CALLBACK, context, node);
}

Expand All @@ -748,7 +748,7 @@ s8 sbp_frame_callback_register(sbp_state_t* s, u16 msg_type,
{
sbp_callback_t callback;
callback.frame = cb;
return sbp_register_callback_generic(s, msg_type, callback,
return sbp_register_callback_generic(s, (sbp_msg_type_t) msg_type, callback,
SBP_FRAME_CALLBACK, context, node);
}

Expand All @@ -766,7 +766,7 @@ s8 sbp_frame_process(sbp_state_t *s, u16 sender_id, u16 msg_type,

s8 sbp_payload_process(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len,
u8 payload[]) {
return process_frame(s, sender_id, msg_type, msg_len, payload,
return process_frame(s, sender_id, (sbp_msg_type_t) msg_type, msg_len, payload,
0, 0, SBP_CALLBACK_FLAG(SBP_MSG_CALLBACK) | SBP_CALLBACK_FLAG(SBP_DECODED_CALLBACK));
}

Expand Down