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: SDFileSystem dspmodified mbed
Diff: merged_code.cpp
- Revision:
- 24:45bcaa34bcaa
- Parent:
- 23:6a16dc53bdad
- Child:
- 25:236d7a498f38
diff -r 6a16dc53bdad -r 45bcaa34bcaa merged_code.cpp
--- a/merged_code.cpp Thu Jun 25 06:36:32 2015 +0000
+++ b/merged_code.cpp Thu Jun 25 07:18:45 2015 +0000
@@ -134,12 +134,12 @@
}
//--------------------------------------------------------------------------------------------------//
-// Send AT Command (Compare with 2 responses) //
+// Send AT Command (Compare with 2 possible responses) //
//--------------------------------------------------------------------------------------------------//
-int sendATcommand2(char* ATcommand, char* expected_answer1, char* expected_answer2, unsigned int timeout)
+bool sendATcommand2(char* ATcommand, char* expected_answer1, char* expected_answer2, unsigned int timeout)
{
int grs=0;
- int answer=0; //x=0 and answer=0, if not put, AT+CCLK?\r is not executed
+ bool answer=0; //x=0 and answer=0, if not put, AT+CCLK?\r is not executed
char response[300];
memset(response, '\0', 100); // Initialize the string
wait_ms(100);
@@ -174,7 +174,52 @@
answer=1;
}
}
- } while((answer !=1) && ((time(NULL) - previous) < timeout)); // Waits for the asnwer with time out
+ } while((answer==0) && ((time(NULL) - previous) < timeout)); // Waits for the asnwer with time out
+ //pc.printf("\r\nanswer %d\r\n",answer);
+ return answer;
+}
+
+//--------------------------------------------------------------------------------------------------//
+// Send AT Command (Compare with 2 serial responses) //
+//--------------------------------------------------------------------------------------------------//
+bool sendATcommand3(char* ATcommand, char* expected_answer1, char* expected_answer2, unsigned int timeout)
+{
+ int grs=0;
+ bool answer=0; //x=0 and answer=0, if not put, AT+CCLK?\r is not executed
+ char response[300];
+ memset(response, '\0', 100); // Initialize the string
+ wait_ms(100);
+ previous = time(NULL);
+ char dummy;
+ do
+ {
+ if(gsm.readable()!=0)
+ {
+ dummy=gsm.getc();
+ //pc.putc(dummy);
+ }
+ }
+ while((time(NULL) - previous) < 1); // Clean the input buffer
+ //pc.printf("\r\n");
+ gsm.printf("%s \r", ATcommand); // Send the AT command
+ grs = 0;
+ previous = time(NULL);
+ do
+ { // this loop waits for the answer
+ if(gsm.readable() != 0)
+ {
+ response[grs] = gsm.getc(); // if there are data in the UART input buffer, reads it and checks for the asnwer
+ pc.putc(response[grs]);
+ grs++;
+ if (strstr(response, expected_answer1) != NULL)
+ { // check if the desired answer is in the response of the module
+ if (strstr(response, expected_answer2) != NULL)
+ { // check if the desired answer is in the response of the module
+ answer=1;
+ }
+ }
+ }
+ } while((answer==0) && ((time(NULL) - previous) < timeout)); // Waits for the asnwer with time out
//pc.printf("\r\nanswer %d\r\n",answer);
return answer;
}
@@ -683,21 +728,19 @@
//--------------------------------------------------------------------------------------------------//
bool gsm_init()
{
- int cnt = 0;
- while(sendATcommand2("AT+CREG?", "+CREG: 1,1", "+CREG: 1,5", 10)==0) //ATcommand with dual response comparison
+ for(int cnt=0;cnt<5;cnt++) //ATcommand with dual response comparison
{
- if(sendATcommand2("AT+CREG=1", "+CREG:1", "+CREG:5", 5))
- {
- pc.printf("creg success");
- return 1;
- }
- ++cnt;
- if(cnt > 5)
- {
- pc.printf("GSM registration failed");
- return 0;
- }
- }
+ if(sendATcommand2("AT+CREG?", "+CREG: 1,1", "+CREG: 1,5", 10)==0){
+ if(sendATcommand2("AT+CREG=1", "+CREG:1", "+CREG:5", 5))
+ {
+ pc.printf("creg success");
+ return 1;
+ }
+ }
+ else return 1;
+ }
+ pc.printf("GSM registration failed");
+ return 0;
}
//--------------------------------------------------------------------------------------------------//
// FTP Connect function //
@@ -817,7 +860,7 @@
sprintf(command2,"%s/%s/\"", "AT+FTPPUTPATH=\"", ftpputpathname); // For FTPPUTPATHNAME Feature
//sprintf(result2,"%s", "OK");
sendATcommand(command2,"OK", 10,0);
- if((sendATcommand("AT+FTPPUT=1", "OK", 10,2))==2)
+ if(sendATcommand3("AT+FTPPUT=1", "OK", "+FTPPUT:1,1,1294",15))
{
//wait(8);
// pc.printf("in loop");
@@ -1029,7 +1072,7 @@
wait(1);
gsm_rst=1;
wait(8);
- if(gsm_init()==0) reset_mod();
+ if(gsm_init()==0) reset_mod(); //COA for gsm init failure TBD
mkdir("/sd/jas",0777);
int old_hour=100,loopcount=0;
pc.printf("\r\nHelloWorld\r\n");