Library for the EM-406 GPS module

Fork of GPS by Simon Ford

Revision:
1:26b920d162f9
Parent:
0:15611c7938a3
--- a/GPS.cpp	Tue Jun 08 14:10:27 2010 +0000
+++ b/GPS.cpp	Tue Nov 29 21:55:08 2016 +0000
@@ -1,3 +1,4 @@
+
 /* mbed EM-406 GPS Module Library
  * Copyright (c) 2008-2010, sford
  *
@@ -21,42 +22,45 @@
  */
  
 #include "GPS.h"
-
+ 
 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
-    _gps.baud(4800);    
+    _gps.baud(9600);    
     longitude = 0.0;
     latitude = 0.0;        
 }
-
+ 
 int GPS::sample() {
     float time;
     char ns, ew;
     int lock;
-
+ 
     while(1) {        
         getline();
-
+      //$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
         // 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(!lock) {   //si lock es 1  hay lecturas ok
                 longitude = 0.0;
                 latitude = 0.0;        
                 return 0;
-            } else {
+            } 
+                else {
                 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);
-                minutes = longitude - (degrees * 100.0f);
-                longitude = degrees + minutes / 60.0f;
+                latitude = (latitude / 100.0f);
+                //float minutes = latitude - (degrees * 100.0f);
+                //latitude = degrees + minutes / 60.0f;    
+                longitude = (longitude / 100.0f);
+                //minutes = longitude - (degrees * 100.0f);
+                //longitude = degrees + minutes / 60.0f;
+                
                 return 1;
             }
         }
     }
 }
-
+ 
+/*
 float GPS::trunc(float v) {
     if(v < 0.0) {
         v*= -1.0;
@@ -67,10 +71,10 @@
     }
     return v;
 }
-
+*/
 void GPS::getline() {
     while(_gps.getc() != '$');    // wait for the start of a line
-    for(int i=0; i<256; i++) {
+    for(int i=0; i<512; i++) {
         msg[i] = _gps.getc();
         if(msg[i] == '\r') {
             msg[i] = 0;
@@ -79,3 +83,4 @@
     }
     error("Overflowed message limit");
 }
+ 
\ No newline at end of file