[136] | 1 | /*
|
---|
| 2 | This file is part of the GSM3 communications library for Arduino
|
---|
| 3 | -- Multi-transport communications platform
|
---|
| 4 | -- Fully asynchronous
|
---|
| 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
|
---|
| 6 | -- Voice calls
|
---|
| 7 | -- SMS
|
---|
| 8 | -- TCP/IP connections
|
---|
| 9 | -- HTTP basic clients
|
---|
| 10 |
|
---|
| 11 | This library has been developed by Telefónica Digital - PDI -
|
---|
| 12 | - Physical Internet Lab, as part as its collaboration with
|
---|
| 13 | Arduino and the Open Hardware Community.
|
---|
| 14 |
|
---|
| 15 | September-December 2012
|
---|
| 16 |
|
---|
| 17 | This library is free software; you can redistribute it and/or
|
---|
| 18 | modify it under the terms of the GNU Lesser General Public
|
---|
| 19 | License as published by the Free Software Foundation; either
|
---|
| 20 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 21 |
|
---|
| 22 | This library is distributed in the hope that it will be useful,
|
---|
| 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 25 | Lesser General Public License for more details.
|
---|
| 26 |
|
---|
| 27 | You should have received a copy of the GNU Lesser General Public
|
---|
| 28 | License along with this library; if not, write to the Free Software
|
---|
| 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 30 |
|
---|
| 31 | The latest version of this library can always be found at
|
---|
| 32 | https://github.com/BlueVia/Official-Arduino
|
---|
| 33 | */
|
---|
| 34 | #ifndef _GSM3MOBILEMOCKUPPROVIDER_
|
---|
| 35 | #define _GSM3MOBILEMOCKUPPROVIDER_
|
---|
| 36 |
|
---|
| 37 | #include <GSM3MobileNetworkProvider.h>
|
---|
| 38 | #include <GSM3MobileVoiceProvider.h>
|
---|
| 39 |
|
---|
| 40 | class GSM3MobileMockupProvider: public GSM3MobileNetworkProvider
|
---|
| 41 | {
|
---|
| 42 | private:
|
---|
| 43 | // Introducing this status is quite "heavy". But something like this should
|
---|
| 44 | // be added to ShieldV1. Or not.
|
---|
| 45 | // Note, in ShieldV1 there is no "RECEIVINGSMS" status.
|
---|
| 46 | enum GSM3_modemlinest_e { IDLE, WAITINGANSWER, SENDINGSMS};
|
---|
| 47 | GSM3_modemlinest_e lineStatus;
|
---|
| 48 | char* msgExample;
|
---|
| 49 | int msgIndex;
|
---|
| 50 |
|
---|
| 51 | public:
|
---|
| 52 |
|
---|
| 53 | /** Minimum socket
|
---|
| 54 | @return 1
|
---|
| 55 | */
|
---|
| 56 | inline int minSocket(){return 1;};
|
---|
| 57 |
|
---|
| 58 | /** Maximum socket
|
---|
| 59 | @return 8
|
---|
| 60 | */
|
---|
| 61 | inline int maxSocket(){return 8;};
|
---|
| 62 |
|
---|
| 63 | /** Constructor */
|
---|
| 64 | GSM3MobileMockupProvider();
|
---|
| 65 |
|
---|
| 66 | /** Get network status
|
---|
| 67 | @return network status
|
---|
| 68 | */
|
---|
| 69 | inline GSM3_NetworkStatus_t getStatus(){return ERROR;};
|
---|
| 70 |
|
---|
| 71 | /** Get voice call status
|
---|
| 72 | @return call status
|
---|
| 73 | */
|
---|
| 74 | inline GSM3_voiceCall_st getvoiceCallStatus(){return IDLE_CALL;};
|
---|
| 75 |
|
---|
| 76 | /** Get last command status
|
---|
| 77 | @return Returns 0 if last command is still executing, 1 success, >1 error
|
---|
| 78 | */
|
---|
| 79 | int ready();
|
---|
| 80 | inline void closeCommand(int code){};
|
---|
| 81 |
|
---|
| 82 | //Configuration functions.
|
---|
| 83 |
|
---|
| 84 | /** Begin connection
|
---|
| 85 | @param pin PIN code
|
---|
| 86 | @return
|
---|
| 87 | */
|
---|
| 88 | int begin(char* pin=0);
|
---|
| 89 |
|
---|
| 90 | /** Check if is modem alive
|
---|
| 91 | @return 0
|
---|
| 92 | */
|
---|
| 93 | inline int isModemAlive(){return 0;};
|
---|
| 94 |
|
---|
| 95 | /** Shutdown the modem (power off really)
|
---|
| 96 | @return true if successful
|
---|
| 97 | */
|
---|
| 98 | inline bool shutdown(){return false;};
|
---|
| 99 |
|
---|
| 100 | //Call functions
|
---|
| 101 |
|
---|
| 102 | /** Launch a voice call
|
---|
| 103 | @param number Phone number to be called
|
---|
| 104 | @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
|
---|
| 105 | */
|
---|
| 106 | inline int voiceCall(const char* number){return 0;};
|
---|
| 107 |
|
---|
| 108 | /** Answer a voice call
|
---|
| 109 | @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
|
---|
| 110 | */
|
---|
| 111 | inline int answerCall(){return 0;};
|
---|
| 112 |
|
---|
| 113 | /** Hang a voice call
|
---|
| 114 | @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
|
---|
| 115 | */
|
---|
| 116 | inline int hangCall(){return 0;};
|
---|
| 117 |
|
---|
| 118 | /** Retrieve phone number of caller
|
---|
| 119 | @param buffer Buffer for copy phone number
|
---|
| 120 | @param bufsize Buffer size
|
---|
| 121 | @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
|
---|
| 122 | */
|
---|
| 123 | inline int retrieveCallingNumber(char* buffer, int*& bufsize){return 0;};
|
---|
| 124 |
|
---|
| 125 | // SMS functions
|
---|
| 126 |
|
---|
| 127 | /** Begin a SMS to send it
|
---|
| 128 | @param number Destination
|
---|
| 129 | @return error command if it exists
|
---|
| 130 | */
|
---|
| 131 | int beginSMS(const char* number);
|
---|
| 132 |
|
---|
| 133 | /** End SMS
|
---|
| 134 | @return error command if it exists
|
---|
| 135 | */
|
---|
| 136 | int endSMS();
|
---|
| 137 |
|
---|
| 138 | /** Check if SMS available and prepare it to be read
|
---|
| 139 | @return error command if it exists
|
---|
| 140 | */
|
---|
| 141 | int availableSMS();
|
---|
| 142 |
|
---|
| 143 | /** Read a byte but do not advance the buffer header (circular buffer)
|
---|
| 144 | @return character
|
---|
| 145 | */
|
---|
| 146 | int peek();
|
---|
| 147 |
|
---|
| 148 | /** Delete the SMS from Modem memory and proccess answer
|
---|
| 149 | */
|
---|
| 150 | void flushSMS();
|
---|
| 151 |
|
---|
| 152 | /** Read sender number phone
|
---|
| 153 | @param number Buffer for save number phone
|
---|
| 154 | @param nlength Buffer length
|
---|
| 155 | @return 1 success, >1 error
|
---|
| 156 | */
|
---|
| 157 | int remoteSMSNumber(char* number, int nlength);
|
---|
| 158 |
|
---|
| 159 | /** Read one char for SMS buffer (advance circular buffer)
|
---|
| 160 | @return character
|
---|
| 161 | */
|
---|
| 162 | int readSMS();
|
---|
| 163 |
|
---|
| 164 | /** Write a SMS character by character
|
---|
| 165 | @param c Character
|
---|
| 166 | */
|
---|
| 167 | void writeSMS(char c);
|
---|
| 168 |
|
---|
| 169 | // Socket functions
|
---|
| 170 |
|
---|
| 171 | /** Connect to a remote TCP server
|
---|
| 172 | @param server String with IP or server name
|
---|
| 173 | @param port Remote port number
|
---|
| 174 | @param id_socket Local socket number
|
---|
| 175 | @return 0 if command running, 1 if success, otherwise error
|
---|
| 176 | */
|
---|
| 177 | int connectTCPClient(const char* server, int port, int id_socket);
|
---|
| 178 |
|
---|
| 179 | // Attention to parameter rewriting in ShieldV1
|
---|
| 180 | /** Write buffer information into a socket
|
---|
| 181 | @param buf Buffer
|
---|
| 182 | @param size Buffer size
|
---|
| 183 | @param idsocket Socket
|
---|
| 184 | */
|
---|
| 185 | void writeSocket(const uint8_t *buf, size_t size, int idsocket);
|
---|
| 186 |
|
---|
| 187 | // ShieldV1 will have two reading mechanisms:
|
---|
| 188 | // Mechanism 1: Call AT+QIRD for size bytes. Put them in the circular buffer,
|
---|
| 189 | // fill buf. Take care to xon/xoff effect, as we may copy just a part of the
|
---|
| 190 | // incoming bytes.
|
---|
| 191 | /** Read socket and put information in a buffer
|
---|
| 192 | @param buf Buffer
|
---|
| 193 | @param size Buffer size
|
---|
| 194 | @param idsocket Socket
|
---|
| 195 | @return
|
---|
| 196 | */
|
---|
| 197 | int readSocket(uint8_t *buf, size_t size, int idsocket);
|
---|
| 198 |
|
---|
| 199 | // Mechanism 2 in ShieldV1:
|
---|
| 200 | // When called "available()" or "read()" reuse readSocket code to execute
|
---|
| 201 | // QIRD SYNCHRONOUSLY. Ask the modem for 1500 bytes but do not copy them anywhere,
|
---|
| 202 | // leave data in the circular buffer. Put buffer head at the start of received data.
|
---|
| 203 | // Peek() will get a character but will not advance the buffer head.
|
---|
| 204 | // Read() will get one character. XON/XOFF will take care of buffer filling
|
---|
| 205 | // If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY
|
---|
| 206 | // If the user executes flush(), execute read() until there is nothing more to read()
|
---|
| 207 | // (the modem gives no way to empty the socket of incoming data)
|
---|
| 208 |
|
---|
| 209 | /** Check if there are data to be read in socket.
|
---|
| 210 | @param idsocket Local socket number
|
---|
| 211 | @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
|
---|
| 212 | */
|
---|
| 213 | int availableSocket(int idsocket);
|
---|
| 214 |
|
---|
| 215 | /** Read data (get a character) available in socket
|
---|
| 216 | @param idsocket Socket
|
---|
| 217 | @param advance Determines if advance the buffer head
|
---|
| 218 | @return character
|
---|
| 219 | */
|
---|
| 220 | int readSocket(int idsocket, bool advance=true);
|
---|
| 221 |
|
---|
| 222 | /** Flush socket
|
---|
| 223 | @param idsocket Socket
|
---|
| 224 | */
|
---|
| 225 | void flushSocket(int idsocket);
|
---|
| 226 |
|
---|
| 227 | // This is the same in ShieldV1
|
---|
| 228 | /** Close a socket
|
---|
| 229 | @param idsocket Socket
|
---|
| 230 | @return 0 if command running, 1 if success, otherwise error
|
---|
| 231 | */
|
---|
| 232 | int disconnectTCP(int idsocket);
|
---|
| 233 |
|
---|
| 234 | // TCP Server. Attention. Changing the int*&. We'll receive a buffer for the IP
|
---|
| 235 | // If the pointer ins NULL just forget it
|
---|
| 236 | // I think that opening a server does not occupy a socket. Is that true?
|
---|
| 237 | /** Establish a TCP connection
|
---|
| 238 | @param port Port
|
---|
| 239 | @param localIP IP address
|
---|
| 240 | @param localIPlength IP address size in characters
|
---|
| 241 | @return command error if exists
|
---|
| 242 | */
|
---|
| 243 | int connectTCPServer(int port, char* localIP, int* localIPlength);
|
---|
| 244 |
|
---|
| 245 | // Modem sockets status. Return TRUE if the modem thinks the socket is occupied.
|
---|
| 246 | // This should be detected through an unrequisited response
|
---|
| 247 | /** Get modem status
|
---|
| 248 | @param s Socket
|
---|
| 249 | @return modem status (true if connected)
|
---|
| 250 | */
|
---|
| 251 | bool getSocketModemStatus(uint8_t s);
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 | };
|
---|
| 255 | #endif
|
---|