sbp.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011-2014 Swift Navigation Inc.
00003  * Contact: Fergus Noble <fergus@swift-nav.com>
00004  *
00005  * This source is subject to the license found in the file 'LICENSE' which must
00006  * be be distributed together with this source. All other rights reserved.
00007  *
00008  * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
00009  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
00010  * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
00011  */
00012 
00013 #ifndef LIBSWIFTNAV_SBP_H
00014 #define LIBSWIFTNAV_SBP_H
00015 
00016 #include "common.h"
00017 
00022 #define SBP_OK              0
00023 
00024 #define SBP_OK_CALLBACK_EXECUTED 1
00025 
00026 #define SBP_OK_CALLBACK_UNDEFINED 2
00027 
00028 #define SBP_CALLBACK_ERROR -1
00029 
00030 #define SBP_CRC_ERROR      -2
00031 
00032 #define SBP_SEND_ERROR     -3
00033 
00034 #define SBP_NULL_ERROR     -4
00035 
00036 
00038 typedef void (*sbp_msg_callback_t)(u16 sender_id, u8 len, u8 msg[], void *context);
00039 
00044 typedef struct sbp_msg_callbacks_node {
00045   u16 msg_type;                        
00046   sbp_msg_callback_t cb;               
00047   void *context;                       
00048   struct sbp_msg_callbacks_node *next; 
00049 } sbp_msg_callbacks_node_t;
00050 
00052 typedef struct {
00053   enum {
00054     WAITING = 0,
00055     GET_TYPE,
00056     GET_SENDER,
00057     GET_LEN,
00058     GET_MSG,
00059     GET_CRC
00060   } state;
00061   u16 msg_type;
00062   u16 sender_id;
00063   u16 crc;
00064   u8 msg_len;
00065   u8 n_read;
00066   u8 msg_buff[256];
00067   void* io_context;
00068   sbp_msg_callbacks_node_t* sbp_msg_callbacks_head;
00069 } sbp_state_t;
00070 
00073 s8 sbp_register_callback(sbp_state_t* s, u16 msg_type, sbp_msg_callback_t cb, void* context,
00074                          sbp_msg_callbacks_node_t *node);
00075 void sbp_clear_callbacks(sbp_state_t* s);
00076 sbp_msg_callbacks_node_t* sbp_find_callback(sbp_state_t* s, u16 msg_type);
00077 void sbp_state_init(sbp_state_t *s);
00078 void sbp_state_set_io_context(sbp_state_t *s, void* context);
00079 s8 sbp_process(sbp_state_t *s, u32 (*read)(u8 *buff, u32 n, void* context));
00080 s8 sbp_send_message(sbp_state_t *s, u16 msg_type, u16 sender_id, u8 len, u8 *payload,
00081                     u32 (*write)(u8 *buff, u32 n, void* context));
00082 
00083 #endif /* LIBSWIFTNAV_SBP_H */
00084 


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:58