-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPSNmea.h
157 lines (120 loc) · 4.74 KB
/
GPSNmea.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA *
* *
***************************************************************************
* *
* (c) Copyright, 2001-2012, ANSR *
* *
***************************************************************************
* *
* Filename: GPSLassen.h *
* *
***************************************************************************/
#ifndef GPSNMEA_H
#define GPSNMEA_H
/**
* @defgroup external External Peripherals
*
* @{
*/
/**
* Read and process the GPS Binary messages from a generic
* GPS engine outputting NMEA strings
*/
class GPSNmea
{
public:
GPSNmea();
GPSData *Data();
bool_t IsDataReady();
void Update();
/**
* Callback to determine if the there is serial data to process from the GPS engine.
*
* @return true if data is in FIFO; otherwise false
*/
virtual bool_t HasData();
/**
* Callback to read the oldest serial data from the GPS engine.
*
* @return oldest byte from serial FIFO
*/
virtual uint8_t ReadData();
/**
* Callback to write serial data to the GPS engine.
*
* @param data 8-bit data to write
*/
virtual void WriteData(uint8_t data);
/**
* Passes any characters from the GPS to the serial port and vice versa
*/
void GpsPassthru();
/**
* Get a pointer to the GPSNmea singleton
*/
static GPSNmea *GetInstance();
private:
static const uint8_t MAX_CMD_LEN = 8; // maximum command length (NMEA address)
static const uint8_t MAX_DATA_LEN = 255; // maximum data length
static const uint8_t MAX_CHAN = 36; // maximum number of channels
static const uint8_t WAYPOINT_ID_LEN = 32; // waypoint max string len
static const uint8_t MAXFIELD = 25;
/// The maximum length of a binary GPS engine message.
static const uint32_t GPSBufferSize = 80;
/// Object that stores the current GPS fix data.
GPSData data;
/// Index into gpsBuffer used to store message data.
uint32_t gpsIndex;
/// GPS Time of Week in seconds.
uint32_t timeOfWeek;
/// Offset in seconds between GPS and UTC time.
uint32_t utcOffset;
/// last altitude in ft
uint32_t lastAltitude;
/// last timestamp in seconds
uint32_t lastTimestamp;
typedef enum
{
STARTOFMESSAGE,
COMMAND,
DATA,
CHECKSUM_1,
CHECKSUM_2
} GPS_PARSE_STATE_MACHINE;
typedef enum
{
GGA,
RMC
} NMEA_PACKET_TYPE;
/// Buffer to store data as it is read from the GPS engine.
char gpsBuffer[GPSBufferSize];
uint8_t calcChecksum; // Calculated NMEA sentence checksum
uint8_t receivedChecksum; // Received NMEA sentence checksum (if exists)
uint16_t index; // Index used for command and data
uint8_t commandBuffer[MAX_CMD_LEN]; // NMEA command
uint8_t dataBuffer[MAX_DATA_LEN]; // NMEA data
/// Flag that is set when a data set has been parsed.
bool_t dataReadyFlag;
GPS_PARSE_STATE_MACHINE gpsParseState;
NMEA_PACKET_TYPE gpsPacketType;
void ProcessCommand(uint8_t *pCommand, uint8_t *pData);
bool GetField(uint8_t *pData, uint8_t *pField, int8_t nFieldNum, int8_t nMaxFieldLen);
void ProcessGPGGA(uint8_t *pData);
void ProcessGPRMC(uint8_t *pData);
};
/** @} */
#endif // #ifndef GPSNMEA_H