Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
Diff: gps_locate.cpp
- Revision:
- 16:2b2f2a3bde5a
- Parent:
- 15:41e3e4613e34
- Child:
- 17:726bbc1b73ee
--- a/gps_locate.cpp Tue Sep 30 18:43:42 2014 +0000 +++ b/gps_locate.cpp Wed Oct 01 08:47:54 2014 +0000 @@ -13,14 +13,27 @@ int gps_locate(struct gps_data_t* gps_data) { + printf("GPS Location begins\r\n"); + // Power on gps GPSI2C gps; + + // Timeout timer + Timer timer; + timer.start(); 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(!coord_ok || !altitude_ok || !speed_ok) { + + if(timer.read() > 20) { + printf("GPS Location TimeOut, abort...\r\n"); + timer.stop(); + return 0; + } + while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) { int len = LENGTH(ret); if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { @@ -49,6 +62,7 @@ } } } - - return 0; + + timer.stop(); + return 1; } \ No newline at end of file