Library for the EM-406 GPS module with time export support added

Fork of GPS by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
WilliamO7
Date:
Mon Mar 05 16:17:03 2018 +0000
Parent:
4:147f30d69bf6
Child:
6:c22b014ae4d0
Commit message:
return number of satellites found

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	Sun Mar 04 23:17:28 2018 +0000
+++ b/GPS.cpp	Mon Mar 05 16:17:03 2018 +0000
@@ -20,29 +20,34 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include <cstdlib>
 #include "GPS.h"
 
 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
     _gps.baud(4800);    
     longitude = 0.0;
     latitude = 0.0;  
-    time_utc = 0.0;      
+    time_utc = 0.0;
+    sats = 0;   
 }
 
 int GPS::sample() {
     float time;
     char ns, ew;
     int lock;
+    char satnum_buf[2];
 
     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(!lock) {
+        if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%s", &time, &latitude, &ns, &longitude, &ew, &lock, satnum_buf) >= 1) { 
+            int satnum = std::atoi(satnum_buf);
+            if(!lock || satnum < 4) {
                 longitude = 0.0;
                 latitude = 0.0;   
-                time_utc = 0.0;     
+                time_utc = 0.0; 
+                sats = satnum;    
                 return 0;
             } else {
                 if(ns == 'S') {    latitude  *= -1.0; }
@@ -54,6 +59,7 @@
                 minutes = longitude - (degrees * 100.0f);
                 longitude = degrees + minutes / 60.0f;
                 time_utc = time;
+                sats = satnum; 
                 return 1;
             }
         }
--- a/GPS.h	Sun Mar 04 23:17:28 2018 +0000
+++ b/GPS.h	Mon Mar 05 16:17:03 2018 +0000
@@ -49,6 +49,9 @@
     /** The time in UTC float format (call sample() to set) */
     float time_utc;
     
+    /** Number of satellites (call sample() to set) */
+    int sats;
+    
 private:
     float trunc(float v);
     void getline();