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 __GSM3_SHIELDV1CLIENTPROVIDER__
|
---|
35 | #define __GSM3_SHIELDV1CLIENTPROVIDER__
|
---|
36 |
|
---|
37 | #include <GSM3MobileClientProvider.h>
|
---|
38 | #include <GSM3ShieldV1BaseProvider.h>
|
---|
39 |
|
---|
40 | class GSM3ShieldV1MultiClientProvider : public GSM3MobileClientProvider, public GSM3ShieldV1BaseProvider
|
---|
41 | {
|
---|
42 | private:
|
---|
43 |
|
---|
44 | int remotePort; // Current operation remote port
|
---|
45 | int idSocket; // Remote ID socket
|
---|
46 | IPAddress remoteIP; // Remote IP address
|
---|
47 |
|
---|
48 | uint16_t sockets;
|
---|
49 |
|
---|
50 | /** Continue to connect TCP client function
|
---|
51 | */
|
---|
52 | void connectTCPClientContinue();
|
---|
53 |
|
---|
54 | /** Continue to disconnect TCP client function
|
---|
55 | */
|
---|
56 | void disconnectTCPContinue();
|
---|
57 |
|
---|
58 | /** Continue to begin socket for write function
|
---|
59 | */
|
---|
60 | void beginWriteSocketContinue();
|
---|
61 |
|
---|
62 | /** Continue to end write socket function
|
---|
63 | */
|
---|
64 | void endWriteSocketContinue();
|
---|
65 |
|
---|
66 | /** Continue to available socket function
|
---|
67 | */
|
---|
68 | void availableSocketContinue();
|
---|
69 |
|
---|
70 | /** Continue to flush socket function
|
---|
71 | */
|
---|
72 | void flushSocketContinue();
|
---|
73 |
|
---|
74 | // GATHER!
|
---|
75 | bool flagReadingSocket; //In case socket data being read, update fullBufferSocket in the next buffer.
|
---|
76 | bool fullBufferSocket; //To detect if the socket data being read needs another buffer.
|
---|
77 | bool client1_server0; //1 Client, 0 Server.
|
---|
78 |
|
---|
79 | /** Parse QIRD response
|
---|
80 | @param rsp Returns true if expected response exists
|
---|
81 | @return true if command executed correctly
|
---|
82 | */
|
---|
83 | bool parseQIRD_head(bool& rsp);
|
---|
84 |
|
---|
85 | public:
|
---|
86 |
|
---|
87 | /** Constructor */
|
---|
88 | GSM3ShieldV1MultiClientProvider();
|
---|
89 |
|
---|
90 | /** Minimum socket
|
---|
91 | @return 0
|
---|
92 | */
|
---|
93 | int minSocket(){return 0;};
|
---|
94 |
|
---|
95 | /** Maximum socket
|
---|
96 | @return 5
|
---|
97 | */
|
---|
98 | int maxSocket(){return 5;};
|
---|
99 |
|
---|
100 | /** Connect to a remote TCP server
|
---|
101 | @param server String with IP or server name
|
---|
102 | @param port Remote port number
|
---|
103 | @param id_socket Local socket number
|
---|
104 | @return 0 if command running, 1 if success, otherwise error
|
---|
105 | */
|
---|
106 | int connectTCPClient(const char* server, int port, int id_socket);
|
---|
107 |
|
---|
108 | /** Connect to a remote TCP server
|
---|
109 | @param add Remote IP address
|
---|
110 | @param port Remote port number
|
---|
111 | @param id_socket Local socket number
|
---|
112 | @return 0 if command running, 1 if success, otherwise error
|
---|
113 | */
|
---|
114 | int connectTCPClient(IPAddress add, int port, int id_socket);
|
---|
115 |
|
---|
116 | /** Begin writing through a socket
|
---|
117 | @param client1Server0 1 if modem acts as client, 0 if acts as server
|
---|
118 | @param id_socket Local socket number
|
---|
119 | @return 0 if command running, 1 if success, otherwise error
|
---|
120 | */
|
---|
121 | void beginWriteSocket(bool client1Server0, int id_socket);
|
---|
122 |
|
---|
123 | /** Write through a socket. MUST go after beginWriteSocket()
|
---|
124 | @param buf characters to be written (final 0 will not be written)
|
---|
125 | */
|
---|
126 | void writeSocket(const char* buf);
|
---|
127 |
|
---|
128 | /** Write through a socket. MUST go after beginWriteSocket()
|
---|
129 | @param c character to be written
|
---|
130 | */
|
---|
131 | void writeSocket(char c);
|
---|
132 |
|
---|
133 | /** Finish current writing
|
---|
134 | */
|
---|
135 | void endWriteSocket();
|
---|
136 |
|
---|
137 | /** Check if there are data to be read in socket.
|
---|
138 | @param client1Server0 1 if modem acts as client, 0 if acts as server
|
---|
139 | @param id_socket Local socket number
|
---|
140 | @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
|
---|
141 | */
|
---|
142 | int availableSocket(bool client, int id_socket); // With "available" and "readSocket" ask the modem for 1500 bytes.
|
---|
143 |
|
---|
144 | /** Read a character from socket
|
---|
145 | @return socket
|
---|
146 | */
|
---|
147 | int readSocket(); //If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY
|
---|
148 |
|
---|
149 | /** Flush socket
|
---|
150 | */
|
---|
151 | void flushSocket();
|
---|
152 |
|
---|
153 | /** Get a character but will not advance the buffer head
|
---|
154 | @return character
|
---|
155 | */
|
---|
156 | int peekSocket();
|
---|
157 |
|
---|
158 | /** Close a socket
|
---|
159 | @param client1Server0 1 if modem acts as client, 0 if acts as server
|
---|
160 | @param id_socket Local socket number
|
---|
161 | @return 0 if command running, 1 if success, otherwise error
|
---|
162 | */
|
---|
163 | int disconnectTCP(bool client1Server0, int id_socket);
|
---|
164 |
|
---|
165 | /** Recognize unsolicited event
|
---|
166 | @param from
|
---|
167 | @return true if successful
|
---|
168 | */
|
---|
169 | bool recognizeUnsolicitedEvent(byte from);
|
---|
170 |
|
---|
171 | /** Manages modem response
|
---|
172 | @param from Initial byte of buffer
|
---|
173 | @param to Final byte of buffer
|
---|
174 | */
|
---|
175 | void manageResponse(byte from, byte to);
|
---|
176 |
|
---|
177 | /** Get last command status
|
---|
178 | @return returns 0 if last command is still executing, 1 success, >1 error
|
---|
179 | */
|
---|
180 | int ready(){return GSM3ShieldV1BaseProvider::ready();};
|
---|
181 |
|
---|
182 | /** Get client socket
|
---|
183 | @param socket
|
---|
184 | @return socket
|
---|
185 | */
|
---|
186 | int getSocket(int socket=-1);
|
---|
187 |
|
---|
188 | /** Release socket
|
---|
189 | @param socket Socket for release
|
---|
190 | */
|
---|
191 | void releaseSocket(int socket);
|
---|
192 |
|
---|
193 | /** Get socket client status
|
---|
194 | @param socket Socket
|
---|
195 | @return socket client status
|
---|
196 | */
|
---|
197 | bool getStatusSocketClient(uint8_t socket);
|
---|
198 |
|
---|
199 | };
|
---|
200 |
|
---|
201 |
|
---|
202 | #endif
|
---|