ghrh
GPRS.h@8:1ee8ba65061a, 2014-05-13 (annotated)
- Committer:
- screamer
- Date:
- Tue May 13 14:28:31 2014 +0000
- Revision:
- 8:1ee8ba65061a
- Parent:
- gprs.h@6:e508f9ee7922
- Child:
- 9:2f5445178940
Fix the source/header files to match the case name of the class. Tune the documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:a5ae94727346 | 1 | /* |
lawliet | 3:48ee24a4b0f3 | 2 | gprs.h |
lawliet | 0:a5ae94727346 | 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:a5ae94727346 | 4 | |
lawliet | 0:a5ae94727346 | 5 | Author:lawliet.zou@gmail.com |
lawliet | 0:a5ae94727346 | 6 | 2013-11-14 |
lawliet | 0:a5ae94727346 | 7 | |
lawliet | 0:a5ae94727346 | 8 | This library is free software; you can redistribute it and/or |
lawliet | 0:a5ae94727346 | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 0:a5ae94727346 | 10 | License as published by the Free Software Foundation; either |
lawliet | 0:a5ae94727346 | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 0:a5ae94727346 | 12 | |
lawliet | 0:a5ae94727346 | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 0:a5ae94727346 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 0:a5ae94727346 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 0:a5ae94727346 | 16 | Lesser General Public License for more details. |
lawliet | 0:a5ae94727346 | 17 | |
lawliet | 0:a5ae94727346 | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 0:a5ae94727346 | 19 | License along with this library; if not, write to the Free Software |
lawliet | 0:a5ae94727346 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 0:a5ae94727346 | 21 | */ |
lawliet | 0:a5ae94727346 | 22 | |
lawliet | 0:a5ae94727346 | 23 | #ifndef __GPRS_H__ |
lawliet | 0:a5ae94727346 | 24 | #define __GPRS_H__ |
lawliet | 0:a5ae94727346 | 25 | |
lawliet | 3:48ee24a4b0f3 | 26 | #include <stdio.h> |
lawliet | 0:a5ae94727346 | 27 | #include "mbed.h" |
lawliet | 3:48ee24a4b0f3 | 28 | |
lawliet | 3:48ee24a4b0f3 | 29 | #define DEFAULT_TIMEOUT 5 |
lawliet | 4:63a2619b423b | 30 | #define SMS_MAX_LENGTH 16 |
lawliet | 4:63a2619b423b | 31 | |
lawliet | 4:63a2619b423b | 32 | enum GPRS_MESSAGE { |
lawliet | 4:63a2619b423b | 33 | MESSAGE_RING = 0, |
lawliet | 4:63a2619b423b | 34 | MESSAGE_SMS = 1, |
lawliet | 4:63a2619b423b | 35 | MESSAGE_ERROR |
lawliet | 4:63a2619b423b | 36 | }; |
lawliet | 4:63a2619b423b | 37 | |
lawliet | 3:48ee24a4b0f3 | 38 | |
lawliet | 2:16985da3a446 | 39 | /** GPRS class. |
lawliet | 2:16985da3a446 | 40 | * Used for mobile communication. attention that GPRS module communicate with MCU in serial protocol |
lawliet | 2:16985da3a446 | 41 | */ |
lawliet | 2:16985da3a446 | 42 | class GPRS |
lawliet | 1:642a8dbe076c | 43 | { |
lawliet | 1:642a8dbe076c | 44 | public: |
lawliet | 2:16985da3a446 | 45 | /** Create GPRS instance |
lawliet | 2:16985da3a446 | 46 | * @param tx uart transmit pin to communicate with GPRS module |
lawliet | 2:16985da3a446 | 47 | * @param rx uart receive pin to communicate with GPRS module |
lawliet | 2:16985da3a446 | 48 | * @param baudRate baud rate of uart communication |
lawliet | 2:16985da3a446 | 49 | * @param number default phone number during mobile communication |
lawliet | 2:16985da3a446 | 50 | */ |
lawliet | 2:16985da3a446 | 51 | GPRS(PinName tx, PinName rx, int baudRate,char *number) : gprsSerial(tx, rx) { |
lawliet | 2:16985da3a446 | 52 | gprsSerial.baud(baudRate); |
lawliet | 2:16985da3a446 | 53 | phoneNumber = number; |
lawliet | 1:642a8dbe076c | 54 | }; |
lawliet | 2:16985da3a446 | 55 | |
screamer | 8:1ee8ba65061a | 56 | /** Init GPRS module including SIM card check & signal strength & network check |
lawliet | 2:16985da3a446 | 57 | * @returns |
screamer | 8:1ee8ba65061a | 58 | * 0 on success, |
lawliet | 2:16985da3a446 | 59 | * -1 on error |
lawliet | 2:16985da3a446 | 60 | */ |
lawliet | 1:642a8dbe076c | 61 | int init(void); |
lawliet | 2:16985da3a446 | 62 | |
screamer | 8:1ee8ba65061a | 63 | /** Check SIM card' Status |
lawliet | 4:63a2619b423b | 64 | * @returns |
screamer | 8:1ee8ba65061a | 65 | * 0 on success, |
lawliet | 4:63a2619b423b | 66 | * -1 on error |
lawliet | 4:63a2619b423b | 67 | */ |
lawliet | 4:63a2619b423b | 68 | int checkSIMStatus(void); |
lawliet | 4:63a2619b423b | 69 | |
screamer | 8:1ee8ba65061a | 70 | /** Check signal strength |
lawliet | 4:63a2619b423b | 71 | * @returns |
screamer | 8:1ee8ba65061a | 72 | * signal strength in number(ex 3,4,5,6,7,8...) on success, |
lawliet | 4:63a2619b423b | 73 | * -1 on error |
lawliet | 4:63a2619b423b | 74 | */ |
lawliet | 4:63a2619b423b | 75 | int checkSignalStrength(void); |
lawliet | 4:63a2619b423b | 76 | |
screamer | 8:1ee8ba65061a | 77 | /** Set SMS format and processing mode |
lawliet | 4:63a2619b423b | 78 | * @returns |
screamer | 8:1ee8ba65061a | 79 | * 0 on success, |
lawliet | 4:63a2619b423b | 80 | * -1 on error |
lawliet | 4:63a2619b423b | 81 | */ |
lawliet | 4:63a2619b423b | 82 | int settingSMS(void); |
lawliet | 4:63a2619b423b | 83 | |
screamer | 8:1ee8ba65061a | 84 | /** Send text SMS |
lawliet | 4:63a2619b423b | 85 | * @param *number phone number which SMS will be send to |
lawliet | 4:63a2619b423b | 86 | * @param *data message that will be send to |
lawliet | 4:63a2619b423b | 87 | * @returns |
screamer | 8:1ee8ba65061a | 88 | * 0 on success, |
lawliet | 4:63a2619b423b | 89 | * -1 on error |
lawliet | 4:63a2619b423b | 90 | */ |
lawliet | 4:63a2619b423b | 91 | int sendSMS(char *number, char *data); |
lawliet | 4:63a2619b423b | 92 | |
screamer | 8:1ee8ba65061a | 93 | /** Read SMS by index |
lawliet | 4:63a2619b423b | 94 | * @param *message buffer used to get SMS message |
screamer | 8:1ee8ba65061a | 95 | * @param index which SMS message to read |
lawliet | 4:63a2619b423b | 96 | * @returns |
screamer | 8:1ee8ba65061a | 97 | * 0 on success, |
lawliet | 4:63a2619b423b | 98 | * -1 on error |
lawliet | 4:63a2619b423b | 99 | */ |
lawliet | 4:63a2619b423b | 100 | int readSMS(char *message, int index); |
lawliet | 4:63a2619b423b | 101 | |
screamer | 8:1ee8ba65061a | 102 | /** Delete SMS message on SIM card |
lawliet | 4:63a2619b423b | 103 | * @param *index the index number which SMS message will be delete |
lawliet | 4:63a2619b423b | 104 | * @returns |
screamer | 8:1ee8ba65061a | 105 | * 0 on success, |
lawliet | 4:63a2619b423b | 106 | * -1 on error |
lawliet | 4:63a2619b423b | 107 | */ |
lawliet | 4:63a2619b423b | 108 | int deleteSMS(int index); |
lawliet | 4:63a2619b423b | 109 | |
screamer | 8:1ee8ba65061a | 110 | /** Read SMS when coming a message,it will be store in messageBuffer. |
lawliet | 4:63a2619b423b | 111 | * @param message buffer used to get SMS message |
lawliet | 4:63a2619b423b | 112 | */ |
lawliet | 4:63a2619b423b | 113 | int getSMS(char* message); |
lawliet | 4:63a2619b423b | 114 | |
screamer | 8:1ee8ba65061a | 115 | /** Call someone |
lawliet | 4:63a2619b423b | 116 | * @param *number the phone number which you want to call |
lawliet | 4:63a2619b423b | 117 | * @returns |
screamer | 8:1ee8ba65061a | 118 | * 0 on success, |
lawliet | 4:63a2619b423b | 119 | * -1 on error |
lawliet | 4:63a2619b423b | 120 | */ |
lawliet | 4:63a2619b423b | 121 | int callUp(char *number); |
lawliet | 4:63a2619b423b | 122 | |
screamer | 8:1ee8ba65061a | 123 | /** Auto answer if coming a call |
lawliet | 4:63a2619b423b | 124 | * @returns |
screamer | 8:1ee8ba65061a | 125 | * 0 on success, |
lawliet | 4:63a2619b423b | 126 | * -1 on error |
lawliet | 4:63a2619b423b | 127 | */ |
lawliet | 4:63a2619b423b | 128 | int answer(void); |
lawliet | 4:63a2619b423b | 129 | |
screamer | 8:1ee8ba65061a | 130 | /** 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 |
lawliet | 4:63a2619b423b | 131 | * @param *check whether to check phone number when get event |
lawliet | 4:63a2619b423b | 132 | * @returns |
screamer | 8:1ee8ba65061a | 133 | * 0 on success, |
lawliet | 4:63a2619b423b | 134 | * -1 on error |
lawliet | 4:63a2619b423b | 135 | */ |
lawliet | 4:63a2619b423b | 136 | int loopHandle(void); |
lawliet | 4:63a2619b423b | 137 | |
screamer | 8:1ee8ba65061a | 138 | /** GPRS network init |
lawliet | 5:ac2342f162fa | 139 | * @param *apn Access Point Name to connect network |
lawliet | 5:ac2342f162fa | 140 | * @param *userName general is empty |
lawliet | 5:ac2342f162fa | 141 | * @param *passWord general is empty |
lawliet | 5:ac2342f162fa | 142 | */ |
screamer | 8:1ee8ba65061a | 143 | |
lawliet | 5:ac2342f162fa | 144 | int networkInit(char* apn, char* userName = NULL, char* passWord = NULL); |
screamer | 8:1ee8ba65061a | 145 | /** Build TCP connect |
lawliet | 4:63a2619b423b | 146 | * @param *ip ip address which will connect to |
lawliet | 4:63a2619b423b | 147 | * @param *port TCP server' port number |
lawliet | 4:63a2619b423b | 148 | * @returns |
screamer | 8:1ee8ba65061a | 149 | * 0 on success, |
lawliet | 4:63a2619b423b | 150 | * -1 on error |
lawliet | 4:63a2619b423b | 151 | */ |
lawliet | 4:63a2619b423b | 152 | int connectTCP(char *ip, char *port); |
lawliet | 4:63a2619b423b | 153 | |
screamer | 8:1ee8ba65061a | 154 | /** Send data to TCP server |
lawliet | 4:63a2619b423b | 155 | * @param *data data that will be send to TCP server |
lawliet | 4:63a2619b423b | 156 | * @returns |
screamer | 8:1ee8ba65061a | 157 | * 0 on success, |
lawliet | 4:63a2619b423b | 158 | * -1 on error |
lawliet | 4:63a2619b423b | 159 | */ |
lawliet | 4:63a2619b423b | 160 | int sendTCPData(char *data); |
lawliet | 4:63a2619b423b | 161 | |
screamer | 8:1ee8ba65061a | 162 | /** Close TCP connection |
lawliet | 4:63a2619b423b | 163 | * @returns |
screamer | 8:1ee8ba65061a | 164 | * 0 on success, |
lawliet | 4:63a2619b423b | 165 | * -1 on error |
lawliet | 4:63a2619b423b | 166 | */ |
lawliet | 4:63a2619b423b | 167 | int closeTCP(void); |
lawliet | 4:63a2619b423b | 168 | |
screamer | 8:1ee8ba65061a | 169 | /** Close TCP service |
lawliet | 4:63a2619b423b | 170 | * @returns |
screamer | 8:1ee8ba65061a | 171 | * 0 on success, |
lawliet | 4:63a2619b423b | 172 | * -1 on error |
lawliet | 4:63a2619b423b | 173 | */ |
lawliet | 4:63a2619b423b | 174 | int shutTCP(void); |
lawliet | 4:63a2619b423b | 175 | |
lawliet | 6:e508f9ee7922 | 176 | Serial gprsSerial; |
lawliet | 4:63a2619b423b | 177 | //USBSerial pc; |
screamer | 8:1ee8ba65061a | 178 | |
lawliet | 4:63a2619b423b | 179 | private: |
screamer | 8:1ee8ba65061a | 180 | /** Read from GPRS module and save to buffer array |
lawliet | 2:16985da3a446 | 181 | * @param *buffer buffer array to save what read from GPRS module |
lawliet | 2:16985da3a446 | 182 | * @param *count the maximal bytes number read from GPRS module |
lawliet | 2:16985da3a446 | 183 | * @returns |
screamer | 8:1ee8ba65061a | 184 | * 0 on success, |
lawliet | 2:16985da3a446 | 185 | * -1 on error |
lawliet | 2:16985da3a446 | 186 | */ |
lawliet | 1:642a8dbe076c | 187 | int readBuffer(char *buffer,int count); |
lawliet | 2:16985da3a446 | 188 | |
screamer | 8:1ee8ba65061a | 189 | /** Send AT command to GPRS module |
lawliet | 2:16985da3a446 | 190 | * @param *cmd command array which will be send to GPRS module |
lawliet | 2:16985da3a446 | 191 | */ |
lawliet | 1:642a8dbe076c | 192 | void sendCmd(char *cmd); |
lawliet | 2:16985da3a446 | 193 | |
screamer | 8:1ee8ba65061a | 194 | /** Check GPRS module response before timeout |
lawliet | 2:16985da3a446 | 195 | * @param *resp correct response which GPRS module will return |
lawliet | 2:16985da3a446 | 196 | * @param *timeout waiting seconds till timeout |
lawliet | 2:16985da3a446 | 197 | * @returns |
screamer | 8:1ee8ba65061a | 198 | * 0 on success, |
lawliet | 2:16985da3a446 | 199 | * -1 on error |
lawliet | 2:16985da3a446 | 200 | */ |
lawliet | 1:642a8dbe076c | 201 | int waitForResp(char *resp, int timeout); |
lawliet | 2:16985da3a446 | 202 | |
screamer | 8:1ee8ba65061a | 203 | /** Send AT command to GPRS module and wait for correct response |
lawliet | 2:16985da3a446 | 204 | * @param *cmd AT command which will be send to GPRS module |
lawliet | 2:16985da3a446 | 205 | * @param *resp correct response which GPRS module will return |
lawliet | 2:16985da3a446 | 206 | * @param *timeout waiting seconds till timeout |
lawliet | 2:16985da3a446 | 207 | * @returns |
screamer | 8:1ee8ba65061a | 208 | * 0 on success, |
lawliet | 2:16985da3a446 | 209 | * -1 on error |
lawliet | 2:16985da3a446 | 210 | */ |
lawliet | 1:642a8dbe076c | 211 | int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout); |
lawliet | 2:16985da3a446 | 212 | |
lawliet | 1:642a8dbe076c | 213 | Timer timeCnt; |
lawliet | 1:642a8dbe076c | 214 | char *phoneNumber; |
lawliet | 4:63a2619b423b | 215 | char messageBuffer[SMS_MAX_LENGTH]; |
lawliet | 0:a5ae94727346 | 216 | }; |
lawliet | 0:a5ae94727346 | 217 | |
lawliet | 0:a5ae94727346 | 218 | #endif |
lawliet | 4:63a2619b423b | 219 |