Tisham Dhar / MBed_Adafruit-GPS-Library

Dependents:   Xadow_MPU9150AHRS Hexi_GPSIMU_Hotshoe

Fork of MBed_Adafruit-GPS-Library by Myron Lee

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"
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 /****************************************
00069 Predefined UBLOX Messages
00070 *****************************************/
00071 #define UBX_DISABLE_ZDA "$PUBX,40,ZDA,0,0,0,0*44"
00072 #define UBX_DISABLE_GLL "$PUBX,40,GLL,0,0,0,0*5C"
00073 #define UBX_DISABLE_VTG "$PUBX,40,VTG,0,0,0,0*5E"
00074 #define UBX_DISABLE_GSV "$PUBX,40,GSV,0,0,0,0*59"
00075 #define UBX_DISABLE_GSA "$PUBX,40,GSA,0,0,0,0*4E"
00076 #define UBX_DISABLE_GGA "$PUBX,40,GGA,0,0,0,0*5A"
00077 #define UBX_DISABLE_RMC "$PUBX,40,RMC,0,0,0,0*47"
00078 
00079 // how long to wait when we're looking for a response
00080 #define MAXWAITSENTENCE 5
00081 
00082 
00083 
00084 class Adafruit_GPS {
00085  public:
00086   void begin(int baud); 
00087 
00088   Adafruit_GPS(Serial * ser);
00089 
00090   char *lastNMEA(void);
00091   bool newNMEAreceived();
00092   void common_init(void);
00093   void sendCommand(char *);
00094   void pause(bool b);
00095 
00096   bool parseNMEA(char *response);
00097   uint8_t parseHex(char c);
00098 
00099   char read(void);
00100   bool parse(char * nmea);
00101   void interruptReads(bool r);
00102 
00103   bool wakeup(void);
00104   bool standby(void);
00105 
00106   uint8_t hour, minute, seconds, year, month, day;
00107   uint16_t milliseconds;
00108   float latitude, longitude, geoidheight, altitude;
00109   float speed, angle, magvariation, HDOP;
00110   char lat, lon, mag;
00111   bool fix;
00112   uint8_t fixquality, satellites;
00113 
00114   bool waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE);
00115   bool LOCUS_StartLogger(void);
00116   bool LOCUS_ReadStatus(void);
00117 
00118   uint16_t LOCUS_serial, LOCUS_records;
00119   uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent;
00120  private:
00121   bool paused;
00122   
00123   Serial * gpsSerial;
00124 };
00125 
00126 #endif