Library for the EM-406 GPS module
Fork of GPS by
Revision 1:26b920d162f9, committed 2016-11-29
- Comitter:
- SSJprocesa
- Date:
- Tue Nov 29 21:55:08 2016 +0000
- Parent:
- 0:15611c7938a3
- Commit message:
- C?digo permite enviar mensajes de texto con la palabra GPS solicitando la ubicaci?n y el dispositivo receptor enviar un mensaje de respuesta con las coordenadas, si env?a PWM45 se configura el dutycycle en 45% a la salida del dispositivo
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 |
diff -r 15611c7938a3 -r 26b920d162f9 GPS.cpp --- 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
diff -r 15611c7938a3 -r 26b920d162f9 GPS.h --- a/GPS.h Tue Jun 08 14:10:27 2010 +0000 +++ b/GPS.h Tue Nov 29 21:55:08 2016 +0000 @@ -19,16 +19,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - + #include "mbed.h" - + #ifndef MBED_GPS_H #define MBED_GPS_H - + /** A GPS interface for reading from a Globalsat EM-406 GPS Module */ class GPS { public: - + /** Create the GPS interface, connected to the specified serial port */ GPS(PinName tx, PinName rx); @@ -41,7 +41,7 @@ /** The longitude (call sample() to set) */ float longitude; - + /** The latitude (call sample() to set) */ float latitude; @@ -51,7 +51,8 @@ Serial _gps; char msg[256]; - + }; - + #endif + \ No newline at end of file