2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
GPS/NMEA.h@44:0d72a8a1288a, 2019-01-07 (annotated)
- Committer:
- shimniok
- Date:
- Mon Jan 07 16:47:33 2019 +0000
- Revision:
- 44:0d72a8a1288a
Rewrote TinyGPS -> NMEA, GPS::read() now returns struct
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 44:0d72a8a1288a | 1 | /* NMEA - a small NMEA-parsing library based on TinyGPS |
shimniok | 44:0d72a8a1288a | 2 | |
shimniok | 44:0d72a8a1288a | 3 | TinyGPS - a small GPS library for Arduino providing basic NMEA parsing |
shimniok | 44:0d72a8a1288a | 4 | Copyright (C) 2008-9 Mikal Hart |
shimniok | 44:0d72a8a1288a | 5 | All rights reserved. |
shimniok | 44:0d72a8a1288a | 6 | |
shimniok | 44:0d72a8a1288a | 7 | This library is free software; you can redistribute it and/or |
shimniok | 44:0d72a8a1288a | 8 | modify it under the terms of the GNU Lesser General Public |
shimniok | 44:0d72a8a1288a | 9 | License as published by the Free Software Foundation; either |
shimniok | 44:0d72a8a1288a | 10 | version 2.1 of the License, or (at your option) any later version. |
shimniok | 44:0d72a8a1288a | 11 | |
shimniok | 44:0d72a8a1288a | 12 | This library is distributed in the hope that it will be useful, |
shimniok | 44:0d72a8a1288a | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
shimniok | 44:0d72a8a1288a | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
shimniok | 44:0d72a8a1288a | 15 | Lesser General Public License for more details. |
shimniok | 44:0d72a8a1288a | 16 | |
shimniok | 44:0d72a8a1288a | 17 | You should have received a copy of the GNU Lesser General Public |
shimniok | 44:0d72a8a1288a | 18 | License along with this library; if not, write to the Free Software |
shimniok | 44:0d72a8a1288a | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
shimniok | 44:0d72a8a1288a | 20 | |
shimniok | 44:0d72a8a1288a | 21 | Ported to mbed by Michael Shimniok |
shimniok | 44:0d72a8a1288a | 22 | */ |
shimniok | 44:0d72a8a1288a | 23 | |
shimniok | 44:0d72a8a1288a | 24 | #ifdef __MBED__ |
shimniok | 44:0d72a8a1288a | 25 | #include "mbed.h" |
shimniok | 44:0d72a8a1288a | 26 | #endif |
shimniok | 44:0d72a8a1288a | 27 | |
shimniok | 44:0d72a8a1288a | 28 | #include <stdint.h> |
shimniok | 44:0d72a8a1288a | 29 | #include <ctype.h> |
shimniok | 44:0d72a8a1288a | 30 | #include "GPS.h" |
shimniok | 44:0d72a8a1288a | 31 | |
shimniok | 44:0d72a8a1288a | 32 | #ifndef __NMEA_h |
shimniok | 44:0d72a8a1288a | 33 | #define __NMEA_h |
shimniok | 44:0d72a8a1288a | 34 | |
shimniok | 44:0d72a8a1288a | 35 | #define _GPS_VERSION 9 // software version of this library |
shimniok | 44:0d72a8a1288a | 36 | #define _GPS_MPH_PER_KNOT 1.15077945 |
shimniok | 44:0d72a8a1288a | 37 | #define _GPS_MPS_PER_KNOT 0.51444444 |
shimniok | 44:0d72a8a1288a | 38 | #define _GPS_KMPH_PER_KNOT 1.852 |
shimniok | 44:0d72a8a1288a | 39 | #define _GPS_MILES_PER_METER 0.00062137112 |
shimniok | 44:0d72a8a1288a | 40 | #define _GPS_KM_PER_METER 0.001 |
shimniok | 44:0d72a8a1288a | 41 | |
shimniok | 44:0d72a8a1288a | 42 | /** An library parsing for parsing select NMEA-0183 sentences |
shimniok | 44:0d72a8a1288a | 43 | * @author Michael Shimniok |
shimniok | 44:0d72a8a1288a | 44 | */ |
shimniok | 44:0d72a8a1288a | 45 | class NMEA: public GPS { |
shimniok | 44:0d72a8a1288a | 46 | public: |
shimniok | 44:0d72a8a1288a | 47 | typedef uint8_t byte; |
shimniok | 44:0d72a8a1288a | 48 | |
shimniok | 44:0d72a8a1288a | 49 | /** Create a new GPS parsing object for parsing NMEA sentences |
shimniok | 44:0d72a8a1288a | 50 | */ |
shimniok | 44:0d72a8a1288a | 51 | NMEA(); |
shimniok | 44:0d72a8a1288a | 52 | |
shimniok | 44:0d72a8a1288a | 53 | /** Parse a single character received from GPS |
shimniok | 44:0d72a8a1288a | 54 | * |
shimniok | 44:0d72a8a1288a | 55 | * @param c is the character received from the GPS |
shimniok | 44:0d72a8a1288a | 56 | * @returns 1 when all sentences received |
shimniok | 44:0d72a8a1288a | 57 | */ |
shimniok | 44:0d72a8a1288a | 58 | virtual int parse(char c); |
shimniok | 44:0d72a8a1288a | 59 | |
shimniok | 44:0d72a8a1288a | 60 | #ifndef _GPS_NO_STATS |
shimniok | 44:0d72a8a1288a | 61 | void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs); |
shimniok | 44:0d72a8a1288a | 62 | #endif |
shimniok | 44:0d72a8a1288a | 63 | |
shimniok | 44:0d72a8a1288a | 64 | /** determine if all sentences parsed |
shimniok | 44:0d72a8a1288a | 65 | * |
shimniok | 44:0d72a8a1288a | 66 | */ |
shimniok | 44:0d72a8a1288a | 67 | inline bool ready() { |
shimniok | 44:0d72a8a1288a | 68 | if (_rmc_ready && _gga_ready) { |
shimniok | 44:0d72a8a1288a | 69 | _rmc_ready = _gga_ready = false; |
shimniok | 44:0d72a8a1288a | 70 | return true; |
shimniok | 44:0d72a8a1288a | 71 | } else { |
shimniok | 44:0d72a8a1288a | 72 | return false; |
shimniok | 44:0d72a8a1288a | 73 | } |
shimniok | 44:0d72a8a1288a | 74 | } |
shimniok | 44:0d72a8a1288a | 75 | |
shimniok | 44:0d72a8a1288a | 76 | /** Reset the ready flags for all the parsed sentences |
shimniok | 44:0d72a8a1288a | 77 | */ |
shimniok | 44:0d72a8a1288a | 78 | inline void reset_ready() { _rmc_ready = _gga_ready = false; } |
shimniok | 44:0d72a8a1288a | 79 | |
shimniok | 44:0d72a8a1288a | 80 | enum {GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999, GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0, |
shimniok | 44:0d72a8a1288a | 81 | GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999, GPS_INVALID_FIX_TIME = 0xFFFFFFFF}; |
shimniok | 44:0d72a8a1288a | 82 | |
shimniok | 44:0d72a8a1288a | 83 | private: |
shimniok | 44:0d72a8a1288a | 84 | enum {_GPS_SENTENCE_GPGGA=0x10, _GPS_SENTENCE_GPRMC=0x20, _GPS_SENTENCE_GPGSV=0x40, _GPS_SENTENCE_OTHER=0}; |
shimniok | 44:0d72a8a1288a | 85 | |
shimniok | 44:0d72a8a1288a | 86 | // properties |
shimniok | 44:0d72a8a1288a | 87 | int _new_time; |
shimniok | 44:0d72a8a1288a | 88 | int _new_hour; |
shimniok | 44:0d72a8a1288a | 89 | int _new_minute; |
shimniok | 44:0d72a8a1288a | 90 | int _new_second; |
shimniok | 44:0d72a8a1288a | 91 | int _new_date; |
shimniok | 44:0d72a8a1288a | 92 | int _new_month; |
shimniok | 44:0d72a8a1288a | 93 | int _new_year; |
shimniok | 44:0d72a8a1288a | 94 | double _new_latitude; |
shimniok | 44:0d72a8a1288a | 95 | double _new_longitude; |
shimniok | 44:0d72a8a1288a | 96 | long _altitude; |
shimniok | 44:0d72a8a1288a | 97 | float _new_altitude; |
shimniok | 44:0d72a8a1288a | 98 | float _new_speed; |
shimniok | 44:0d72a8a1288a | 99 | float _new_course; |
shimniok | 44:0d72a8a1288a | 100 | float _new_hdop; |
shimniok | 44:0d72a8a1288a | 101 | unsigned int _new_sat_count; |
shimniok | 44:0d72a8a1288a | 102 | unsigned long _last_time_fix, _new_time_fix; |
shimniok | 44:0d72a8a1288a | 103 | unsigned long _last_position_fix, _new_position_fix; |
shimniok | 44:0d72a8a1288a | 104 | |
shimniok | 44:0d72a8a1288a | 105 | // parsing state variables |
shimniok | 44:0d72a8a1288a | 106 | byte _parity; |
shimniok | 44:0d72a8a1288a | 107 | bool _is_checksum_term; |
shimniok | 44:0d72a8a1288a | 108 | char _term[15]; |
shimniok | 44:0d72a8a1288a | 109 | byte _sentence_type; |
shimniok | 44:0d72a8a1288a | 110 | byte _term_number; |
shimniok | 44:0d72a8a1288a | 111 | uint8_t _term_offset; |
shimniok | 44:0d72a8a1288a | 112 | bool _gps_data_good; |
shimniok | 44:0d72a8a1288a | 113 | bool _rmc_ready; |
shimniok | 44:0d72a8a1288a | 114 | bool _gga_ready; |
shimniok | 44:0d72a8a1288a | 115 | |
shimniok | 44:0d72a8a1288a | 116 | double parse_degrees(); |
shimniok | 44:0d72a8a1288a | 117 | int from_hex(char a); |
shimniok | 44:0d72a8a1288a | 118 | int parse_int(); |
shimniok | 44:0d72a8a1288a | 119 | double parse_decimal(); |
shimniok | 44:0d72a8a1288a | 120 | bool term_complete(); |
shimniok | 44:0d72a8a1288a | 121 | bool gpsisdigit(char c) { return c >= '0' && c <= '9'; } |
shimniok | 44:0d72a8a1288a | 122 | int gpsstrcmp(const char *str1, const char *str2); |
shimniok | 44:0d72a8a1288a | 123 | }; |
shimniok | 44:0d72a8a1288a | 124 | |
shimniok | 44:0d72a8a1288a | 125 | #endif |