Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
Diff: main.cpp
- Revision:
- 17:726bbc1b73ee
- Parent:
- 16:2b2f2a3bde5a
--- 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
