GPS with Altitude

Fork of GPS by

Revision:
Parent:
0:15611c7938a3
```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;
+            }
}
}
}
```