A library for the SIM900 module to enable calling, answering, sending and receiving SMS messages

Dependents:   Seeed_GPRS_Shield_GSM BluetoothNONIN HealthCare_Graduation

Fork of GSM by Components

Files at this revision

API Documentation at this revision

Comitter:
lawliet
Date:
Mon Apr 28 12:32:12 2014 +0000
Parent:
6:e508f9ee7922
Child:
9:2f5445178940
Commit message:
update loopHandle function

Changed in this revision

gprs.cpp Show annotated file Show diff for this revision Revisions of this file
gprs.h Show annotated file Show diff for this revision Revisions of this file
--- 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;
         }
     }
--- a/gprs.h	Mon Feb 10 03:23:02 2014 +0000
+++ b/gprs.h	Mon Apr 28 12:32:12 2014 +0000
@@ -26,8 +26,9 @@
 #include <stdio.h>
 #include "mbed.h"
 
-#define DEFAULT_TIMEOUT     5
-#define SMS_MAX_LENGTH      16
+#define DEFAULT_TIMEOUT         5
+#define SMS_MAX_LENGTH          16
+
 
 enum GPRS_MESSAGE {
     MESSAGE_RING = 0,
@@ -49,10 +50,11 @@
      *  @param number default phone number during mobile communication
      */
     GPRS(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) {
-        gprsSerial.baud(baudRate);
+        //gprsSerial.baud(baudRate);
         phoneNumber = number;
     };
-
+    
+    int powerCheck(void);
     /** init GPRS module including SIM card check & signal strength & network check
      *  @returns
      *      0 on success