PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

178 rindas
5.6KB

  1. /*
  2. TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
  3. Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
  4. Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
  5. Precision improvements suggested by Wayne Holder.
  6. Copyright (C) 2008-2013 Mikal Hart
  7. All rights reserved.
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef TinyGPS_h
  21. #define TinyGPS_h
  22. #if defined(ARDUINO) && ARDUINO >= 100
  23. #include "Arduino.h"
  24. #else
  25. #include "WProgram.h"
  26. #endif
  27. #include <stdlib.h>
  28. #define _GPS_VERSION 13 // software version of this library
  29. #define _GPS_MPH_PER_KNOT 1.15077945
  30. #define _GPS_MPS_PER_KNOT 0.51444444
  31. #define _GPS_KMPH_PER_KNOT 1.852
  32. #define _GPS_MILES_PER_METER 0.00062137112
  33. #define _GPS_KM_PER_METER 0.001
  34. // #define _GPS_NO_STATS
  35. class TinyGPS
  36. {
  37. public:
  38. enum {
  39. GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999,
  40. GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0,
  41. GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999,
  42. GPS_INVALID_FIX_TIME = 0xFFFFFFFF, GPS_INVALID_SATELLITES = 0xFF,
  43. GPS_INVALID_HDOP = 0xFFFFFFFF
  44. };
  45. static const float GPS_INVALID_F_ANGLE, GPS_INVALID_F_ALTITUDE, GPS_INVALID_F_SPEED;
  46. TinyGPS();
  47. bool encode(char c); // process one character received from GPS
  48. TinyGPS &operator << (char c) {encode(c); return *this;}
  49. // lat/long in MILLIONTHs of a degree and age of fix in milliseconds
  50. // (note: versions 12 and earlier gave lat/long in 100,000ths of a degree.
  51. void get_position(long *latitude, long *longitude, unsigned long *fix_age = 0);
  52. // date as ddmmyy, time as hhmmsscc, and age in milliseconds
  53. void get_datetime(unsigned long *date, unsigned long *time, unsigned long *age = 0);
  54. // signed altitude in centimeters (from GPGGA sentence)
  55. inline long altitude() { return _altitude; }
  56. // course in last full GPRMC sentence in 100th of a degree
  57. inline unsigned long course() { return _course; }
  58. // speed in last full GPRMC sentence in 100ths of a knot
  59. inline unsigned long speed() { return _speed; }
  60. // satellites used in last full GPGGA sentence
  61. inline unsigned short satellites() { return _numsats; }
  62. // horizontal dilution of precision in 100ths
  63. inline unsigned long hdop() { return _hdop; }
  64. inline char* constellations() { return _constellations; }
  65. inline uint32_t* trackedSatellites() { return tracked_sat_rec; }
  66. void f_get_position(float *latitude, float *longitude, unsigned long *fix_age = 0);
  67. void crack_datetime(int *year, byte *month, byte *day,
  68. byte *hour, byte *minute, byte *second, byte *hundredths = 0, unsigned long *fix_age = 0);
  69. float f_altitude();
  70. float f_course();
  71. float f_speed_knots();
  72. float f_speed_mph();
  73. float f_speed_mps();
  74. float f_speed_kmph();
  75. static int library_version() { return _GPS_VERSION; }
  76. static float distance_between (float lat1, float long1, float lat2, float long2);
  77. static float course_to (float lat1, float long1, float lat2, float long2);
  78. static const char *cardinal(float course);
  79. #ifndef _GPS_NO_STATS
  80. void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
  81. #endif
  82. private:
  83. enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_GNGNS, _GPS_SENTENCE_GNGSA,
  84. _GPS_SENTENCE_GPGSV, _GPS_SENTENCE_GLGSV, _GPS_SENTENCE_OTHER};
  85. // properties
  86. unsigned long _time, _new_time;
  87. unsigned long _date, _new_date;
  88. long _latitude, _new_latitude;
  89. long _longitude, _new_longitude;
  90. long _altitude, _new_altitude;
  91. unsigned long _speed, _new_speed;
  92. unsigned long _course, _new_course;
  93. unsigned long _hdop, _new_hdop;
  94. unsigned short _numsats, _new_numsats;
  95. unsigned long _last_time_fix, _new_time_fix;
  96. unsigned long _last_position_fix, _new_position_fix;
  97. // parsing state variables
  98. byte _parity;
  99. bool _is_checksum_term;
  100. char _term[15];
  101. byte _sentence_type;
  102. byte _term_number;
  103. byte _term_offset;
  104. bool _gps_data_good;
  105. struct TrackedSattelites {
  106. uint8_t prn; //"pseudo-random noise" sequences, or Gold codes. GPS sats are listed here http://en.wikipedia.org/wiki/List_of_GPS_satellites
  107. uint8_t strength; //in dB
  108. };
  109. char _constellations[5];
  110. uint8_t _sat_used_count;
  111. //format:
  112. //bit 0-7: sat ID
  113. //bit 8-14: snr (dB), max 99dB
  114. //bit 15: used in solution (when tracking)
  115. uint32_t tracked_sat_rec[24]; //TODO: externalize array size
  116. int _tracked_satellites_index;
  117. uint8_t _sat_index;
  118. #ifndef _GPS_NO_STATS
  119. // statistics
  120. unsigned long _encoded_characters;
  121. unsigned short _good_sentences;
  122. unsigned short _failed_checksum;
  123. unsigned short _passed_checksum;
  124. #endif
  125. // internal utilities
  126. int from_hex(char a);
  127. unsigned long parse_decimal();
  128. unsigned long parse_degrees();
  129. bool term_complete();
  130. bool gpsisdigit(char c) { return c >= '0' && c <= '9'; }
  131. long gpsatol(const char *str);
  132. int gpsstrcmp(const char *str1, const char *str2);
  133. };
  134. #if !defined(ARDUINO)
  135. // Arduino 0012 workaround
  136. #undef int
  137. #undef char
  138. #undef long
  139. #undef byte
  140. #undef float
  141. #undef abs
  142. #undef round
  143. #endif
  144. #endif