-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGPSParser.h
98 lines (77 loc) · 2.57 KB
/
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
////////////////////////////////////////////////////////////
// Author: Jon Bennett ([email protected]) http://jondbennett.com
//
// GPSParser - efficient NMEA string parser
////////////////////////////////////////////////////////////
#ifndef GPSPARSER_H
#define GPSPARSER_H
//#define CGPSParser_DEBUG
#include "GPSDefs.h"
#include "GPSParserData.h"
#include "GPSParserSentences.h"
#include "GPSPos.h"
////////////////////////////////////////////////////////////
// Author: Jon Bennett ([email protected]) http://jondbennett.com
//
// Efficient portable parser for GPS strings - uses double
// Handles GPGGA, GPGSA, GPGSV, GPRMC, GPVTG.
// Inspired by:
// TinyGPS (Mikal Hart) https://github.com/mikalhart/TinyGPS
// and
// NMEA library
// NMEA library URL: http://nmea.sourceforge.net)
///////////////////////////////////////////////////////////
// State machine states
typedef enum GPSParser_State_E
{
GPSParser_S_WaitingForStart = 0, // Waiting for $
GPSParser_S_ParsingTerms, // Processing comma-separated terms
GPSParser_S_ProcessingChecksum // Checking the checksum term
} GPSParser_State_T;
// Largest distance between commas and such
#define CGPSParser_TERMSIZE (16)
// The actual string parser. Data is decoded by
// the individual sentence objects
class CGPSParser
{
protected:
// Current state machine state
GPSParser_State_T m_state;
// Location to accumulate data as the parse
// progresses. Mostly for the stuff between
// commas
char m_term[CGPSParser_TERMSIZE];
int m_termOffset;
int m_termNumber;
// Running checksum
unsigned char m_checksum;
// Term processing. This mediates between the
// simple parser and the more complicated
// GPS sentence objects
bool parseChar(unsigned char _c);
void AddTermChar(unsigned char _c);
void processTerm(); // Returns true when valid and recognized sentence is complete
unsigned char from_hex(unsigned char _a);
// Sentence currently being parsed
GPSSentenceData_T m_gpsSentenceData;
GPSSentence_T m_currentSentenceType;
GPSSentence_T SelectSentence();
// Accumulated parser data
CGPSParserData m_GPSData;
#ifdef CGPSParser_DEBUG
int m_GPSParser_LineNumber; // We start on line one
int m_GPSParser_ValidLines;
#endif
public:
CGPSParser();
virtual ~CGPSParser();
void reset();
// Returns true if any sentences were processed (data may have changed)
bool parse(const unsigned char _buf[], unsigned int _bufLen);
CGPSParserData &getGPSData() { return m_GPSData; }
#ifdef CGPSParser_DEBUG
int getLineNumber() { return m_GPSParser_LineNumber; }
int getValidLines() { return m_GPSParser_ValidLines; }
#endif
};
#endif