forked from UIPEthernet/UIPEthernet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIPClient.cpp
663 lines (631 loc) · 19.9 KB
/
UIPClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/*
UIPClient.cpp - Arduino implementation of a uIP wrapper class.
Copyright (c) 2013 Norbert Truchsess <[email protected]>
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utility/logging.h"
extern "C"
{
#include "utility/uipopt.h"
#include "utility/uip.h"
#include "utility/uip_arp.h"
#include "string.h"
}
#include "UIPEthernet.h"
#include "UIPClient.h"
#if UIP_UDP
#include "Dns.h"
#endif
#if defined(__AVR__)
#include <avr/wdt.h>
#endif
#if defined(__MBED__)
#include "mbed/millis.h"
#endif
#define UIP_TCP_PHYH_LEN UIP_LLH_LEN+UIP_IPTCPH_LEN
uip_userdata_t UIPClient::all_data[UIP_NUM_INTERFACES][UIP_CONNS];
UIPClient::UIPClient() :
data(NULL)
{
}
UIPClient::UIPClient(uip_userdata_t* conn_data) :
data(conn_data)
{
}
int
UIPClient::connect(IPAddress ip, uint16_t port)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::connect(IPAddress ip, uint16_t port) DEBUG_V3:Function started"));
#endif
stop();
uip_ipaddr_t ipaddr;
uip_ip_addr(ipaddr, ip);
struct uip_conn* conn = uip_connect(&ipaddr, htons(port));
if (conn)
{
#if UIP_CONNECT_TIMEOUT > 0
int32_t timeout = millis() + 1000 * UIP_CONNECT_TIMEOUT;
#endif
while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
{
uip_eth[if_idx]->tick();
if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
{
data = (uip_userdata_t*) conn->appstate;
#if ACTLOGLEVEL>=LOG_DEBUG
LogObject.uart_send_str(F("UIPClient::connect DEBUG:connected, state: "));
LogObject.uart_send_dec(data->state);
LogObject.uart_send_str(F(", first packet in: "));
LogObject.uart_send_decln(data->packets_in[0]);
#endif
return 1;
}
#if UIP_CONNECT_TIMEOUT > 0
if (((int32_t)(millis() - timeout)) > 0)
{
conn->tcpstateflags = UIP_CLOSED;
break;
}
#endif
}
}
return 0;
}
int
UIPClient::connect(const char *host, uint16_t port)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::connect(const char *host, uint16_t port) DEBUG_V3:Function started"));
#endif
// Look up the host first
int ret = 0;
#if UIP_UDP
DNSClient dns;
IPAddress remote_addr;
dns.begin(uip_eth[if_idx]->_dnsServerAddress);
ret = dns.getHostByName(host, remote_addr);
if (ret == 1) {
return connect(remote_addr, port);
}
#endif
return ret;
}
void
UIPClient::stop()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V3:Function started"));
#endif
if (data && data->state)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V2:Before stop(), with data"));
_dumpAllData();
#endif
_flushBlocks(&data->packets_in[0]);
if (data->state & UIP_CLIENT_REMOTECLOSED)
{
data->state = 0;
}
else
{
data->state |= UIP_CLIENT_CLOSE;
}
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V2:after stop()"));
_dumpAllData();
#endif
}
#if ACTLOGLEVEL>=LOG_DEBUG_V3
else
{
LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V3:stop(), data: NULL"));
}
#endif
data = NULL;
uip_eth[if_idx]->tick();
}
uint8_t
UIPClient::connected()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::connected() DEBUG_V3:Function started"));
#endif
return (data && (data->packets_in[0] != NOBLOCK || (data->state & UIP_CLIENT_CONNECTED))) ? 1 : 0;
}
bool
UIPClient::operator==(const UIPClient& rhs)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::operator==(const UIPClient& rhs) DEBUG_V3:Function started"));
#endif
return data && rhs.data && (data == rhs.data);
}
UIPClient::operator bool()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::operator bool() DEBUG_V3:Function started"));
#endif
uip_eth[if_idx]->tick();
return data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK);
}
size_t
UIPClient::write(uint8_t c)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::write(uint8_t c) DEBUG_V3:Function started"));
#endif
return _write(data, &c, 1);
}
size_t
UIPClient::write(const uint8_t *buf, size_t size)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::write(const uint8_t *buf, size_t size) DEBUG_V3:Function started"));
#endif
return _write(data, buf, size);
}
uint16_t
UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) DEBUG_V3:Function started"));
#endif
int remain = size;
uint16_t written;
#if UIP_ATTEMPTS_ON_WRITE > 0
uint16_t attempts = UIP_ATTEMPTS_ON_WRITE;
#endif
repeat:
uip_eth[if_idx]->tick();
if (u && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
{
uint8_t p = _currentBlock(&u->packets_out[0]);
if (u->packets_out[p] == NOBLOCK)
{
newpacket:
u->packets_out[p] = uip_enc[if_idx]->allocBlock(UIP_SOCKET_DATALEN);
if (u->packets_out[p] == NOBLOCK)
{
#if UIP_ATTEMPTS_ON_WRITE > 0
if ((--attempts)>0)
#endif
#if UIP_ATTEMPTS_ON_WRITE != 0
goto repeat;
#endif
goto ready;
}
u->out_pos = 0;
}
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_str(F("UIPClient::_write DEBUG_V2:writePacket("));
LogObject.uart_send_dec(u->packets_out[p]);
LogObject.uart_send_str(F(") pos: "));
LogObject.uart_send_dec(u->out_pos);
LogObject.uart_send_str(F(", buf["));
LogObject.uart_send_dec(size-remain);
LogObject.uart_send_str(F("-"));
LogObject.uart_send_dec(remain);
LogObject.uart_send_str(F("]: '"));
for (uint16_t i=size-remain; i<=remain; i++)
{
LogObject.uart_send_hex(buf[i]);
LogObject.uart_send_str(F(" "));
}
LogObject.uart_send_strln(F("'"));
#endif
written = uip_enc[if_idx]->writePacket(u->packets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain);
remain -= written;
u->out_pos+=written;
if (remain > 0)
{
if (p == UIP_SOCKET_NUMPACKETS-1)
{
#if UIP_ATTEMPTS_ON_WRITE > 0
if ((--attempts)>0)
#endif
#if UIP_ATTEMPTS_ON_WRITE != 0
goto repeat;
#endif
goto ready;
}
p++;
goto newpacket;
}
ready:
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_str(F("UIPClient::_write DEBUG_V2: READY"));
#endif
#if UIP_CLIENT_TIMER >= 0
u->timer = millis()+UIP_CLIENT_TIMER;
#endif
return size-remain;
}
//return -1; -1 is wrong because return type is unsigned
return 0;
}
int
UIPClient::available()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::available() DEBUG_V3:Function started"));
#endif
if (*this)
return _available(data);
return 0;
}
int
UIPClient::_available(uip_userdata_t *u)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_available(uip_userdata_t *u) DEBUG_V3:Function started"));
#endif
int len = 0;
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
{
len += uip_enc[if_idx]->blockSize(u->packets_in[i]);
}
return len;
}
int
UIPClient::read(uint8_t *buf, size_t size)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::read(uint8_t *buf, size_t size) DEBUG_V3:Function started"));
#endif
if (*this)
{
uint16_t remain = size;
if (data->packets_in[0] == NOBLOCK)
return 0;
uint16_t read;
do
{
read = uip_enc[if_idx]->readPacket(data->packets_in[0],0,buf+size-remain,remain);
if (read == uip_enc[if_idx]->blockSize(data->packets_in[0]))
{
remain -= read;
_eatBlock(&data->packets_in[0]);
if (uip_stopped(&uip_conns[if_idx][data->conn_index]) && !(data->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
data->state |= UIP_CLIENT_RESTART;
if (data->packets_in[0] == NOBLOCK)
{
if (data->state & UIP_CLIENT_REMOTECLOSED)
{
data->state = 0;
data = NULL;
}
return size-remain;
}
}
else
{
uip_enc[if_idx]->resizeBlock(data->packets_in[0],read);
break;
}
}
while(remain > 0);
return size;
}
return -1;
}
int
UIPClient::read()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::read() DEBUG_V3:Function started"));
#endif
uint8_t c;
if (read(&c,1) <= 0)
return -1;
return c;
}
int
UIPClient::peek()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::peek() DEBUG_V3:Function started"));
#endif
if (*this)
{
if (data->packets_in[0] != NOBLOCK)
{
uint8_t c;
uip_enc[if_idx]->readPacket(data->packets_in[0],0,&c,1);
return c;
}
}
return -1;
}
void
UIPClient::flush()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::flush() DEBUG_V3:Function started"));
#endif
if (*this)
{
_flushBlocks(&data->packets_in[0]);
}
}
void
uipclient_appcall(void)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V3:Function started"));
#endif
uint16_t send_len = 0;
uip_userdata_t *u = (uip_userdata_t*)uip_conn[if_idx]->appstate;
if (!u && uip_connected())
{
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_connected"));
UIPClient::_dumpAllData();
#endif
u = (uip_userdata_t*) UIPClient::_allocateData();
if (u)
{
uip_conn[if_idx]->appstate = u;
#if ACTLOGLEVEL>=LOG_DEBUG_V1
LogObject.uart_send_str(F("uipclient_appcall(void) DEBUG_V1:UIPClient allocated state: "));
LogObject.uart_send_binln(u->state);
#endif
}
#if ACTLOGLEVEL>=LOG_ERR
else
LogObject.uart_send_strln(F("uipclient_appcall(void) ERROR:UIPClient allocation failed"));
#endif
}
if (u)
{
if (uip_newdata())
{
#if ACTLOGLEVEL>=LOG_DEBUG
LogObject.uart_send_str(F("uipclient_appcall(void) DEBUG:UIPClient uip_newdata, uip_len:"));
LogObject.uart_send_decln(uip_len[if_idx]);
#endif
if (uip_len[if_idx] && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
{
for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++)
{
if (u->packets_in[i] == NOBLOCK)
{
u->packets_in[i] = uip_enc[if_idx]->allocBlock(uip_len[if_idx]);
if (u->packets_in[i] != NOBLOCK)
{
uip_enc[if_idx]->copyPacket(u->packets_in[i],0,uip_eth[if_idx]->in_packet,((uint8_t*)uip_appdata[if_idx])-uip_buf[if_idx],uip_len[if_idx]);
if (i == UIP_SOCKET_NUMPACKETS-1)
uip_stop();
goto finish_newdata;
}
}
}
uip_eth[if_idx]->packetstate &= ~UIPETHERNET_FREEPACKET;
uip_stop();
}
}
finish_newdata:
if (u->state & UIP_CLIENT_RESTART)
{
u->state &= ~UIP_CLIENT_RESTART;
uip_restart();
}
// If the connection has been closed, save received but unread data.
if (uip_closed() || uip_timedout())
{
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_closed"));
UIPClient::_dumpAllData();
#endif
// drop outgoing packets not sent yet:
UIPClient::_flushBlocks(&u->packets_out[0]);
if (u->packets_in[0] != NOBLOCK)
{
((uip_userdata_closed_t *)u)->lport = uip_conn[if_idx]->lport;
u->state |= UIP_CLIENT_REMOTECLOSED;
}
else
u->state = 0;
// disassociate appdata.
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:After UIPClient uip_closed"));
UIPClient::_dumpAllData();
#endif
uip_conn[if_idx]->appstate = NULL;
goto finish;
}
if (uip_acked())
{
#if ACTLOGLEVEL>=LOG_DEBUG
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG:UIPClient uip_acked"));
#endif
UIPClient::_eatBlock(&u->packets_out[0]);
}
if (uip_poll() || uip_rexmit())
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V3:UIPClient uip_poll || uip_rexmit"));
#endif
if (u->packets_out[0] != NOBLOCK)
{
if (u->packets_out[1] == NOBLOCK)
{
send_len = u->out_pos;
if (send_len > 0)
{
uip_enc[if_idx]->resizeBlock(u->packets_out[0],0,send_len);
}
}
else
send_len = uip_enc[if_idx]->blockSize(u->packets_out[0]);
if (send_len > 0)
{
uip_eth[if_idx]->uip_hdrlen = ((uint8_t*)uip_appdata[if_idx])-uip_buf[if_idx];
uip_eth[if_idx]->uip_packet = uip_enc[if_idx]->allocBlock(uip_eth[if_idx]->uip_hdrlen+send_len);
if (uip_eth[if_idx]->uip_packet != NOBLOCK)
{
uip_enc[if_idx]->copyPacket(uip_eth[if_idx]->uip_packet,uip_eth[if_idx]->uip_hdrlen,u->packets_out[0],0,send_len);
uip_eth[if_idx]->packetstate |= UIPETHERNET_SENDPACKET;
}
}
goto finish;
}
}
// don't close connection unless all outgoing packets are sent
if (u->state & UIP_CLIENT_CLOSE)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient state UIP_CLIENT_CLOSE"));
UIPClient::_dumpAllData();
#endif
if (u->packets_out[0] == NOBLOCK)
{
u->state = 0;
uip_conn[if_idx]->appstate = NULL;
uip_close();
#if ACTLOGLEVEL>=LOG_DEBUG_V2
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:no blocks out -> free userdata"));
UIPClient::_dumpAllData();
#endif
}
else
{
uip_stop();
#if ACTLOGLEVEL>=LOG_DEBUG
LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG:blocks outstanding transfer -> uip_stop()"));
#endif
}
}
}
finish:
uip_send(uip_appdata[if_idx],send_len);
uip_len[if_idx] = send_len;
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_str(F("uipclient_appcall(void) DEBUG_V3: uip_len set to:"));
LogObject.uart_send_decln(uip_len[if_idx]);
#endif
}
uip_userdata_t *
UIPClient::_allocateData()
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_allocateData() DEBUG_V3:Function started"));
#endif
for ( uint8_t sock = 0; sock < UIP_CONNS; sock++ )
{
uip_userdata_t* data = &all_data[if_idx][sock];
if (!data->state)
{
data->conn_index = uip_conn[if_idx] - uip_conns[if_idx];
data->state = UIP_CLIENT_CONNECTED;
memset(&data->packets_in[0],0,sizeof(uip_userdata_t)-sizeof(data->state));
return data;
}
}
return NULL;
}
uint8_t
UIPClient::_currentBlock(memhandle* block)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_currentBlock(memhandle* block) DEBUG_V3:Function started"));
#endif
for (uint8_t i = 1; i < UIP_SOCKET_NUMPACKETS; i++)
{
if (block[i] == NOBLOCK)
return i-1;
}
return UIP_SOCKET_NUMPACKETS-1;
}
void
UIPClient::_eatBlock(memhandle* block)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_eatBlock(memhandle* block) DEBUG_V3:Function started"));
#endif
#if ACTLOGLEVEL>=LOG_DEBUG
memhandle* start = block;
LogObject.uart_send_str(F("UIPClient::_eatBlock DEBUG:eatblock("));
LogObject.uart_send_dec(*block);
LogObject.uart_send_str(F("): "));
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
{
LogObject.uart_send_dec(start[i]);
LogObject.uart_send_str(F(" "));
}
LogObject.uart_send_str(F("-> "));
#endif
uip_enc[if_idx]->freeBlock(block[0]);
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS-1; i++)
{
block[i] = block[i+1];
}
block[UIP_SOCKET_NUMPACKETS-1] = NOBLOCK;
#if ACTLOGLEVEL>=LOG_DEBUG
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
{
LogObject.uart_send_dec(start[i]);
LogObject.uart_send_str(F(" "));
}
LogObject.uart_send_strln(F(""));
#endif
}
void
UIPClient::_flushBlocks(memhandle* block)
{
#if ACTLOGLEVEL>=LOG_DEBUG_V3
LogObject.uart_send_strln(F("UIPClient::_flushBlocks(memhandle* block) DEBUG_V3:Function started"));
#endif
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
{
uip_enc[if_idx]->freeBlock(block[i]);
block[i] = NOBLOCK;
}
}
#if ACTLOGLEVEL>=LOG_DEBUG_V2
void
UIPClient::_dumpAllData(void) {
for (uint8_t i=0; i < UIP_CONNS; i++)
{
LogObject.uart_send_str(F("UIPClient::_dumpAllData() DEBUG_V2:UIPClient::all_data["));
LogObject.uart_send_dec(i);
LogObject.uart_send_str(F("], state:"));
LogObject.uart_send_binln(all_data[if_idx][i].state);
LogObject.uart_send_str(F("packets_in: "));
for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++)
{
LogObject.uart_send_dec(all_data[if_idx][i].packets_in[j]);
LogObject.uart_send_str(F(" "));
}
LogObject.uart_send_strln(F(""));
if (all_data[if_idx][i].state & UIP_CLIENT_REMOTECLOSED)
{
LogObject.uart_send_str(F("state remote closed, local port: "));
LogObject.uart_send_decln(htons(((uip_userdata_closed_t *)(&all_data[if_idx][i]))->lport));
}
else
{
LogObject.uart_send_str(F("packets_out: "));
for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++)
{
LogObject.uart_send_dec(all_data[if_idx][i].packets_out[j]);
LogObject.uart_send_str(F(" "));
}
LogObject.uart_send_strln(F(""));
LogObject.uart_send_str(F("out_pos: "));
LogObject.uart_send_decln(all_data[if_idx][i].out_pos);
}
}
}
#endif