offer some API for GPRS use, such as call / sms / tcp connect

Dependents:   SDP_Testing

Fork of GPRS by wei zou

Committer:
lawliet
Date:
Tue Jan 21 06:44:58 2014 +0000
Revision:
4:63a2619b423b
Parent:
3:48ee24a4b0f3
Child:
5:ac2342f162fa
verison 2.0 (fix several errors)

Who changed what in which revision?

UserRevisionLine numberNew 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
lawliet 2:16985da3a446 56 /** init GPRS module including SIM card check & signal strength & network check
lawliet 2:16985da3a446 57 * @returns
lawliet 2:16985da3a446 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
lawliet 4:63a2619b423b 63 /** check SIM card' Status
lawliet 4:63a2619b423b 64 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 70 /** check signal strength
lawliet 4:63a2619b423b 71 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 77 /** set SMS format and processing mode
lawliet 4:63a2619b423b 78 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 93 /** read SMS by index
lawliet 4:63a2619b423b 94 * @param *message buffer used to get SMS message
lawliet 4:63a2619b423b 95 * @param index which SMS message to read
lawliet 4:63a2619b423b 96 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 115 /** call someone
lawliet 4:63a2619b423b 116 * @param *number the phone number which you want to call
lawliet 4:63a2619b423b 117 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 123 /** auto answer if coming a call
lawliet 4:63a2619b423b 124 * @returns
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 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
lawliet 4:63a2619b423b 138 /** build TCP connect
lawliet 4:63a2619b423b 139 * @param *ip ip address which will connect to
lawliet 4:63a2619b423b 140 * @param *port TCP server' port number
lawliet 4:63a2619b423b 141 * @returns
lawliet 4:63a2619b423b 142 * 0 on success
lawliet 4:63a2619b423b 143 * -1 on error
lawliet 4:63a2619b423b 144 */
lawliet 4:63a2619b423b 145 int connectTCP(char *ip, char *port);
lawliet 4:63a2619b423b 146
lawliet 4:63a2619b423b 147 /** send data to TCP server
lawliet 4:63a2619b423b 148 * @param *data data that will be send to TCP server
lawliet 4:63a2619b423b 149 * @returns
lawliet 4:63a2619b423b 150 * 0 on success
lawliet 4:63a2619b423b 151 * -1 on error
lawliet 4:63a2619b423b 152 */
lawliet 4:63a2619b423b 153 int sendTCPData(char *data);
lawliet 4:63a2619b423b 154
lawliet 4:63a2619b423b 155 /** close TCP connection
lawliet 4:63a2619b423b 156 * @returns
lawliet 4:63a2619b423b 157 * 0 on success
lawliet 4:63a2619b423b 158 * -1 on error
lawliet 4:63a2619b423b 159 */
lawliet 4:63a2619b423b 160 int closeTCP(void);
lawliet 4:63a2619b423b 161
lawliet 4:63a2619b423b 162 /** close TCP service
lawliet 4:63a2619b423b 163 * @returns
lawliet 4:63a2619b423b 164 * 0 on success
lawliet 4:63a2619b423b 165 * -1 on error
lawliet 4:63a2619b423b 166 */
lawliet 4:63a2619b423b 167 int shutTCP(void);
lawliet 4:63a2619b423b 168
lawliet 4:63a2619b423b 169
lawliet 4:63a2619b423b 170 //USBSerial pc;
lawliet 4:63a2619b423b 171 private:
lawliet 2:16985da3a446 172 /** read from GPRS module and save to buffer array
lawliet 2:16985da3a446 173 * @param *buffer buffer array to save what read from GPRS module
lawliet 2:16985da3a446 174 * @param *count the maximal bytes number read from GPRS module
lawliet 2:16985da3a446 175 * @returns
lawliet 2:16985da3a446 176 * 0 on success
lawliet 2:16985da3a446 177 * -1 on error
lawliet 2:16985da3a446 178 */
lawliet 1:642a8dbe076c 179 int readBuffer(char *buffer,int count);
lawliet 2:16985da3a446 180
lawliet 2:16985da3a446 181 /** send AT command to GPRS module
lawliet 2:16985da3a446 182 * @param *cmd command array which will be send to GPRS module
lawliet 2:16985da3a446 183 */
lawliet 1:642a8dbe076c 184 void sendCmd(char *cmd);
lawliet 2:16985da3a446 185
lawliet 2:16985da3a446 186 /** check GPRS module response before timeout
lawliet 2:16985da3a446 187 * @param *resp correct response which GPRS module will return
lawliet 2:16985da3a446 188 * @param *timeout waiting seconds till timeout
lawliet 2:16985da3a446 189 * @returns
lawliet 2:16985da3a446 190 * 0 on success
lawliet 2:16985da3a446 191 * -1 on error
lawliet 2:16985da3a446 192 */
lawliet 1:642a8dbe076c 193 int waitForResp(char *resp, int timeout);
lawliet 2:16985da3a446 194
lawliet 2:16985da3a446 195 /** send AT command to GPRS module and wait for correct response
lawliet 2:16985da3a446 196 * @param *cmd AT command which will be send to GPRS module
lawliet 2:16985da3a446 197 * @param *resp correct response which GPRS module will return
lawliet 2:16985da3a446 198 * @param *timeout waiting seconds till timeout
lawliet 2:16985da3a446 199 * @returns
lawliet 2:16985da3a446 200 * 0 on success
lawliet 2:16985da3a446 201 * -1 on error
lawliet 2:16985da3a446 202 */
lawliet 1:642a8dbe076c 203 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout);
lawliet 2:16985da3a446 204
lawliet 1:642a8dbe076c 205 Serial gprsSerial;
lawliet 1:642a8dbe076c 206 Timer timeCnt;
lawliet 1:642a8dbe076c 207 char *phoneNumber;
lawliet 4:63a2619b423b 208 char messageBuffer[SMS_MAX_LENGTH];
lawliet 0:a5ae94727346 209 };
lawliet 0:a5ae94727346 210
lawliet 0:a5ae94727346 211 #endif
lawliet 4:63a2619b423b 212