Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
gps_locate.cpp
- Committer:
- aroulin
- Date:
- 2014-09-30
- Revision:
- 7:eeef6f9fa1db
- Parent:
- 4:f1708f6ec905
- Child:
- 13:3c1f0b8c1d21
File content as of revision 7:eeef6f9fa1db:
#include "gps_locate.h" #include "GPS.h" int gps_on(void) { return 0; } int gps_off(void) { return 0; } int gps_locate(struct gps_data_t* gps_data) { // Power on gps GPSI2C gps; bool coord_ok = false, altitude_ok = false, speed_ok = false; int ret = 0; char buf[512] = {0}; while(!coord_ok || !altitude_ok || !speed_ok) { while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) { int len = LENGTH(ret); if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { if (!strncmp("$GPGLL", buf, 6)) { double la = 0, lo = 0; char ch; if (gps.getNmeaAngle(1,buf,len,la) && gps.getNmeaAngle(3,buf,len,lo) && gps.getNmeaItem(6,buf,len,ch) && ch == 'A') { gps_data->lo = lo; gps_data->la = la; coord_ok = true; } } else if (!strncmp("$GPGGA", buf, 6)) { double a = 0; if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] gps_data->altitude = a; altitude_ok = true; } else if (!strncmp("$GPVTG", buf, 6)) { double s = 0; if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] gps_data->speed = s; speed_ok = true; } } } } return 0; }