diff --git a/README b/README index 7218fad..c7368c6 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is UIPEthernet version 1.58 +This is UIPEthernet version 1.59 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! @@ -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 diff --git a/UIPEthernet/src/UIPClient.cpp b/UIPEthernet/src/UIPClient.cpp index 21ddd79..d199cfe 100644 --- a/UIPEthernet/src/UIPClient.cpp +++ b/UIPEthernet/src/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()) { @@ -360,17 +361,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; } } @@ -407,7 +407,7 @@ uipclient_appcall(void) UIPClient::_dumpAllData(); #endif uip_conn->appstate = NULL; - goto nodata; + goto finish; } if (uip_acked()) { @@ -425,26 +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; } + goto finish; } } // don't close connection unless all outgoing packets are sent @@ -473,9 +472,9 @@ uipclient_appcall(void) } } } -nodata: - UIPEthernetClass::uip_packet = NOBLOCK; - uip_len=0; + finish: + uip_send(uip_appdata,send_len); + uip_len = send_len; } uip_userdata_t * diff --git a/UIPEthernet/src/UIPEthernet.cpp b/UIPEthernet/src/UIPEthernet.cpp index cf7d67c..91ec70a 100644 --- a/UIPEthernet/src/UIPEthernet.cpp +++ b/UIPEthernet/src/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; @@ -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/UIPEthernet/src/utility/Enc28J60Network.cpp b/UIPEthernet/src/utility/Enc28J60Network.cpp index 2e5febc..9c154cd 100644 --- a/UIPEthernet/src/utility/Enc28J60Network.cpp +++ b/UIPEthernet/src/utility/Enc28J60Network.cpp @@ -243,8 +243,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;