Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 00009 #ifndef __GSM_H__ 00010 #define __GSM_H__ 00011 00012 #include <stdio.h> 00013 #include "mbed.h" 00014 00015 #define DEFAULT_TIMEOUT 5 00016 #define SMS_MAX_LENGTH 16 00017 00018 00019 enum GSM_MESSAGE { 00020 MESSAGE_RING = 0, 00021 MESSAGE_SMS = 1, 00022 MESSAGE_ERROR 00023 }; 00024 00025 00026 /** GSM class. 00027 * Used for mobile communication. attention that GSM module communicate with MCU in serial protocol 00028 */ 00029 class GSM 00030 { 00031 public: 00032 /** Create GSM instance 00033 * @param tx uart transmit pin to communicate with GSM module 00034 * @param rx uart receive pin to communicate with GSM module 00035 * @param baudRate baud rate of uart communication 00036 * @param number default phone number during mobile communication 00037 */ 00038 GSM(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) { 00039 gprsSerial.baud(baudRate); 00040 phoneNumber = number; 00041 }; 00042 00043 // Fonctions rajoutées pour le projet HAB ; 00044 void gprs_message(char * url , char * message); 00045 00046 00047 00048 00049 int powerCheck(void); 00050 /** init GSM module including SIM card check & signal strength & network check 00051 * @returns 00052 * 0 on success, 00053 * -1 on error 00054 */ 00055 int init(void); 00056 00057 /** Check SIM card' Status 00058 * @returns 00059 * 0 on success, 00060 * -1 on error 00061 */ 00062 int checkSIMStatus(void); 00063 00064 /** Check signal strength 00065 * @returns 00066 * signal strength in number(ex 3,4,5,6,7,8...) on success, 00067 * -1 on error 00068 */ 00069 int checkSignalStrength(void); 00070 00071 /** Set SMS format and processing mode 00072 * @returns 00073 * 0 on success, 00074 * -1 on error 00075 */ 00076 int settingSMS(void); 00077 00078 /** Send text SMS 00079 * @param *number phone number which SMS will be send to 00080 * @param *data message that will be send to 00081 * @returns 00082 * 0 on success, 00083 * -1 on error 00084 */ 00085 int sendSMS(char *number, char *data); 00086 00087 /** Read SMS by index 00088 * @param *message buffer used to get SMS message 00089 * @param index which SMS message to read 00090 * @returns 00091 * 0 on success, 00092 * -1 on error 00093 */ 00094 int readSMS(char *message, int index); 00095 00096 /** Delete SMS message on SIM card 00097 * @param *index the index number which SMS message will be delete 00098 * @returns 00099 * 0 on success, 00100 * -1 on error 00101 */ 00102 int deleteSMS(int index); 00103 00104 /** Read SMS when coming a message,it will be store in messageBuffer. 00105 * @param message buffer used to get SMS message 00106 */ 00107 int getSMS(char* message); 00108 00109 /** Call someone 00110 * @param *number the phone number which you want to call 00111 * @returns 00112 * 0 on success, 00113 * -1 on error 00114 */ 00115 int callUp(char *number); 00116 00117 /** Auto answer if coming a call 00118 * @returns 00119 * 0 on success, 00120 * -1 on error 00121 */ 00122 int answer(void); 00123 00124 /** 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 00125 * @param *check whether to check phone number when get event 00126 * @returns 00127 * 0 on success, 00128 * -1 on error 00129 */ 00130 int loopHandle(void); 00131 00132 /** GSM network init 00133 * @param *apn Access Point Name to connect network 00134 * @param *userName general is empty 00135 * @param *passWord general is empty 00136 */ 00137 00138 int networkInit(char* apn, char* userName = NULL, char* passWord = NULL); 00139 /** Build TCP connect 00140 * @param *ip ip address which will connect to 00141 * @param *port TCP server' port number 00142 * @returns 00143 * 0 on success, 00144 * -1 on error 00145 */ 00146 int connectTCP(char *ip, char *port); 00147 00148 /** Send data to TCP server 00149 * @param *data data that will be send to TCP server 00150 * @returns 00151 * 0 on success, 00152 * -1 on error 00153 */ 00154 int sendTCPData(char *data); 00155 00156 /** Close TCP connection 00157 * @returns 00158 * 0 on success, 00159 * -1 on error 00160 */ 00161 int closeTCP(void); 00162 00163 /** Close TCP service 00164 * @returns 00165 * 0 on success, 00166 * -1 on error 00167 */ 00168 int shutTCP(void); 00169 00170 Serial gprsSerial; 00171 //USBSerial pc; 00172 00173 00174 00175 private: 00176 00177 00178 /** Read from GSM module and save to buffer array 00179 * @param *buffer buffer array to save what read from GSM module 00180 * @param *count the maximal bytes number read from GSM module 00181 * @returns 00182 * 0 on success, 00183 * -1 on error 00184 */ 00185 int readBuffer(char *buffer,int count); 00186 00187 /** Send AT command to GSM module 00188 * @param *cmd command array which will be send to GSM module 00189 */ 00190 void sendCmd(char *cmd); 00191 00192 /** Check GSM module response before timeout 00193 * @param *resp correct response which GSM module will return 00194 * @param *timeout waiting seconds till timeout 00195 * @returns 00196 * 0 on success, 00197 * -1 on error 00198 */ 00199 int waitForResp(char *resp, int timeout); 00200 00201 /** Send AT command to GSM module and wait for correct response 00202 * @param *cmd AT command which will be send to GSM module 00203 * @param *resp correct response which GSM module will return 00204 * @param *timeout waiting seconds till timeout 00205 * @returns 00206 * 0 on success, 00207 * -1 on error 00208 */ 00209 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout); 00210 00211 Timer timeCnt; 00212 char *phoneNumber; 00213 char messageBuffer[SMS_MAX_LENGTH]; 00214 }; 00215 00216 #endif 00217
Generated on Mon Jul 25 2022 08:45:16 by
1.7.2