1 | #include <GSM3ShieldV1MultiClientProvider.h>
|
---|
2 | #include <GSM3ShieldV1ModemCore.h>
|
---|
3 |
|
---|
4 | const char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC=";
|
---|
5 |
|
---|
6 | #define __TOUTFLUSH__ 10000
|
---|
7 |
|
---|
8 | GSM3ShieldV1MultiClientProvider::GSM3ShieldV1MultiClientProvider()
|
---|
9 | {
|
---|
10 | theGSM3MobileClientProvider=this;
|
---|
11 | theGSM3ShieldV1ModemCore.registerUMProvider(this);
|
---|
12 | };
|
---|
13 |
|
---|
14 | //Response management.
|
---|
15 | void GSM3ShieldV1MultiClientProvider::manageResponse(byte from, byte to)
|
---|
16 | {
|
---|
17 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
|
---|
18 | {
|
---|
19 | case XON:
|
---|
20 | if (flagReadingSocket)
|
---|
21 | {
|
---|
22 | // flagReadingSocket = 0;
|
---|
23 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
|
---|
24 | }
|
---|
25 | else theGSM3ShieldV1ModemCore.setOngoingCommand(NONE);
|
---|
26 | break;
|
---|
27 | case NONE:
|
---|
28 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
|
---|
29 | break;
|
---|
30 | case CONNECTTCPCLIENT:
|
---|
31 | connectTCPClientContinue();
|
---|
32 | break;
|
---|
33 | case DISCONNECTTCP:
|
---|
34 | disconnectTCPContinue();
|
---|
35 | break;
|
---|
36 | case BEGINWRITESOCKET:
|
---|
37 | beginWriteSocketContinue();
|
---|
38 | break;
|
---|
39 | case ENDWRITESOCKET:
|
---|
40 | endWriteSocketContinue();
|
---|
41 | break;
|
---|
42 | case AVAILABLESOCKET:
|
---|
43 | availableSocketContinue();
|
---|
44 | break;
|
---|
45 | case FLUSHSOCKET:
|
---|
46 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
|
---|
47 | flushSocketContinue();
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | //Connect TCP main function.
|
---|
53 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(const char* server, int port, int id_socket)
|
---|
54 | {
|
---|
55 | theGSM3ShieldV1ModemCore.setPort(port);
|
---|
56 | idSocket = id_socket;
|
---|
57 |
|
---|
58 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server);
|
---|
59 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT);
|
---|
60 | connectTCPClientContinue();
|
---|
61 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
62 | }
|
---|
63 |
|
---|
64 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(IPAddress add, int port, int id_socket)
|
---|
65 | {
|
---|
66 | remoteIP=add;
|
---|
67 | theGSM3ShieldV1ModemCore.setPhoneNumber(0);
|
---|
68 | return connectTCPClient(0, port, id_socket);
|
---|
69 | }
|
---|
70 |
|
---|
71 | //Connect TCP continue function.
|
---|
72 | void GSM3ShieldV1MultiClientProvider::connectTCPClientContinue()
|
---|
73 | {
|
---|
74 | bool resp;
|
---|
75 | // 0: Dot or DNS notation activation
|
---|
76 | // 1: Disable SW flow control
|
---|
77 | // 2: Waiting for IFC OK
|
---|
78 | // 3: Start-up TCP connection "AT+QIOPEN"
|
---|
79 | // 4: Wait for connection OK
|
---|
80 | // 5: Wait for CONNECT
|
---|
81 |
|
---|
82 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
83 | case 1:
|
---|
84 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false);
|
---|
85 | if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&&
|
---|
86 | ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9'))))
|
---|
87 | {
|
---|
88 | theGSM3ShieldV1ModemCore.print('1');
|
---|
89 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | theGSM3ShieldV1ModemCore.print('0');
|
---|
94 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
95 | }
|
---|
96 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
97 | break;
|
---|
98 | case 2:
|
---|
99 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
100 | {
|
---|
101 | //Response received
|
---|
102 | if(resp)
|
---|
103 | {
|
---|
104 | // AT+QIOPEN
|
---|
105 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false);
|
---|
106 | theGSM3ShieldV1ModemCore.print(idSocket);
|
---|
107 | theGSM3ShieldV1ModemCore.print(",\"TCP\",\"");
|
---|
108 | if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)
|
---|
109 | {
|
---|
110 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber());
|
---|
111 | }
|
---|
112 | else
|
---|
113 | {
|
---|
114 | remoteIP.printTo(theGSM3ShieldV1ModemCore);
|
---|
115 | }
|
---|
116 | theGSM3ShieldV1ModemCore.print('"');
|
---|
117 | theGSM3ShieldV1ModemCore.print(',');
|
---|
118 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort());
|
---|
119 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
120 | theGSM3ShieldV1ModemCore.setCommandCounter(3);
|
---|
121 | }
|
---|
122 | else theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
123 | }
|
---|
124 | break;
|
---|
125 |
|
---|
126 | case 3:
|
---|
127 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
128 | {
|
---|
129 | // Response received
|
---|
130 | if(resp)
|
---|
131 | {
|
---|
132 | // OK Received
|
---|
133 | // Great. Go for the next step
|
---|
134 | theGSM3ShieldV1ModemCore.setCommandCounter(4);
|
---|
135 | }
|
---|
136 | else theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
137 | }
|
---|
138 | break;
|
---|
139 | case 4:
|
---|
140 | char auxLocate [12];
|
---|
141 | prepareAuxLocate(PSTR("CONNECT OK"), auxLocate);
|
---|
142 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate))
|
---|
143 | {
|
---|
144 | // Response received
|
---|
145 | if(resp)
|
---|
146 | {
|
---|
147 | // Received CONNECT OK
|
---|
148 | // Great. We're done
|
---|
149 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
150 | }
|
---|
151 | else
|
---|
152 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
153 | }
|
---|
154 | break;
|
---|
155 |
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | //Disconnect TCP main function.
|
---|
160 | int GSM3ShieldV1MultiClientProvider::disconnectTCP(bool client1Server0, int id_socket)
|
---|
161 | {
|
---|
162 | idSocket = id_socket;
|
---|
163 |
|
---|
164 | // First of all, we will flush the socket synchronously
|
---|
165 | unsigned long m;
|
---|
166 | m=millis();
|
---|
167 | flushSocket();
|
---|
168 | while(((millis()-m)< __TOUTFLUSH__ )&&(ready()==0))
|
---|
169 | delay(10);
|
---|
170 |
|
---|
171 | // Could not flush the communications... strange
|
---|
172 | if(ready()==0)
|
---|
173 | {
|
---|
174 | theGSM3ShieldV1ModemCore.setCommandError(2);
|
---|
175 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
176 | }
|
---|
177 |
|
---|
178 | // Set up the command
|
---|
179 | client1_server0 = client1Server0;
|
---|
180 | flagReadingSocket=0;
|
---|
181 | theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP);
|
---|
182 | disconnectTCPContinue();
|
---|
183 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
184 | }
|
---|
185 |
|
---|
186 | //Disconnect TCP continue function
|
---|
187 | void GSM3ShieldV1MultiClientProvider::disconnectTCPContinue()
|
---|
188 | {
|
---|
189 | bool resp;
|
---|
190 | // 1: Send AT+QISRVC
|
---|
191 | // 2: "AT+QICLOSE"
|
---|
192 | // 3: Wait for OK
|
---|
193 |
|
---|
194 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
195 | case 1:
|
---|
196 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false);
|
---|
197 | if (client1_server0) theGSM3ShieldV1ModemCore.print('1');
|
---|
198 | else theGSM3ShieldV1ModemCore.print('2');
|
---|
199 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
200 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
201 | break;
|
---|
202 | case 2:
|
---|
203 | // Parse response to QISRVC
|
---|
204 | theGSM3ShieldV1ModemCore.genericParse_rsp(resp);
|
---|
205 | if(resp)
|
---|
206 | {
|
---|
207 | // Send QICLOSE command
|
---|
208 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE="),false);
|
---|
209 | theGSM3ShieldV1ModemCore.print(idSocket);
|
---|
210 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
211 | theGSM3ShieldV1ModemCore.setCommandCounter(3);
|
---|
212 | }
|
---|
213 | else
|
---|
214 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
215 | break;
|
---|
216 | case 3:
|
---|
217 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
218 | {
|
---|
219 | theGSM3ShieldV1ModemCore.setCommandCounter(0);
|
---|
220 | if (resp)
|
---|
221 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
222 | else
|
---|
223 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
224 | }
|
---|
225 | break;
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | //Write socket first chain main function.
|
---|
230 | void GSM3ShieldV1MultiClientProvider::beginWriteSocket(bool client1Server0, int id_socket)
|
---|
231 | {
|
---|
232 | idSocket = id_socket;
|
---|
233 | client1_server0 = client1Server0;
|
---|
234 | theGSM3ShieldV1ModemCore.openCommand(this,BEGINWRITESOCKET);
|
---|
235 | beginWriteSocketContinue();
|
---|
236 | }
|
---|
237 |
|
---|
238 | //Write socket first chain continue function.
|
---|
239 | void GSM3ShieldV1MultiClientProvider::beginWriteSocketContinue()
|
---|
240 | {
|
---|
241 | bool resp;
|
---|
242 | // 1: Send AT+QISRVC
|
---|
243 | // 2: Send AT+QISEND
|
---|
244 | // 3: wait for > and Write text
|
---|
245 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
246 | case 1:
|
---|
247 | // AT+QISRVC
|
---|
248 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false);
|
---|
249 | if (client1_server0)
|
---|
250 | theGSM3ShieldV1ModemCore.print('1');
|
---|
251 | else
|
---|
252 | theGSM3ShieldV1ModemCore.print('2');
|
---|
253 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
254 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
255 | break;
|
---|
256 | case 2:
|
---|
257 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
258 | {
|
---|
259 | // Response received
|
---|
260 | if(resp)
|
---|
261 | {
|
---|
262 | // AT+QISEND
|
---|
263 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISEND="), false);
|
---|
264 | theGSM3ShieldV1ModemCore.print(idSocket);
|
---|
265 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
266 | theGSM3ShieldV1ModemCore.setCommandCounter(3);
|
---|
267 | }
|
---|
268 | else
|
---|
269 | {
|
---|
270 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
271 | }
|
---|
272 | }
|
---|
273 | break;
|
---|
274 | case 3:
|
---|
275 | char aux[2];
|
---|
276 | aux[0]='>';
|
---|
277 | aux[1]=0;
|
---|
278 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux))
|
---|
279 | {
|
---|
280 | if(resp)
|
---|
281 | {
|
---|
282 | // Received ">"
|
---|
283 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
284 | }
|
---|
285 | else
|
---|
286 | {
|
---|
287 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
288 | }
|
---|
289 | }
|
---|
290 | break;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | //Write socket next chain function.
|
---|
295 | void GSM3ShieldV1MultiClientProvider::writeSocket(const char* buf)
|
---|
296 | {
|
---|
297 | theGSM3ShieldV1ModemCore.print(buf);
|
---|
298 | }
|
---|
299 |
|
---|
300 | //Write socket character function.
|
---|
301 | void GSM3ShieldV1MultiClientProvider::writeSocket(char c)
|
---|
302 | {
|
---|
303 | theGSM3ShieldV1ModemCore.print(c);
|
---|
304 | }
|
---|
305 |
|
---|
306 | //Write socket last chain main function.
|
---|
307 | void GSM3ShieldV1MultiClientProvider::endWriteSocket()
|
---|
308 | {
|
---|
309 | theGSM3ShieldV1ModemCore.openCommand(this,ENDWRITESOCKET);
|
---|
310 | endWriteSocketContinue();
|
---|
311 | }
|
---|
312 |
|
---|
313 | //Write socket last chain continue function.
|
---|
314 | void GSM3ShieldV1MultiClientProvider::endWriteSocketContinue()
|
---|
315 | {
|
---|
316 | bool resp;
|
---|
317 | // 1: Write text (ctrl-Z)
|
---|
318 | // 2: Wait for OK
|
---|
319 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
320 | case 1:
|
---|
321 | theGSM3ShieldV1ModemCore.write(26); // Ctrl-Z
|
---|
322 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
323 | break;
|
---|
324 | case 2:
|
---|
325 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
326 | {
|
---|
327 | // OK received
|
---|
328 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
329 | else theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
330 | }
|
---|
331 | break;
|
---|
332 | }
|
---|
333 | }
|
---|
334 |
|
---|
335 | //Available socket main function.
|
---|
336 | int GSM3ShieldV1MultiClientProvider::availableSocket(bool client1Server0, int id_socket)
|
---|
337 | {
|
---|
338 | if(flagReadingSocket==1)
|
---|
339 | {
|
---|
340 | theGSM3ShieldV1ModemCore.setCommandError(1);
|
---|
341 | return 1;
|
---|
342 | }
|
---|
343 | client1_server0 = client1Server0;
|
---|
344 | idSocket = id_socket;
|
---|
345 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
|
---|
346 | availableSocketContinue();
|
---|
347 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
348 | }
|
---|
349 |
|
---|
350 | //Available socket continue function.
|
---|
351 | void GSM3ShieldV1MultiClientProvider::availableSocketContinue()
|
---|
352 | {
|
---|
353 | bool resp;
|
---|
354 | // 1: AT+QIRD
|
---|
355 | // 2: Wait for OK and Next necessary AT+QIRD
|
---|
356 |
|
---|
357 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
358 | case 1:
|
---|
359 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIRD=0,"),false);
|
---|
360 | if (client1_server0)
|
---|
361 | theGSM3ShieldV1ModemCore.print('1');
|
---|
362 | else
|
---|
363 | theGSM3ShieldV1ModemCore.print('2');
|
---|
364 | theGSM3ShieldV1ModemCore.print(',');
|
---|
365 | theGSM3ShieldV1ModemCore.print(idSocket);
|
---|
366 | theGSM3ShieldV1ModemCore.print(",1500");
|
---|
367 | // theGSM3ShieldV1ModemCore.print(",120");
|
---|
368 | theGSM3ShieldV1ModemCore.print('\r');
|
---|
369 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
370 | break;
|
---|
371 | case 2:
|
---|
372 | if(parseQIRD_head(resp))
|
---|
373 | {
|
---|
374 | if (!resp)
|
---|
375 | {
|
---|
376 | theGSM3ShieldV1ModemCore.closeCommand(4);
|
---|
377 | }
|
---|
378 | else
|
---|
379 | {
|
---|
380 | flagReadingSocket=1;
|
---|
381 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
382 | }
|
---|
383 | }
|
---|
384 | else
|
---|
385 | {
|
---|
386 | theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
387 | }
|
---|
388 | break;
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | //Read Socket Parse head.
|
---|
393 | bool GSM3ShieldV1MultiClientProvider::parseQIRD_head(bool& rsp)
|
---|
394 | {
|
---|
395 | char _qird [8];
|
---|
396 | prepareAuxLocate(PSTR("+QIRD:"), _qird);
|
---|
397 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
|
---|
398 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(_qird))
|
---|
399 | {
|
---|
400 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true);
|
---|
401 | // Saving more memory, reuse _qird
|
---|
402 | _qird[0]='\n';
|
---|
403 | _qird[1]=0;
|
---|
404 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true);
|
---|
405 | rsp = true;
|
---|
406 | return true;
|
---|
407 | }
|
---|
408 | else if(theGSM3ShieldV1ModemCore.theBuffer().locate("OK"))
|
---|
409 | {
|
---|
410 | rsp = false;
|
---|
411 | return true;
|
---|
412 | }
|
---|
413 | else
|
---|
414 | {
|
---|
415 | rsp = false;
|
---|
416 | return false;
|
---|
417 | }
|
---|
418 | }
|
---|
419 | /*
|
---|
420 | //Read socket main function.
|
---|
421 | int GSM3ShieldV1MultiClientProvider::readSocket()
|
---|
422 | {
|
---|
423 | char charSocket;
|
---|
424 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read();
|
---|
425 | //Case buffer not full
|
---|
426 | if (!fullBufferSocket)
|
---|
427 | {
|
---|
428 | //The last part of the buffer after data is CRLFOKCRLF
|
---|
429 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125)
|
---|
430 | {
|
---|
431 | //Start again availableSocket function.
|
---|
432 | flagReadingSocket=0;
|
---|
433 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
|
---|
434 | availableSocketContinue();
|
---|
435 | }
|
---|
436 | }
|
---|
437 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127)
|
---|
438 | {
|
---|
439 | // The buffer is full, no more action is possible until we have read()
|
---|
440 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
441 | flagReadingSocket = 1;
|
---|
442 | theGSM3ShieldV1ModemCore.openCommand(this,XON);
|
---|
443 | theGSM3ShieldV1ModemCore.gss.spaceAvailable();
|
---|
444 | //A small delay to assure data received after xon.
|
---|
445 | delay(10);
|
---|
446 | }
|
---|
447 | //To distinguish the case no more available data in socket.
|
---|
448 | if (ready()==1)
|
---|
449 | return charSocket;
|
---|
450 | else
|
---|
451 | return 0;
|
---|
452 | }
|
---|
453 | */
|
---|
454 | int GSM3ShieldV1MultiClientProvider::readSocket()
|
---|
455 | {
|
---|
456 | char charSocket;
|
---|
457 |
|
---|
458 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0)
|
---|
459 | {
|
---|
460 | Serial.println();Serial.println("*");
|
---|
461 | return 0;
|
---|
462 | }
|
---|
463 |
|
---|
464 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read();
|
---|
465 | //Case buffer not full
|
---|
466 | if (!fullBufferSocket)
|
---|
467 | {
|
---|
468 | //The last part of the buffer after data is CRLFOKCRLF
|
---|
469 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125)
|
---|
470 | {
|
---|
471 | //Start again availableSocket function.
|
---|
472 | flagReadingSocket=0;
|
---|
473 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
|
---|
474 | availableSocketContinue();
|
---|
475 | }
|
---|
476 | }
|
---|
477 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()>=100)
|
---|
478 | {
|
---|
479 | // The buffer was full, we have to let the data flow again
|
---|
480 | // theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
481 | flagReadingSocket = 1;
|
---|
482 | theGSM3ShieldV1ModemCore.openCommand(this,XON);
|
---|
483 | theGSM3ShieldV1ModemCore.gss.spaceAvailable();
|
---|
484 | //A small delay to assure data received after xon.
|
---|
485 | delay(100);
|
---|
486 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes() >=6)
|
---|
487 | fullBufferSocket=false;
|
---|
488 | }
|
---|
489 |
|
---|
490 | return charSocket;
|
---|
491 |
|
---|
492 | }
|
---|
493 |
|
---|
494 | //Read socket main function.
|
---|
495 | int GSM3ShieldV1MultiClientProvider::peekSocket()
|
---|
496 | {
|
---|
497 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0);
|
---|
498 | }
|
---|
499 |
|
---|
500 |
|
---|
501 | //Flush SMS main function.
|
---|
502 | void GSM3ShieldV1MultiClientProvider::flushSocket()
|
---|
503 | {
|
---|
504 | flagReadingSocket=0;
|
---|
505 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET);
|
---|
506 | flushSocketContinue();
|
---|
507 | }
|
---|
508 |
|
---|
509 | //Send SMS continue function.
|
---|
510 | void GSM3ShieldV1MultiClientProvider::flushSocketContinue()
|
---|
511 | {
|
---|
512 | bool resp;
|
---|
513 | // 1: Deleting SMS
|
---|
514 | // 2: wait for OK
|
---|
515 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
516 | case 1:
|
---|
517 | //DEBUG
|
---|
518 | //Serial.println("Flushing Socket.");
|
---|
519 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
520 | if (fullBufferSocket)
|
---|
521 | {
|
---|
522 | //Serial.println("Buffer flushed.");
|
---|
523 | theGSM3ShieldV1ModemCore.gss.spaceAvailable();
|
---|
524 | }
|
---|
525 | else
|
---|
526 | {
|
---|
527 | //Serial.println("Socket flushed completely.");
|
---|
528 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
529 | }
|
---|
530 | break;
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | //URC recognize.
|
---|
535 | // Momentarily, we will not recognize "closes" in client mode
|
---|
536 | bool GSM3ShieldV1MultiClientProvider::recognizeUnsolicitedEvent(byte oldTail)
|
---|
537 | {
|
---|
538 | return false;
|
---|
539 | }
|
---|
540 |
|
---|
541 | int GSM3ShieldV1MultiClientProvider::getSocket(int socket)
|
---|
542 | {
|
---|
543 | if(socket==-1)
|
---|
544 | {
|
---|
545 | int i;
|
---|
546 | for(i=minSocket(); i<=maxSocket(); i++)
|
---|
547 | {
|
---|
548 | if (!(sockets&(0x0001<<i)))
|
---|
549 | {
|
---|
550 | sockets|=((0x0001)<<i);
|
---|
551 | return i;
|
---|
552 | }
|
---|
553 | }
|
---|
554 | }
|
---|
555 | else
|
---|
556 | {
|
---|
557 | if (!(sockets&(0x0001<<socket)))
|
---|
558 | {
|
---|
559 | sockets|=((0x0001)<<socket);
|
---|
560 | return socket;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | return -1;
|
---|
564 | }
|
---|
565 |
|
---|
566 | void GSM3ShieldV1MultiClientProvider::releaseSocket(int socket)
|
---|
567 | {
|
---|
568 | if (sockets&((0x0001)<<socket))
|
---|
569 | sockets^=((0x0001)<<socket);
|
---|
570 | }
|
---|
571 |
|
---|
572 | bool GSM3ShieldV1MultiClientProvider::getStatusSocketClient(uint8_t socket)
|
---|
573 | {
|
---|
574 | if(socket>8)
|
---|
575 | return 0;
|
---|
576 | if(sockets&(0x0001<<socket))
|
---|
577 | return 1;
|
---|
578 | else
|
---|
579 | return 0;
|
---|
580 | };
|
---|
581 |
|
---|
582 |
|
---|
583 |
|
---|