nmea gps library - without any serial
Dependents: HARP2 HARP3 20180621_FT813
Fork of GPS_parser by
NMEA GPS Serial Output parser.
Routine taken from NMEA Software Standard (NMEA 0183) http://www.winsystems.com/software/nmea.pdf
Only handles GGA and RMC Messages
nmea_parser.h@10:a6e1707fdec0, 2012-12-17 (annotated)
- Committer:
- tylerjw
- Date:
- Mon Dec 17 23:42:13 2012 +0000
- Revision:
- 10:a6e1707fdec0
- Parent:
- 9:9b2351e25a84
publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerjw | 9:9b2351e25a84 | 1 | /* |
tylerjw | 9:9b2351e25a84 | 2 | * @file nmea_parser.h |
tylerjw | 9:9b2351e25a84 | 3 | * @author Tyler Weaver |
tylerjw | 9:9b2351e25a84 | 4 | * |
tylerjw | 9:9b2351e25a84 | 5 | * @section LICENSE |
tylerjw | 9:9b2351e25a84 | 6 | * |
tylerjw | 9:9b2351e25a84 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
tylerjw | 9:9b2351e25a84 | 8 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
tylerjw | 9:9b2351e25a84 | 9 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
tylerjw | 9:9b2351e25a84 | 10 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
tylerjw | 9:9b2351e25a84 | 11 | * furnished to do so, subject to the following conditions: |
tylerjw | 9:9b2351e25a84 | 12 | * |
tylerjw | 9:9b2351e25a84 | 13 | * The above copyright notice and this permission notice shall be included in all copies or |
tylerjw | 9:9b2351e25a84 | 14 | * substantial portions of the Software. |
tylerjw | 9:9b2351e25a84 | 15 | * |
tylerjw | 9:9b2351e25a84 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
tylerjw | 9:9b2351e25a84 | 17 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
tylerjw | 9:9b2351e25a84 | 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
tylerjw | 9:9b2351e25a84 | 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
tylerjw | 9:9b2351e25a84 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
tylerjw | 9:9b2351e25a84 | 21 | * |
tylerjw | 9:9b2351e25a84 | 22 | * @section DESCRIPTION |
tylerjw | 9:9b2351e25a84 | 23 | * |
tylerjw | 9:9b2351e25a84 | 24 | * NMEA GPS Serial Output parser. |
tylerjw | 9:9b2351e25a84 | 25 | * Routine taken from NMEA Software Standard (NMEA 0183) |
tylerjw | 9:9b2351e25a84 | 26 | * http://www.winsystems.com/software/nmea.pdf |
tylerjw | 9:9b2351e25a84 | 27 | * |
tylerjw | 9:9b2351e25a84 | 28 | * Only handles GGA and RMC Messages |
tylerjw | 9:9b2351e25a84 | 29 | */ |
tylerjw | 9:9b2351e25a84 | 30 | |
tylerjw | 5:94daced1e61a | 31 | #include "mbed.h" |
tylerjw | 5:94daced1e61a | 32 | |
tylerjw | 9:9b2351e25a84 | 33 | #ifndef MBED_NMEA_PARSER_H |
tylerjw | 9:9b2351e25a84 | 34 | #define MBED_NMEA_PARSER_H |
tylerjw | 5:94daced1e61a | 35 | |
tylerjw | 5:94daced1e61a | 36 | #define NO_LOCK 1 |
tylerjw | 5:94daced1e61a | 37 | #define NOT_PARSED 2 |
tylerjw | 5:94daced1e61a | 38 | #define GGA 3 |
tylerjw | 5:94daced1e61a | 39 | #define GLL 4 |
tylerjw | 5:94daced1e61a | 40 | #define RMC 5 |
tylerjw | 5:94daced1e61a | 41 | #define VTG 6 |
tylerjw | 5:94daced1e61a | 42 | |
tylerjw | 5:94daced1e61a | 43 | #define PI (3.141592653589793) |
tylerjw | 5:94daced1e61a | 44 | |
tylerjw | 9:9b2351e25a84 | 45 | /** A NmeaParser interface for parsing NMEA gps serial output */ |
tylerjw | 9:9b2351e25a84 | 46 | class NmeaParser |
tylerjw | 7:01a8379370e4 | 47 | { |
tylerjw | 5:94daced1e61a | 48 | public: |
tylerjw | 5:94daced1e61a | 49 | |
tylerjw | 9:9b2351e25a84 | 50 | /** |
tylerjw | 9:9b2351e25a84 | 51 | * Default Constructor |
tylerjw | 9:9b2351e25a84 | 52 | * Initalizes variables |
tylerjw | 9:9b2351e25a84 | 53 | */ |
tylerjw | 9:9b2351e25a84 | 54 | NmeaParser(); |
tylerjw | 7:01a8379370e4 | 55 | |
tylerjw | 7:01a8379370e4 | 56 | /** Parse the incoming GPS data, returning whether there is a lock |
tylerjw | 7:01a8379370e4 | 57 | * |
tylerjw | 9:9b2351e25a84 | 58 | * Routine from NMEA Software Standard (NMEA 0183) |
tylerjw | 9:9b2351e25a84 | 59 | * |
tylerjw | 7:01a8379370e4 | 60 | * @param line the nmea string to parse, uses tokenizer vs sscanf |
tylerjw | 5:94daced1e61a | 61 | * @return 1 if there was a lock when the sample was taken (and therefore .longitude and .latitude are valid), else 0 |
tylerjw | 5:94daced1e61a | 62 | */ |
tylerjw | 7:01a8379370e4 | 63 | int parse(char *); |
tylerjw | 9:9b2351e25a84 | 64 | |
tylerjw | 9:9b2351e25a84 | 65 | /** |
tylerjw | 9:9b2351e25a84 | 66 | * @returns quality of signal (0 = No GPS, 1 = GPS, 2 = DGPS) |
tylerjw | 9:9b2351e25a84 | 67 | */ |
tylerjw | 9:9b2351e25a84 | 68 | int quality(); |
tylerjw | 9:9b2351e25a84 | 69 | /** |
tylerjw | 9:9b2351e25a84 | 70 | * From RMC message |
tylerjw | 9:9b2351e25a84 | 71 | * @returns date in ddmmyy format |
tylerjw | 9:9b2351e25a84 | 72 | */ |
tylerjw | 9:9b2351e25a84 | 73 | int date(); |
tylerjw | 9:9b2351e25a84 | 74 | /** |
tylerjw | 9:9b2351e25a84 | 75 | * @returns time in utc format hhmmss.ss format |
tylerjw | 9:9b2351e25a84 | 76 | */ |
tylerjw | 9:9b2351e25a84 | 77 | float utc_time(); |
tylerjw | 9:9b2351e25a84 | 78 | /** |
tylerjw | 9:9b2351e25a84 | 79 | * @returns Longitude in NMEA format dddmm.mm |
tylerjw | 9:9b2351e25a84 | 80 | */ |
tylerjw | 9:9b2351e25a84 | 81 | float longitude(); |
tylerjw | 9:9b2351e25a84 | 82 | /** |
tylerjw | 9:9b2351e25a84 | 83 | * @returns Latitude in NMEA format dddmm.mm |
tylerjw | 9:9b2351e25a84 | 84 | */ |
tylerjw | 9:9b2351e25a84 | 85 | float latitude(); |
tylerjw | 9:9b2351e25a84 | 86 | /** |
tylerjw | 9:9b2351e25a84 | 87 | * @returns Altitude Mean Sea Level (MSL) in Meters |
tylerjw | 9:9b2351e25a84 | 88 | */ |
tylerjw | 9:9b2351e25a84 | 89 | float msl_altitude(); |
tylerjw | 9:9b2351e25a84 | 90 | /** |
tylerjw | 9:9b2351e25a84 | 91 | * @returns track (heading) made good in degrees true. |
tylerjw | 9:9b2351e25a84 | 92 | */ |
tylerjw | 9:9b2351e25a84 | 93 | float track(); |
tylerjw | 9:9b2351e25a84 | 94 | /** |
tylerjw | 9:9b2351e25a84 | 95 | * @returns speed over ground in knots |
tylerjw | 9:9b2351e25a84 | 96 | */ |
tylerjw | 9:9b2351e25a84 | 97 | float speed(); |
tylerjw | 9:9b2351e25a84 | 98 | /** |
tylerjw | 9:9b2351e25a84 | 99 | * @returns number of satellites in use |
tylerjw | 9:9b2351e25a84 | 100 | */ |
tylerjw | 9:9b2351e25a84 | 101 | int satellite_count(); |
tylerjw | 7:01a8379370e4 | 102 | |
tylerjw | 9:9b2351e25a84 | 103 | /** |
tylerjw | 9:9b2351e25a84 | 104 | * @returns longitude in decimal form (calculated) |
tylerjw | 9:9b2351e25a84 | 105 | */ |
tylerjw | 9:9b2351e25a84 | 106 | float calc_dec_longitude(); |
tylerjw | 9:9b2351e25a84 | 107 | /** |
tylerjw | 9:9b2351e25a84 | 108 | * @returns longitude in decimal form (calculated) |
tylerjw | 9:9b2351e25a84 | 109 | */ |
tylerjw | 9:9b2351e25a84 | 110 | float calc_dec_latitude(); |
tylerjw | 9:9b2351e25a84 | 111 | /** |
tylerjw | 9:9b2351e25a84 | 112 | * @returns altitude MSL in feet (calculated) |
tylerjw | 9:9b2351e25a84 | 113 | */ |
tylerjw | 9:9b2351e25a84 | 114 | float calc_altitude_ft(); |
tylerjw | 9:9b2351e25a84 | 115 | /** |
tylerjw | 9:9b2351e25a84 | 116 | * Initial bearing is the angle to fly at for the shortest flight between two points on a sphere. |
tylerjw | 9:9b2351e25a84 | 117 | * Calculations from: http://www.movable-type.co.uk/scripts/latlong.html |
tylerjw | 9:9b2351e25a84 | 118 | * |
tylerjw | 9:9b2351e25a84 | 119 | * Uses current position and calculates to the inputed point. |
tylerjw | 9:9b2351e25a84 | 120 | * |
tylerjw | 9:9b2351e25a84 | 121 | * @param latitude of target point |
tylerjw | 9:9b2351e25a84 | 122 | * @param longitude of target point |
tylerjw | 9:9b2351e25a84 | 123 | * @returns initial bearing for flying to given point |
tylerjw | 9:9b2351e25a84 | 124 | */ |
tylerjw | 9:9b2351e25a84 | 125 | float calc_initial_bearing(float, float); |
tylerjw | 9:9b2351e25a84 | 126 | /** |
tylerjw | 9:9b2351e25a84 | 127 | * Uses the shortest distance across a sphere (haversine formula) to calculate distance |
tylerjw | 9:9b2351e25a84 | 128 | * |
tylerjw | 9:9b2351e25a84 | 129 | * Uses current position and calculates to the inputed point. |
tylerjw | 9:9b2351e25a84 | 130 | * |
tylerjw | 9:9b2351e25a84 | 131 | * @param latitude of target point |
tylerjw | 9:9b2351e25a84 | 132 | * @param longitude of target point |
tylerjw | 9:9b2351e25a84 | 133 | * @returns distance in miles to given point |
tylerjw | 9:9b2351e25a84 | 134 | */ |
tylerjw | 5:94daced1e61a | 135 | double calc_dist_to_mi(float, float); |
tylerjw | 9:9b2351e25a84 | 136 | /** |
tylerjw | 9:9b2351e25a84 | 137 | * Uses the calc_dist_to_mi then converts to kilometers. |
tylerjw | 9:9b2351e25a84 | 138 | * |
tylerjw | 9:9b2351e25a84 | 139 | * @param latitude of target point |
tylerjw | 9:9b2351e25a84 | 140 | * @param longitude of target point |
tylerjw | 9:9b2351e25a84 | 141 | * @returns distance in kilometers to given point |
tylerjw | 9:9b2351e25a84 | 142 | */ |
tylerjw | 5:94daced1e61a | 143 | double calc_dist_to_km(float, float); |
tylerjw | 5:94daced1e61a | 144 | private: |
tylerjw | 5:94daced1e61a | 145 | float nmea_to_dec(float, char); |
tylerjw | 7:01a8379370e4 | 146 | char *my_token(char *,char); |
tylerjw | 7:01a8379370e4 | 147 | |
tylerjw | 9:9b2351e25a84 | 148 | char stat_string_[128]; // used in my_token |
tylerjw | 9:9b2351e25a84 | 149 | char *current_; |
tylerjw | 5:94daced1e61a | 150 | |
tylerjw | 9:9b2351e25a84 | 151 | char *field_[50]; // used by parse nmea |
tylerjw | 7:01a8379370e4 | 152 | |
tylerjw | 5:94daced1e61a | 153 | // calculated values |
tylerjw | 9:9b2351e25a84 | 154 | volatile float dec_longitude_; |
tylerjw | 9:9b2351e25a84 | 155 | volatile float dec_latitude_; |
tylerjw | 7:01a8379370e4 | 156 | |
tylerjw | 5:94daced1e61a | 157 | // GGA - Global Positioning System Fixed Data |
tylerjw | 9:9b2351e25a84 | 158 | volatile float utc_time_; |
tylerjw | 9:9b2351e25a84 | 159 | volatile float latitude_; |
tylerjw | 9:9b2351e25a84 | 160 | volatile char lat_reference_; |
tylerjw | 9:9b2351e25a84 | 161 | volatile float longitude_; |
tylerjw | 9:9b2351e25a84 | 162 | volatile char long_reference_; |
tylerjw | 9:9b2351e25a84 | 163 | volatile int quality_; |
tylerjw | 9:9b2351e25a84 | 164 | volatile int satellite_count_; |
tylerjw | 9:9b2351e25a84 | 165 | volatile float hdop_; |
tylerjw | 9:9b2351e25a84 | 166 | volatile float msl_altitude_; |
tylerjw | 9:9b2351e25a84 | 167 | volatile char msl_altitude_unit_; |
tylerjw | 7:01a8379370e4 | 168 | |
tylerjw | 5:94daced1e61a | 169 | // RMC - Recommended Minimmum Specific GNS Data |
tylerjw | 9:9b2351e25a84 | 170 | volatile char rmc_status_; |
tylerjw | 9:9b2351e25a84 | 171 | volatile float speed_; |
tylerjw | 9:9b2351e25a84 | 172 | volatile float track_; |
tylerjw | 9:9b2351e25a84 | 173 | volatile int date_; |
tylerjw | 5:94daced1e61a | 174 | }; |
tylerjw | 5:94daced1e61a | 175 | |
tylerjw | 5:94daced1e61a | 176 | #endif |