Basic GPS message parser

Fork of GPS by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Wed Aug 19 06:58:44 2015 +0000
Parent:
0:15611c7938a3
Child:
2:8c97b7918a94
Commit message:
commit

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
--- a/GPS.cpp	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.cpp	Wed Aug 19 06:58:44 2015 +0000
@@ -23,13 +23,13 @@
 #include "GPS.h"
 
 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
-    _gps.baud(4800);    
+    _gps.baud(38400);    
     longitude = 0.0;
     latitude = 0.0;        
 }
 
 int GPS::sample() {
-    float time;
+    //float time;
     char ns, ew;
     int lock;
 
@@ -37,20 +37,28 @@
         getline();
 
         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
+        // GPGGA,212700.000,5124.4324,N,00115.7464,W,1,8,1.30,113.7,M,47.5,M,,*47
+        // 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(!lock) {
                 longitude = 0.0;
                 latitude = 0.0;        
                 return 0;
             } else {
+                //printf("%s\n\r",msg);
                 if(ns == 'S') {    latitude  *= -1.0; }
                 if(ew == 'W') {    longitude *= -1.0; }
                 float degrees = trunc(latitude / 100.0f);
                 float minutes = latitude - (degrees * 100.0f);
-                latitude = degrees + minutes / 60.0f;    
-                degrees = trunc(longitude / 100.0f * 0.01f);
+                //printf("LAT degrees %f, minutes %f\n\r",degrees,minutes);
+                latitude = degrees + (minutes / 60.0f);    
+                
+                degrees = trunc(longitude / 100.0f);    // * 0.01f);
                 minutes = longitude - (degrees * 100.0f);
-                longitude = degrees + minutes / 60.0f;
+                //printf("LON degrees %f, minutes %f\n\r",degrees,minutes);
+                longitude = degrees + (minutes / 60.0f);
                 return 1;
             }
         }
@@ -78,4 +86,5 @@
         }
     }
     error("Overflowed message limit");
+//    printf("Overflow");
 }
--- a/GPS.h	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.h	Wed Aug 19 06:58:44 2015 +0000
@@ -45,6 +45,9 @@
     /** The latitude (call sample() to set) */
     float latitude;
     
+    /** The time from the message */
+    float time;
+    
 private:
     float trunc(float v);
     void getline();