-
Notifications
You must be signed in to change notification settings - Fork 2
/
neo_m8_gps.h
97 lines (67 loc) · 2.26 KB
/
neo_m8_gps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* neo_m8_gps.h
*
* Created on: Jul 17, 2018
* Author: alexis
*/
#ifndef NEO_M8_GPS_H_
#define NEO_M8_GPS_H_
/* Standard libraries */
#include <stdbool.h>
#include <stdint.h>
#include "usart.h"
#include "neo_m8_ubx_structs.h"
#define GPS_UART_INSTANCE UART6
#define GPS_UART_HANDLER huart6
extern UART_HandleTypeDef GPS_UART_HANDLER;
/* Header struct used to have readable value (especially length, needed for the CRC calculation) */
typedef struct {
uint8_t class;
uint8_t id;
uint16_t length; /* Payload length */
} UBXHeader;
typedef struct {
UBXHeader header;
char payload[172];
} UBXMsg;
typedef enum {
UBX_NO_DATA,
UBX_WAITING_MORE_DATA,
UBX_INCORRECT_PACKET_RXD,
UBX_NEW_DATA
} UBX_OP_RESULT;
/* Rx callback when a byte is rxd */
void neoRxCallback(char c);
/* Initialize the ring buffer */
void neoInitRxBuf(void);
/*Return number of elems inside the buffer */
uint32_t neoNumElemBuf(void);
/* Process the ring buffer to find a correct message */
UBX_OP_RESULT neoRetrieveMsg(void);
uint8_t neoGetMsgClass();
uint8_t neoGetMsgId();
uint16_t neoGetPayloadSize();
/* Updates */
void UBXUpdate_NAV_PVT(ubx_nav_pvt_msg_t * dest);
/* Private API */
/* Returns true if Sync Bytes are found into the ring buffer, and dequeue'd*/
bool neoFindSyncBytes();
/* Read 4 bytes from the ring buffer */
bool neoRetrieveHeaderBytes(char* buf);
/* Peek bytes from the ring buffer to parse the Header informations into a readable struct */
bool neoBuildHeader(UBXHeader* header);
/* Dequeue N elements from the ring buffer used by the GPS */
bool neoDequeueFromRing(uint32_t n);
/* Copy a UBX Packet without the SYNC Bytes and the CRC into a raw buffer */
bool neoCopyPacketFromRing(char* rbuffer, uint32_t n);
/* Enumeration of the GPS Decode state machine */
typedef enum {
UBX_LOOKING_FOR_SYNC, /* Looking for Sync char 1 and Sync char 2 */
UBX_BUILDING_MSG_INFOS, /* MSG Infos is Class, ID, and Length bytes (4) */
UBX_BUILDING_MSG_PAYLOAD, /* Retrieving 'Length' bytes */
UBX_BUILDING_CRC, /* Retrieving 2 bytes (CRC) */
UBX_CHECKING_CRC, /* Checking CRC, switch to first state if CRC is wrong,
* or to valid msg if it is right */
UBX_VALID_MSG /* Valid message retrieved */
} UBX_NEO_M8_DECODE_STATE;
#endif /* NEO_M8_GPS_H_ */