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: GPS MODSERIAL mbed-rtos mbed
Diff: main.cpp
- Revision:
- 7:db9226b9b037
- Parent:
- 6:32c25fb48fd2
- Child:
- 8:d4773b6449c5
diff -r 32c25fb48fd2 -r db9226b9b037 main.cpp
--- a/main.cpp Mon Oct 08 06:34:31 2012 +0000
+++ b/main.cpp Tue Oct 09 06:20:57 2012 +0000
@@ -10,8 +10,11 @@
const string GoogleChunk = "https://maps.google.com.au/maps?q=";
const string GoogleExtras = "&z=20";
char GPRSbuffer[512];
+char NUMBER[11];
+char MESSAGE[5];
string dump;
int index;
+long int number;
int i = 0;
GPS gps(p9,p10);
@@ -47,7 +50,7 @@
GPRS.printf("AT+CMGF=1\r\n");
wait(1);
// Set the phone number
- GPRS.printf("AT+CMGS=\"+614<<NUMBER>>\"\r\n");
+ GPRS.printf("AT+CMGS=\"+%s\"\r\n", NUMBER);
wait(1);
// Write out the GPS data in a message
GPRS.printf("Time: %4.2f \nAltitude: %3.2fm\nSpeed: %3.2f Kn\nHeading: %3.2f Deg\nValidity: %c\nFix: %s\nSatellites: %d", gps.time, gps.altitude, gps.speed, gps.heading,gps.validity,gps.fixtype,gps.satellites);
@@ -57,7 +60,7 @@
wait(3);
GPRS.printf("AT+CMGF=1\r\n");
wait(1);
- GPRS.printf("AT+CMGS=\"+614<<NUMBER>>\"\r\n");
+ GPRS.printf("AT+CMGS=\"+%s\"\r\n", NUMBER);
wait(1);
GPRS.printf("Find me at....\n %s%f,%f%s", GoogleChunk, gps.latitude, gps.longitude, GoogleExtras);
wait(1);
@@ -79,27 +82,43 @@
i++;
}
// Uncomment the following to debug
-
- pc.printf("buffer = %s", GPRSbuffer);
-
+ //pc.printf("\nbuffer = %s", GPRSbuffer);
// If we get an SMS notification....
if (sscanf(GPRSbuffer, "$$+CMTI: \"SM\",%d", &index)>0) {
+ i=0;
pc.printf("\nSMS recieved @ index [%d]", index);
- // Do the send SMS routine...
+ memset(GPRSbuffer, '0', 512);
+ i = 0;
+ GPRS.printf("AT+CMGR=%d\r\n", index);
+ wait(1);
+ }
+
+ if (strncmp(GPRSbuffer, "$$+CMGR",7) == 0 ) {
+ for (int k = 24; k < 35; k++) {
+ NUMBER[k-24] = GPRSbuffer[k];
+ }
+ for (int k = 64; k < 68; k++) {
+ MESSAGE[k-64] = GPRSbuffer[k];
+ }
sendSms();
- // Wait for the cascade of \r\nOK\r\n\r\nOK\r\n's from the SMS's to finish
- wait(4);
- // Flush out any left in the serial buffer
- GPRS.rxBufferFlush();
+ //wait(4);
// Reset the GPRS buffer
memset(GPRSbuffer, '0', 512);
// Reset the char counter
i = 0;
- }
- if (strncmp(GPRSbuffer, "$$RING",6) == 0) {
- //dump = "fixed";
- GPRS.printf("ATH0\r\n");
+ }
+
+ if (strncmp(GPRSbuffer, "$$+CMGS",7) == 0) {
+ // Reset the GPRS buffer
+ memset(GPRSbuffer, '0', 512);
+ // Reset the char counter
+ i = 0;
+ }
+
+ if (strncmp(GPRSbuffer, "$$RING",6) == 0) {
+ //dump = "fixed";
+ GPRS.printf("ATH0\r\n");
wait(1);
// Flush any incoming rings in the MODSERIAL buffer
GPRS.rxBufferFlush();
@@ -107,21 +126,22 @@
// Do the send SMS routine...
sendSms();
// Wait for the cascade of [\r\nOK\r\n][\r\nOK\r\n]'s from the SMS's to finish
- wait(4);
+ //wait(4);
// Flush out any left in the serial buffer
GPRS.rxBufferFlush();
// Reset the GPRS buffer
memset(GPRSbuffer, '0', 512);
// Reset the char counter
i = 0;
- } else {
- GPRS.rxBufferFlush();
- // Reset the GPRS buffer
- memset(GPRSbuffer, '0', 512);
- // Reset the char counter
- i = 0;
- pc.printf("\nWaiting for SMS or call...\n");
}
+
+ // Reset the GPRS buffer
+ memset(GPRSbuffer, '0', 512);
+ // Reset the char counter
+ i = 0;
+ pc.printf("\nWaiting for SMS or call...\n");
+ pc.printf("\nThe last number was :+%s", NUMBER);
+ pc.printf("\nThe last message was :%s", MESSAGE);
}
int main()