Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TinyGPS_h
00022 #define TinyGPS_h
00023
00024 #include "WProgram.h"
00025
00026 #define _GPS_VERSION 9 // software version of this library
00027 #define _GPS_MPH_PER_KNOT 1.15077945
00028 #define _GPS_MPS_PER_KNOT 0.51444444
00029 #define _GPS_KMPH_PER_KNOT 1.852
00030 #define _GPS_MILES_PER_METER 0.00062137112
00031 #define _GPS_KM_PER_METER 0.001
00032
00033
00034 class TinyGPS
00035 {
00036 public:
00037 TinyGPS();
00038 bool encode(char c);
00039 TinyGPS &operator << (char c) {encode(c); return *this;}
00040
00041
00042 inline void get_position(long *latitude, long *longitude, unsigned long *fix_age = 0)
00043 {
00044 if (latitude) *latitude = _latitude;
00045 if (longitude) *longitude = _longitude;
00046 if (fix_age) *fix_age = _last_position_fix == GPS_INVALID_FIX_TIME ?
00047 GPS_INVALID_AGE : millis() - _last_position_fix;
00048 }
00049
00050
00051 inline void get_datetime(unsigned long *date, unsigned long *time, unsigned long *fix_age = 0)
00052 {
00053 if (date) *date = _date;
00054 if (time) *time = _time;
00055 if (fix_age) *fix_age = _last_time_fix == GPS_INVALID_FIX_TIME ?
00056 GPS_INVALID_AGE : millis() - _last_time_fix;
00057 }
00058
00059
00060 inline long altitude() { return _altitude; }
00061
00062
00063 inline unsigned long course() { return _course; }
00064
00065
00066 unsigned long speed() { return _speed; }
00067
00068 #ifndef _GPS_NO_STATS
00069 void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
00070 #endif
00071
00072 inline void f_get_position(float *latitude, float *longitude, unsigned long *fix_age = 0)
00073 {
00074 long lat, lon;
00075 get_position(&lat, &lon, fix_age);
00076 *latitude = lat / 100000.0;
00077 *longitude = lon / 100000.0;
00078 }
00079
00080 inline void crack_datetime(int *year, byte *month, byte *day,
00081 byte *hour, byte *minute, byte *second, byte *hundredths = 0, unsigned long *fix_age = 0)
00082 {
00083 unsigned long date, time;
00084 get_datetime(&date, &time, fix_age);
00085 if (year)
00086 {
00087 *year = date % 100;
00088 *year += *year > 80 ? 1900 : 2000;
00089 }
00090 if (month) *month = (date / 100) % 100;
00091 if (day) *day = date / 10000;
00092 if (hour) *hour = time / 1000000;
00093 if (minute) *minute = (time / 10000) % 100;
00094 if (second) *second = (time / 100) % 100;
00095 if (hundredths) *hundredths = time % 100;
00096 }
00097
00098 inline float f_altitude() { return altitude() / 100.0; }
00099 inline float f_course() { return course() / 100.0; }
00100 inline float f_speed_knots() { return speed() / 100.0; }
00101 inline float f_speed_mph() { return _GPS_MPH_PER_KNOT * f_speed_knots(); }
00102 inline float f_speed_mps() { return _GPS_MPS_PER_KNOT * f_speed_knots(); }
00103 inline float f_speed_kmph() { return _GPS_KMPH_PER_KNOT * f_speed_knots(); }
00104
00105 static int library_version() { return _GPS_VERSION; }
00106
00107 enum {GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999, GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0,
00108 GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999, GPS_INVALID_FIX_TIME = 0xFFFFFFFF};
00109
00110 private:
00111 enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_OTHER};
00112
00113
00114 unsigned long _time, _new_time;
00115 unsigned long _date, _new_date;
00116 long _latitude, _new_latitude;
00117 long _longitude, _new_longitude;
00118 long _altitude, _new_altitude;
00119 unsigned long _speed, _new_speed;
00120 unsigned long _course, _new_course;
00121
00122 unsigned long _last_time_fix, _new_time_fix;
00123 unsigned long _last_position_fix, _new_position_fix;
00124
00125
00126 byte _parity;
00127 bool _is_checksum_term;
00128 char _term[15];
00129 byte _sentence_type;
00130 byte _term_number;
00131 byte _term_offset;
00132 bool _gps_data_good;
00133
00134 #ifndef _GPS_NO_STATS
00135
00136 unsigned long _encoded_characters;
00137 unsigned short _good_sentences;
00138 unsigned short _failed_checksum;
00139 unsigned short _passed_checksum;
00140 #endif
00141
00142
00143 int from_hex(char a);
00144 unsigned long parse_decimal();
00145 unsigned long parse_degrees();
00146 bool term_complete();
00147 bool gpsisdigit(char c) { return c >= '0' && c <= '9'; }
00148 long gpsatol(const char *str);
00149 int gpsstrcmp(const char *str1, const char *str2);
00150 };
00151
00152
00153 #undef int
00154 #undef char
00155 #undef long
00156 #undef byte
00157 #undef float
00158 #undef abs
00159 #undef round
00160
00161 #endif