Basic GPS message parser

Fork of GPS by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Tue Aug 22 15:23:05 2017 +0000
Parent:
2:8c97b7918a94
Commit message:
Added Altitude

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 8c97b7918a94 -r ac28455d8e5a GPS.cpp
--- a/GPS.cpp	Mon Feb 15 20:56:20 2016 +0000
+++ b/GPS.cpp	Tue Aug 22 15:23:05 2017 +0000
@@ -25,13 +25,16 @@
 GPS::GPS(PinName tx, PinName rx, int baudrate) : _gps(tx, rx) {
     _gps.baud(baudrate);    
     longitude = 0.0;
-    latitude = 0.0;        
+    latitude = 0.0;
+    altitude = 0.0;
 }
 
 int GPS::sample() {
     //float time;
     char ns, ew;
     int lock;
+    int satsInUse;
+    float hdop;
 
     while(1) {        
         getline();
@@ -41,10 +44,11 @@
         // Position -1.929107, 51.407211
         //          51.4136298,-1.2670097
         //Position -1.262323, 51.407383
-        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", &time, &latitude, &ns, &longitude, &ew, &lock, &satsInUse, &hdop, &altitude) >= 1) { 
             if(!lock) {
                 longitude = 0.0;
-                latitude = 0.0;        
+                latitude = 0.0;
+                altitude = 0;
                 return 0;
             } else {
                 //printf("%s\n\r",msg);
diff -r 8c97b7918a94 -r ac28455d8e5a GPS.h
--- a/GPS.h	Mon Feb 15 20:56:20 2016 +0000
+++ b/GPS.h	Tue Aug 22 15:23:05 2017 +0000
@@ -48,6 +48,9 @@
     /** The time from the message */
     float time;
     
+    /** Altitude */
+    float altitude;
+    
 private:
     float trunc(float v);
     void getline();