From b2a2ae740ad4ea052e31c0c0f375bce0edd44a18 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Thu, 9 Oct 2014 18:57:57 +0200 Subject: [PATCH 1/8] README set version to 1.08 --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index ec51f2d..5b7a9e9 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is UIPEthernet version 1.07 +This is UIPEthernet version 1.08 An plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Just include 'UIPEthernet.h' instead of 'Ethernet.h' and use all your code written for the stock Arduino Ethernet lib! From 4060f86716a2b2d53b68bf81a604e33feb0c3bc1 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 08:53:02 +0200 Subject: [PATCH 2/8] UIPClient: save 40 bytes flash by reordering incoming packet processing --- UIPClient.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/UIPClient.cpp b/UIPClient.cpp index 21ddd79..7b8dde3 100644 --- a/UIPClient.cpp +++ b/UIPClient.cpp @@ -360,17 +360,16 @@ uipclient_appcall(void) #endif if (uip_len && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED))) { - memhandle newPacket = Enc28J60Network::allocBlock(uip_len); - if (newPacket != NOBLOCK) + for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++) { - for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++) + if (u->packets_in[i] == NOBLOCK) { - if (u->packets_in[i] == NOBLOCK) + u->packets_in[i] = Enc28J60Network::allocBlock(uip_len); + if (u->packets_in[i] != NOBLOCK) { + Enc28J60Network::copyPacket(u->packets_in[i],0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len); if (i == UIP_SOCKET_NUMPACKETS-1) uip_stop(); - Enc28J60Network::copyPacket(newPacket,0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len); - u->packets_in[i] = newPacket; goto finish_newdata; } } From 202fadc538fc928192bc3bbc38da8324ca546e16 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 09:29:12 +0200 Subject: [PATCH 3/8] UIClient remove unnessesary cleanup of uip_packet --- UIPClient.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/UIPClient.cpp b/UIPClient.cpp index 7b8dde3..d71ef71 100644 --- a/UIPClient.cpp +++ b/UIPClient.cpp @@ -473,7 +473,6 @@ uipclient_appcall(void) } } nodata: - UIPEthernetClass::uip_packet = NOBLOCK; uip_len=0; } From b8a370c887dcae71f95122aa6cd0bdb09b3ae616 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 09:37:16 +0200 Subject: [PATCH 4/8] UIPEthernet.networkSend: fix cleanup of UIPETHERNET_SENDPACKET flag to avoid call of Enc28J60Network.sendPacket wich NOBLOCK argument --- UIPEthernet.cpp | 1 + utility/Enc28J60Network.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/UIPEthernet.cpp b/UIPEthernet.cpp index cf7d67c..c28ffb3 100644 --- a/UIPEthernet.cpp +++ b/UIPEthernet.cpp @@ -291,6 +291,7 @@ boolean UIPEthernetClass::network_send() Serial.println(uip_hdrlen); #endif Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_hdrlen); + packetstate &= ~ UIPETHERNET_SENDPACKET; goto sendandfree; } uip_packet = Enc28J60Network::allocBlock(uip_len); diff --git a/utility/Enc28J60Network.cpp b/utility/Enc28J60Network.cpp index 9c6e29a..c7c66fb 100644 --- a/utility/Enc28J60Network.cpp +++ b/utility/Enc28J60Network.cpp @@ -215,8 +215,6 @@ Enc28J60Network::blockSize(memhandle handle) void Enc28J60Network::sendPacket(memhandle handle) { - if (handle == NOBLOCK) - return; memblock *packet = &blocks[handle]; uint16_t start = packet->begin-1; uint16_t end = start + packet->size; From e82db8c130d73335b7edc4ec160691db9b0219d2 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 09:43:45 +0200 Subject: [PATCH 5/8] UIPEthernet: cosmetics --- UIPEthernet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UIPEthernet.cpp b/UIPEthernet.cpp index c28ffb3..91ec70a 100644 --- a/UIPEthernet.cpp +++ b/UIPEthernet.cpp @@ -183,7 +183,7 @@ UIPEthernetClass::tick() Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE); if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP)) { - uip_packet = in_packet; + uip_packet = in_packet; //required for upper_layer_checksum of in_packet! #ifdef UIPETHERNET_DEBUG Serial.print(F("readPacket type IP, uip_len: ")); Serial.println(uip_len); @@ -220,7 +220,7 @@ UIPEthernetClass::tick() } } -unsigned long now = millis(); + unsigned long now = millis(); #if UIP_CLIENT_TIMER >= 0 boolean periodic = (long)( now - periodic_timer ) >= 0; From 7f8fbc0dcf49fcb6e3268fa655224da020cf2678 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 09:50:58 +0200 Subject: [PATCH 6/8] UIPClient: cleanup uip_len if uip_poll/uip_rexmit is unable to allocate outgoing block --- UIPClient.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UIPClient.cpp b/UIPClient.cpp index d71ef71..e285970 100644 --- a/UIPClient.cpp +++ b/UIPClient.cpp @@ -441,8 +441,10 @@ uipclient_appcall(void) Enc28J60Network::copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,uip_len); UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET; uip_send(uip_appdata,uip_len); + return; } - return; + else + goto nodata; } } } From 9c58463da8140861e72865ccc73d18893e751ff3 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 13:00:16 +0200 Subject: [PATCH 7/8] UIPClient: ensure uip_slen (uip.c internal) is set allways set (as it's not cleared bevore poll-requests) (saves 14 bytes of flash) --- UIPClient.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/UIPClient.cpp b/UIPClient.cpp index e285970..d199cfe 100644 --- a/UIPClient.cpp +++ b/UIPClient.cpp @@ -329,6 +329,7 @@ UIPClient::flush() void uipclient_appcall(void) { + uint16_t send_len = 0; uip_userdata_t *u = (uip_userdata_t*)uip_conn->appstate; if (!u && uip_connected()) { @@ -406,7 +407,7 @@ uipclient_appcall(void) UIPClient::_dumpAllData(); #endif uip_conn->appstate = NULL; - goto nodata; + goto finish; } if (uip_acked()) { @@ -424,28 +425,25 @@ uipclient_appcall(void) { if (u->packets_out[1] == NOBLOCK) { - uip_len = u->out_pos; - if (uip_len > 0) + send_len = u->out_pos; + if (send_len > 0) { - Enc28J60Network::resizeBlock(u->packets_out[0],0,uip_len); + Enc28J60Network::resizeBlock(u->packets_out[0],0,send_len); } } else - uip_len = Enc28J60Network::blockSize(u->packets_out[0]); - if (uip_len > 0) + send_len = Enc28J60Network::blockSize(u->packets_out[0]); + if (send_len > 0) { UIPEthernetClass::uip_hdrlen = ((uint8_t*)uip_appdata)-uip_buf; - UIPEthernetClass::uip_packet = Enc28J60Network::allocBlock(UIPEthernetClass::uip_hdrlen+uip_len); + UIPEthernetClass::uip_packet = Enc28J60Network::allocBlock(UIPEthernetClass::uip_hdrlen+send_len); if (UIPEthernetClass::uip_packet != NOBLOCK) { - Enc28J60Network::copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,uip_len); + Enc28J60Network::copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,send_len); UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET; - uip_send(uip_appdata,uip_len); - return; } - else - goto nodata; } + goto finish; } } // don't close connection unless all outgoing packets are sent @@ -474,8 +472,9 @@ uipclient_appcall(void) } } } -nodata: - uip_len=0; + finish: + uip_send(uip_appdata,send_len); + uip_len = send_len; } uip_userdata_t * From f5c84d473cf32b0dd720c747f8688a0f05e758fa Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 13 Oct 2014 13:06:52 +0200 Subject: [PATCH 8/8] update README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 5b7a9e9..84f50b6 100644 --- a/README +++ b/README @@ -28,7 +28,7 @@ On a Mac, you will want to create a folder named "libraries" in in the "Document Or you download the zipped version of the library from https://github.com/ntruchsess/arduino_uip/releases, and copy the contained directory UIPEthernet to [path to Arduino distribution]\libraries\UIPEthernet. -If you are running Arduino-IDE 1.5.x use release-version 1.57 or checkout branch 'Arduino_1.5.5' +If you are running Arduino-IDE 1.5.x use release-version 1.59 or checkout branch 'Arduino_1.5.x' Additional information can be found on the Arduino website: http://www.arduino.cc/en/Hacking/Libraries