.

Dependents:   My_GPS_BLE

Fork of SerialGPS by Components

Revision:
1:1d60e6a0ffd9
Parent:
0:15611c7938a3
diff -r 15611c7938a3 -r 1d60e6a0ffd9 GPS.cpp
--- a/GPS.cpp	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.cpp	Sat Nov 02 16:17:58 2013 +0000
@@ -1,5 +1,6 @@
-/* mbed EM-406 GPS Module Library
+/* mbed GPS Module Library
  * Copyright (c) 2008-2010, sford
+ * Copyright (c) 2013, B.Adryan
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -22,27 +23,36 @@
  
 #include "GPS.h"
 
-GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
-    _gps.baud(4800);    
+GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) {
+    _gps.baud(Baud);    
     longitude = 0.0;
     latitude = 0.0;        
 }
 
 int GPS::sample() {
-    float time;
-    char ns, ew;
+    char ns, ew, unit;
     int lock;
 
     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(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &sats, &hdop, &alt, &unit, &geoid) >= 1) { 
             if(!lock) {
+                time = 0.0;
                 longitude = 0.0;
-                latitude = 0.0;        
+                latitude = 0.0;
+                sats = 0;
+                hdop = 0.0;
+                alt = 0.0;
+                geoid = 0.0;        
                 return 0;
             } else {
+                //GPGGA format according http://aprs.gids.nl/nmea/#gga
+                // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
+                // hdop (float), altitude (float), M, geoid (float), M, , ,  
+                //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
+                
                 if(ns == 'S') {    latitude  *= -1.0; }
                 if(ew == 'W') {    longitude *= -1.0; }
                 float degrees = trunc(latitude / 100.0f);
@@ -78,4 +88,4 @@
         }
     }
     error("Overflowed message limit");
-}
+}
\ No newline at end of file