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:28:31 2014 +0000
Parent:
6:e508f9ee7922
Child:
9:2f5445178940
Commit message:
Fix the source/header files to match the case name of the class. Tune the documentation

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
gprs.cpp Show diff for this revision Revisions of this file
gprs.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPRS.cpp	Tue May 13 14:28:31 2014 +0000
@@ -0,0 +1,332 @@
+/*
+  gprs.cpp
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:lawliet.zou@gmail.com
+  2013-11-14
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include "GPRS.h"
+
+int GPRS::readBuffer(char *buffer,int count)
+{
+    int i = 0;
+    timeCnt.start();  // start timer
+    while(1) {
+        while (gprsSerial.readable()) {
+            char c = gprsSerial.getc();
+            if (c == '\r' || c == '\n') c = '$';
+            buffer[i++] = c;
+            if(i > count)break;
+        }
+        if(i > count)break;
+        if(timeCnt.read() > DEFAULT_TIMEOUT) {
+            timeCnt.stop();
+            timeCnt.reset();
+            break;
+        }
+    }
+    wait(0.5);
+    while(gprsSerial.readable()) {	// display the other thing..
+        char c = gprsSerial.getc();
+    }
+    return 0;
+}
+
+void cleanBuffer(char *buffer, int count)
+{
+    for(int i=0; i < count; i++) {
+        buffer[i] = '\0';
+    }
+}
+
+void GPRS::sendCmd(char *cmd)
+{
+    gprsSerial.puts(cmd);
+}
+
+int GPRS::waitForResp(char *resp, int timeout)
+{
+    int len = strlen(resp);
+    int sum=0;
+    timeCnt.start();
+
+    while(1) {
+        if(gprsSerial.readable()) {
+            char c = gprsSerial.getc();
+            sum = (c==resp[sum]) ? sum+1 : 0;
+            if(sum == len)break;
+        }
+        if(timeCnt.read() > timeout) {	// time out
+            timeCnt.stop();
+            timeCnt.reset();
+            return -1;
+        }
+    }
+    timeCnt.stop();                	// stop timer
+    timeCnt.reset();             		// clear timer
+    while(gprsSerial.readable()) {  	// display the other thing..
+        char c = gprsSerial.getc();
+    }
+
+    return 0;
+}
+
+int GPRS::sendCmdAndWaitForResp(char *cmd, char *resp, int timeout)
+{
+    sendCmd(cmd);
+    return waitForResp(resp,timeout);
+}
+
+int GPRS::init(void)
+{
+    if(0 != checkSIMStatus()) {
+        return -1;
+    }
+    if(checkSignalStrength()<1) {
+        return -1;
+    }
+    if(0 != settingSMS()) {
+        return -1;
+    }
+    return 0;
+}
+
+int GPRS::checkSIMStatus(void)
+{
+    char gprsBuffer[30];
+    int count = 0;
+    cleanBuffer(gprsBuffer,30);
+    while(count < 3) {
+        sendCmd("AT+CPIN?\r\n");
+        readBuffer(gprsBuffer,30);
+        if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
+            break;
+        }
+        count++;
+        wait(1);
+    }
+
+    if(count == 3) {
+        return -1;
+    }
+    return 0;
+}
+
+int GPRS::checkSignalStrength(void)
+{
+    char gprsBuffer[100];
+    int index,count = 0;
+    cleanBuffer(gprsBuffer,100);
+    while(count < 3) {
+        sendCmd("AT+CSQ\r\n");
+        readBuffer(gprsBuffer,25);
+        if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
+            break;
+        }
+        count++;
+        wait(1);
+    }
+    if(count == 3) {
+        return -1;
+    }
+    return index;
+}
+
+int GPRS::settingSMS(void)
+{
+    if(0 != sendCmdAndWaitForResp("AT+CNMI=2,2\r\n", "OK", DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    if(0 != sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    return 0;
+}
+
+int GPRS::sendSMS(char *number, char *data)
+{
+    char cmd[64];
+    while(gprsSerial.readable()) {
+        char c = gprsSerial.getc();
+    }
+    snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n",number);
+    if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    wait(1);
+    gprsSerial.puts(data);
+    gprsSerial.putc((char)0x1a);
+    return 0;
+}
+
+int GPRS::readSMS(char *message, int index)
+{
+    int i = 0;
+    char gprsBuffer[100];
+    char *p,*s;
+    gprsSerial.printf("AT+CMGR=%d\r\n",index);
+    cleanBuffer(gprsBuffer,100);
+    readBuffer(gprsBuffer,100);
+    if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
+        return -1;
+    }
+    if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
+        p = s + 6;
+        while((*p != '$')&&(i < SMS_MAX_LENGTH-1)) {
+            message[i++] = *(p++);
+        }
+        message[i] = '\0';
+    }
+    return 0;
+}
+
+int GPRS::deleteSMS(int index)
+{
+    char cmd[32];
+    snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
+    sendCmd(cmd);
+    return 0;
+}
+
+int GPRS::getSMS(char* message)
+{
+    if(NULL != messageBuffer) {
+        strncpy(message,messageBuffer,SMS_MAX_LENGTH);
+    }
+    return 0;
+}
+
+int GPRS::callUp(char *number)
+{
+    if(0 != sendCmdAndWaitForResp("AT+COLP=1\r\n","OK",5)) {
+        return -1;
+    }
+    wait(1);
+    gprsSerial.printf("\r\nATD%s;\r\n",NULL==number?phoneNumber:number);
+    return 0;
+}
+
+int GPRS::answer(void)
+{
+    gprsSerial.printf("ATA\r\n");
+    return 0;
+}
+
+int GPRS::loopHandle(void)
+{
+    char gprsBuffer[100];
+    int i = 0;
+    char *s = NULL;
+    cleanBuffer(gprsBuffer,100);
+    while(gprsSerial.readable()) {
+        char c = gprsSerial.getc();
+    }
+    wait(1);
+START:
+    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();
+            break;
+        }
+    }
+    if(NULL != strstr(gprsBuffer,"RING")) {
+        return MESSAGE_RING;
+    } else if(NULL != (s = strstr(gprsBuffer,"+CMT"))) { //SMS: $$+CMTI: "SM",24$$
+        if(NULL != (s = strstr(gprsBuffer,"+32"))) {
+            s += 6;
+            int i = 0;
+            cleanBuffer(messageBuffer,SMS_MAX_LENGTH);
+            while((*s != '$')&&(i < SMS_MAX_LENGTH-1)) {
+                messageBuffer[i++] = *(s++);
+            }
+            messageBuffer[i] = '\0';
+            return MESSAGE_SMS;
+        } else {
+            goto START;
+        }
+    } else {
+        goto START;
+    }
+}
+
+int GPRS::networkInit(char* apn, char* userName, char* passWord)
+{
+    char cstt[64];
+    snprintf(cstt,sizeof(cstt),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",apn,userName,passWord);
+    if(0 != sendCmdAndWaitForResp(cstt, "OK", DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    return 0;
+}
+
+int GPRS::connectTCP(char *ip, char *port)
+{
+    char cipstart[64];
+#if 0
+    if(0 != sendCmdAndWaitForResp("AT+CSTT=\"CMNET\",\"\",\"\"\r\n", "OK", 5)) {
+        return -1;
+    }
+#endif
+    sprintf(cipstart, "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"\r\n", ip, port);
+    if(0 != sendCmdAndWaitForResp(cipstart, "OK", DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    return 0;
+}
+int GPRS::sendTCPData(char *data)
+{
+    char cmd[64];
+    int len = strlen(data);
+    snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d\r\n",len);
+    if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    if(0 != sendCmdAndWaitForResp(data,"OK",DEFAULT_TIMEOUT)) {
+        return -1;
+    }
+    return 0;
+}
+
+int GPRS::closeTCP(void)
+{
+    sendCmd("AT+CIPCLOSE\r\n");
+    return 0;
+}
+
+int GPRS::shutTCP(void)
+{
+    sendCmd("AT+CIPSHUT\r\n");
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPRS.h	Tue May 13 14:28:31 2014 +0000
@@ -0,0 +1,219 @@
+/*
+  gprs.h
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:lawliet.zou@gmail.com
+  2013-11-14
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __GPRS_H__
+#define __GPRS_H__
+
+#include <stdio.h>
+#include "mbed.h"
+
+#define DEFAULT_TIMEOUT     5
+#define SMS_MAX_LENGTH      16
+
+enum GPRS_MESSAGE {
+    MESSAGE_RING = 0,
+    MESSAGE_SMS  = 1,
+    MESSAGE_ERROR
+};
+
+
+/** GPRS class.
+ *  Used for mobile communication. attention that GPRS module communicate with MCU in serial protocol
+ */
+class GPRS
+{
+public:
+    /** Create GPRS instance
+     *  @param tx  uart transmit pin to communicate with GPRS module
+     *  @param rx  uart receive pin to communicate with GPRS module
+     *  @param baudRate baud rate of uart communication
+     *  @param number default phone number during mobile communication
+     */
+    GPRS(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) {
+        gprsSerial.baud(baudRate);
+        phoneNumber = number;
+    };
+
+    /** Init GPRS module including SIM card check & signal strength & network check
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int init(void);
+
+    /** Check SIM card' Status
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int checkSIMStatus(void);
+
+    /** Check signal strength
+     *  @returns
+     *      signal strength in number(ex 3,4,5,6,7,8...) on success,
+     *      -1 on error
+     */
+    int checkSignalStrength(void);
+
+    /** Set SMS format and processing mode
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int settingSMS(void);
+
+    /** Send text SMS
+     *  @param  *number    phone number which SMS will be send to
+     *  @param  *data   message that will be send to
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int sendSMS(char *number, char *data);
+
+    /** Read SMS by index
+     *  @param  *message   buffer used to get SMS message
+     *  @param  index    which SMS message to read
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int readSMS(char *message, int index);
+
+    /** Delete SMS message on SIM card
+     *  @param  *index    the index number which SMS message will be delete
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int deleteSMS(int index);
+
+    /** Read SMS when coming a message,it will be store in messageBuffer.
+     *  @param message  buffer used to get SMS message
+     */
+    int getSMS(char* message);
+
+    /** Call someone
+     *  @param  *number    the phone number which you want to call
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int callUp(char *number);
+
+    /** Auto answer if coming a call
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int answer(void);
+
+    /** A loop to wait for some event. if a call comes in, it will auto answer it and if a SMS message comes in, it will read the message
+     *  @param  *check    whether to check phone number when get event
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int loopHandle(void);
+
+    /** GPRS network init
+     *  @param *apn Access  Point Name to connect network
+     *  @param *userName    general is empty
+     *  @param *passWord    general is empty
+     */
+
+    int networkInit(char* apn, char* userName = NULL, char* passWord = NULL);
+    /** Build TCP connect
+     *  @param  *ip    ip address which will connect to
+     *  @param  *port   TCP server' port number
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int connectTCP(char *ip, char *port);
+
+    /** Send data to TCP server
+     *  @param  *data    data that will be send to TCP server
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int sendTCPData(char *data);
+
+    /** Close TCP connection
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int closeTCP(void);
+
+    /** Close TCP service
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int shutTCP(void);
+
+    Serial gprsSerial;
+    //USBSerial pc;
+
+private:
+    /** Read from GPRS module and save to buffer array
+     *  @param  *buffer buffer array to save what read from GPRS module
+     *  @param  *count  the maximal bytes number read from GPRS module
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int readBuffer(char *buffer,int count);
+
+    /** Send AT command to GPRS module
+     *  @param  *cmd command array which will be send to GPRS module
+     */
+    void sendCmd(char *cmd);
+
+    /** Check GPRS module response before timeout
+     *  @param  *resp   correct response which GPRS module will return
+     *  @param  *timeout    waiting seconds till timeout
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int waitForResp(char *resp, int timeout);
+
+    /** Send AT command to GPRS module and wait for correct response
+     *  @param  *cmd    AT command which will be send to GPRS module
+     *  @param  *resp   correct response which GPRS module will return
+     *  @param  *timeout    waiting seconds till timeout
+     *  @returns
+     *      0 on success,
+     *      -1 on error
+     */
+    int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout);
+
+    Timer timeCnt;
+    char *phoneNumber;
+    char messageBuffer[SMS_MAX_LENGTH];
+};
+
+#endif
+
--- a/gprs.cpp	Mon Feb 10 03:23:02 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,332 +0,0 @@
-/*
-  gprs.cpp
-  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Author:lawliet.zou@gmail.com
-  2013-11-14
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#include "gprs.h"
-
-int GPRS::readBuffer(char *buffer,int count)
-{
-    int i = 0;
-    timeCnt.start();  // start timer
-    while(1) {
-        while (gprsSerial.readable()) {
-            char c = gprsSerial.getc();
-            if (c == '\r' || c == '\n') c = '$';
-            buffer[i++] = c;
-            if(i > count)break;
-        }
-        if(i > count)break;
-        if(timeCnt.read() > DEFAULT_TIMEOUT) {
-            timeCnt.stop();
-            timeCnt.reset();
-            break;
-        }
-    }
-    wait(0.5);
-    while(gprsSerial.readable()) {	// display the other thing..
-        char c = gprsSerial.getc();
-    }
-    return 0;
-}
-
-void cleanBuffer(char *buffer, int count)
-{
-    for(int i=0; i < count; i++) {
-        buffer[i] = '\0';
-    }
-}
-
-void GPRS::sendCmd(char *cmd)
-{
-    gprsSerial.puts(cmd);
-}
-
-int GPRS::waitForResp(char *resp, int timeout)
-{
-    int len = strlen(resp);
-    int sum=0;
-    timeCnt.start();
-
-    while(1) {
-        if(gprsSerial.readable()) {
-            char c = gprsSerial.getc();
-            sum = (c==resp[sum]) ? sum+1 : 0;
-            if(sum == len)break;
-        }
-        if(timeCnt.read() > timeout) {	// time out
-            timeCnt.stop();
-            timeCnt.reset();
-            return -1;
-        }
-    }
-    timeCnt.stop();                	// stop timer
-    timeCnt.reset();             		// clear timer
-    while(gprsSerial.readable()) {  	// display the other thing..
-        char c = gprsSerial.getc();
-    }
-
-    return 0;
-}
-
-int GPRS::sendCmdAndWaitForResp(char *cmd, char *resp, int timeout)
-{
-    sendCmd(cmd);
-    return waitForResp(resp,timeout);
-}
-
-int GPRS::init(void)
-{
-    if(0 != checkSIMStatus()) {
-        return -1;
-    }
-    if(checkSignalStrength()<1) {
-        return -1;
-    }
-    if(0 != settingSMS()) {
-        return -1;
-    }
-    return 0;
-}
-
-int GPRS::checkSIMStatus(void)
-{
-    char gprsBuffer[30];
-    int count = 0;
-    cleanBuffer(gprsBuffer,30);
-    while(count < 3) {
-        sendCmd("AT+CPIN?\r\n");
-        readBuffer(gprsBuffer,30);
-        if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
-            break;
-        }
-        count++;
-        wait(1);
-    }
-
-    if(count == 3) {
-        return -1;
-    }
-    return 0;
-}
-
-int GPRS::checkSignalStrength(void)
-{
-    char gprsBuffer[100];
-    int index,count = 0;
-    cleanBuffer(gprsBuffer,100);
-    while(count < 3) {
-        sendCmd("AT+CSQ\r\n");
-        readBuffer(gprsBuffer,25);
-        if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
-            break;
-        }
-        count++;
-        wait(1);
-    }
-    if(count == 3) {
-        return -1;
-    }
-    return index;
-}
-
-int GPRS::settingSMS(void)
-{
-    if(0 != sendCmdAndWaitForResp("AT+CNMI=2,2\r\n", "OK", DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    if(0 != sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    return 0;
-}
-
-int GPRS::sendSMS(char *number, char *data)
-{
-    char cmd[64];
-    while(gprsSerial.readable()) {
-        char c = gprsSerial.getc();
-    }
-    snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n",number);
-    if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    wait(1);
-    gprsSerial.puts(data);
-    gprsSerial.putc((char)0x1a);
-    return 0;
-}
-
-int GPRS::readSMS(char *message, int index)
-{
-    int i = 0;
-    char gprsBuffer[100];
-    char *p,*s;
-    gprsSerial.printf("AT+CMGR=%d\r\n",index);
-    cleanBuffer(gprsBuffer,100);
-    readBuffer(gprsBuffer,100);
-    if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
-        return -1;
-    }
-    if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
-        p = s + 6;
-        while((*p != '$')&&(i < SMS_MAX_LENGTH-1)) {
-            message[i++] = *(p++);
-        }
-        message[i] = '\0';
-    }
-    return 0;
-}
-
-int GPRS::deleteSMS(int index)
-{
-    char cmd[32];
-    snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
-    sendCmd(cmd);
-    return 0;
-}
-
-int GPRS::getSMS(char* message)
-{
-    if(NULL != messageBuffer) {
-        strncpy(message,messageBuffer,SMS_MAX_LENGTH);
-    }
-    return 0;
-}
-
-int GPRS::callUp(char *number)
-{
-    if(0 != sendCmdAndWaitForResp("AT+COLP=1\r\n","OK",5)) {
-        return -1;
-    }
-    wait(1);
-    gprsSerial.printf("\r\nATD%s;\r\n",NULL==number?phoneNumber:number);
-    return 0;
-}
-
-int GPRS::answer(void)
-{
-    gprsSerial.printf("ATA\r\n");
-    return 0;
-}
-
-int GPRS::loopHandle(void)
-{
-    char gprsBuffer[100];
-    int i = 0;
-    char *s = NULL;
-    cleanBuffer(gprsBuffer,100);
-    while(gprsSerial.readable()) {
-        char c = gprsSerial.getc();
-    }
-    wait(1);
-START:
-    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();
-            break;
-        }
-    }
-    if(NULL != strstr(gprsBuffer,"RING")) {
-        return MESSAGE_RING;
-    } else if(NULL != (s = strstr(gprsBuffer,"+CMT"))) { //SMS: $$+CMTI: "SM",24$$
-        if(NULL != (s = strstr(gprsBuffer,"+32"))) {
-            s += 6;
-            int i = 0;
-            cleanBuffer(messageBuffer,SMS_MAX_LENGTH);
-            while((*s != '$')&&(i < SMS_MAX_LENGTH-1)) {
-                messageBuffer[i++] = *(s++);
-            }
-            messageBuffer[i] = '\0';
-            return MESSAGE_SMS;
-        } else {
-            goto START;
-        }
-    } else {
-        goto START;
-    }
-}
-
-int GPRS::networkInit(char* apn, char* userName, char* passWord)
-{
-    char cstt[64];
-    snprintf(cstt,sizeof(cstt),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",apn,userName,passWord);
-    if(0 != sendCmdAndWaitForResp(cstt, "OK", DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    return 0;
-}
-
-int GPRS::connectTCP(char *ip, char *port)
-{
-    char cipstart[64];
-#if 0
-    if(0 != sendCmdAndWaitForResp("AT+CSTT=\"CMNET\",\"\",\"\"\r\n", "OK", 5)) {
-        return -1;
-    }
-#endif
-    sprintf(cipstart, "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"\r\n", ip, port);
-    if(0 != sendCmdAndWaitForResp(cipstart, "OK", DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    return 0;
-}
-int GPRS::sendTCPData(char *data)
-{
-    char cmd[64];
-    int len = strlen(data);
-    snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d\r\n",len);
-    if(0 != sendCmdAndWaitForResp(cmd,">",DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    if(0 != sendCmdAndWaitForResp(data,"OK",DEFAULT_TIMEOUT)) {
-        return -1;
-    }
-    return 0;
-}
-
-int GPRS::closeTCP(void)
-{
-    sendCmd("AT+CIPCLOSE\r\n");
-    return 0;
-}
-
-int GPRS::shutTCP(void)
-{
-    sendCmd("AT+CIPSHUT\r\n");
-    return 0;
-}
--- a/gprs.h	Mon Feb 10 03:23:02 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,217 +0,0 @@
-/*
-  gprs.h
-  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Author:lawliet.zou@gmail.com
-  2013-11-14
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-#ifndef __GPRS_H__
-#define __GPRS_H__
-
-#include <stdio.h>
-#include "mbed.h"
-
-#define DEFAULT_TIMEOUT     5
-#define SMS_MAX_LENGTH      16
-
-enum GPRS_MESSAGE {
-    MESSAGE_RING = 0,
-    MESSAGE_SMS  = 1,
-    MESSAGE_ERROR
-};
-
-
-/** GPRS class.
- *  Used for mobile communication. attention that GPRS module communicate with MCU in serial protocol
- */
-class GPRS
-{
-public:
-    /** Create GPRS instance
-     *  @param tx  uart transmit pin to communicate with GPRS module
-     *  @param rx  uart receive pin to communicate with GPRS module
-     *  @param baudRate baud rate of uart communication
-     *  @param number default phone number during mobile communication
-     */
-    GPRS(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) {
-        gprsSerial.baud(baudRate);
-        phoneNumber = number;
-    };
-
-    /** init GPRS module including SIM card check & signal strength & network check
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int init(void);
-
-    /** check SIM card' Status
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int checkSIMStatus(void);
-
-    /** check signal strength
-     *  @returns
-     *      signal strength in number(ex 3,4,5,6,7,8...) on success
-     *      -1 on error
-     */
-    int checkSignalStrength(void);
-
-    /** set SMS format and processing mode
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int settingSMS(void);
-
-    /** send text SMS
-     *  @param  *number    phone number which SMS will be send to
-     *  @param  *data   message that will be send to
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int sendSMS(char *number, char *data);
-
-    /** read SMS by index
-     *  @param  *message   buffer used to get SMS message
-         *  @param  index    which SMS message to read
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int readSMS(char *message, int index);
-
-    /** delete SMS message on SIM card
-     *  @param  *index    the index number which SMS message will be delete
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int deleteSMS(int index);
-
-    /** read SMS when coming a message,it will be store in messageBuffer.
-     *  @param message  buffer used to get SMS message
-     */
-    int getSMS(char* message);
-
-    /** call someone
-     *  @param  *number    the phone number which you want to call
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int callUp(char *number);
-
-    /** auto answer if coming a call
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int answer(void);
-
-    /** a loop to wait for some event. if a call comes in, it will auto answer it and if a SMS message comes in, it will read the message
-     *  @param  *check    whether to check phone number when get event
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int loopHandle(void);
-
-    /** gprs network init
-     *  @param *apn Access  Point Name to connect network
-     *  @param *userName    general is empty
-     *  @param *passWord    general is empty
-     */
-    int networkInit(char* apn, char* userName = NULL, char* passWord = NULL);
-    /** build TCP connect
-     *  @param  *ip    ip address which will connect to
-     *  @param  *port   TCP server' port number
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int connectTCP(char *ip, char *port);
-
-    /** send data to TCP server
-     *  @param  *data    data that will be send to TCP server
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int sendTCPData(char *data);
-
-    /** close TCP connection
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int closeTCP(void);
-
-    /** close TCP service
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int shutTCP(void);
-
-    Serial gprsSerial;
-    //USBSerial pc;
-private:
-    /** read from GPRS module and save to buffer array
-     *  @param  *buffer buffer array to save what read from GPRS module
-     *  @param  *count  the maximal bytes number read from GPRS module
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int readBuffer(char *buffer,int count);
-
-    /** send AT command to GPRS module
-     *  @param  *cmd command array which will be send to GPRS module
-     */
-    void sendCmd(char *cmd);
-
-    /** check GPRS module response before timeout
-     *  @param  *resp   correct response which GPRS module will return
-     *  @param  *timeout    waiting seconds till timeout
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int waitForResp(char *resp, int timeout);
-
-    /** send AT command to GPRS module and wait for correct response
-     *  @param  *cmd    AT command which will be send to GPRS module
-     *  @param  *resp   correct response which GPRS module will return
-     *  @param  *timeout    waiting seconds till timeout
-     *  @returns
-     *      0 on success
-     *      -1 on error
-     */
-    int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout);
-
-    Timer timeCnt;
-    char *phoneNumber;
-    char messageBuffer[SMS_MAX_LENGTH];
-};
-
-#endif
-