GPS code for Adafruit ultimate GPS

Dependents:   demo_gps_sdcard zeus

Fork of GPS by Simon Ford

Revision:
1:35fcaa2209af
Parent:
0:15611c7938a3
--- a/GPS.h	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.h	Tue Jun 16 12:03:20 2015 +0000
@@ -21,10 +21,64 @@
  */
 
 #include "mbed.h"
+#include <stdint.h>
+#include <math.h>
+#include <ctype.h>
 
 #ifndef MBED_GPS_H
 #define MBED_GPS_H
 
+// different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
+#define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
+#define PMTK_SET_NMEA_UPDATE_5HZ  "$PMTK220,200*2C"
+#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
+#define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C"
+#define PMTK_SET_BAUD_9600 "$PMTK251,9600*17"
+// turn on only the second sentence (GPRMC)
+#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"
+// turn on gga only
+#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"
+// turn on GPRMC and GGA
+#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"
+// turn on ALL THE DATA
+#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"
+// turn on gga and gsv
+#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"
+// trun on gsv only
+#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"
+// turn off output
+#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"
+ // turn on gpzda
+#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"
+// turn oh gpzda and gga
+#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"
+// turn on  VTG, GGA and GSA. GSA is only sent once every five transmissions.
+#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"
+// to generate your own sentences, check out the MTK command datasheet and use a checksum calculator
+// such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html
+
+#define PMTK_LOCUS_STARTLOG  "$PMTK185,0*22"
+#define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C"
+#define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38"
+#define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22"
+#define LOCUS_OVERLAP 0
+#define LOCUS_FULLSTOP 1
+
+// standby command & boot successful message
+#define PMTK_STANDBY "$PMTK161,0*28"
+#define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36"  // Not needed currently
+#define PMTK_AWAKE "$PMTK010,002*2D"
+
+// ask for the release and version
+#define PMTK_Q_RELEASE "$PMTK605*31"
+
+// request for updates on antenna status 
+#define PGCMD_ANTENNA "$PGCMD,33,1*6C" 
+#define PGCMD_NOANTENNA "$PGCMD,33,0*6D" 
+
+// how long to wait when we're looking for a response
+#define MAXWAITSENTENCE 5
+
 /**  A GPS interface for reading from a Globalsat EM-406 GPS Module */
 class GPS {
 public:
@@ -33,25 +87,40 @@
      */    
     GPS(PinName tx, PinName rx);
     
-    /** Sample the incoming GPS data, returning whether there is a lock
-     * 
-     * @return 1 if there was a lock when the sample was taken (and therefore .longitude and .latitude are valid), else 0
-     */
-    int sample();
-    
-    /** The longitude (call sample() to set) */
-    float longitude;
-
-    /** The latitude (call sample() to set) */
-    float latitude;
-    
+    void pause(bool b);
+    char read(void);
+    void sendCommand(char *);
+    void setBaud(int baud);
+    void setSetup(void);
+    char *lastNMEA(void);
+    bool newNMEAreceived();
+    bool parseNMEA(char *response);
+    uint8_t parseHex(char c);
+    bool parse(char * nmea);
+    void interruptReads(bool r);
+    bool wakeup(void);
+    bool standby(void);
+    uint8_t hour, minute, seconds, year, month, day;
+    uint16_t milliseconds;
+    float timef, latitude, longitude, geoidheight, altitude, lat_deg, lon_deg;
+    float speed, angle, magvariation, HDOP;
+    char lat, lon, mag;
+    bool fix;
+    uint8_t fixquality, satellites;
+    bool waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE);
+    bool LOCUS_StartLogger(void);
+    bool LOCUS_ReadStatus(void);
+    uint16_t LOCUS_serial, LOCUS_records;
+    uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent;
 private:
     float trunc(float v);
     void getline();
-    
+    bool paused;
     Serial _gps;
-    char msg[256];
+    char msg[1024];
 
 };
 
+extern GPS gps;
+
 #endif