GPS code for Adafruit ultimate GPS

Dependents:   demo_gps_sdcard zeus

Fork of GPS by Simon Ford

Committer:
cmkachur
Date:
Tue Sep 22 23:05:13 2015 +0000
Revision:
2:509abe8eda59
Parent:
1:35fcaa2209af
Add ability to read and store analog input data for the phase detectors. ; Allow use of $GPGGA for GPS fix. ; Code refactoring.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:15611c7938a3 1 /* mbed EM-406 GPS Module Library
simon 0:15611c7938a3 2 * Copyright (c) 2008-2010, sford
simon 0:15611c7938a3 3 *
simon 0:15611c7938a3 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:15611c7938a3 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:15611c7938a3 6 * in the Software without restriction, including without limitation the rights
simon 0:15611c7938a3 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:15611c7938a3 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:15611c7938a3 9 * furnished to do so, subject to the following conditions:
simon 0:15611c7938a3 10 *
simon 0:15611c7938a3 11 * The above copyright notice and this permission notice shall be included in
simon 0:15611c7938a3 12 * all copies or substantial portions of the Software.
simon 0:15611c7938a3 13 *
simon 0:15611c7938a3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:15611c7938a3 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:15611c7938a3 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:15611c7938a3 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:15611c7938a3 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:15611c7938a3 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:15611c7938a3 20 * THE SOFTWARE.
simon 0:15611c7938a3 21 */
simon 0:15611c7938a3 22
simon 0:15611c7938a3 23 #include "mbed.h"
ftagius 1:35fcaa2209af 24 #include <stdint.h>
ftagius 1:35fcaa2209af 25 #include <math.h>
ftagius 1:35fcaa2209af 26 #include <ctype.h>
simon 0:15611c7938a3 27
simon 0:15611c7938a3 28 #ifndef MBED_GPS_H
simon 0:15611c7938a3 29 #define MBED_GPS_H
simon 0:15611c7938a3 30
ftagius 1:35fcaa2209af 31 // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
ftagius 1:35fcaa2209af 32 #define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F"
ftagius 1:35fcaa2209af 33 #define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C"
ftagius 1:35fcaa2209af 34 #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
ftagius 1:35fcaa2209af 35 #define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C"
ftagius 1:35fcaa2209af 36 #define PMTK_SET_BAUD_9600 "$PMTK251,9600*17"
ftagius 1:35fcaa2209af 37 // turn on only the second sentence (GPRMC)
ftagius 1:35fcaa2209af 38 #define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
ftagius 1:35fcaa2209af 39 // turn on gga only
ftagius 1:35fcaa2209af 40 #define PMTK_SET_NMEA_OUTPUT_GGA "$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
ftagius 1:35fcaa2209af 41 // turn on GPRMC and GGA
ftagius 1:35fcaa2209af 42 #define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
ftagius 1:35fcaa2209af 43 // turn on ALL THE DATA
ftagius 1:35fcaa2209af 44 #define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
ftagius 1:35fcaa2209af 45 // turn on gga and gsv
ftagius 1:35fcaa2209af 46 #define PMTK_SET_NMEA_OUTPUT_GGA_GSV "$PMTK314,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
ftagius 1:35fcaa2209af 47 // trun on gsv only
ftagius 1:35fcaa2209af 48 #define PMTK_SET_NMEA_OUTPUT_GSV "$PMTK314,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
ftagius 1:35fcaa2209af 49 // turn off output
ftagius 1:35fcaa2209af 50 #define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
ftagius 1:35fcaa2209af 51 // turn on gpzda
ftagius 1:35fcaa2209af 52 #define PMTK_SET_NMEA_OUTPUT_GPZDA "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*29"
ftagius 1:35fcaa2209af 53 // turn oh gpzda and gga
ftagius 1:35fcaa2209af 54 #define PMTK_SET_NMEA_OUTPUT_GPZDA_GGA "$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*28"
ftagius 1:35fcaa2209af 55 // turn on VTG, GGA and GSA. GSA is only sent once every five transmissions.
ftagius 1:35fcaa2209af 56 #define PMTK_SET_NMEA_OUTPUT_VTG_GGA_GSA "$PMTK314,0,0,1,1,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2D"
ftagius 1:35fcaa2209af 57 // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator
ftagius 1:35fcaa2209af 58 // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html
ftagius 1:35fcaa2209af 59
ftagius 1:35fcaa2209af 60 #define PMTK_LOCUS_STARTLOG "$PMTK185,0*22"
ftagius 1:35fcaa2209af 61 #define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C"
ftagius 1:35fcaa2209af 62 #define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38"
ftagius 1:35fcaa2209af 63 #define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22"
ftagius 1:35fcaa2209af 64 #define LOCUS_OVERLAP 0
ftagius 1:35fcaa2209af 65 #define LOCUS_FULLSTOP 1
ftagius 1:35fcaa2209af 66
ftagius 1:35fcaa2209af 67 // standby command & boot successful message
ftagius 1:35fcaa2209af 68 #define PMTK_STANDBY "$PMTK161,0*28"
ftagius 1:35fcaa2209af 69 #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36" // Not needed currently
ftagius 1:35fcaa2209af 70 #define PMTK_AWAKE "$PMTK010,002*2D"
ftagius 1:35fcaa2209af 71
ftagius 1:35fcaa2209af 72 // ask for the release and version
ftagius 1:35fcaa2209af 73 #define PMTK_Q_RELEASE "$PMTK605*31"
ftagius 1:35fcaa2209af 74
ftagius 1:35fcaa2209af 75 // request for updates on antenna status
ftagius 1:35fcaa2209af 76 #define PGCMD_ANTENNA "$PGCMD,33,1*6C"
ftagius 1:35fcaa2209af 77 #define PGCMD_NOANTENNA "$PGCMD,33,0*6D"
ftagius 1:35fcaa2209af 78
ftagius 1:35fcaa2209af 79 // how long to wait when we're looking for a response
ftagius 1:35fcaa2209af 80 #define MAXWAITSENTENCE 5
ftagius 1:35fcaa2209af 81
simon 0:15611c7938a3 82 /** A GPS interface for reading from a Globalsat EM-406 GPS Module */
simon 0:15611c7938a3 83 class GPS {
simon 0:15611c7938a3 84 public:
simon 0:15611c7938a3 85
simon 0:15611c7938a3 86 /** Create the GPS interface, connected to the specified serial port
simon 0:15611c7938a3 87 */
simon 0:15611c7938a3 88 GPS(PinName tx, PinName rx);
simon 0:15611c7938a3 89
ftagius 1:35fcaa2209af 90 void pause(bool b);
ftagius 1:35fcaa2209af 91 char read(void);
ftagius 1:35fcaa2209af 92 void sendCommand(char *);
ftagius 1:35fcaa2209af 93 void setBaud(int baud);
ftagius 1:35fcaa2209af 94 void setSetup(void);
ftagius 1:35fcaa2209af 95 char *lastNMEA(void);
ftagius 1:35fcaa2209af 96 bool newNMEAreceived();
ftagius 1:35fcaa2209af 97 bool parseNMEA(char *response);
ftagius 1:35fcaa2209af 98 uint8_t parseHex(char c);
ftagius 1:35fcaa2209af 99 bool parse(char * nmea);
ftagius 1:35fcaa2209af 100 void interruptReads(bool r);
ftagius 1:35fcaa2209af 101 bool wakeup(void);
ftagius 1:35fcaa2209af 102 bool standby(void);
ftagius 1:35fcaa2209af 103 uint8_t hour, minute, seconds, year, month, day;
ftagius 1:35fcaa2209af 104 uint16_t milliseconds;
ftagius 1:35fcaa2209af 105 float timef, latitude, longitude, geoidheight, altitude, lat_deg, lon_deg;
ftagius 1:35fcaa2209af 106 float speed, angle, magvariation, HDOP;
ftagius 1:35fcaa2209af 107 char lat, lon, mag;
ftagius 1:35fcaa2209af 108 bool fix;
ftagius 1:35fcaa2209af 109 uint8_t fixquality, satellites;
ftagius 1:35fcaa2209af 110 bool waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE);
ftagius 1:35fcaa2209af 111 bool LOCUS_StartLogger(void);
ftagius 1:35fcaa2209af 112 bool LOCUS_ReadStatus(void);
ftagius 1:35fcaa2209af 113 uint16_t LOCUS_serial, LOCUS_records;
ftagius 1:35fcaa2209af 114 uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent;
simon 0:15611c7938a3 115 private:
simon 0:15611c7938a3 116 float trunc(float v);
simon 0:15611c7938a3 117 void getline();
ftagius 1:35fcaa2209af 118 bool paused;
simon 0:15611c7938a3 119 Serial _gps;
ftagius 1:35fcaa2209af 120 char msg[1024];
simon 0:15611c7938a3 121
simon 0:15611c7938a3 122 };
simon 0:15611c7938a3 123
ftagius 1:35fcaa2209af 124 extern GPS gps;
ftagius 1:35fcaa2209af 125
simon 0:15611c7938a3 126 #endif