Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
Revision 17:726bbc1b73ee, committed 2014-10-05
- Comitter:
- aroulin
- Date:
- Sun Oct 05 12:38:04 2014 +0000
- Parent:
- 16:2b2f2a3bde5a
- Commit message:
- PIN in argument of sms_init;
Changed in this revision
--- a/gps_locate.cpp Wed Oct 01 08:47:54 2014 +0000 +++ b/gps_locate.cpp Sun Oct 05 12:38:04 2014 +0000 @@ -1,17 +1,7 @@ #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) +int gps_locate(struct gps_data_t* gps_data, int timeout) { printf("GPS Location begins\r\n"); @@ -28,7 +18,7 @@ char buf[512] = {0}; while(!coord_ok || !altitude_ok || !speed_ok) { - if(timer.read() > 20) { + if(timer.read() > timeout) { printf("GPS Location TimeOut, abort...\r\n"); timer.stop(); return 0;
--- a/gps_locate.h Wed Oct 01 08:47:54 2014 +0000 +++ b/gps_locate.h Sun Oct 05 12:38:04 2014 +0000 @@ -10,10 +10,10 @@ /* Get GPS Location, blocks until received - all informations needed, Timeout after 20 seconds + all informations needed, Timeout after timeout seconds returns: 1 if gps infos are correct, 0 otherwise */ -int gps_locate(struct gps_data_t* gps_data); +int gps_locate(struct gps_data_t* gps_data, int timeout); #endif \ No newline at end of file
--- a/main.cpp Wed Oct 01 08:47:54 2014 +0000 +++ b/main.cpp Sun Oct 05 12:38:04 2014 +0000 @@ -5,39 +5,38 @@ int main() { - Timer programTimer; - - programTimer.start(); - struct gps_data_t gps_data; - 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); - } + // While 1 + // Wait for OBJTRACK SMS + // Get GPS Location, if timeout, send last known location + // Send back SMS with location MDMSerial mdm; - init_sms_features(&mdm); - - struct sms_data_t sms; - 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\r\n"); - send_sms(&sms); + if(!init_sms_features(&mdm, "5554")) + return 0; - printf("And then wait to receive one\r\n"); + struct sms_data_t sms; char buf1[32]; char buf2[256]; sms.phone_num = buf1; sms.msg_buf = buf2; - 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; + + struct gps_data_t gps_data; + memset(&gps_data, 0, sizeof(gps_data)); + + while(1) { + printf("Waiting for SMS\r\n"); + fflush(stdout); + while(!read_sms(&sms)); + printf("Received sms from phone number: %s\r\n", sms.phone_num); + printf("%s\r\n", sms.msg_buf); + if(strncmp("OBJTRACK", sms.msg_buf, 5) == 0) { + gps_locate(&gps_data, 10); + printf("Sending GPS Location"); + fflush(stdout); + snprintf(sms.msg_buf, 256, "My location is: https://maps.google.com/?q=%.5f,%.5f\r\n", gps_data.la, gps_data.lo); + send_sms(&sms); } - } + } - programTimer.stop(); - printf("Program time: %f seconds\r\n", programTimer.read()); return 0; } \ No newline at end of file
--- a/sms_lib.cpp Wed Oct 01 08:47:54 2014 +0000 +++ b/sms_lib.cpp Sun Oct 05 12:38:04 2014 +0000 @@ -4,12 +4,10 @@ static MDMSerial *mdm; -int init_sms_features(MDMSerial *_mdm) +int init_sms_features(MDMSerial *_mdm, char* SIMPIN) { mdm = _mdm; - static const char *SIMPIN = "5554"; - MDMParser::DevStatus devStatus = {}; MDMParser::NetStatus netStatus = {}; bool mdmOk = mdm->init(SIMPIN, &devStatus);
--- a/sms_lib.h Wed Oct 01 08:47:54 2014 +0000 +++ b/sms_lib.h Sun Oct 05 12:38:04 2014 +0000 @@ -8,7 +8,7 @@ char *msg_buf; }; -int init_sms_features(MDMSerial *_mdm); +int init_sms_features(MDMSerial *_mdm, char* SIMPIN); int send_sms(struct sms_data_t *sms); int read_sms(struct sms_data_t *sms);