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
GSM.h
00001 /* 00002 GSM.h 00003 2013 Copyright (c) Seeed Technology Inc. All right reserved. 00004 00005 Author:lawliet.zou@gmail.com 00006 2013-11-14 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef __GSM_H__ 00024 #define __GSM_H__ 00025 00026 #include <stdio.h> 00027 #include "mbed.h" 00028 00029 #define DEFAULT_TIMEOUT 5 00030 #define SMS_MAX_LENGTH 16 00031 00032 00033 enum GSM_MESSAGE { 00034 MESSAGE_RING = 0, 00035 MESSAGE_SMS = 1, 00036 MESSAGE_ERROR 00037 }; 00038 00039 00040 /** GSM class. 00041 * Used for mobile communication. attention that GSM module communicate with MCU in serial protocol 00042 */ 00043 class GSM 00044 { 00045 public: 00046 /** Create GSM instance 00047 * @param tx uart transmit pin to communicate with GSM module 00048 * @param rx uart receive pin to communicate with GSM module 00049 * @param baudRate baud rate of uart communication 00050 * @param number default phone number during mobile communication 00051 */ 00052 GSM(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) { 00053 //gprsSerial.baud(baudRate); 00054 phoneNumber = number; 00055 }; 00056 00057 int powerCheck(void); 00058 /** init GSM module including SIM card check & signal strength & network check 00059 * @returns 00060 * 0 on success, 00061 * -1 on error 00062 */ 00063 int init(void); 00064 00065 /** Check SIM card' Status 00066 * @returns 00067 * 0 on success, 00068 * -1 on error 00069 */ 00070 int checkSIMStatus(void); 00071 00072 /** Check signal strength 00073 * @returns 00074 * signal strength in number(ex 3,4,5,6,7,8...) on success, 00075 * -1 on error 00076 */ 00077 int checkSignalStrength(void); 00078 00079 /** Set SMS format and processing mode 00080 * @returns 00081 * 0 on success, 00082 * -1 on error 00083 */ 00084 int settingSMS(void); 00085 00086 /** Send text SMS 00087 * @param *number phone number which SMS will be send to 00088 * @param *data message that will be send to 00089 * @returns 00090 * 0 on success, 00091 * -1 on error 00092 */ 00093 int sendSMS(char *number, char *data); 00094 00095 /** Read SMS by index 00096 * @param *message buffer used to get SMS message 00097 * @param index which SMS message to read 00098 * @returns 00099 * 0 on success, 00100 * -1 on error 00101 */ 00102 int readSMS(char *message, int index); 00103 00104 /** Delete SMS message on SIM card 00105 * @param *index the index number which SMS message will be delete 00106 * @returns 00107 * 0 on success, 00108 * -1 on error 00109 */ 00110 int deleteSMS(int index); 00111 00112 /** Read SMS when coming a message,it will be store in messageBuffer. 00113 * @param message buffer used to get SMS message 00114 */ 00115 int getSMS(char* message); 00116 00117 /** Call someone 00118 * @param *number the phone number which you want to call 00119 * @returns 00120 * 0 on success, 00121 * -1 on error 00122 */ 00123 int callUp(char *number); 00124 00125 /** Auto answer if coming a call 00126 * @returns 00127 * 0 on success, 00128 * -1 on error 00129 */ 00130 int answer(void); 00131 00132 /** 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 00133 * @param *check whether to check phone number when get event 00134 * @returns 00135 * 0 on success, 00136 * -1 on error 00137 */ 00138 int loopHandle(void); 00139 00140 /** GSM network init 00141 * @param *apn Access Point Name to connect network 00142 * @param *userName general is empty 00143 * @param *passWord general is empty 00144 */ 00145 00146 int networkInit(char* apn, char* userName = NULL, char* passWord = NULL); 00147 /** Build TCP connect 00148 * @param *ip ip address which will connect to 00149 * @param *port TCP server' port number 00150 * @returns 00151 * 0 on success, 00152 * -1 on error 00153 */ 00154 int connectTCP(char *ip, char *port); 00155 00156 /** Send data to TCP server 00157 * @param *data data that will be send to TCP server 00158 * @returns 00159 * 0 on success, 00160 * -1 on error 00161 */ 00162 int sendTCPData(char *data); 00163 00164 /** Close TCP connection 00165 * @returns 00166 * 0 on success, 00167 * -1 on error 00168 */ 00169 int closeTCP(void); 00170 00171 /** Close TCP service 00172 * @returns 00173 * 0 on success, 00174 * -1 on error 00175 */ 00176 int shutTCP(void); 00177 00178 Serial gprsSerial; 00179 //USBSerial pc; 00180 00181 private: 00182 /** Read from GSM module and save to buffer array 00183 * @param *buffer buffer array to save what read from GSM module 00184 * @param *count the maximal bytes number read from GSM module 00185 * @returns 00186 * 0 on success, 00187 * -1 on error 00188 */ 00189 int readBuffer(char *buffer,int count); 00190 00191 /** Send AT command to GSM module 00192 * @param *cmd command array which will be send to GSM module 00193 */ 00194 void sendCmd(char *cmd); 00195 00196 /** Check GSM module response before timeout 00197 * @param *resp correct response which GSM module will return 00198 * @param *timeout waiting seconds till timeout 00199 * @returns 00200 * 0 on success, 00201 * -1 on error 00202 */ 00203 int waitForResp(char *resp, int timeout); 00204 00205 /** Send AT command to GSM module and wait for correct response 00206 * @param *cmd AT command which will be send to GSM module 00207 * @param *resp correct response which GSM module will return 00208 * @param *timeout waiting seconds till timeout 00209 * @returns 00210 * 0 on success, 00211 * -1 on error 00212 */ 00213 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout); 00214 00215 Timer timeCnt; 00216 char *phoneNumber; 00217 char messageBuffer[SMS_MAX_LENGTH]; 00218 }; 00219 00220 #endif 00221
Generated on Wed Jul 13 2022 12:00:07 by
