Library is based on mlee350's library (MBed_Adafruit-GPS-Library) for Adafruit's GPS module (GlobalTop's MTK3339). Includes two CRITIAL bug fixes, as well as minor updates from Adafruit's Arduino library.
Fork of MBed_Adafruit-GPS-Library by
MBed_Adafruit_GPS.h@2:d8e1e37eea36, 2018-01-13 (annotated)
- Committer:
- hobbyguy77
- Date:
- Sat Jan 13 14:03:41 2018 +0000
- Revision:
- 2:d8e1e37eea36
- Parent:
- 1:96d7d157b384
Renamed waitForSentence param to be a bit more intuitive.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mlee350 | 0:a23e3099bb0a | 1 | /*********************************** |
mlee350 | 0:a23e3099bb0a | 2 | This is the Adafruit GPS library - the ultimate GPS library |
mlee350 | 0:a23e3099bb0a | 3 | for the ultimate GPS module! |
mlee350 | 0:a23e3099bb0a | 4 | |
mlee350 | 0:a23e3099bb0a | 5 | Tested and works great with the Adafruit Ultimate GPS module |
mlee350 | 0:a23e3099bb0a | 6 | using MTK33x9 chipset |
mlee350 | 0:a23e3099bb0a | 7 | ------> http://www.adafruit.com/products/746 |
mlee350 | 0:a23e3099bb0a | 8 | Pick one up today at the Adafruit electronics shop |
mlee350 | 0:a23e3099bb0a | 9 | and help support open source hardware & software! -ada |
mlee350 | 0:a23e3099bb0a | 10 | |
mlee350 | 0:a23e3099bb0a | 11 | Adafruit invests time and resources providing this open source code, |
mlee350 | 0:a23e3099bb0a | 12 | please support Adafruit and open-source hardware by purchasing |
mlee350 | 0:a23e3099bb0a | 13 | products from Adafruit! |
mlee350 | 0:a23e3099bb0a | 14 | |
mlee350 | 0:a23e3099bb0a | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. |
mlee350 | 0:a23e3099bb0a | 16 | BSD license, check license.txt for more information |
mlee350 | 0:a23e3099bb0a | 17 | All text above must be included in any redistribution |
mlee350 | 0:a23e3099bb0a | 18 | ****************************************/ |
mlee350 | 0:a23e3099bb0a | 19 | #include "mbed.h" |
mlee350 | 0:a23e3099bb0a | 20 | #include <stdint.h> |
mlee350 | 0:a23e3099bb0a | 21 | #include <math.h> |
mlee350 | 0:a23e3099bb0a | 22 | #include <ctype.h> |
mlee350 | 0:a23e3099bb0a | 23 | |
mlee350 | 0:a23e3099bb0a | 24 | #ifndef _MBED_ADAFRUIT_GPS_H |
mlee350 | 0:a23e3099bb0a | 25 | #define _MBED_ADAFRUIT_GPS_H |
mlee350 | 0:a23e3099bb0a | 26 | |
mlee350 | 0:a23e3099bb0a | 27 | |
mlee350 | 0:a23e3099bb0a | 28 | // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz) |
hobbyguy77 | 1:96d7d157b384 | 29 | // Note that these only control the rate at which the position is echoed, to actually speed up the |
hobbyguy77 | 1:96d7d157b384 | 30 | // position fix you must also send one of the position fix rate commands below too. |
hobbyguy77 | 1:96d7d157b384 | 31 | #define PMTK_SET_NMEA_UPDATE_100_MILLIHERTZ "$PMTK220,10000*2F" // Once every 10 seconds, 100 millihertz. |
hobbyguy77 | 1:96d7d157b384 | 32 | #define PMTK_SET_NMEA_UPDATE_200_MILLIHERTZ "$PMTK220,5000*1B" // Once every 5 seconds, 200 millihertz. |
mlee350 | 0:a23e3099bb0a | 33 | #define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" |
hobbyguy77 | 1:96d7d157b384 | 34 | #define PMTK_SET_NMEA_UPDATE_2HZ "$PMTK220,500*2B" |
mlee350 | 0:a23e3099bb0a | 35 | #define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" |
mlee350 | 0:a23e3099bb0a | 36 | #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F" |
hobbyguy77 | 1:96d7d157b384 | 37 | // Position fix update rate commands. |
hobbyguy77 | 1:96d7d157b384 | 38 | #define PMTK_API_SET_FIX_CTL_100_MILLIHERTZ "$PMTK300,10000,0,0,0,0*2C" // Once every 10 seconds, 100 millihertz. |
hobbyguy77 | 1:96d7d157b384 | 39 | #define PMTK_API_SET_FIX_CTL_200_MILLIHERTZ "$PMTK300,5000,0,0,0,0*18" // Once every 5 seconds, 200 millihertz. |
hobbyguy77 | 1:96d7d157b384 | 40 | #define PMTK_API_SET_FIX_CTL_1HZ "$PMTK300,1000,0,0,0,0*1C" |
hobbyguy77 | 1:96d7d157b384 | 41 | #define PMTK_API_SET_FIX_CTL_5HZ "$PMTK300,200,0,0,0,0*2F" |
hobbyguy77 | 1:96d7d157b384 | 42 | // Can't fix position faster than 5 times a second! |
mlee350 | 0:a23e3099bb0a | 43 | |
mlee350 | 0:a23e3099bb0a | 44 | |
mlee350 | 0:a23e3099bb0a | 45 | #define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C" |
mlee350 | 0:a23e3099bb0a | 46 | #define PMTK_SET_BAUD_9600 "$PMTK251,9600*17" |
mlee350 | 0:a23e3099bb0a | 47 | |
mlee350 | 0:a23e3099bb0a | 48 | // turn on only the second sentence (GPRMC) |
mlee350 | 0:a23e3099bb0a | 49 | #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" |
mlee350 | 0:a23e3099bb0a | 50 | // turn on GPRMC and GGA |
mlee350 | 0:a23e3099bb0a | 51 | #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" |
mlee350 | 0:a23e3099bb0a | 52 | // turn on ALL THE DATA |
mlee350 | 0:a23e3099bb0a | 53 | #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" |
mlee350 | 0:a23e3099bb0a | 54 | // turn off output |
mlee350 | 0:a23e3099bb0a | 55 | #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" |
mlee350 | 0:a23e3099bb0a | 56 | |
mlee350 | 0:a23e3099bb0a | 57 | // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator |
mlee350 | 0:a23e3099bb0a | 58 | // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html |
mlee350 | 0:a23e3099bb0a | 59 | |
mlee350 | 0:a23e3099bb0a | 60 | #define PMTK_LOCUS_STARTLOG "$PMTK185,0*22" |
mlee350 | 0:a23e3099bb0a | 61 | #define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C" |
mlee350 | 0:a23e3099bb0a | 62 | #define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38" |
mlee350 | 0:a23e3099bb0a | 63 | #define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22" |
mlee350 | 0:a23e3099bb0a | 64 | #define LOCUS_OVERLAP 0 |
mlee350 | 0:a23e3099bb0a | 65 | #define LOCUS_FULLSTOP 1 |
mlee350 | 0:a23e3099bb0a | 66 | |
hobbyguy77 | 1:96d7d157b384 | 67 | #define PMTK_ENABLE_SBAS "$PMTK313,1*2E" |
hobbyguy77 | 1:96d7d157b384 | 68 | #define PMTK_ENABLE_WAAS "$PMTK301,2*2E" |
hobbyguy77 | 1:96d7d157b384 | 69 | |
mlee350 | 0:a23e3099bb0a | 70 | // standby command & boot successful message |
mlee350 | 0:a23e3099bb0a | 71 | #define PMTK_STANDBY "$PMTK161,0*28" |
mlee350 | 0:a23e3099bb0a | 72 | #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36" // Not needed currently |
hobbyguy77 | 1:96d7d157b384 | 73 | //$PMTK010,001*2E |
hobbyguy77 | 1:96d7d157b384 | 74 | //$PMTK010,002*2D |
mlee350 | 0:a23e3099bb0a | 75 | #define PMTK_AWAKE "$PMTK010,002*2D" |
mlee350 | 0:a23e3099bb0a | 76 | |
mlee350 | 0:a23e3099bb0a | 77 | // ask for the release and version |
mlee350 | 0:a23e3099bb0a | 78 | #define PMTK_Q_RELEASE "$PMTK605*31" |
mlee350 | 0:a23e3099bb0a | 79 | |
mlee350 | 0:a23e3099bb0a | 80 | // request for updates on antenna status |
mlee350 | 0:a23e3099bb0a | 81 | #define PGCMD_ANTENNA "$PGCMD,33,1*6C" |
mlee350 | 0:a23e3099bb0a | 82 | #define PGCMD_NOANTENNA "$PGCMD,33,0*6D" |
mlee350 | 0:a23e3099bb0a | 83 | |
mlee350 | 0:a23e3099bb0a | 84 | // how long to wait when we're looking for a response |
hobbyguy77 | 1:96d7d157b384 | 85 | #define MAXWAITSENTENCE 10 |
mlee350 | 0:a23e3099bb0a | 86 | |
mlee350 | 0:a23e3099bb0a | 87 | |
mlee350 | 0:a23e3099bb0a | 88 | |
mlee350 | 0:a23e3099bb0a | 89 | class Adafruit_GPS { |
mlee350 | 0:a23e3099bb0a | 90 | public: |
mlee350 | 0:a23e3099bb0a | 91 | void begin(int baud); |
mlee350 | 0:a23e3099bb0a | 92 | |
mlee350 | 0:a23e3099bb0a | 93 | Adafruit_GPS(Serial * ser); |
mlee350 | 0:a23e3099bb0a | 94 | |
mlee350 | 0:a23e3099bb0a | 95 | char *lastNMEA(void); |
mlee350 | 0:a23e3099bb0a | 96 | bool newNMEAreceived(); |
mlee350 | 0:a23e3099bb0a | 97 | void common_init(void); |
mlee350 | 0:a23e3099bb0a | 98 | void sendCommand(char *); |
mlee350 | 0:a23e3099bb0a | 99 | void pause(bool b); |
mlee350 | 0:a23e3099bb0a | 100 | |
mlee350 | 0:a23e3099bb0a | 101 | bool parseNMEA(char *response); |
mlee350 | 0:a23e3099bb0a | 102 | uint8_t parseHex(char c); |
mlee350 | 0:a23e3099bb0a | 103 | |
mlee350 | 0:a23e3099bb0a | 104 | char read(void); |
mlee350 | 0:a23e3099bb0a | 105 | bool parse(char * nmea); |
mlee350 | 0:a23e3099bb0a | 106 | void interruptReads(bool r); |
mlee350 | 0:a23e3099bb0a | 107 | |
mlee350 | 0:a23e3099bb0a | 108 | bool wakeup(void); |
mlee350 | 0:a23e3099bb0a | 109 | bool standby(void); |
mlee350 | 0:a23e3099bb0a | 110 | |
mlee350 | 0:a23e3099bb0a | 111 | uint8_t hour, minute, seconds, year, month, day; |
mlee350 | 0:a23e3099bb0a | 112 | uint16_t milliseconds; |
mlee350 | 0:a23e3099bb0a | 113 | float latitude, longitude, geoidheight, altitude; |
mlee350 | 0:a23e3099bb0a | 114 | float speed, angle, magvariation, HDOP; |
mlee350 | 0:a23e3099bb0a | 115 | char lat, lon, mag; |
mlee350 | 0:a23e3099bb0a | 116 | bool fix; |
mlee350 | 0:a23e3099bb0a | 117 | uint8_t fixquality, satellites; |
mlee350 | 0:a23e3099bb0a | 118 | |
hobbyguy77 | 2:d8e1e37eea36 | 119 | bool waitForSentence(const char *sentence, uint8_t max = MAXWAITSENTENCE); |
mlee350 | 0:a23e3099bb0a | 120 | bool LOCUS_StartLogger(void); |
mlee350 | 0:a23e3099bb0a | 121 | bool LOCUS_ReadStatus(void); |
mlee350 | 0:a23e3099bb0a | 122 | |
mlee350 | 0:a23e3099bb0a | 123 | uint16_t LOCUS_serial, LOCUS_records; |
mlee350 | 0:a23e3099bb0a | 124 | uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent; |
mlee350 | 0:a23e3099bb0a | 125 | private: |
mlee350 | 0:a23e3099bb0a | 126 | bool paused; |
mlee350 | 0:a23e3099bb0a | 127 | |
mlee350 | 0:a23e3099bb0a | 128 | Serial * gpsSerial; |
mlee350 | 0:a23e3099bb0a | 129 | }; |
mlee350 | 0:a23e3099bb0a | 130 | |
mlee350 | 0:a23e3099bb0a | 131 | #endif |