@@ -372,14 +372,8 @@ s8 sbp_process(sbp_state_t *s, u32 (*read)(u8 *buff, u32 n, void *context))
372372 if (s -> crc == crc ) {
373373
374374 /* Message complete, process it. */
375- s8 ret = SBP_OK_CALLBACK_UNDEFINED ;
376- sbp_msg_callbacks_node_t * node ;
377- for (node = s -> sbp_msg_callbacks_head ; node ; node = node -> next ) {
378- if (node -> msg_type == s -> msg_type ) {
379- (* node -> cb )(s -> sender_id , s -> msg_len , s -> msg_buff , node -> context );
380- ret = SBP_OK_CALLBACK_EXECUTED ;
381- }
382- }
375+ s8 ret = sbp_process_payload (s , s -> sender_id , s -> msg_type , s -> msg_len ,
376+ s -> msg_buff );
383377 return ret ;
384378 } else {
385379 return SBP_CRC_ERROR ;
@@ -395,6 +389,33 @@ s8 sbp_process(sbp_state_t *s, u32 (*read)(u8 *buff, u32 n, void *context))
395389 return SBP_OK ;
396390}
397391
392+ /** Directly process a SBP message.
393+ * If a SBP message has already been decoded (for example, from a binary
394+ * stream or from a JSON log file) use this function to directly process it.
395+ *
396+ * \param s State structure
397+ * \param sender_id SBP message sender id
398+ * \param msg_type SBP message type
399+ * \param msg_len SBP message length
400+ * \param payload SBP message payload
401+ * \return `SBP_OK_CALLBACK_EXECUTED` (1) if message decoded and callback executed,
402+ * `SBP_OK_CALLBACK_UNDEFINED` (2) if message decoded with no associated
403+ * callback.
404+ */
405+ s8 sbp_process_payload (sbp_state_t * s , u16 sender_id , u16 msg_type , u8 msg_len ,
406+ u8 payload []) {
407+ s8 ret = SBP_OK_CALLBACK_UNDEFINED ;
408+ sbp_msg_callbacks_node_t * node ;
409+ for (node = s -> sbp_msg_callbacks_head ; node ; node = node -> next ) {
410+ if (node -> msg_type == msg_type ) {
411+ (* node -> cb )(sender_id , msg_len , payload , node -> context );
412+ ret = SBP_OK_CALLBACK_EXECUTED ;
413+ }
414+ }
415+ return ret ;
416+ }
417+
418+
398419/** Send SBP messages.
399420 * Takes an SBP message payload, type and sender ID then writes a message to
400421 * the output stream using the supplied `write` function with the correct
0 commit comments