Forked para SNOCC
Fork of GPS by
Diff: GPS.cpp
- Revision:
- 1:1de2fc75bf38
- Parent:
- 0:15611c7938a3
--- a/GPS.cpp Tue Jun 08 14:10:27 2010 +0000 +++ b/GPS.cpp Sun Dec 04 20:14:00 2016 +0000 @@ -23,37 +23,101 @@ #include "GPS.h" GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) { - _gps.baud(4800); + _gps.baud(9600); // Cambio baudrate a 9600 longitude = 0.0; - latitude = 0.0; + latitude = 0.0; + } int GPS::sample() { float time; - char ns, ew; + char ns, ew, signal; // Agrego signal para parsear el campo NMEA que indica es estado de señal. 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(!lock) { + /* + GGA - essential fix data which provide 3D location and accuracy data. + + $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 + +Where: + GGA Global Positioning System Fix Data + 123519 Fix taken at 12:35:19 UTC + 4807.038,N Latitude 48 deg 07.038' N + 01131.000,E Longitude 11 deg 31.000' E + 1 Fix quality: 0 = invalid + 1 = GPS fix (SPS) + 2 = DGPS fix + 3 = PPS fix + 4 = Real Time Kinematic + 5 = Float RTK + 6 = estimated (dead reckoning) (2.3 feature) + 7 = Manual input mode + 8 = Simulation mode + 08 Number of satellites being tracked + 0.9 Horizontal dilution of position + 545.4,M Altitude, Meters, above mean sea level + 46.9,M Height of geoid (mean sea level) above WGS84 + ellipsoid + (empty field) time in seconds since last DGPS update + (empty field) DGPS station ID number + *47 the checksum data, always begins with * + */ + + + /* + sscanf(msg, "GN %s",mensaje1); + sscanf(msg, "GP,%s", mensaje2); + sscanf(msg, "GSV,%s", mensaje3); + sscanf(msg, "G,%s", mensaje4); + */ + // $GPRMC,194530.000,A,3051.8007,N,10035.9989,W,1.49,111.67,310714,,,A*74 Esta es la trama GP. En nuestro caso es GN: + + if(sscanf(msg, "GNRMC, %f,%c,%f,%c,%f,%c,%f", &time, &signal, &latitude, &ns, &longitude, &ew, &speed) >=1){ + // Agrego las siguientes lineas porque originalmente se analizaba el mensaje GGA y se evaluaba "lock" para saber si habia datos validos + // y ahora evaluo si la señal (signal) está Available (A) o Void (V). Lo dejo asi por si se retorna a GGA. + + if(signal == 'A'){ + lock = 1; + } + else { + lock = 0; + } + + // if(sscanf(msg, "GNGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) { + + + + if(!lock) { + longitude = 0.0; - latitude = 0.0; + latitude = 0.0; + speed = 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); + float degrees = trunc(latitude / 100.0f); // El formato del campo es GGMM.MMMM: Divido por 100 y tomo parte entera para los grados. + float minutes = latitude - (degrees * 100.0f); // Resto los grados y me quedo con los minutos + latitude = degrees + minutes / 60.0f; // Convierto a decimal sumando grados y dividiendo entre 60 los minutos + //degrees = trunc(longitude / 100.0f * 0.01f); // Corrijo esta linea porque es como dividir por 10000. + degrees = trunc(longitude / 100.0f); // Repito para la latitud. minutes = longitude - (degrees * 100.0f); longitude = degrees + minutes / 60.0f; + speed *= 1.852000f; // Convierto nudos a km/h + return 1; + } } + } }