Slight update to sford's GPS library. Returns more data from the NMEA sentence and allows for different serial speeds (e.g. used for the Adafruit Ultimate GPSv3 Breakout Board).

Dependents:   GPS_HelloWorld servo_sensor

Fork of GPS by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
8fromPi
Date:
Sat Nov 02 16:17:58 2013 +0000
Parent:
0:15611c7938a3
Commit message:
GPS lib from sford with light modifications to get more data from the NMEA sentence and to allow for modules with different serial speeds

Changed in this revision

GPS.cpp Show annotated file Show diff for this revision Revisions of this file
GPS.h Show annotated file Show diff for this revision Revisions of this file
diff -r 15611c7938a3 -r 1d60e6a0ffd9 GPS.cpp
--- a/GPS.cpp	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.cpp	Sat Nov 02 16:17:58 2013 +0000
@@ -1,5 +1,6 @@
-/* mbed EM-406 GPS Module Library
+/* mbed GPS Module Library
  * Copyright (c) 2008-2010, sford
+ * Copyright (c) 2013, B.Adryan
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -22,27 +23,36 @@
  
 #include "GPS.h"
 
-GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
-    _gps.baud(4800);    
+GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
+    _gps.baud(Baud);    
     longitude = 0.0;
     latitude = 0.0;        
 }
 
 int GPS::sample() {
-    float time;
-    char ns, ew;
+    char ns, ew, unit;
     int lock;
 
     while(1) {        
         getline();
 
         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
-        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) { 
+        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &sats, &hdop, &alt, &unit, &geoid) >= 1) { 
             if(!lock) {
+                time = 0.0;
                 longitude = 0.0;
-                latitude = 0.0;        
+                latitude = 0.0;
+                sats = 0;
+                hdop = 0.0;
+                alt = 0.0;
+                geoid = 0.0;        
                 return 0;
             } else {
+                //GPGGA format according http://aprs.gids.nl/nmea/#gga
+                // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
+                // hdop (float), altitude (float), M, geoid (float), M, , ,  
+                //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
+                
                 if(ns == 'S') {    latitude  *= -1.0; }
                 if(ew == 'W') {    longitude *= -1.0; }
                 float degrees = trunc(latitude / 100.0f);
@@ -78,4 +88,4 @@
         }
     }
     error("Overflowed message limit");
-}
+}
\ No newline at end of file
diff -r 15611c7938a3 -r 1d60e6a0ffd9 GPS.h
--- a/GPS.h	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.h	Sat Nov 02 16:17:58 2013 +0000
@@ -1,5 +1,6 @@
-/* mbed EM-406 GPS Module Library
+/* mbed GPS Module Library
  * Copyright (c) 2008-2010, sford
+ * Copyright (c) 2013, B.Adryan
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -25,13 +26,15 @@
 #ifndef MBED_GPS_H
 #define MBED_GPS_H
 
-/**  A GPS interface for reading from a Globalsat EM-406 GPS Module */
+/**  A GPS interface for reading from a serial GPS module */
 class GPS {
 public:
 
-    /** Create the GPS interface, connected to the specified serial port
+    /** Create the GPS interface, connected to the specified serial port and speed.
+     *  for example, GlobalSat EM406-A (e.g. on SparkFun GPS Shield) is 4800 Baud,
+     *  Adafruit Ultimate GPSv3 (connected to serial) is 9600 Baud
      */    
-    GPS(PinName tx, PinName rx);
+    GPS(PinName tx, PinName rx, int Baud);
     
     /** Sample the incoming GPS data, returning whether there is a lock
      * 
@@ -45,13 +48,33 @@
     /** The latitude (call sample() to set) */
     float latitude;
     
+    /** The time (call sample() to set) */
+    float time;
+    
+    /** Number of satellites received (call sample() to set) */
+    int sats;
+    
+    /** Horizontal dilusion of precision (call sample() to set) */
+    float hdop;
+    
+    /** The altitude (call sample() to set)
+        Note that the accurate altitude is corrected by the geoid
+        See http://homepages.slingshot.co.nz/~geoff36/datum.htm
+    */
+    float alt;
+    
+    /** The geoid (call sample() to set) */
+    float  geoid;
+    
+    /** The NMEA sentence */
+    char msg[256];
+    
+    
 private:
     float trunc(float v);
     void getline();
     
     Serial _gps;
-    char msg[256];
-
 };
 
-#endif
+#endif
\ No newline at end of file