10 #ifndef LIBRTCM3_RTCM3_H
11 #define LIBRTCM3_RTCM3_H
14 #define READ_RESERVED 1
16 #define READ_MESSAGE 3
17 #define READ_CHECKSUM 4
19 #define RTCM3_PREAMBLE 0xD3
20 #define RTCM3_MSG_1005 0x69
21 #define RTCM3_MSG_1077 0xB1
22 #define RTCM3_MSG_1087 0xBB
34 #define GOT_CHECKSUM1 8
36 #define UBX_PREAMBLE1 0xB5 // Sync 1
37 #define UBX_PREAMBLE2 0x62 // Sync 2
38 #define UBX_NAV_SVIN 0x3B
39 #define GPS_UBX_MAX_PAYLOAD 255
41 #define GPS_UBX_ERR_NONE 0
42 #define GPS_UBX_ERR_OVERRUN 1
43 #define GPS_UBX_ERR_MSG_TOO_LONG 2
44 #define GPS_UBX_ERR_CHECKSUM 3
45 #define GPS_UBX_ERR_UNEXPECTED 4
46 #define GPS_UBX_ERR_OUT_OF_SYNC 5
53 #define UBX_NAV_SVIN_VERSION(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+0))
54 #define UBX_NAV_SVIN_RES1(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+1))
55 #define UBX_NAV_SVIN_RES2(_ubx_payload) (uint16_t)(*((uint8_t*)_ubx_payload+2)|*((uint8_t*)_ubx_payload+1+2)<<8)
56 #define UBX_NAV_SVIN_ITOW(_ubx_payload) (uint32_t)(*((uint8_t*)_ubx_payload+4)|*((uint8_t*)_ubx_payload+1+4)<<8|((uint32_t)*((uint8_t*)_ubx_payload+2+4))<<16|((uint32_t)*((uint8_t*)_ubx_payload+3+4))<<24)
57 #define UBX_NAV_SVIN_dur(_ubx_payload) (uint32_t)(*((uint8_t*)_ubx_payload+8)|*((uint8_t*)_ubx_payload+1+8)<<8|((uint32_t)*((uint8_t*)_ubx_payload+2+8))<<16|((uint32_t)*((uint8_t*)_ubx_payload+3+8))<<24)
58 #define UBX_NAV_SVIN_meanX(_ubx_payload) (int32_t)(*((uint8_t*)_ubx_payload+12)|*((uint8_t*)_ubx_payload+1+12)<<8|((int32_t)*((uint8_t*)_ubx_payload+2+12))<<16|((int32_t)*((uint8_t*)_ubx_payload+3+12))<<24)
59 #define UBX_NAV_SVIN_meanY(_ubx_payload) (int32_t)(*((uint8_t*)_ubx_payload+16)|*((uint8_t*)_ubx_payload+1+16)<<8|((int32_t)*((uint8_t*)_ubx_payload+2+16))<<16|((int32_t)*((uint8_t*)_ubx_payload+3+16))<<24)
60 #define UBX_NAV_SVIN_meanZ(_ubx_payload) (int32_t)(*((uint8_t*)_ubx_payload+20)|*((uint8_t*)_ubx_payload+1+20)<<8|((int32_t)*((uint8_t*)_ubx_payload+2+20))<<16|((int32_t)*((uint8_t*)_ubx_payload+3+20))<<24)
61 #define UBX_NAV_SVIN_meanXHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+24))
62 #define UBX_NAV_SVIN_meanYHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+25))
63 #define UBX_NAV_SVIN_meanZHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+26))
64 #define UBX_NAV_SVIN_RES3(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+27))
65 #define UBX_NAV_SVIN_meanACC(_ubx_payload) (uint32_t)(*((uint8_t*)_ubx_payload+28)|*((uint8_t*)_ubx_payload+1+28)<<8|((uint32_t)*((uint8_t*)_ubx_payload+2+28))<<16|((uint32_t)*((uint8_t*)_ubx_payload+3+28))<<24)
66 #define UBX_NAV_SVIN_OBS(_ubx_payload) (uint32_t)(*((uint8_t*)_ubx_payload+32)|*((uint8_t*)_ubx_payload+1+32)<<8|((uint32_t)*((uint8_t*)_ubx_payload+2+32))<<16|((uint32_t)*((uint8_t*)_ubx_payload+3+32))<<24)
67 #define UBX_NAV_SVIN_Valid(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+36))
68 #define UBX_NAV_SVIN_Active(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+37))
69 #define UBX_NAV_SVIN_RES4(_ubx_payload) (uint16_t)(*((uint8_t*)_ubx_payload+38)|*((uint8_t*)_ubx_payload+1+38)<<8)
79 #define RTCM_OK_CALLBACK_EXECUTED 1
81 #define RTCM_OK_CALLBACK_UNDEFINED 2
83 #define RTCM_CALLBACK_ERROR -1
85 #define RTCM_CRC_ERROR -2
87 #define RTCM_SEND_ERROR -3
89 #define RTCM_NULL_ERROR -4
115 u8 msg_buff[1024 + 6 + 1];
134 unsigned int RTCMgetbitu(
unsigned char *,
int,
int);
239 while ((p = p->
next));
328 #ifdef DEBUG_PRINT_PACKAGE
329 printf(
"0x%x ", buff);
359 #ifdef DEBUG_PRINT_PACKAGE
448 if (buff != s->
ck_a) {
455 if (buff != s->
ck_b) {
489 unsigned int bits = 0;
491 for (i = pos; i < pos + lenb; i++) { bits = (bits << 1) + ((buff[i / 8] >> (7 - i % 8)) & 1u); }
498 if (lenb <= 0 || 32 <= lenb || !(bits & (1u << (lenb - 1)))) {
return (
int)bits; }
499 return (
int)(bits | (~0u << lenb));
s8 ubx_process(msg_state_t *s, unsigned char buff)
void msg_state_init(msg_state_t *s)
Initialize an msg_state_t struct before use.
void rtcm3_clear_callbacks(msg_state_t *s)
Clear all registered callbacks.
int8_t s8
Signed 8-bit integer.
static double RTCMgetbits_38(unsigned char *, int)
#define RTCM_OK
Return value indicating success.
#define GPS_UBX_ERR_OUT_OF_SYNC
s8 rtcm3_process(msg_state_t *s, unsigned char buff)
Read and process RTCM3 messages.
unsigned int RTCMgetbitu(unsigned char *, int, int)
rtcm3_msg_callbacks_node_t * rtcm3_msg_callbacks_head
s8 rtcm3_register_callback(msg_state_t *s, u16 msg_type, rtcm3_msg_callback_t cb, rtcm3_msg_callbacks_node_t *node)
Register a callback for a message type.
uint8_t u8
Unsigned 8-bit integer.
#define GPS_UBX_ERR_MSG_TOO_LONG
struct rtcm3_msg_callbacks_node * next
Pointer to next node in list.
#define RTCM_CALLBACK_ERROR
Return value indicating an error with the callback (function defined).
rtcm3_msg_callbacks_node_t * rtcm3_find_callback(msg_state_t *s, u16 msg_type)
Find the callback function associated with a message type.
#define RTCM_OK_CALLBACK_EXECUTED
Return value indicating message decoded and callback executed by rtcm3_process.
int RTCMgetbits(unsigned char *, int, int)
uint16_t u16
Unsigned 16-bit integer.
#define RTCM_NULL_ERROR
Return value indicating an error occured because an argument was NULL.
void(* rtcm3_msg_callback_t)(u8 len, u8 msg[])
RTCM3 callback function prototype definition.
u16 msg_type
Message ID associated with callback.
#define GPS_UBX_MAX_PAYLOAD
#define RTCM_OK_CALLBACK_UNDEFINED
Return value indicating message decoded with no associated callback in rtcm3_process.
#define GPS_UBX_ERR_UNEXPECTED
struct rtcm3_msg_callbacks_node rtcm3_msg_callbacks_node_t
RTCM3 callback node.
rtcm3_msg_callback_t cb
Pointer to callback function.
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
#define GPS_UBX_ERR_CHECKSUM