16 #define SBP_PREAMBLE 0x55
174 ((n->cb == cb) && (n->msg_type == msg_type) && (n->context == context)))
221 if (n->
next == node) {
311 if ((0 == s) || (0 == read)) {
337 s->
state = GET_SENDER;
422 (*node->
cb)(sender_id, msg_len, payload, node->
context);
460 s32 (*write)(
u8 *buff,
u32 n,
void *context))
463 if (len != 0 && payload == 0)
467 if ((0 == s) || (0 == write))
void sbp_clear_callbacks(sbp_state_t *s)
Clear all registered callbacks.
void(* sbp_msg_callback_t)(u16 sender_id, u8 len, u8 msg[], void *context)
SBP callback function prototype definition.
#define SBP_CALLBACK_ERROR
Return value indicating an error with the callback (function defined).
s8 sbp_send_message(sbp_state_t *s, u16 msg_type, u16 sender_id, u8 len, u8 *payload, s32(*write)(u8 *buff, u32 n, void *context))
Send SBP messages.
u16 msg_type
Message ID associated with callback.
int8_t s8
Signed 8-bit integer.
#define SBP_CRC_ERROR
Return value indicating a CRC error.
sbp_msg_callbacks_node_t * sbp_msg_callbacks_head
s8 sbp_register_callback(sbp_state_t *s, u16 msg_type, sbp_msg_callback_t cb, void *context, sbp_msg_callbacks_node_t *node)
Register a callback for a message type.
#define SBP_WRITE_ERROR
Return value indicating an error occured in the write() operation.
uint8_t u8
Unsigned 8-bit integer.
#define SBP_SEND_ERROR
Return value indicating an error occured whilst sending an SBP message.
s8 sbp_remove_callback(sbp_state_t *s, sbp_msg_callbacks_node_t *node)
Remove a registered callback.
#define SBP_OK_CALLBACK_EXECUTED
Return value indicating message decoded and callback executed by sbp_process.
#define SBP_OK_CALLBACK_UNDEFINED
Return value indicating message decoded with no associated callback in sbp_process.
s8 sbp_process_payload(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len, u8 payload[])
Directly process a SBP message.
enum sbp_state_t::@0 state
void sbp_state_set_io_context(sbp_state_t *s, void *context)
Set a context to pass to all function pointer calls made by sbp functions This helper function sets a...
#define SBP_OK
Return value indicating success.
State structure for processing SBP messages.
uint16_t u16
Unsigned 16-bit integer.
uint32_t u32
Unsigned 32-bit integer.
#define SBP_READ_ERROR
Return value indicating an error occured in the read() operation.
void sbp_state_init(sbp_state_t *s)
Initialize an sbp_state_t struct before use.
#define SBP_NULL_ERROR
Return value indicating an error occured because an argument was NULL.
sbp_msg_callback_t cb
Pointer to callback function.
s8 sbp_process(sbp_state_t *s, s32(*read)(u8 *buff, u32 n, void *context))
Read and process SBP messages.
u16 crc16_ccitt(const u8 *buf, u32 len, u16 crc)
Calculate CCITT 16-bit Cyclical Redundancy Check (CRC16).
int32_t s32
Signed 32-bit integer.
void * context
Pointer to a context.
struct sbp_msg_callbacks_node * next
Pointer to next node in list.