this is a test code for Mbed_Shield_GPRS_Call_Up_Test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lawliet
Date:
Wed Nov 20 08:55:24 2013 +0000
Commit message:
Initial Version Of Mbed Shield GPRS Call up Test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c527f1f10d44 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 20 08:55:24 2013 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+
+Serial gprs(p28,p27); //Hardware Serial
+//Serial gprs(p9,p10);   //Software Serial
+Serial pc(USBTX,USBRX);
+
+Timer timeCnt;
+
+int waitForResp(char *resp, int timeout)
+{
+    int len = strlen(resp);
+    int sum=0;
+    timeCnt.start();
+
+    while(1) {
+        if(gprs.readable()) {
+            char c = gprs.getc();
+            sum = (c==resp[sum]) ? sum+1 : 0;
+            if(sum == len)break;
+        }
+        if(timeCnt.read() > timeout) {  // time out
+            timeCnt.stop();
+            timeCnt.reset();
+            pc.printf("Error:time out");
+            return -1;
+        }
+    }
+    timeCnt.stop();                 // stop timer
+    timeCnt.reset();                    // clear timer
+    while(gprs.readable()) {      // display the other thing..
+        char c = gprs.getc();
+    }
+
+    return 0;
+}
+
+int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout)
+{
+    gprs.puts(cmd);
+    return waitForResp(resp,timeout);
+}
+
+int callUp(char *number)
+{
+    if(0 != sendCmdAndWaitForResp("AT+COLP=1\r\n","OK",5)) {
+        pc.printf("Error:COLP");
+        return -1;
+    }
+    wait(1);
+    gprs.printf("\r\nATD%s;\r\n",number);
+    return 0;
+}
+
+int main()
+{
+    pc.baud(19200);
+    gprs.baud(19200);
+
+    for(int i = 0; i < 5; i++) {
+        wait(1);
+        printf("wait\n");
+    }
+    callUp("139****7382");
+    while(1);
+}
\ No newline at end of file
diff -r 000000000000 -r c527f1f10d44 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 20 08:55:24 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file