libsbp  v2.4.7
sbp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2014 Swift Navigation Inc.
3  * Contact: Fergus Noble <fergus@swift-nav.com>
4  *
5  * This source is subject to the license found in the file 'LICENSE' which must
6  * be be distributed together with this source. All other rights reserved.
7  *
8  * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef LIBSBP_SBP_H
14 #define LIBSBP_SBP_H
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include "common.h"
21 
26 #define SBP_OK 0
27 
28 #define SBP_OK_CALLBACK_EXECUTED 1
29 
30 #define SBP_OK_CALLBACK_UNDEFINED 2
31 
32 #define SBP_CALLBACK_ERROR -1
33 
34 #define SBP_CRC_ERROR -2
35 
36 #define SBP_SEND_ERROR -3
37 
38 #define SBP_NULL_ERROR -4
39 
40 #define SBP_WRITE_ERROR -5
41 
42 #define SBP_READ_ERROR -6
43 
45 #define SBP_SENDER_ID 0x42
46 
48 typedef void (*sbp_msg_callback_t)(u16 sender_id, u8 len, u8 msg[], void *context);
49 
54 typedef struct sbp_msg_callbacks_node {
57  void *context;
60 
62 typedef struct {
63  enum {
64  WAITING = 0,
69  GET_CRC
70  } state;
76  u8 msg_buff[256];
77  void* io_context;
79 } sbp_state_t;
80 
83 s8 sbp_register_callback(sbp_state_t* s, u16 msg_type, sbp_msg_callback_t cb, void* context,
88 void sbp_state_set_io_context(sbp_state_t *s, void* context);
89 s8 sbp_process(sbp_state_t *s, s32 (*read)(u8 *buff, u32 n, void* context));
90 s8 sbp_process_payload(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len,
91  u8 payload[]);
92 s8 sbp_send_message(sbp_state_t *s, u16 msg_type, u16 sender_id, u8 len, u8 *payload,
93  s32 (*write)(u8 *buff, u32 n, void* context));
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif /* LIBSBP_SBP_H */
100 
SBP callback node.
Definition: sbp.h:54
void sbp_clear_callbacks(sbp_state_t *s)
Clear all registered callbacks.
Definition: sbp.c:233
void(* sbp_msg_callback_t)(u16 sender_id, u8 len, u8 msg[], void *context)
SBP callback function prototype definition.
Definition: sbp.h:48
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.
Definition: sbp.c:459
u16 sender_id
Definition: sbp.h:72
u16 msg_type
Message ID associated with callback.
Definition: sbp.h:55
int8_t s8
Signed 8-bit integer.
Definition: common.h:32
sbp_msg_callbacks_node_t * sbp_msg_callbacks_head
Definition: sbp.h:78
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.
Definition: sbp.c:161
uint8_t u8
Unsigned 8-bit integer.
Definition: common.h:40
s8 sbp_remove_callback(sbp_state_t *s, sbp_msg_callbacks_node_t *node)
Remove a registered callback.
Definition: sbp.c:212
u16 crc
Definition: sbp.h:73
s8 sbp_process_payload(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len, u8 payload[])
Directly process a SBP message.
Definition: sbp.c:416
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...
Definition: sbp.c:264
State structure for processing SBP messages.
Definition: sbp.h:62
uint16_t u16
Unsigned 16-bit integer.
Definition: common.h:42
u8 msg_len
Definition: sbp.h:74
uint32_t u32
Unsigned 32-bit integer.
Definition: common.h:44
struct sbp_msg_callbacks_node sbp_msg_callbacks_node_t
SBP callback node.
u16 msg_type
Definition: sbp.h:71
void sbp_state_init(sbp_state_t *s)
Initialize an sbp_state_t struct before use.
Definition: sbp.c:246
sbp_msg_callback_t cb
Pointer to callback function.
Definition: sbp.h:56
s8 sbp_process(sbp_state_t *s, s32(*read)(u8 *buff, u32 n, void *context))
Read and process SBP messages.
Definition: sbp.c:308
void * io_context
Definition: sbp.h:77
int32_t s32
Signed 32-bit integer.
Definition: common.h:36
u8 n_read
Definition: sbp.h:75
void * context
Pointer to a context.
Definition: sbp.h:57
struct sbp_msg_callbacks_node * next
Pointer to next node in list.
Definition: sbp.h:58