nmea gps library - without any serial

Dependents:   HARP2 HARP3 20180621_FT813

Fork of GPS_parser by Tyler Weaver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nmea_parser.h Source File

nmea_parser.h

00001 /*
00002  * @file nmea_parser.h
00003  * @author Tyler Weaver
00004  *
00005  * @section LICENSE
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00008  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00009  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00010  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in all copies or
00014  * substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00017  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00018  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * @section DESCRIPTION
00023  *
00024  * NMEA GPS Serial Output parser.
00025  * Routine taken from NMEA Software Standard (NMEA 0183)
00026  * http://www.winsystems.com/software/nmea.pdf
00027  *
00028  * Only handles GGA and RMC Messages
00029  */
00030 
00031 #include "mbed.h"
00032 
00033 #ifndef MBED_NMEA_PARSER_H
00034 #define MBED_NMEA_PARSER_H
00035 
00036 #define NO_LOCK     1
00037 #define NOT_PARSED  2
00038 #define GGA         3
00039 #define GLL         4
00040 #define RMC         5
00041 #define VTG         6
00042 
00043 #define PI (3.141592653589793)
00044 
00045 /**  A NmeaParser interface for parsing NMEA gps serial output */
00046 class NmeaParser
00047 {
00048 public:
00049 
00050     /**
00051     * Default Constructor
00052     * Initalizes variables
00053     */
00054     NmeaParser();
00055 
00056     /** Parse the incoming GPS data, returning whether there is a lock
00057      *
00058      * Routine from NMEA Software Standard (NMEA 0183)
00059      *
00060      * @param line the nmea string to parse, uses tokenizer vs sscanf 
00061      * @return 1 if there was a lock when the sample was taken (and therefore .longitude and .latitude are valid), else 0
00062      */
00063     int parse(char *);
00064     
00065     /**
00066     * @returns quality of signal (0 = No GPS, 1 = GPS, 2 = DGPS)
00067     */
00068     int quality ();
00069     /**
00070     * From RMC message
00071     * @returns date in ddmmyy format
00072     */
00073     int date();
00074     /**
00075     * @returns time in utc format hhmmss.ss format
00076     */
00077     float utc_time ();
00078     /**
00079     * @returns Longitude in NMEA format dddmm.mm
00080     */
00081     float longitude ();
00082     /**
00083     * @returns Latitude in NMEA format dddmm.mm
00084     */
00085     float latitude ();
00086     /**
00087     * @returns Altitude Mean Sea Level (MSL) in Meters
00088     */
00089     float msl_altitude ();
00090     /**
00091     * @returns track (heading) made good in degrees true.
00092     */
00093     float track ();
00094     /**
00095     * @returns speed over ground in knots
00096     */
00097     float speed ();
00098     /**
00099     * @returns number of satellites in use
00100     */
00101     int satellite_count ();
00102 
00103     /**
00104     * @returns longitude in decimal form (calculated)
00105     */
00106     float calc_dec_longitude ();
00107     /**
00108     * @returns longitude in decimal form (calculated)
00109     */
00110     float calc_dec_latitude ();
00111     /**
00112     * @returns altitude MSL in feet (calculated)
00113     */
00114     float calc_altitude_ft ();
00115     /**
00116     * Initial bearing is the angle to fly at for the shortest flight between two points on a sphere.
00117     * Calculations from: http://www.movable-type.co.uk/scripts/latlong.html
00118     *
00119     * Uses current position and calculates to the inputed point.
00120     *
00121     * @param latitude of target point
00122     * @param longitude of target point
00123     * @returns initial bearing for flying to given point
00124     */
00125     float calc_initial_bearing(float, float);
00126     /**
00127     * Uses the shortest distance across a sphere (haversine formula) to calculate distance
00128     *
00129     * Uses current position and calculates to the inputed point.
00130     *
00131     * @param latitude of target point
00132     * @param longitude of target point
00133     * @returns distance in miles to given point
00134     */
00135     double calc_dist_to_mi(float, float);
00136     /**
00137     * Uses the calc_dist_to_mi then converts to kilometers.
00138     *
00139     * @param latitude of target point
00140     * @param longitude of target point
00141     * @returns distance in kilometers to given point
00142     */
00143     double calc_dist_to_km(float, float);
00144 private:
00145     float nmea_to_dec(float, char);
00146     char *my_token(char *,char);
00147 
00148     char stat_string_[128]; // used in my_token
00149     char *current_;
00150     
00151     char *field_[50]; // used by parse nmea
00152 
00153     // calculated values
00154     volatile float dec_longitude_;
00155     volatile float dec_latitude_;
00156 
00157     // GGA - Global Positioning System Fixed Data
00158     volatile float utc_time_;
00159     volatile float latitude_;
00160     volatile char lat_reference_;
00161     volatile float longitude_;
00162     volatile char long_reference_;
00163     volatile int quality_;
00164     volatile int satellite_count_;
00165     volatile float hdop_;
00166     volatile float msl_altitude_;
00167     volatile char msl_altitude_unit_;
00168 
00169     // RMC - Recommended Minimmum Specific GNS Data
00170     volatile char rmc_status_;
00171     volatile float speed_;
00172     volatile float track_;
00173     volatile int date_;
00174 };
00175 
00176 #endif