GPS_parser.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef GPS_PARSER_H
  2. #define GPS_PARSER_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <esp_timer.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define GPS_PARSER_MAX_FIELD_SIZE 15
  10. #define GPS_PARSER_MPH_PER_KNOT 1.15077945
  11. #define GPS_PARSER_MPS_PER_KNOT 0.51444444
  12. #define GPS_PARSER_KMPH_PER_KNOT 1.852
  13. #define GPS_PARSER_MILES_PER_METER 0.00062137112
  14. #define GPS_PARSER_KM_PER_METER 0.001
  15. #define GPS_PARSER_FEET_PER_METER 3.2808399
  16. #define GPS_PARSER_EARTH_MEAN_RADIUS 6371009
  17. static inline uint32_t gps_parser_millis(void)
  18. {
  19. return (uint32_t)(esp_timer_get_time() / 1000ULL);
  20. }
  21. typedef struct {
  22. uint16_t deg;
  23. uint32_t billionths;
  24. bool negative;
  25. } gps_raw_degrees_t;
  26. typedef struct {
  27. bool valid;
  28. bool updated;
  29. gps_raw_degrees_t rawLatData;
  30. gps_raw_degrees_t rawLngData;
  31. gps_raw_degrees_t rawNewLatData;
  32. gps_raw_degrees_t rawNewLngData;
  33. char fixQuality;
  34. char newFixQuality;
  35. char fixMode;
  36. char newFixMode;
  37. uint32_t lastCommitTime;
  38. } gps_location_t;
  39. typedef struct {
  40. bool valid;
  41. bool updated;
  42. uint32_t date;
  43. uint32_t newDate;
  44. uint32_t lastCommitTime;
  45. } gps_date_t;
  46. typedef struct {
  47. bool valid;
  48. bool updated;
  49. uint32_t time;
  50. uint32_t newTime;
  51. uint32_t lastCommitTime;
  52. } gps_time_t;
  53. typedef struct {
  54. bool valid;
  55. bool updated;
  56. uint32_t lastCommitTime;
  57. int32_t val;
  58. int32_t newval;
  59. } gps_decimal_t;
  60. typedef struct {
  61. bool valid;
  62. bool updated;
  63. uint32_t lastCommitTime;
  64. uint32_t val;
  65. uint32_t newval;
  66. } gps_integer_t;
  67. typedef struct {
  68. uint8_t parity;
  69. bool isChecksumTerm;
  70. char term[GPS_PARSER_MAX_FIELD_SIZE + 1];
  71. uint8_t curSentenceType;
  72. uint8_t curTermNumber;
  73. uint8_t curTermOffset;
  74. bool sentenceHasFix;
  75. gps_location_t location;
  76. gps_date_t date;
  77. gps_time_t time;
  78. gps_decimal_t speed;
  79. gps_decimal_t course;
  80. gps_decimal_t altitude;
  81. gps_integer_t satellites;
  82. gps_decimal_t hdop;
  83. uint32_t encodedCharCount;
  84. uint32_t sentencesWithFixCount;
  85. uint32_t failedChecksumCount;
  86. uint32_t passedChecksumCount;
  87. } gps_parser_t;
  88. void gps_parser_init(gps_parser_t *gps);
  89. bool gps_parser_encode(gps_parser_t *gps, char c);
  90. bool gps_location_is_valid(const gps_location_t *location);
  91. bool gps_location_is_updated(const gps_location_t *location);
  92. uint32_t gps_location_age(const gps_location_t *location);
  93. double gps_location_lat(const gps_location_t *location);
  94. double gps_location_lng(const gps_location_t *location);
  95. char gps_location_fix_quality(const gps_location_t *location);
  96. char gps_location_fix_mode(const gps_location_t *location);
  97. bool gps_date_is_valid(const gps_date_t *date);
  98. uint16_t gps_date_year(const gps_date_t *date);
  99. uint8_t gps_date_month(const gps_date_t *date);
  100. uint8_t gps_date_day(const gps_date_t *date);
  101. bool gps_time_is_valid(const gps_time_t *time);
  102. uint8_t gps_time_hour(const gps_time_t *time);
  103. uint8_t gps_time_minute(const gps_time_t *time);
  104. uint8_t gps_time_second(const gps_time_t *time);
  105. uint8_t gps_time_centisecond(const gps_time_t *time);
  106. bool gps_decimal_is_valid(const gps_decimal_t *value);
  107. int32_t gps_decimal_value(const gps_decimal_t *value);
  108. gps_integer_t *gps_get_satellites(gps_parser_t *gps);
  109. uint32_t gps_parser_chars_processed(const gps_parser_t *gps);
  110. uint32_t gps_parser_sentences_with_fix(const gps_parser_t *gps);
  111. uint32_t gps_parser_failed_checksum(const gps_parser_t *gps);
  112. uint32_t gps_parser_passed_checksum(const gps_parser_t *gps);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif // GPS_PARSER_H