Adafruit Ultimate GPS Arduino library adapted for mBed use. Original found at https://github.com/adafruit/Adafruit-GPS-Library.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MBed_Adafruit_GPS.h Source File

MBed_Adafruit_GPS.h

00001 /***********************************
00002 This is the Adafruit GPS library - the ultimate GPS library
00003 for the ultimate GPS module!
00004 
00005 Tested and works great with the Adafruit Ultimate GPS module
00006 using MTK33x9 chipset
00007     ------> http://www.adafruit.com/products/746
00008 Pick one up today at the Adafruit electronics shop 
00009 and help support open source hardware & software! -ada
00010 
00011 Adafruit invests time and resources providing this open source code, 
00012 please support Adafruit and open-source hardware by purchasing 
00013 products from Adafruit!
00014 
00015 Written by Limor Fried/Ladyada  for Adafruit Industries.  
00016 BSD license, check license.txt for more information
00017 All text above must be included in any redistribution
00018 ****************************************/
00019 #include "mbed.h"
00020 #include <stdint.h>
00021 #include <math.h>
00022 #include <ctype.h>
00023 
00024 #ifndef _MBED_ADAFRUIT_GPS_H
00025 #define _MBED_ADAFRUIT_GPS_H
00026 
00027 
00028 // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
00029 #define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
00030 #define PMTK_SET_NMEA_UPDATE_5HZ  "$PMTK220,200*2C"
00031 #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
00032 
00033 
00034 #define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C"
00035 #define PMTK_SET_BAUD_9600 "$PMTK251,9600*17"
00036 
00037 // turn on only the second sentence (GPRMC)
00038 #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\r\n"
00039 // turn on GPRMC and GGA
00040 #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"
00041 // turn on ALL THE DATA
00042 #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"
00043 // turn off output
00044 #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"
00045 
00046 // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator
00047 // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html
00048 
00049 #define PMTK_LOCUS_STARTLOG  "$PMTK185,0*22"
00050 #define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C"
00051 #define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38"
00052 #define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22"
00053 #define LOCUS_OVERLAP 0
00054 #define LOCUS_FULLSTOP 1
00055 
00056 // standby command & boot successful message
00057 #define PMTK_STANDBY "$PMTK161,0*28"
00058 #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36"  // Not needed currently
00059 #define PMTK_AWAKE "$PMTK010,002*2D"
00060 
00061 // ask for the release and version
00062 #define PMTK_Q_RELEASE "$PMTK605*31"
00063 
00064 // request for updates on antenna status 
00065 #define PGCMD_ANTENNA "$PGCMD,33,1*6C" 
00066 #define PGCMD_NOANTENNA "$PGCMD,33,0*6D" 
00067 
00068 // how long to wait when we're looking for a response
00069 #define MAXWAITSENTENCE 5
00070 
00071 
00072 
00073 class Adafruit_GPS {
00074  public:
00075   void begin(int baud); 
00076 
00077   Adafruit_GPS(Serial * ser);
00078 
00079   char *lastNMEA(void);
00080   bool newNMEAreceived();
00081   void common_init(void);
00082   void sendCommand(char *);
00083   void pause(bool b);
00084 
00085   bool parseNMEA(char *response);
00086   uint8_t parseHex(char c);
00087 
00088   char read(void);
00089   bool parse(char * nmea);
00090   void interruptReads(bool r);
00091 
00092   bool wakeup(void);
00093   bool standby(void);
00094   bool hasFix(void);
00095 
00096   uint8_t hour, minute, seconds, year, month, day;
00097   uint16_t milliseconds;
00098   float latitude, longitude, geoidheight, altitude;
00099   float speed, angle, magvariation, HDOP;
00100   char lat, lon, mag;
00101   bool fix;
00102   uint8_t fixquality, satellites;
00103 
00104   bool waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE);
00105   bool LOCUS_StartLogger(void);
00106   bool LOCUS_ReadStatus(void);
00107 
00108   uint16_t LOCUS_serial, LOCUS_records;
00109   uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent;
00110  private:
00111   bool paused;
00112   
00113   Serial * gpsSerial;
00114 };
00115 
00116 #endif