rhr
Diff: gprs.h
- Revision:
- 4:63a2619b423b
- Parent:
- 3:48ee24a4b0f3
- Child:
- 5:ac2342f162fa
diff -r 48ee24a4b0f3 -r 63a2619b423b gprs.h --- a/gprs.h Fri Jan 10 05:59:36 2014 +0000 +++ b/gprs.h Tue Jan 21 06:44:58 2014 +0000 @@ -27,6 +27,14 @@ #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 @@ -52,6 +60,115 @@ */ 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); + + /** 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); + + + //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 @@ -85,116 +202,11 @@ */ int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout); - /** 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); - - /** check network is ok or not - * @returns - * 0 on success - * -1 on error - */ - int networkInit(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 if get a SMS - * @param *buffer buffer that get from GPRS module(when getting a SMS, GPRS module will return a buffer array) - * @param *message buffer used to get SMS message - * @param check whether to check phone number(we may only want to read SMS from specified phone number) - * @returns - * 0 on success - * -1 on error - */ - int readSMS(char *buffer, char *message, bool check); - - /** 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); - - /** 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 loop(bool check); - - /** 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); - - /** used for serial debug, you can specify tx and rx pin and then communicate with GPRS module with common AT commands - */ - void serialDebug(PinName tx, PinName rx); - -private: Serial gprsSerial; Timer timeCnt; char *phoneNumber; + char messageBuffer[SMS_MAX_LENGTH]; }; #endif +