RUI3 (RAK Unified Interface 3) - RAK4631
TinyGPS++.h
Go to the documentation of this file.
1 /*
2 TinyGPS++ - a small GPS library for Arduino providing universal NMEA parsing
3 Based on work by and "distanceBetween" and "courseTo" courtesy of Maarten Lamers.
4 Suggestion to add satellites, courseTo(), and cardinal() by Matt Monson.
5 Location precision improvements suggested by Wayne Holder.
6 Copyright (C) 2008-2013 Mikal Hart
7 All rights reserved.
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef __TinyGPSPlus_h
25 #define __TinyGPSPlus_h
26 
27 //#if defined(ARDUINO) && ARDUINO >= 100
28 //#include "Arduino.h"
29 //#else
30 //#include "WProgram.h"
31 //#endif
32 //#include "ruiTop.h"
33 #include "udrv_rtc.h"
34 #include <math.h>
35 
36 #include <limits.h>
37 
38 #define _GPS_VERSION "1.0.2" // software version of this library
39 #define _GPS_MPH_PER_KNOT 1.15077945
40 #define _GPS_MPS_PER_KNOT 0.51444444
41 #define _GPS_KMPH_PER_KNOT 1.852
42 #define _GPS_MILES_PER_METER 0.00062137112
43 #define _GPS_KM_PER_METER 0.001
44 #define _GPS_FEET_PER_METER 3.2808399
45 #define _GPS_MAX_FIELD_SIZE 15
46 
47 struct RawDegrees
48 {
49  uint16_t deg;
50  uint32_t billionths;
51  bool negative;
52 public:
53  RawDegrees() : deg(0), billionths(0), negative(false)
54  {}
55 };
56 
58 {
59  friend class TinyGPSPlus;
60 public:
61  bool isValid() const { return valid; }
62  bool isUpdated() const { return updated; }
63  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
64  const RawDegrees &rawLat() { updated = false; return rawLatData; }
65  const RawDegrees &rawLng() { updated = false; return rawLngData; }
66  double lat();
67  double lng();
68 
69  TinyGPSLocation() : valid(false), updated(false)
70  {}
71 
72 private:
73  bool valid, updated;
74  RawDegrees rawLatData, rawLngData, rawNewLatData, rawNewLngData;
75  uint32_t lastCommitTime;
76  void commit();
77  void setLatitude(const char *term);
78  void setLongitude(const char *term);
79 };
80 
82 {
83  friend class TinyGPSPlus;
84 public:
85  bool isValid() const { return valid; }
86  bool isUpdated() const { return updated; }
87  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
88 
89  uint32_t value() { updated = false; return date; }
90  uint16_t year();
91  uint8_t month();
92  uint8_t day();
93 
94  TinyGPSDate() : valid(false), updated(false), date(0)
95  {}
96 
97 private:
98  bool valid, updated;
99  uint32_t date, newDate;
100  uint32_t lastCommitTime;
101  void commit();
102  void setDate(const char *term);
103 };
104 
106 {
107  friend class TinyGPSPlus;
108 public:
109  bool isValid() const { return valid; }
110  bool isUpdated() const { return updated; }
111  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
112 
113  uint32_t value() { updated = false; return time; }
114  uint8_t hour();
115  uint8_t minute();
116  uint8_t second();
117  uint8_t centisecond();
118 
119  TinyGPSTime() : valid(false), updated(false), time(0)
120  {}
121 
122 private:
123  bool valid, updated;
124  uint32_t time, newTime;
125  uint32_t lastCommitTime;
126  void commit();
127  void setTime(const char *term);
128 };
129 
131 {
132  friend class TinyGPSPlus;
133 public:
134  bool isValid() const { return valid; }
135  bool isUpdated() const { return updated; }
136  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
137  int32_t value() { updated = false; return val; }
138 
139  TinyGPSDecimal() : valid(false), updated(false), val(0)
140  {}
141 
142 private:
143  bool valid, updated;
144  uint32_t lastCommitTime;
145  int32_t val, newval;
146  void commit();
147  void set(const char *term);
148 };
149 
151 {
152  friend class TinyGPSPlus;
153 public:
154  bool isValid() const { return valid; }
155  bool isUpdated() const { return updated; }
156  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
157  uint32_t value() { updated = false; return val; }
158 
159  TinyGPSInteger() : valid(false), updated(false), val(0)
160  {}
161 
162 private:
163  bool valid, updated;
164  uint32_t lastCommitTime;
165  uint32_t val, newval;
166  void commit();
167  void set(const char *term);
168 };
169 
171 {
172  double knots() { return value() / 100.0; }
173  double mph() { return _GPS_MPH_PER_KNOT * value() / 100.0; }
174  double mps() { return _GPS_MPS_PER_KNOT * value() / 100.0; }
175  double kmph() { return _GPS_KMPH_PER_KNOT * value() / 100.0; }
176 };
177 
179 {
180  double deg() { return value() / 100.0; }
181 };
182 
184 {
185  double meters() { return value() / 100.0; }
186  double miles() { return _GPS_MILES_PER_METER * value() / 100.0; }
187  double kilometers() { return _GPS_KM_PER_METER * value() / 100.0; }
188  double feet() { return _GPS_FEET_PER_METER * value() / 100.0; }
189 };
190 
192 {
193  double hdop() { return value() / 100.0; }
194 };
195 
196 class TinyGPSPlus;
198 {
199 public:
201  TinyGPSCustom(TinyGPSPlus &gps, const char *sentenceName, int termNumber);
202  void begin(TinyGPSPlus &gps, const char *_sentenceName, int _termNumber);
203 
204  bool isUpdated() const { return updated; }
205  bool isValid() const { return valid; }
206  uint32_t age() const { return valid ? (unsigned long)udrv_rtc_get_timestamp((RtcID_E)SYS_RTC_COUNTER_PORT) - lastCommitTime : (uint32_t)ULONG_MAX; }
207  const char *value() { updated = false; return buffer; }
208 
209 private:
210  void commit();
211  void set(const char *term);
212 
213  char stagingBuffer[_GPS_MAX_FIELD_SIZE + 1];
214  char buffer[_GPS_MAX_FIELD_SIZE + 1];
215  unsigned long lastCommitTime;
216  bool valid, updated;
217  const char *sentenceName;
218  int termNumber;
219  friend class TinyGPSPlus;
220  TinyGPSCustom *next;
221 };
222 
224 {
225 public:
226  TinyGPSPlus();
227  bool encode(char c); // process one character received from GPS
228  TinyGPSPlus &operator << (char c) {encode(c); return *this;}
229 
238 
239  static const char *libraryVersion() { return _GPS_VERSION; }
240 
241  static double distanceBetween(double lat1, double long1, double lat2, double long2);
242  static double courseTo(double lat1, double long1, double lat2, double long2);
243  static const char *cardinal(double course);
244 
245  static int32_t parseDecimal(const char *term);
246  static void parseDegrees(const char *term, RawDegrees &deg);
247 
248  uint32_t charsProcessed() const { return encodedCharCount; }
249  uint32_t sentencesWithFix() const { return sentencesWithFixCount; }
250  uint32_t failedChecksum() const { return failedChecksumCount; }
251  uint32_t passedChecksum() const { return passedChecksumCount; }
252 
253 private:
254  enum {GPS_SENTENCE_GPGGA, GPS_SENTENCE_GPRMC, GPS_SENTENCE_OTHER};
255 
256  // parsing state variables
257  uint8_t parity;
258  bool isChecksumTerm;
259  char term[_GPS_MAX_FIELD_SIZE];
260  uint8_t curSentenceType;
261  uint8_t curTermNumber;
262  uint8_t curTermOffset;
263  bool sentenceHasFix;
264 
265  // custom element support
266  friend class TinyGPSCustom;
267  TinyGPSCustom *customElts;
268  TinyGPSCustom *customCandidates;
269  void insertCustom(TinyGPSCustom *pElt, const char *sentenceName, int index);
270 
271  // statistics
272  uint32_t encodedCharCount;
273  uint32_t sentencesWithFixCount;
274  uint32_t failedChecksumCount;
275  uint32_t passedChecksumCount;
276 
277  // internal utilities
278  int fromHex(char a);
279  bool endOfTermHandler();
280 };
281 
282 #endif // def(__TinyGPSPlus_h)
double meters()
Definition: TinyGPS++.h:185
double mps()
Definition: TinyGPS++.h:174
Definition: TinyGPS++.h:183
bool negative
Definition: TinyGPS++.h:51
TinyGPSInteger satellites
Definition: TinyGPS++.h:236
TinyGPSCourse course
Definition: TinyGPS++.h:234
static const char * libraryVersion()
Definition: TinyGPS++.h:239
TinyGPSDate()
Definition: TinyGPS++.h:94
bool isValid() const
Definition: TinyGPS++.h:205
uint32_t sentencesWithFix() const
Definition: TinyGPS++.h:249
uint16_t deg
Definition: TinyGPS++.h:49
double kilometers()
Definition: TinyGPS++.h:187
RtcID_E
Definition: udrv_rtc.h:12
#define _GPS_MILES_PER_METER
Definition: TinyGPS++.h:42
TinyGPSDate date
Definition: TinyGPS++.h:231
uint32_t age() const
Definition: TinyGPS++.h:206
uint32_t age() const
Definition: TinyGPS++.h:111
bool isUpdated() const
Definition: TinyGPS++.h:155
uint32_t age() const
Definition: TinyGPS++.h:156
bool isValid() const
Definition: TinyGPS++.h:61
Definition: TinyGPS++.h:150
#define _GPS_FEET_PER_METER
Definition: TinyGPS++.h:44
bool isUpdated() const
Definition: TinyGPS++.h:110
Definition: TinyGPS++.h:191
const RawDegrees & rawLat()
Definition: TinyGPS++.h:64
uint64_t udrv_rtc_get_timestamp(RtcID_E timer_id)
#define _GPS_KMPH_PER_KNOT
Definition: TinyGPS++.h:41
double kmph()
Definition: TinyGPS++.h:175
TinyGPSLocation location
Definition: TinyGPS++.h:230
bool isUpdated() const
Definition: TinyGPS++.h:135
#define _GPS_MPS_PER_KNOT
Definition: TinyGPS++.h:40
uint32_t billionths
Definition: TinyGPS++.h:50
TinyGPSHDOP hdop
Definition: TinyGPS++.h:237
double miles()
Definition: TinyGPS++.h:186
TinyGPSTime time
Definition: TinyGPS++.h:232
TinyGPSInteger()
Definition: TinyGPS++.h:159
Definition: TinyGPS++.h:130
bool isUpdated() const
Definition: TinyGPS++.h:86
#define _GPS_MAX_FIELD_SIZE
Definition: TinyGPS++.h:45
bool isUpdated() const
Definition: TinyGPS++.h:204
TinyGPSLocation()
Definition: TinyGPS++.h:69
Definition: TinyGPS++.h:57
bool isValid() const
Definition: TinyGPS++.h:109
Definition: TinyGPS++.h:197
Definition: TinyGPS++.h:178
bool isValid() const
Definition: TinyGPS++.h:85
TinyGPSTime()
Definition: TinyGPS++.h:119
uint32_t age() const
Definition: TinyGPS++.h:136
TinyGPSDecimal()
Definition: TinyGPS++.h:139
Definition: TinyGPS++.h:105
bool isUpdated() const
Definition: TinyGPS++.h:62
TinyGPSSpeed speed
Definition: TinyGPS++.h:233
Definition: TinyGPS++.h:170
uint32_t value()
Definition: TinyGPS++.h:157
uint32_t charsProcessed() const
Definition: TinyGPS++.h:248
#define _GPS_KM_PER_METER
Definition: TinyGPS++.h:43
double feet()
Definition: TinyGPS++.h:188
uint32_t passedChecksum() const
Definition: TinyGPS++.h:251
double mph()
Definition: TinyGPS++.h:173
uint32_t failedChecksum() const
Definition: TinyGPS++.h:250
bool isValid() const
Definition: TinyGPS++.h:154
const RawDegrees & rawLng()
Definition: TinyGPS++.h:65
double hdop()
Definition: TinyGPS++.h:193
double deg()
Definition: TinyGPS++.h:180
int32_t value()
Definition: TinyGPS++.h:137
const char * value()
Definition: TinyGPS++.h:207
TinyGPSAltitude altitude
Definition: TinyGPS++.h:235
Definition: TinyGPS++.h:47
Definition: TinyGPS++.h:81
bool isValid() const
Definition: TinyGPS++.h:134
uint32_t value()
Definition: TinyGPS++.h:89
Definition: TinyGPS++.h:223
double knots()
Definition: TinyGPS++.h:172
uint32_t value()
Definition: TinyGPS++.h:113
#define _GPS_MPH_PER_KNOT
Definition: TinyGPS++.h:39
#define _GPS_VERSION
Definition: TinyGPS++.h:38
uint32_t age() const
Definition: TinyGPS++.h:87
uint32_t age() const
Definition: TinyGPS++.h:63
RawDegrees()
Definition: TinyGPS++.h:53
TinyGPSCustom()
Definition: TinyGPS++.h:200