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_4072 0x72
22 #define RTCM3_MSG_1077 0xB1
23 #define RTCM3_MSG_1087 0xBB
24 #define RTCM3_MSG_1230 0xE6
36 #define GOT_CHECKSUM1 8
38 #define UBX_PREAMBLE1 0xB5
39 #define UBX_PREAMBLE2 0x62
40 #define UBX_NAV_SVIN 0x3B
41 #define GPS_UBX_MAX_PAYLOAD 255
43 #define GPS_UBX_ERR_NONE 0
44 #define GPS_UBX_ERR_OVERRUN 1
45 #define GPS_UBX_ERR_MSG_TOO_LONG 2
46 #define GPS_UBX_ERR_CHECKSUM 3
47 #define GPS_UBX_ERR_UNEXPECTED 4
48 #define GPS_UBX_ERR_OUT_OF_SYNC 5
55 #define UBX_NAV_SVIN_VERSION(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+0))
56 #define UBX_NAV_SVIN_RES1(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+1))
57 #define UBX_NAV_SVIN_RES2(_ubx_payload) (uint16_t)(*((uint8_t*)_ubx_payload+2)|*((uint8_t*)_ubx_payload+1+2)<<8)
58 #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)
59 #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)
60 #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)
61 #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)
62 #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)
63 #define UBX_NAV_SVIN_meanXHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+24))
64 #define UBX_NAV_SVIN_meanYHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+25))
65 #define UBX_NAV_SVIN_meanZHP(_ubx_payload) (int8_t)(*((uint8_t*)_ubx_payload+26))
66 #define UBX_NAV_SVIN_RES3(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+27))
67 #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)
68 #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)
69 #define UBX_NAV_SVIN_Valid(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+36))
70 #define UBX_NAV_SVIN_Active(_ubx_payload) (uint8_t)(*((uint8_t*)_ubx_payload+37))
71 #define UBX_NAV_SVIN_RES4(_ubx_payload) (uint16_t)(*((uint8_t*)_ubx_payload+38)|*((uint8_t*)_ubx_payload+1+38)<<8)
81 #define RTCM_OK_CALLBACK_EXECUTED 1
83 #define RTCM_OK_CALLBACK_UNDEFINED 2
85 #define RTCM_CALLBACK_ERROR -1
87 #define RTCM_CRC_ERROR -2
89 #define RTCM_SEND_ERROR -3
91 #define RTCM_NULL_ERROR -4
117 u8 msg_buff[1024 + 6 + 1];
136 unsigned int RTCMgetbitu(
unsigned char *,
int,
int);
189 if (
s->rtcm3_msg_callbacks_head == 0) {
190 s->rtcm3_msg_callbacks_head = node;
213 s->rtcm3_msg_callbacks_head = 0;
227 if (!
s->rtcm3_msg_callbacks_head) {
237 if (
p->msg_type == msg_type) {
241 while ((
p =
p->next));
324 if (
s->n_read == (1024 + 6) &&
s->state !=
UNINIT) {
330 #ifdef DEBUG_PRINT_PACKAGE
331 printf(
"0x%x ",
buff);
343 s->msg_buff[
s->n_read] =
buff;
361 #ifdef DEBUG_PRINT_PACKAGE
373 #ifdef DEBUG_PRINT_PACKAGE
374 printf(
"Unknown message type %u\n",
RTCMgetbitu(
s->msg_buff, 24 + 0, 12));
379 s->msg_len =
s->n_read;
387 (*node->
cb)(
s->msg_len,
s->msg_buff);
440 s->msg_len |= (
buff << 8);
449 s->msg_buff[
s->n_read] =
buff;
451 if (
s->n_read >=
s->msg_len) {
456 if (
buff !=
s->ck_a) {
463 if (
buff !=
s->ck_b) {
476 (*node->
cb)(
s->msg_len,
s->msg_buff);
492 return s->error_last;
497 unsigned int bits = 0;
499 for (i = pos; i < pos + lenb; i++) { bits = (bits << 1) + ((
buff[i / 8] >> (7 - i % 8)) & 1u); }
506 if (lenb <= 0 || 32 <= lenb || !(bits & (1u << (lenb - 1)))) {
return (
int)bits; }
507 return (
int)(bits | (~0u << lenb));
uint8_t u8
Unsigned 8-bit integer.
int8_t s8
Signed 8-bit integer.
uint16_t u16
Unsigned 16-bit integer.
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_UNEXPECTED
struct rtcm3_msg_callbacks_node rtcm3_msg_callbacks_node_t
RTCM3 callback node.
void(* rtcm3_msg_callback_t)(u8 len, u8 msg[])
RTCM3 callback function prototype definition.
s8 ubx_process(msg_state_t *s, unsigned char buff)
#define RTCM_OK
Return value indicating success.
#define RTCM_OK_CALLBACK_UNDEFINED
Return value indicating message decoded with no associated callback in rtcm3_process.
void msg_state_init(msg_state_t *s)
Initialize an msg_state_t struct before use.
#define GPS_UBX_ERR_MSG_TOO_LONG
rtcm3_msg_callbacks_node_t * rtcm3_find_callback(msg_state_t *s, u16 msg_type)
Find the callback function associated with a message type.
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.
#define RTCM_OK_CALLBACK_EXECUTED
Return value indicating message decoded and callback executed by rtcm3_process.
#define GPS_UBX_ERR_CHECKSUM
unsigned int RTCMgetbitu(unsigned char *, int, int)
#define RTCM_NULL_ERROR
Return value indicating an error occured because an argument was NULL.
#define RTCM_CALLBACK_ERROR
Return value indicating an error with the callback (function defined).
struct rtcm3_msg_callbacks_node * next
Pointer to next node in list.
s8 rtcm3_process(msg_state_t *s, unsigned char buff)
Read and process RTCM3 messages.
u16 msg_type
Message ID associated with callback.
rtcm3_msg_callback_t cb
Pointer to callback function.
#define GPS_UBX_MAX_PAYLOAD
rtcm3_msg_callbacks_node_t * rtcm3_msg_callbacks_head
void rtcm3_clear_callbacks(msg_state_t *s)
Clear all registered callbacks.
#define GPS_UBX_ERR_OUT_OF_SYNC
static double RTCMgetbits_38(unsigned char *, int)
int RTCMgetbits(unsigned char *, int, int)