ok

Revision:
7:1278e9dde24e
Parent:
5:ac2342f162fa
--- a/gprs.cpp	Mon Feb 10 03:23:02 2014 +0000
+++ b/gprs.cpp	Mon Apr 28 12:32:12 2014 +0000
@@ -91,8 +91,17 @@
     return waitForResp(resp,timeout);
 }
 
+int GPRS::powerCheck(void)
+{
+	return sendCmdAndWaitForResp("AT\r\n", "OK", 2);	
+}
+
 int GPRS::init(void)
 {
+    for(int i = 0; i < 3; i++){
+    	sendCmdAndWaitForResp("AT\r\n", "OK", DEFAULT_TIMEOUT);
+    	wait(0.5);
+    }
     if(0 != checkSIMStatus()) {
         return -1;
     }
@@ -229,35 +238,35 @@
 int GPRS::loopHandle(void)
 {
     char gprsBuffer[100];
-    int i = 0;
+    int i;
     char *s = NULL;
-    cleanBuffer(gprsBuffer,100);
     while(gprsSerial.readable()) {
         char c = gprsSerial.getc();
     }
-    wait(1);
+    wait(0.5);
 START:
+	cleanBuffer(gprsBuffer,100);
+	i = 0;
     while(1) {
         if(gprsSerial.readable()) {
-            break;
-        }
-        wait(1);
-    }
-    timeCnt.start();  // start timer
-    while(1) {
-        while (gprsSerial.readable()) {
-            char c = gprsSerial.getc();
-            if (c == '\r' || c == '\n') c = '$';
-            gprsBuffer[i] = c;
-            i++;
-            if(i > 100) {
-                i = 0;
-                break;
-            }
-        }
-        if(timeCnt.read() > 5) {          // time out
-            timeCnt.stop();
-            timeCnt.reset();
+		    timeCnt.start();  // start timer
+		    while(1) {
+		        while (gprsSerial.readable()) {
+		            char c = gprsSerial.getc();
+		            if (c == '\r' || c == '\n') c = '$';
+		            gprsBuffer[i] = c;
+		            i++;
+		            if(i > 100) {
+		                i = 0;
+		                break;
+		            }
+		        }
+		        if(timeCnt.read() > 2) {          // time out
+		            timeCnt.stop();
+		            timeCnt.reset();
+		            break;
+		        }
+		    }
             break;
         }
     }