mbed port of the TinyGPSPlus library for Arduino, by Mikal Hart. The port is heavily inspired by Sergey Drobyshevskiy (dROb)'s port of the TinyGPS library.
Dependents: ZZ_SSL_Main_L476 Sample_program_Font72
Fork of TinyGPSPlus by
TinyGPSPlus.h
00001 /* 00002 TinyGPS++ - a small GPS library for Arduino providing universal NMEA parsing 00003 Based on work by and "distanceBetween" and "courseTo" courtesy of Maarten Lamers. 00004 Suggestion to add satellites, courseTo(), and cardinal() by Matt Monson. 00005 Location precision improvements suggested by Wayne Holder. 00006 Copyright (C) 2008-2013 Mikal Hart 00007 All rights reserved. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef __TinyGPSPlus_h 00025 #define __TinyGPSPlus_h 00026 00027 /*#if defined(ARDUINO) && ARDUINO >= 100 00028 #include "Arduino.h" 00029 #else 00030 #include "WProgram.h" 00031 #endif 00032 */ 00033 00034 #include "mbed.h" 00035 #include "types.h" 00036 00037 #include <stdlib.h> 00038 #include <limits.h> 00039 00040 #define _GPS_VERSION "0.92" // software version of this library 00041 #define _GPS_MPH_PER_KNOT 1.15077945 00042 #define _GPS_MPS_PER_KNOT 0.51444444 00043 #define _GPS_KMPH_PER_KNOT 1.852 00044 #define _GPS_MILES_PER_METER 0.00062137112 00045 #define _GPS_KM_PER_METER 0.001 00046 #define _GPS_FEET_PER_METER 3.2808399 00047 #define _GPS_MAX_FIELD_SIZE 15 00048 00049 #define PI 3.1415926535897932384626433832795 00050 #define HALF_PI 1.5707963267948966192313216916398 00051 #define TWO_PI 6.283185307179586476925286766559 00052 #define DEG_TO_RAD 0.017453292519943295769236907684886 00053 #define RAD_TO_DEG 57.295779513082320876798154814105 00054 #define EULER 2.718281828459045235360287471352 00055 #define radians(deg) ((deg)*DEG_TO_RAD) 00056 #define degrees(rad) ((rad)*RAD_TO_DEG) 00057 #define sq(x) ((x)*(x)) 00058 00059 00060 struct RawDegrees 00061 { 00062 uint16_t deg; 00063 uint32_t billionths; 00064 bool negative; 00065 public: 00066 RawDegrees() : deg(0), billionths(0), negative(false) 00067 {} 00068 }; 00069 00070 struct TinyGPSLocation 00071 { 00072 friend class TinyGPSPlus; 00073 public: 00074 bool isValid() const { return valid; } 00075 bool isUpdated() const { return updated; } 00076 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00077 const RawDegrees &rawLat() { updated = false; return rawLatData; } 00078 const RawDegrees &rawLng() { updated = false; return rawLngData; } 00079 double lat(); 00080 double lng(); 00081 00082 TinyGPSLocation() : valid(false), updated(false) 00083 {} 00084 00085 private: 00086 bool valid, updated; 00087 RawDegrees rawLatData, rawLngData, rawNewLatData, rawNewLngData; 00088 uint32_t lastCommitTime; 00089 void commit(); 00090 void setLatitude(const char *term); 00091 void setLongitude(const char *term); 00092 }; 00093 00094 struct TinyGPSDate 00095 { 00096 friend class TinyGPSPlus; 00097 public: 00098 bool isValid() const { return valid; } 00099 bool isUpdated() const { return updated; } 00100 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00101 00102 uint32_t value() { updated = false; return date; } 00103 uint16_t year(); 00104 uint8_t month(); 00105 uint8_t day(); 00106 00107 TinyGPSDate() : valid(false), updated(false), date(0) 00108 {} 00109 00110 private: 00111 bool valid, updated; 00112 uint32_t date, newDate; 00113 uint32_t lastCommitTime; 00114 void commit(); 00115 void setDate(const char *term); 00116 }; 00117 00118 struct TinyGPSTime 00119 { 00120 friend class TinyGPSPlus; 00121 public: 00122 bool isValid() const { return valid; } 00123 bool isUpdated() const { return updated; } 00124 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00125 00126 uint32_t value() { updated = false; return time; } 00127 uint8_t hour(); 00128 uint8_t minute(); 00129 uint8_t second(); 00130 uint8_t centisecond(); 00131 00132 TinyGPSTime() : valid(false), updated(false), time(0) 00133 {} 00134 00135 private: 00136 bool valid, updated; 00137 uint32_t time, newTime; 00138 uint32_t lastCommitTime; 00139 void commit(); 00140 void setTime(const char *term); 00141 }; 00142 00143 struct TinyGPSDecimal 00144 { 00145 friend class TinyGPSPlus; 00146 public: 00147 bool isValid() const { return valid; } 00148 bool isUpdated() const { return updated; } 00149 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00150 int32_t value() { updated = false; return val; } 00151 00152 TinyGPSDecimal() : valid(false), updated(false), val(0) 00153 {} 00154 00155 private: 00156 bool valid, updated; 00157 uint32_t lastCommitTime; 00158 int32_t val, newval; 00159 void commit(); 00160 void set(const char *term); 00161 }; 00162 00163 struct TinyGPSInteger 00164 { 00165 friend class TinyGPSPlus; 00166 public: 00167 bool isValid() const { return valid; } 00168 bool isUpdated() const { return updated; } 00169 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00170 uint32_t value() { updated = false; return val; } 00171 00172 TinyGPSInteger() : valid(false), updated(false), val(0) 00173 {} 00174 00175 private: 00176 bool valid, updated; 00177 uint32_t lastCommitTime; 00178 uint32_t val, newval; 00179 void commit(); 00180 void set(const char *term); 00181 }; 00182 00183 struct TinyGPSSpeed : TinyGPSDecimal 00184 { 00185 double knots() { return value() / 100.0; } 00186 double mph() { return _GPS_MPH_PER_KNOT * value() / 100.0; } 00187 double mps() { return _GPS_MPS_PER_KNOT * value() / 100.0; } 00188 double kmph() { return _GPS_KMPH_PER_KNOT * value() / 100.0; } 00189 }; 00190 00191 struct TinyGPSCourse : public TinyGPSDecimal 00192 { 00193 double deg() { return value() / 100.0; } 00194 }; 00195 00196 struct TinyGPSAltitude : TinyGPSDecimal 00197 { 00198 double meters() { return value() / 100.0; } 00199 double miles() { return _GPS_MILES_PER_METER * value() / 100.0; } 00200 double kilometers() { return _GPS_KM_PER_METER * value() / 100.0; } 00201 double feet() { return _GPS_FEET_PER_METER * value() / 100.0; } 00202 }; 00203 00204 class TinyGPSPlus; 00205 class TinyGPSCustom 00206 { 00207 public: 00208 TinyGPSCustom() {}; 00209 TinyGPSCustom(TinyGPSPlus &gps, const char *sentenceName, int termNumber); 00210 void begin(TinyGPSPlus &gps, const char *_sentenceName, int _termNumber); 00211 00212 bool isUpdated() const { return updated; } 00213 bool isValid() const { return valid; } 00214 uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; } 00215 const char *value() { updated = false; return buffer; } 00216 00217 private: 00218 void commit(); 00219 void set(const char *term); 00220 00221 char stagingBuffer[_GPS_MAX_FIELD_SIZE + 1]; 00222 char buffer[_GPS_MAX_FIELD_SIZE + 1]; 00223 unsigned long lastCommitTime; 00224 bool valid, updated; 00225 const char *sentenceName; 00226 int termNumber; 00227 friend class TinyGPSPlus; 00228 TinyGPSCustom *next; 00229 }; 00230 00231 class TinyGPSPlus 00232 { 00233 public: 00234 TinyGPSPlus(); 00235 bool encode(char c); // process one character received from GPS 00236 TinyGPSPlus &operator << (char c) {encode(c); return *this;} 00237 00238 TinyGPSLocation location; 00239 TinyGPSDate date; 00240 TinyGPSTime time; 00241 TinyGPSSpeed speed; 00242 TinyGPSCourse course; 00243 TinyGPSAltitude altitude; 00244 TinyGPSInteger satellites; 00245 TinyGPSDecimal hdop; 00246 00247 static const char *libraryVersion() { return _GPS_VERSION; } 00248 00249 static double distanceBetween(double lat1, double long1, double lat2, double long2); 00250 static double courseTo(double lat1, double long1, double lat2, double long2); 00251 static const char *cardinal(double course); 00252 00253 static int32_t parseDecimal(const char *term); 00254 static void parseDegrees(const char *term, RawDegrees °); 00255 00256 uint32_t charsProcessed() const { return encodedCharCount; } 00257 uint32_t sentencesWithFix() const { return sentencesWithFixCount; } 00258 uint32_t failedChecksum() const { return failedChecksumCount; } 00259 uint32_t passedChecksum() const { return passedChecksumCount; } 00260 00261 private: 00262 enum {GPS_SENTENCE_GPGGA, GPS_SENTENCE_GPRMC, GPS_SENTENCE_OTHER}; 00263 00264 // parsing state variables 00265 uint8_t parity; 00266 bool isChecksumTerm; 00267 char term[_GPS_MAX_FIELD_SIZE]; 00268 uint8_t curSentenceType; 00269 uint8_t curTermNumber; 00270 uint8_t curTermOffset; 00271 bool sentenceHasFix; 00272 00273 // custom element support 00274 friend class TinyGPSCustom; 00275 TinyGPSCustom *customElts; 00276 TinyGPSCustom *customCandidates; 00277 void insertCustom(TinyGPSCustom *pElt, const char *sentenceName, int index); 00278 00279 00280 // statistics 00281 uint32_t encodedCharCount; 00282 uint32_t sentencesWithFixCount; 00283 uint32_t failedChecksumCount; 00284 uint32_t passedChecksumCount; 00285 00286 // internal utilities 00287 int fromHex(char a); 00288 bool endOfTermHandler(); 00289 }; 00290 00291 #endif // def(__TinyGPSPlus_h)
Generated on Tue Jul 12 2022 18:09:53 by
