Prototyping the Adaptable Emergency System on an C027 board.

Dependencies:   C027_Support mbed

Fork of c027_prototyping by Philémon Favrod

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "gps_locate.h"
00003 #include "sms_lib.h"
00004 #include "MDM.h"
00005 
00006 int main() {
00007     
00008     // While 1
00009         // Wait for OBJTRACK SMS
00010         // Get GPS Location, if timeout, send last known location
00011         // Send back SMS with location
00012     
00013     MDMSerial mdm;
00014     if(!init_sms_features(&mdm, "5554"))
00015         return 0;
00016     
00017     struct sms_data_t sms;
00018     char buf1[32];
00019     char buf2[256];
00020     sms.phone_num = buf1;
00021     sms.msg_buf = buf2;
00022     
00023     struct gps_data_t gps_data;
00024     memset(&gps_data, 0, sizeof(gps_data));
00025     
00026     while(1) {
00027         printf("Waiting for SMS\r\n");
00028         fflush(stdout);
00029         while(!read_sms(&sms));
00030         printf("Received sms from phone number: %s\r\n", sms.phone_num);
00031         printf("%s\r\n", sms.msg_buf);
00032         if(strncmp("OBJTRACK", sms.msg_buf, 5) == 0) {
00033             gps_locate(&gps_data, 10);
00034             printf("Sending GPS Location");
00035             fflush(stdout);
00036             snprintf(sms.msg_buf, 256, "My location is: https://maps.google.com/?q=%.5f,%.5f\r\n", gps_data.la, gps_data.lo);
00037             send_sms(&sms);
00038         }
00039     }
00040     
00041     return 0;
00042 }