nmea gps library

Dependents:   mDot_LoRa_Connect_CSA_Light mDot_LoRa_Connect_CSA_Rain mDot_LoRa_Connect_CSA_RH_Temp mDot_LoRa_Connect_CSA_Thermistor

Committer:
tylerjw
Date:
Fri Nov 23 19:57:17 2012 +0000
Revision:
1:39d75e44b214
Parent:
0:3611af72bfd7
gps library for micro track gps (nmea); location correct; distance and heading incorrect

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:3611af72bfd7 1 #include "mbed.h"
tylerjw 0:3611af72bfd7 2
tylerjw 0:3611af72bfd7 3 #ifndef MBED_GPS_H
tylerjw 0:3611af72bfd7 4 #define MBED_GPS_H
tylerjw 0:3611af72bfd7 5
tylerjw 0:3611af72bfd7 6 #define NO_LOCK 1
tylerjw 0:3611af72bfd7 7 #define NOT_PARSED 2
tylerjw 0:3611af72bfd7 8 #define GGA 3
tylerjw 0:3611af72bfd7 9 #define GLL 4
tylerjw 0:3611af72bfd7 10 #define RMC 5
tylerjw 0:3611af72bfd7 11 #define VTG 6
tylerjw 0:3611af72bfd7 12
tylerjw 0:3611af72bfd7 13 #define PI (3.141592653589793)
tylerjw 0:3611af72bfd7 14
tylerjw 0:3611af72bfd7 15 /** A GPS interface for reading from a Globalsat EM-406 GPS Module */
tylerjw 0:3611af72bfd7 16 class GPS {
tylerjw 0:3611af72bfd7 17 public:
tylerjw 0:3611af72bfd7 18
tylerjw 0:3611af72bfd7 19 /** Create the GPS interface, connected to the specified serial port
tylerjw 0:3611af72bfd7 20 */
tylerjw 0:3611af72bfd7 21 GPS(PinName tx, PinName rx);
tylerjw 0:3611af72bfd7 22
tylerjw 0:3611af72bfd7 23 /** Sample the incoming GPS data, returning whether there is a lock
tylerjw 0:3611af72bfd7 24 *
tylerjw 0:3611af72bfd7 25 * @return 1 if there was a lock when the sample was taken (and therefore .longitude and .latitude are valid), else 0
tylerjw 0:3611af72bfd7 26 */
tylerjw 0:3611af72bfd7 27 int sample();
tylerjw 0:3611af72bfd7 28 float get_nmea_longitude();
tylerjw 0:3611af72bfd7 29 float get_nmea_latitude();
tylerjw 0:3611af72bfd7 30 float get_dec_longitude();
tylerjw 0:3611af72bfd7 31 float get_dec_latitude();
tylerjw 0:3611af72bfd7 32 float get_msl_altitude();
tylerjw 0:3611af72bfd7 33 float get_course_t();
tylerjw 0:3611af72bfd7 34 float get_course_m();
tylerjw 0:3611af72bfd7 35 float get_speed_k();
tylerjw 0:3611af72bfd7 36 float get_speed_km();
tylerjw 0:3611af72bfd7 37 int get_satelites();
tylerjw 0:3611af72bfd7 38 float get_altitude_ft();
tylerjw 0:3611af72bfd7 39
tylerjw 0:3611af72bfd7 40 // navigational functions
tylerjw 0:3611af72bfd7 41 float calc_course_to(float, float);
tylerjw 0:3611af72bfd7 42 double calc_dist_to_mi(float, float);
tylerjw 0:3611af72bfd7 43 double calc_dist_to_ft(float, float);
tylerjw 0:3611af72bfd7 44 double calc_dist_to_km(float, float);
tylerjw 0:3611af72bfd7 45 double calc_dist_to_m(float, float);
tylerjw 0:3611af72bfd7 46
tylerjw 0:3611af72bfd7 47 #ifdef OPEN_LOG
tylerjw 0:3611af72bfd7 48 void start_log(void);
tylerjw 0:3611af72bfd7 49 void new_file(void);
tylerjw 0:3611af72bfd7 50 void stop_log(void);
tylerjw 0:3611af72bfd7 51 #endif
tylerjw 0:3611af72bfd7 52
tylerjw 0:3611af72bfd7 53 private:
tylerjw 0:3611af72bfd7 54 float nmea_to_dec(float, char);
tylerjw 0:3611af72bfd7 55 float trunc(float v);
tylerjw 0:3611af72bfd7 56 void getline();
tylerjw 0:3611af72bfd7 57 void format_for_log(void);
tylerjw 0:3611af72bfd7 58
tylerjw 0:3611af72bfd7 59 Serial _gps;
tylerjw 0:3611af72bfd7 60 char msg[1024];
tylerjw 0:3611af72bfd7 61 char bfr[1030];
tylerjw 0:3611af72bfd7 62 bool is_logging;
tylerjw 0:3611af72bfd7 63 #ifdef OPEN_LOG
tylerjw 0:3611af72bfd7 64 Logger _openLog;
tylerjw 0:3611af72bfd7 65 #endif
tylerjw 0:3611af72bfd7 66 // calculated values
tylerjw 0:3611af72bfd7 67 float dec_longitude;
tylerjw 0:3611af72bfd7 68 float dec_latitude;
tylerjw 0:3611af72bfd7 69 float altitude_ft;
tylerjw 0:3611af72bfd7 70
tylerjw 0:3611af72bfd7 71 // GGA - Global Positioning System Fixed Data
tylerjw 0:3611af72bfd7 72 float nmea_longitude;
tylerjw 0:3611af72bfd7 73 float nmea_latitude;
tylerjw 0:3611af72bfd7 74 float utc_time;
tylerjw 0:3611af72bfd7 75 char ns, ew;
tylerjw 0:3611af72bfd7 76 int lock;
tylerjw 0:3611af72bfd7 77 int satelites;
tylerjw 0:3611af72bfd7 78 float hdop;
tylerjw 0:3611af72bfd7 79 float msl_altitude;
tylerjw 0:3611af72bfd7 80 char msl_units;
tylerjw 0:3611af72bfd7 81
tylerjw 0:3611af72bfd7 82 // RMC - Recommended Minimmum Specific GNS Data
tylerjw 0:3611af72bfd7 83 char rmc_status;
tylerjw 0:3611af72bfd7 84 float speed_k;
tylerjw 0:3611af72bfd7 85 float course_d;
tylerjw 0:3611af72bfd7 86 int date;
tylerjw 0:3611af72bfd7 87
tylerjw 0:3611af72bfd7 88 // GLL
tylerjw 0:3611af72bfd7 89 char gll_status;
tylerjw 0:3611af72bfd7 90
tylerjw 0:3611af72bfd7 91 // VTG - Course over ground, ground speed
tylerjw 0:3611af72bfd7 92 float course_t; // ground speed true
tylerjw 0:3611af72bfd7 93 char course_t_unit;
tylerjw 0:3611af72bfd7 94 float course_m; // magnetic
tylerjw 0:3611af72bfd7 95 char course_m_unit;
tylerjw 0:3611af72bfd7 96 char speed_k_unit;
tylerjw 0:3611af72bfd7 97 float speed_km; // speek km/hr
tylerjw 0:3611af72bfd7 98 char speed_km_unit;
tylerjw 0:3611af72bfd7 99 };
tylerjw 0:3611af72bfd7 100
tylerjw 0:3611af72bfd7 101 #endif