Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
Revision 16:2b2f2a3bde5a, committed 2014-10-01
- Comitter:
- aroulin
- Date:
- Wed Oct 01 08:47:54 2014 +0000
- Parent:
- 15:41e3e4613e34
- Child:
- 17:726bbc1b73ee
- Commit message:
- Adds some timers to timeout GPS test and receive SMS test
Changed in this revision
--- 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
--- a/gps_locate.h Tue Sep 30 18:43:42 2014 +0000 +++ b/gps_locate.h Wed Oct 01 08:47:54 2014 +0000 @@ -6,12 +6,14 @@ double lo; double altitude; double speed; -}; +}; -int gps_on(void); - -int gps_off(void); - +/* + Get GPS Location, blocks until received + all informations needed, Timeout after 20 seconds + + returns: 1 if gps infos are correct, 0 otherwise +*/ int gps_locate(struct gps_data_t* gps_data); #endif \ No newline at end of file
--- a/main.cpp Tue Sep 30 18:43:42 2014 +0000 +++ b/main.cpp Wed Oct 01 08:47:54 2014 +0000 @@ -4,27 +4,40 @@ #include "MDM.h" int main() { - printf("Hello here is the position: "); + + Timer programTimer; + + programTimer.start(); struct gps_data_t gps_data; - gps_locate(&gps_data); - printf("https://maps.google.com/?q=%.5f,%.5f\n", gps_data.la, gps_data.lo); + if(gps_locate(&gps_data)) { + printf("Hello here is the position: "); + printf("https://maps.google.com/?q=%.5f,%.5f\r\n", gps_data.la, gps_data.lo); + } MDMSerial mdm; init_sms_features(&mdm); struct sms_data_t sms; - sms.phone_num = "+41774084185"; + sms.phone_num = "+41763211792"; sms.msg_buf = "Je suis une carte u-blox. Tu veux etre mon ami ?"; - printf("Now I will send a SMS\n"); + printf("Now I will send a SMS\r\n"); send_sms(&sms); + printf("And then wait to receive one\r\n"); char buf1[32]; char buf2[256]; sms.phone_num = buf1; sms.msg_buf = buf2; - - while(!read_sms(&sms)); - printf("Received sms from %s:\n%s\n", sms.phone_num, sms.msg_buf); - printf("End"); + Timer smsTimer; + smsTimer.start(); + while(smsTimer.read() < 40) { + if(read_sms(&sms)) { + printf("Received sms from %s:\r\n%s\r\n", sms.phone_num, sms.msg_buf); + break; + } + } + + programTimer.stop(); + printf("Program time: %f seconds\r\n", programTimer.read()); return 0; } \ No newline at end of file
--- a/main.cpp.orig Tue Sep 30 18:43:42 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#include "mbed.h" -#include "gps_locate.h" -#include "sms_lib.h" -#include "MDM.h" - -int main() { - printf("Hello here is the position: "); - struct gps_data_t gps_data; - gps_locate(&gps_data); - printf("https://maps.google.com/?q=%.5f,%.5f\n", gps_data.la, gps_data.lo); - - MDMSerial mdm; - init_sms_features(&mdm); - struct sms_data_t sms; - sms.phone_num = "+41774084185"; - sms.msg_buf = "Je suis une carte u-blox. Tu veux etre mon ami ?"; - printf("Now I will send a SMS\n"); - send_sms(&sms); - - char buf1[32]; - char buf2[256]; - sms.phone_num = buf1; - sms.msg_buf = buf2; - while(!read_sms(&sms)); - printf("Received sms from %s:\n%s\n", sms.phone_num, sms.msg_buf); - printf("End"); - return 0; -} \ No newline at end of file