TinyGPS.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(void), course_to(void), and cardinal(void), 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. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include <stdbool.h>
  26. #include <stdlib.h>
  27. #include <math.h>
  28. #include "stm32f4xx.h"
  29. #include "bexus_sysclock.h"
  30. #define _GPS_VERSION 13 // software version of this library
  31. #define _GPS_MPH_PER_KNOT 1.15077945
  32. #define _GPS_MPS_PER_KNOT 0.51444444
  33. #define _GPS_KMPH_PER_KNOT 1.852
  34. #define _GPS_MILES_PER_METER 0.00062137112
  35. #define _GPS_KM_PER_METER 0.001
  36. // #define _GPS_NO_STATS
  37. void setupTinyGps(void);
  38. enum {
  39. GPS_INVALID_AGE = -1, GPS_INVALID_ANGLE = 999999999,
  40. GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0,
  41. GPS_INVALID_TIME = -1, GPS_INVALID_SPEED = 999999999,
  42. GPS_INVALID_FIX_TIME = -1, GPS_INVALID_SATELLITES = 0xFF,
  43. GPS_INVALID_HDOP = -1
  44. };
  45. extern const float GPS_INVALID_F_ANGLE;
  46. extern const float GPS_INVALID_F_ALTITUDE;
  47. extern const float GPS_INVALID_F_SPEED;
  48. bool encode(char c); // process one character received from GPS
  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);
  52. // date as ddmmyy, time as hhmmsscc, and age in milliseconds
  53. void get_datetime(unsigned long *date, unsigned long *time, unsigned long *age);
  54. void f_get_position(float *latitude, float *longitude, unsigned long *fix_age);
  55. void crack_datetime(int *year, uint8_t *month, uint8_t *day,
  56. uint8_t *hour, uint8_t *minute, uint8_t *second, uint8_t *hundredths, unsigned long *fix_age);
  57. float f_altitude(void);
  58. float f_course(void);
  59. float f_speed_knots(void);
  60. float f_speed_mph(void);
  61. float f_speed_mps(void);
  62. float f_speed_kmph(void);
  63. static int library_version(void) { return _GPS_VERSION; }
  64. static const char *cardinal(float course);
  65. #ifndef _GPS_NO_STATS
  66. void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
  67. #endif
  68. enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_OTHER};
  69. // parsing state variables
  70. extern uint8_t _parity;
  71. extern bool _is_checksum_term;
  72. extern char _term[15];
  73. extern uint8_t _sentence_type;
  74. extern uint8_t _term_number;
  75. extern uint8_t _term_offset;
  76. extern bool _gps_data_good;
  77. extern unsigned long _hdop;
  78. // signed altitude in centimeters (from GPGGA sentence)
  79. inline long altitude(void);
  80. // course in last full GPRMC sentence in 100th of a degree
  81. inline unsigned long course(void);
  82. // speed in last full GPRMC sentence in 100ths of a knot
  83. inline unsigned long speed(void);
  84. // satellites used in last full GPGGA sentence
  85. inline unsigned short satellites(void);
  86. // horizontal dilution of precision in 100ths
  87. inline unsigned long hdop(void);
  88. // internal utilities
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif