@@ -3,7 +3,7 @@ TinyGPS++ - a small GPS library for Arduino providing universal NMEA parsing
33Based on work by and "distanceBetween" and "courseTo" courtesy of Maarten Lamers.
44Suggestion to add satellites, courseTo(), and cardinal() by Matt Monson.
55Location precision improvements suggested by Wayne Holder.
6- Copyright (C) 2008-2013 Mikal Hart
6+ Copyright (C) 2008-2024 Mikal Hart
77All rights reserved.
88
99This library is free software; you can redistribute it and/or
@@ -27,10 +27,21 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2727#include < ctype.h>
2828#include < stdlib.h>
2929
30- #define _GPRMCterm " GPRMC"
31- #define _GPGGAterm " GPGGA"
32- #define _GNRMCterm " GNRMC"
33- #define _GNGGAterm " GNGGA"
30+ #define _RMCterm " RMC"
31+ #define _GGAterm " GGA"
32+
33+ #if !defined(ARDUINO) && !defined(__AVR__)
34+ // Alternate implementation of millis() that relies on std
35+ unsigned long millis ()
36+ {
37+ static auto start_time = std::chrono::high_resolution_clock::now ();
38+
39+ auto end_time = std::chrono::high_resolution_clock::now ();
40+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
41+
42+ return static_cast <unsigned long >(duration.count ());
43+ }
44+ #endif
3445
3546TinyGPSPlus::TinyGPSPlus ()
3647 : parity(0 )
@@ -170,7 +181,7 @@ bool TinyGPSPlus::endOfTermHandler()
170181
171182 switch (curSentenceType)
172183 {
173- case GPS_SENTENCE_GPRMC :
184+ case GPS_SENTENCE_RMC :
174185 date.commit ();
175186 time.commit ();
176187 if (sentenceHasFix)
@@ -180,7 +191,7 @@ bool TinyGPSPlus::endOfTermHandler()
180191 course.commit ();
181192 }
182193 break ;
183- case GPS_SENTENCE_GPGGA :
194+ case GPS_SENTENCE_GGA :
184195 time.commit ();
185196 if (sentenceHasFix)
186197 {
@@ -209,10 +220,10 @@ bool TinyGPSPlus::endOfTermHandler()
209220 // the first term determines the sentence type
210221 if (curTermNumber == 0 )
211222 {
212- if (! strcmp ( term, _GPRMCterm) || !strcmp (term, _GNRMCterm ))
213- curSentenceType = GPS_SENTENCE_GPRMC ;
214- else if (! strcmp ( term, _GPGGAterm) || !strcmp (term, _GNGGAterm ))
215- curSentenceType = GPS_SENTENCE_GPGGA ;
223+ if (term[ 0 ] == ' G ' && strchr ( " PNABL " , term[ 1 ]) != NULL && !strcmp (term + 2 , _RMCterm ))
224+ curSentenceType = GPS_SENTENCE_RMC ;
225+ else if (term[ 0 ] == ' G ' && strchr ( " PNABL " , term[ 1 ]) != NULL && !strcmp (term + 2 , _GGAterm ))
226+ curSentenceType = GPS_SENTENCE_GGA ;
216227 else
217228 curSentenceType = GPS_SENTENCE_OTHER;
218229
@@ -227,50 +238,54 @@ bool TinyGPSPlus::endOfTermHandler()
227238 if (curSentenceType != GPS_SENTENCE_OTHER && term[0 ])
228239 switch (COMBINE (curSentenceType, curTermNumber))
229240 {
230- case COMBINE (GPS_SENTENCE_GPRMC , 1 ): // Time in both sentences
231- case COMBINE (GPS_SENTENCE_GPGGA , 1 ):
241+ case COMBINE (GPS_SENTENCE_RMC , 1 ): // Time in both sentences
242+ case COMBINE (GPS_SENTENCE_GGA , 1 ):
232243 time.setTime (term);
233244 break ;
234- case COMBINE (GPS_SENTENCE_GPRMC , 2 ): // GPRMC validity
245+ case COMBINE (GPS_SENTENCE_RMC , 2 ): // RMC validity
235246 sentenceHasFix = term[0 ] == ' A' ;
236247 break ;
237- case COMBINE (GPS_SENTENCE_GPRMC , 3 ): // Latitude
238- case COMBINE (GPS_SENTENCE_GPGGA , 2 ):
248+ case COMBINE (GPS_SENTENCE_RMC , 3 ): // Latitude
249+ case COMBINE (GPS_SENTENCE_GGA , 2 ):
239250 location.setLatitude (term);
240251 break ;
241- case COMBINE (GPS_SENTENCE_GPRMC , 4 ): // N/S
242- case COMBINE (GPS_SENTENCE_GPGGA , 3 ):
252+ case COMBINE (GPS_SENTENCE_RMC , 4 ): // N/S
253+ case COMBINE (GPS_SENTENCE_GGA , 3 ):
243254 location.rawNewLatData .negative = term[0 ] == ' S' ;
244255 break ;
245- case COMBINE (GPS_SENTENCE_GPRMC , 5 ): // Longitude
246- case COMBINE (GPS_SENTENCE_GPGGA , 4 ):
256+ case COMBINE (GPS_SENTENCE_RMC , 5 ): // Longitude
257+ case COMBINE (GPS_SENTENCE_GGA , 4 ):
247258 location.setLongitude (term);
248259 break ;
249- case COMBINE (GPS_SENTENCE_GPRMC , 6 ): // E/W
250- case COMBINE (GPS_SENTENCE_GPGGA , 5 ):
260+ case COMBINE (GPS_SENTENCE_RMC , 6 ): // E/W
261+ case COMBINE (GPS_SENTENCE_GGA , 5 ):
251262 location.rawNewLngData .negative = term[0 ] == ' W' ;
252263 break ;
253- case COMBINE (GPS_SENTENCE_GPRMC , 7 ): // Speed (GPRMC )
264+ case COMBINE (GPS_SENTENCE_RMC , 7 ): // Speed (RMC )
254265 speed.set (term);
255266 break ;
256- case COMBINE (GPS_SENTENCE_GPRMC , 8 ): // Course (GPRMC )
267+ case COMBINE (GPS_SENTENCE_RMC , 8 ): // Course (RMC )
257268 course.set (term);
258269 break ;
259- case COMBINE (GPS_SENTENCE_GPRMC , 9 ): // Date (GPRMC )
270+ case COMBINE (GPS_SENTENCE_RMC , 9 ): // Date (RMC )
260271 date.setDate (term);
261272 break ;
262- case COMBINE (GPS_SENTENCE_GPGGA , 6 ): // Fix data (GPGGA )
273+ case COMBINE (GPS_SENTENCE_GGA , 6 ): // Fix data (GGA )
263274 sentenceHasFix = term[0 ] > ' 0' ;
275+ location.newFixQuality = (TinyGPSLocation::Quality)term[0 ];
264276 break ;
265- case COMBINE (GPS_SENTENCE_GPGGA , 7 ): // Satellites used (GPGGA )
277+ case COMBINE (GPS_SENTENCE_GGA , 7 ): // Satellites used (GGA )
266278 satellites.set (term);
267279 break ;
268- case COMBINE (GPS_SENTENCE_GPGGA , 8 ): // HDOP
280+ case COMBINE (GPS_SENTENCE_GGA , 8 ): // HDOP
269281 hdop.set (term);
270282 break ;
271- case COMBINE (GPS_SENTENCE_GPGGA , 9 ): // Altitude (GPGGA )
283+ case COMBINE (GPS_SENTENCE_GGA , 9 ): // Altitude (GGA )
272284 altitude.set (term);
273285 break ;
286+ case COMBINE (GPS_SENTENCE_RMC, 12 ):
287+ location.newFixMode = (TinyGPSLocation::Mode)term[0 ];
288+ break ;
274289 }
275290
276291 // Set custom values as needed
@@ -286,7 +301,7 @@ double TinyGPSPlus::distanceBetween(double lat1, double long1, double lat2, doub
286301{
287302 // returns distance in meters between two positions, both specified
288303 // as signed decimal-degrees latitude and longitude. Uses great-circle
289- // distance computation for hypothetical sphere of radius 6372795 meters.
304+ // distance computation for hypothetical sphere of radius 6371009 meters.
290305 // Because Earth is no exact sphere, rounding errors may be up to 0.5%.
291306 // Courtesy of Maarten Lamers
292307 double delta = radians (long1-long2);
@@ -304,7 +319,7 @@ double TinyGPSPlus::distanceBetween(double lat1, double long1, double lat2, doub
304319 delta = sqrt (delta);
305320 double denom = (slat1 * slat2) + (clat1 * clat2 * cdlong);
306321 delta = atan2 (delta, denom);
307- return delta * 6372795 ;
322+ return delta * _GPS_EARTH_MEAN_RADIUS ;
308323}
309324
310325double TinyGPSPlus::courseTo (double lat1, double long1, double lat2, double long2)
@@ -338,6 +353,8 @@ void TinyGPSLocation::commit()
338353{
339354 rawLatData = rawNewLatData;
340355 rawLngData = rawNewLngData;
356+ fixQuality = newFixQuality;
357+ fixMode = newFixMode;
341358 lastCommitTime = millis ();
342359 valid = updated = true ;
343360}
@@ -484,7 +501,7 @@ void TinyGPSCustom::commit()
484501
485502void TinyGPSCustom::set (const char *term)
486503{
487- strncpy (this ->stagingBuffer , term, sizeof (this ->stagingBuffer ));
504+ strncpy (this ->stagingBuffer , term, sizeof (this ->stagingBuffer ) - 1 );
488505}
489506
490507void TinyGPSPlus::insertCustom (TinyGPSCustom *pElt, const char *sentenceName, int termNumber)
0 commit comments