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:
screamer
Date:
Tue May 13 14:32:33 2014 +0000
Parent:
8:1ee8ba65061a
Parent:
7:1278e9dde24e
Child:
10:24671d8aa0c9
Commit message:
Merge

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	Tue May 13 14:28:31 2014 +0000
+++ b/GPRS.cpp	Tue May 13 14:32:33 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	Tue May 13 14:28:31 2014 +0000
+++ b/GPRS.h	Tue May 13 14:32:33 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,11 +50,12 @@
      *  @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;
     };
-
-    /** Init GPRS module including SIM card check & signal strength & network check
+    
+    int powerCheck(void);
+    /** init GPRS module including SIM card check & signal strength & network check
      *  @returns
      *      0 on success,
      *      -1 on error