Library for the EM-406 GPS module with time export support added
Fork of GPS by
Diff: GPS.cpp
- Revision:
- 5:fdac9c46157b
- Parent:
- 4:147f30d69bf6
--- 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; } }