TinyGPS++.h
Go to the documentation of this file.
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 #include <limits.h>
00033 
00034 #define _GPS_VERSION "0.92" // software version of this library
00035 #define _GPS_MPH_PER_KNOT 1.15077945
00036 #define _GPS_MPS_PER_KNOT 0.51444444
00037 #define _GPS_KMPH_PER_KNOT 1.852
00038 #define _GPS_MILES_PER_METER 0.00062137112
00039 #define _GPS_KM_PER_METER 0.001
00040 #define _GPS_FEET_PER_METER 3.2808399
00041 #define _GPS_MAX_FIELD_SIZE 15
00042 
00043 struct RawDegrees
00044 {
00045    uint16_t deg;
00046    uint32_t billionths;
00047    bool negative;
00048 public:
00049    RawDegrees() : deg(0), billionths(0), negative(false)
00050    {}
00051 };
00052 
00053 struct TinyGPSLocation
00054 {
00055    friend class TinyGPSPlus;
00056 public:
00057    bool isValid() const    { return valid; }
00058    bool isUpdated() const  { return updated; }
00059    uint32_t age() const    { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00060    const RawDegrees &rawLat()     { updated = false; return rawLatData; }
00061    const RawDegrees &rawLng()     { updated = false; return rawLngData; }
00062    double lat();
00063    double lng();
00064 
00065    TinyGPSLocation() : valid(false), updated(false)
00066    {}
00067 
00068 private:
00069    bool valid, updated;
00070    RawDegrees rawLatData, rawLngData, rawNewLatData, rawNewLngData;
00071    uint32_t lastCommitTime;
00072    void commit();
00073    void setLatitude(const char *term);
00074    void setLongitude(const char *term);
00075 };
00076 
00077 struct TinyGPSDate
00078 {
00079    friend class TinyGPSPlus;
00080 public:
00081    bool isValid() const       { return valid; }
00082    bool isUpdated() const     { return updated; }
00083    uint32_t age() const       { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00084 
00085    uint32_t value()           { updated = false; return date; }
00086    uint16_t year();
00087    uint8_t month();
00088    uint8_t day();
00089 
00090    TinyGPSDate() : valid(false), updated(false), date(0)
00091    {}
00092 
00093 private:
00094    bool valid, updated;
00095    uint32_t date, newDate;
00096    uint32_t lastCommitTime;
00097    void commit();
00098    void setDate(const char *term);
00099 };
00100 
00101 struct TinyGPSTime
00102 {
00103    friend class TinyGPSPlus;
00104 public:
00105    bool isValid() const       { return valid; }
00106    bool isUpdated() const     { return updated; }
00107    uint32_t age() const       { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00108 
00109    uint32_t value()           { updated = false; return time; }
00110    uint8_t hour();
00111    uint8_t minute();
00112    uint8_t second();
00113    uint8_t centisecond();
00114 
00115    TinyGPSTime() : valid(false), updated(false), time(0)
00116    {}
00117 
00118 private:
00119    bool valid, updated;
00120    uint32_t time, newTime;
00121    uint32_t lastCommitTime;
00122    void commit();
00123    void setTime(const char *term);
00124 };
00125 
00126 struct TinyGPSDecimal
00127 {
00128    friend class TinyGPSPlus;
00129 public:
00130    bool isValid() const    { return valid; }
00131    bool isUpdated() const  { return updated; }
00132    uint32_t age() const    { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00133    int32_t value()         { updated = false; return val; }
00134 
00135    TinyGPSDecimal() : valid(false), updated(false), val(0)
00136    {}
00137 
00138 private:
00139    bool valid, updated;
00140    uint32_t lastCommitTime;
00141    int32_t val, newval;
00142    void commit();
00143    void set(const char *term);
00144 };
00145 
00146 struct TinyGPSInteger
00147 {
00148    friend class TinyGPSPlus;
00149 public:
00150    bool isValid() const    { return valid; }
00151    bool isUpdated() const  { return updated; }
00152    uint32_t age() const    { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00153    uint32_t value()        { updated = false; return val; }
00154 
00155    TinyGPSInteger() : valid(false), updated(false), val(0)
00156    {}
00157 
00158 private:
00159    bool valid, updated;
00160    uint32_t lastCommitTime;
00161    uint32_t val, newval;
00162    void commit();
00163    void set(const char *term);
00164 };
00165 
00166 struct TinyGPSSpeed : TinyGPSDecimal
00167 {
00168    double knots()    { return value() / 100.0; }
00169    double mph()      { return _GPS_MPH_PER_KNOT * value() / 100.0; }
00170    double mps()      { return _GPS_MPS_PER_KNOT * value() / 100.0; }
00171    double kmph()     { return _GPS_KMPH_PER_KNOT * value() / 100.0; }
00172 };
00173 
00174 struct TinyGPSCourse : public TinyGPSDecimal
00175 {
00176    double deg()      { return value() / 100.0; }
00177 };
00178 
00179 struct TinyGPSAltitude : TinyGPSDecimal
00180 {
00181    double meters()       { return value() / 100.0; }
00182    double miles()        { return _GPS_MILES_PER_METER * value() / 100.0; }
00183    double kilometers()   { return _GPS_KM_PER_METER * value() / 100.0; }
00184    double feet()         { return _GPS_FEET_PER_METER * value() / 100.0; }
00185 };
00186 
00187 class TinyGPSPlus;
00188 class TinyGPSCustom
00189 {
00190 public:
00191    TinyGPSCustom() {};
00192    TinyGPSCustom(TinyGPSPlus &gps, const char *sentenceName, int termNumber);
00193    void begin(TinyGPSPlus &gps, const char *_sentenceName, int _termNumber);
00194 
00195    bool isUpdated() const  { return updated; }
00196    bool isValid() const    { return valid; }
00197    uint32_t age() const    { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
00198    const char *value()     { updated = false; return buffer; }
00199 
00200 private:
00201    void commit();
00202    void set(const char *term);
00203 
00204    char stagingBuffer[_GPS_MAX_FIELD_SIZE + 1];
00205    char buffer[_GPS_MAX_FIELD_SIZE + 1];
00206    unsigned long lastCommitTime;
00207    bool valid, updated;
00208    const char *sentenceName;
00209    int termNumber;
00210    friend class TinyGPSPlus;
00211    TinyGPSCustom *next;
00212 };
00213 
00214 class TinyGPSPlus
00215 {
00216 public:
00217   TinyGPSPlus();
00218   bool encode(char c); // process one character received from GPS
00219   TinyGPSPlus &operator << (char c) {encode(c); return *this;}
00220 
00221   TinyGPSLocation location;
00222   TinyGPSDate date;
00223   TinyGPSTime time;
00224   TinyGPSSpeed speed;
00225   TinyGPSCourse course;
00226   TinyGPSAltitude altitude;
00227   TinyGPSInteger satellites;
00228   TinyGPSDecimal hdop;
00229 
00230   static const char *libraryVersion() { return _GPS_VERSION; }
00231 
00232   static double distanceBetween(double lat1, double long1, double lat2, double long2);
00233   static double courseTo(double lat1, double long1, double lat2, double long2);
00234   static const char *cardinal(double course);
00235 
00236   static int32_t parseDecimal(const char *term);
00237   static void parseDegrees(const char *term, RawDegrees &deg);
00238 
00239   uint32_t charsProcessed()   const { return encodedCharCount; }
00240   uint32_t sentencesWithFix() const { return sentencesWithFixCount; }
00241   uint32_t failedChecksum()   const { return failedChecksumCount; }
00242   uint32_t passedChecksum()   const { return passedChecksumCount; }
00243 
00244 private:
00245   enum {GPS_SENTENCE_GPGGA, GPS_SENTENCE_GPRMC, GPS_SENTENCE_OTHER};
00246 
00247   // parsing state variables
00248   uint8_t parity;
00249   bool isChecksumTerm;
00250   char term[_GPS_MAX_FIELD_SIZE];
00251   uint8_t curSentenceType;
00252   uint8_t curTermNumber;
00253   uint8_t curTermOffset;
00254   bool sentenceHasFix;
00255 
00256   // custom element support
00257   friend class TinyGPSCustom;
00258   TinyGPSCustom *customElts;
00259   TinyGPSCustom *customCandidates;
00260   void insertCustom(TinyGPSCustom *pElt, const char *sentenceName, int index);
00261 
00262   // statistics
00263   uint32_t encodedCharCount;
00264   uint32_t sentencesWithFixCount;
00265   uint32_t failedChecksumCount;
00266   uint32_t passedChecksumCount;
00267 
00268   // internal utilities
00269   int fromHex(char a);
00270   bool endOfTermHandler();
00271 };
00272 
00273 #endif // def(__TinyGPSPlus_h)


ric_mc
Author(s): RoboTiCan
autogenerated on Fri May 20 2016 03:48:56