Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
main.cpp@17:726bbc1b73ee, 2014-10-05 (annotated)
- Committer:
- aroulin
- Date:
- Sun Oct 05 12:38:04 2014 +0000
- Revision:
- 17:726bbc1b73ee
- Parent:
- 16:2b2f2a3bde5a
PIN in argument of sms_init;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
philemonf | 0:164fb9518d1a | 1 | #include "mbed.h" |
aroulin | 7:eeef6f9fa1db | 2 | #include "gps_locate.h" |
aroulin | 13:3c1f0b8c1d21 | 3 | #include "sms_lib.h" |
philemonf | 11:5354c4819b25 | 4 | #include "MDM.h" |
philemonf | 1:23ffa0e091bc | 5 | |
philemonf | 0:164fb9518d1a | 6 | int main() { |
aroulin | 16:2b2f2a3bde5a | 7 | |
aroulin | 17:726bbc1b73ee | 8 | // While 1 |
aroulin | 17:726bbc1b73ee | 9 | // Wait for OBJTRACK SMS |
aroulin | 17:726bbc1b73ee | 10 | // Get GPS Location, if timeout, send last known location |
aroulin | 17:726bbc1b73ee | 11 | // Send back SMS with location |
aroulin | 13:3c1f0b8c1d21 | 12 | |
aroulin | 14:d1f114749b3c | 13 | MDMSerial mdm; |
aroulin | 17:726bbc1b73ee | 14 | if(!init_sms_features(&mdm, "5554")) |
aroulin | 17:726bbc1b73ee | 15 | return 0; |
aroulin | 13:3c1f0b8c1d21 | 16 | |
aroulin | 17:726bbc1b73ee | 17 | struct sms_data_t sms; |
aroulin | 14:d1f114749b3c | 18 | char buf1[32]; |
aroulin | 14:d1f114749b3c | 19 | char buf2[256]; |
aroulin | 14:d1f114749b3c | 20 | sms.phone_num = buf1; |
aroulin | 14:d1f114749b3c | 21 | sms.msg_buf = buf2; |
aroulin | 17:726bbc1b73ee | 22 | |
aroulin | 17:726bbc1b73ee | 23 | struct gps_data_t gps_data; |
aroulin | 17:726bbc1b73ee | 24 | memset(&gps_data, 0, sizeof(gps_data)); |
aroulin | 17:726bbc1b73ee | 25 | |
aroulin | 17:726bbc1b73ee | 26 | while(1) { |
aroulin | 17:726bbc1b73ee | 27 | printf("Waiting for SMS\r\n"); |
aroulin | 17:726bbc1b73ee | 28 | fflush(stdout); |
aroulin | 17:726bbc1b73ee | 29 | while(!read_sms(&sms)); |
aroulin | 17:726bbc1b73ee | 30 | printf("Received sms from phone number: %s\r\n", sms.phone_num); |
aroulin | 17:726bbc1b73ee | 31 | printf("%s\r\n", sms.msg_buf); |
aroulin | 17:726bbc1b73ee | 32 | if(strncmp("OBJTRACK", sms.msg_buf, 5) == 0) { |
aroulin | 17:726bbc1b73ee | 33 | gps_locate(&gps_data, 10); |
aroulin | 17:726bbc1b73ee | 34 | printf("Sending GPS Location"); |
aroulin | 17:726bbc1b73ee | 35 | fflush(stdout); |
aroulin | 17:726bbc1b73ee | 36 | snprintf(sms.msg_buf, 256, "My location is: https://maps.google.com/?q=%.5f,%.5f\r\n", gps_data.la, gps_data.lo); |
aroulin | 17:726bbc1b73ee | 37 | send_sms(&sms); |
aroulin | 16:2b2f2a3bde5a | 38 | } |
aroulin | 17:726bbc1b73ee | 39 | } |
aroulin | 16:2b2f2a3bde5a | 40 | |
philemonf | 1:23ffa0e091bc | 41 | return 0; |
aroulin | 14:d1f114749b3c | 42 | } |