GPS with Altitude

Dependents:   Vodafone_SEDS

Fork of GPS by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
richardemeadows
Date:
Mon Jun 09 16:48:04 2014 +0000
Parent:
0:15611c7938a3
Commit message:
Added Altitude Decoding

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 586757e9ad1b GPS.cpp
--- a/GPS.cpp	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.cpp	Mon Jun 09 16:48:04 2014 +0000
@@ -29,30 +29,39 @@
 }
 
 int GPS::sample() {
-    float time;
+    float time, hdop;
     char ns, ew;
     int lock;
 
     while(1) {        
         getline();
+        
+        printf("MSG: %s\r\n", msg);
 
         // 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(!lock) {
-                longitude = 0.0;
-                latitude = 0.0;        
-                return 0;
-            } else {
-                if(ns == 'S') {    latitude  *= -1.0; }
-                if(ew == 'W') {    longitude *= -1.0; }
+        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &satellites, &hdop, &altitude) >= 1) {
+            
+            printf("LOCK: %d\r\n", lock);
+             
+            if(lock == 1 || lock == 2 || lock == 6) { // GPS or Differential GPS or Dead Reckoning Fix
                 float degrees = trunc(latitude / 100.0f);
                 float minutes = latitude - (degrees * 100.0f);
                 latitude = degrees + minutes / 60.0f;    
-                degrees = trunc(longitude / 100.0f * 0.01f);
+                
+                degrees = trunc(longitude / 100.0f);
                 minutes = longitude - (degrees * 100.0f);
                 longitude = degrees + minutes / 60.0f;
+                
+                if(ns == 'S') { latitude  *= -1.0; }
+                if(ew == 'W') { longitude *= -1.0; }
+                
                 return 1;
-            }
+            } else {
+                longitude = 0.0;
+                latitude = 0.0;  
+                altitude = 0.0;      
+                return 0;
+            }   
         }
     }
 }
diff -r 15611c7938a3 -r 586757e9ad1b GPS.h
--- a/GPS.h	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.h	Mon Jun 09 16:48:04 2014 +0000
@@ -45,6 +45,12 @@
     /** The latitude (call sample() to set) */
     float latitude;
     
+    /** The number of satellites in use (call sample() to set) */
+    int satellites;
+    
+    /** The altitude (call sample() to set) */
+    float altitude;
+    
 private:
     float trunc(float v);
     void getline();