Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Update LibraryPatches
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Nov 25, 2022
1 parent 43e2f9f commit 5ffac34
Show file tree
Hide file tree
Showing 25 changed files with 8,946 additions and 8,154 deletions.
338 changes: 182 additions & 156 deletions LibraryPatches/Ethernet/src/Ethernet.cpp

Large diffs are not rendered by default.

569 changes: 307 additions & 262 deletions LibraryPatches/Ethernet/src/Ethernet.h

Large diffs are not rendered by default.

332 changes: 169 additions & 163 deletions LibraryPatches/Ethernet/src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
Version: 1.0.9
Copyright 2018 Paul Stoffregen
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Expand All @@ -34,11 +34,11 @@
1.0.2 K Hoang 20/02/2020 Add support to UIPEthernet library for ENC28J60
1.0.3 K Hoang 23/02/2020 Add support to SAM DUE / SAMD21 boards
1.0.4 K Hoang 16/04/2020 Add support to SAMD51 boards
1.0.5 K Hoang 24/04/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense,
Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B30_ublox, etc.
1.0.5 K Hoang 24/04/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense,
Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B30_ublox, etc.
More Custom Ethernet libraries supported such as Ethernet2, Ethernet3, EthernetLarge
1.0.6 K Hoang 27/04/2020 Add support to ESP32/ESP8266 boards
1.0.7 K Hoang 30/04/2020 Add ENC28J60 support to ESP32/ESP8266 boards
1.0.6 K Hoang 27/04/2020 Add support to ESP32/ESP8266 boards
1.0.7 K Hoang 30/04/2020 Add ENC28J60 support to ESP32/ESP8266 boards
1.0.8 K Hoang 12/05/2020 Fix W5x00 support for ESP8266 boards.
1.0.9 K Hoang 15/05/2020 Add EthernetWrapper.h for easier W5x00 support as well as more Ethernet libs in the future.
*****************************************************************************************************************************/
Expand All @@ -52,193 +52,199 @@ uint16_t EthernetServer::server_port[MAX_SOCK_NUM];

void EthernetServer::begin()
{
uint8_t sockindex = Ethernet.socketBegin(SnMR::TCP, _port);
if (sockindex < MAX_SOCK_NUM)
{
if (Ethernet.socketListen(sockindex))
{
server_port[sockindex] = _port;
}
else
{
Ethernet.socketDisconnect(sockindex);
}
}
uint8_t sockindex = Ethernet.socketBegin(SnMR::TCP, _port);

if (sockindex < MAX_SOCK_NUM)
{
if (Ethernet.socketListen(sockindex))
{
server_port[sockindex] = _port;
}
else
{
Ethernet.socketDisconnect(sockindex);
}
}
}

EthernetClient EthernetServer::available()
{
bool listening = false;
uint8_t sockindex = MAX_SOCK_NUM;
uint8_t chip, maxindex=MAX_SOCK_NUM;

chip = W5100.getChip();
if (!chip)
return EthernetClient(MAX_SOCK_NUM);
//KH, set W5100 to max 2 sockets to increase buffer size
if (chip == 51)
{
bool listening = false;
uint8_t sockindex = MAX_SOCK_NUM;
uint8_t chip, maxindex = MAX_SOCK_NUM;

chip = W5100.getChip();

if (!chip)
return EthernetClient(MAX_SOCK_NUM);

//KH, set W5100 to max 2 sockets to increase buffer size
if (chip == 51)
{
#ifdef ETHERNET_LARGE_BUFFERS
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

for (uint8_t i=0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
uint8_t stat = Ethernet.socketStatus(i);
if (stat == SnSR::ESTABLISHED || stat == SnSR::CLOSE_WAIT)
{
if (Ethernet.socketRecvAvailable(i) > 0)
{
sockindex = i;
}
else
{
// remote host closed connection, our end still open
if (stat == SnSR::CLOSE_WAIT)
{
Ethernet.socketDisconnect(i);
// status becomes LAST_ACK for short time
}
}
}
else if (stat == SnSR::LISTEN)
{
listening = true;
}
else if (stat == SnSR::CLOSED)
{
server_port[i] = 0;
}
}
}

if (!listening)
{
begin();
}

return EthernetClient(sockindex);
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

for (uint8_t i = 0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
uint8_t stat = Ethernet.socketStatus(i);

if (stat == SnSR::ESTABLISHED || stat == SnSR::CLOSE_WAIT)
{
if (Ethernet.socketRecvAvailable(i) > 0)
{
sockindex = i;
}
else
{
// remote host closed connection, our end still open
if (stat == SnSR::CLOSE_WAIT)
{
Ethernet.socketDisconnect(i);
// status becomes LAST_ACK for short time
}
}
}
else if (stat == SnSR::LISTEN)
{
listening = true;
}
else if (stat == SnSR::CLOSED)
{
server_port[i] = 0;
}
}
}

if (!listening)
{
begin();
}

return EthernetClient(sockindex);
}

EthernetClient EthernetServer::accept()
{
bool listening = false;
uint8_t sockindex = MAX_SOCK_NUM;
uint8_t chip, maxindex=MAX_SOCK_NUM;
bool listening = false;
uint8_t sockindex = MAX_SOCK_NUM;
uint8_t chip, maxindex = MAX_SOCK_NUM;

chip = W5100.getChip();

chip = W5100.getChip();

if (!chip)
return EthernetClient(MAX_SOCK_NUM);
if (!chip)
return EthernetClient(MAX_SOCK_NUM);

//KH, set W5100 to max 2 sockets to increase buffer size
if (chip == 51)
{
if (chip == 51)
{
#ifdef ETHERNET_LARGE_BUFFERS
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}
for (uint8_t i=0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
uint8_t stat = Ethernet.socketStatus(i);
if (sockindex == MAX_SOCK_NUM && (stat == SnSR::ESTABLISHED || stat == SnSR::CLOSE_WAIT))
{
// Return the connected client even if no data received.
// Some protocols like FTP expect the server to send the
// first data.
sockindex = i;
server_port[i] = 0; // only return the client once
}
else if (stat == SnSR::LISTEN)
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

for (uint8_t i = 0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
uint8_t stat = Ethernet.socketStatus(i);

if (sockindex == MAX_SOCK_NUM && (stat == SnSR::ESTABLISHED || stat == SnSR::CLOSE_WAIT))
{
// Return the connected client even if no data received.
// Some protocols like FTP expect the server to send the
// first data.
sockindex = i;
server_port[i] = 0; // only return the client once
}
else if (stat == SnSR::LISTEN)
{
listening = true;
}
else if (stat == SnSR::CLOSED)
{
server_port[i] = 0;
}
}
}
if (!listening)
begin();
return EthernetClient(sockindex);
listening = true;
}
else if (stat == SnSR::CLOSED)
{
server_port[i] = 0;
}
}
}

if (!listening)
begin();

return EthernetClient(sockindex);
}

EthernetServer::operator bool()
{
uint8_t maxindex=MAX_SOCK_NUM;
uint8_t maxindex = MAX_SOCK_NUM;

//KH, set W5100 to max 2 sockets to increase buffer size
if (W5100.getChip() == 51)
{
if (W5100.getChip() == 51)
{
#ifdef ETHERNET_LARGE_BUFFERS
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

for (uint8_t i=0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
if (Ethernet.socketStatus(i) == SnSR::LISTEN)
{
return true; // server is listening for incoming clients
}
}
}
return false;
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

for (uint8_t i = 0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
if (Ethernet.socketStatus(i) == SnSR::LISTEN)
{
return true; // server is listening for incoming clients
}
}
}

return false;
}

size_t EthernetServer::write(uint8_t b)
{
return write(&b, 1);
return write(&b, 1);
}

size_t EthernetServer::write(const uint8_t *buffer, size_t size)
{
uint8_t chip, maxindex=MAX_SOCK_NUM;
uint8_t chip, maxindex = MAX_SOCK_NUM;

chip = W5100.getChip();

chip = W5100.getChip();
if (!chip) return 0;
if (!chip)
return 0;

//KH, set W5100 to max 2 sockets to increase buffer size
if (chip == 51)
{
if (chip == 51)
{
#ifdef ETHERNET_LARGE_BUFFERS
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

available();

for (uint8_t i=0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
if (Ethernet.socketStatus(i) == SnSR::ESTABLISHED)
{
Ethernet.socketSend(i, buffer, size);
}
}
}
return size;
maxindex = 2; // W5100 chip never supports more than 4 sockets
#else
maxindex = 4; // W5100 chip never supports more than 4 sockets. Original
#endif
}

available();

for (uint8_t i = 0; i < maxindex; i++)
{
if (server_port[i] == _port)
{
if (Ethernet.socketStatus(i) == SnSR::ESTABLISHED)
{
Ethernet.socketSend(i, buffer, size);
}
}
}

return size;
}
Loading

0 comments on commit 5ffac34

Please sign in to comment.