-
Notifications
You must be signed in to change notification settings - Fork 1
/
ao_GpsParser.h
155 lines (129 loc) · 3.59 KB
/
ao_GpsParser.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
/*
* This lib provides a basic GPS parser for the RMC and GGA sentence.
*
Licence:
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef AO_GPSPARSER_H
#define AO_GPSPARSER_H
#include "ao_Parser.h"
#define GPS_WORD_LENGTH 12
// Bits in newData
#define GPS_SENTENCE_RMC 01
#define GPS_SENTENCE_GGA 02
const char GPS_Header[] PROGMEM = {
6,4, // string length and number of lines
'G' ,'P' ,'R' ,'M' ,'C' ,'\0',
'G' ,'N' ,'R' ,'M' ,'C' ,'\0',
'G' ,'P' ,'G' ,'G' ,'A' ,'\0',
'G' ,'N' ,'G' ,'G' ,'A' ,'\0',
};
union Clock {
struct {
uint8_t year; // 00 - 99
uint8_t month; // 01 - 12
uint8_t day; // 01 - 31
};
struct {
uint8_t hour; // 00 - 23
uint8_t minute; // 00 - 59
uint8_t second; // 00 - 59
};
uint8_t c[3];
};
union ValGPS {
struct {
uint16_t minute; // 00xx * 4096 + nachkomma
uint8_t degs; // degrees
uint8_t nesw; // 0b0xx0.0000
};
uint32_t d; // for quick access
};
struct GpsData { // main gps data structure
Clock time;
Clock date;
char valid; // A:okay V:invalid
ValGPS latitude;
ValGPS longitude;
uint16_t altitude; //
uint16_t speed; //
uint16_t course;
// uint8_t satellites; //
uint8_t fix;
};
// -- generic sentence
class GpsInterface{
public:
GpsInterface(void);
virtual void transferData(void)=0;
virtual void checkWord(void)=0;
bool nextChar(char c);
uint8_t doCrc(char c);
uint8_t getCharToNibble(char c);
// sentence
uint8_t wordCnt;
uint8_t charCnt;
char wordBuf[GPS_WORD_LENGTH];
uint8_t status;
// CRC
uint8_t crcCntDat;
uint8_t crcSum;
uint8_t crcValue;
static volatile uint8_t newData; // there is only one status for all interfaces
// RMC=01, GGA=02
};
// -- GPRMC sentence specific
class GPS_Rmc: public GpsInterface {
public:
GPS_Rmc(GpsData *gpd);
virtual void checkWord(void);
virtual void transferData(void);
private:
void readClock(Clock &clock);
void readValGPS(ValGPS °);
GpsData *gpdata;
// transfer these data if CRC is okay
Clock date;
Clock time;
char valid;
ValGPS latitude;
ValGPS longitude;
uint16_t speed;
uint16_t course;
};
// -- GPGGA sentence specific
class GPS_Gga: public GpsInterface {
public:
GPS_Gga(GpsData *gpd);
virtual void checkWord(void);
virtual void transferData(void);
GpsData *gpdata;
private:
// transfer these data if CRC is okay
uint8_t fix;
// uint8_t satellites;
uint16_t altitude;
};
//-- Master class
class GPS_Parser{
public:
GPS_Parser(void);
uint8_t parseStream(char c); // call to parse character
uint8_t available(void); // returns parser status per sentence, see newData
void done(uint8_t what); // clears parser status sentence number in newData
GpsData gpsData; // gps data store
private:
Parser pa; // header parser
GpsInterface *gpi; // pointer to sentence parser
uint8_t state; // detected header number
};
#endif