Skip to content

Commit

Permalink
EthernetServerPrint class for write-to-all-clients server
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Sep 23, 2020
1 parent 5a82eb8 commit 7b06101
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

EthernetENC is the Ethernet library for ENC28J60. It is a modern version of the UIPEthernet library.
EthernetENC is the Ethernet library for ENC28J60. It is a modern version of [the UIPEthernet library](https://github.com/jandrassy/EthernetENC/wiki/UIPEthernet).

The modernization includes:
* Ethernet 2.0 library functions
* Ethernet 2.0.0 Arduino library functions
* compatible include file names EthernetClient.h, EthernetServer.h and EthernetUdp.h
* support of many Arduino architectures by using the SPI library
* SPI transactions to share the SPI bus with devices with different communication settings
* SPI communication at 20 MHz if the MCU supports it, else on the maximum supported by the MCU
* client.flush() to send the packet immediately
* calls yield() in blocking functions
* Arduino 1.5 library format built with dot_a_linkage option for optimal build result

[The documentation of Arduino Ethernet library](https://www.arduino.cc/en/Reference/Ethernet) applies for classes and functions descriptions.

Limitations:
* UDP.beginMulticast is not supported, because the uIP stack doesn't support multicast
* UDB broadcasts receiving is turned off on ENC to lower the processing load on the library
* EthernetServer doesn't support the print-to-all-clients functionality, because it takes flash memory space and RAM (10 bytes) and nobody uses it

This library doesn't have examples, because examples of the Arduino Ethernet library apply. You can find them in the Arduino IDE Examples menu Ethernet section. Only change `#include <Ethernet.h>` to `#include <EthernetENC.h>`. Some examples require [a little change](https://github.com/jandrassy/EthernetENC/wiki/Examples).

This library is based on the Norbert Truchsess's arduino-uip original source code repository and uses experience from the development of the multiarchitecture support by Cassy. Applicable fixes and enhancements from developed of EthernetENC were transfered to Cassy's UIPEthernet.
This library is based on the Norbert Truchsess's arduino-uip original source code repository and uses experience from the development of the multi-architecture support by Cassy. Applicable fixes and enhancements from developed of EthernetENC were transfered to Cassy's UIPEthernet.

**You can find more information in project's [Wiki](https://github.com/jandrassy/EthernetENC/wiki).**

Expand Down
24 changes: 24 additions & 0 deletions src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,27 @@ void UIPServer::end() {
UIPServer::operator bool() {
return listening;
}

size_t UIPServer::writeToAllClients(const uint8_t *buf, size_t size)
{
size_t ret = 0;
for ( uip_userdata_t* data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++ )
{
if ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->conn_index].lport ==_port)
{
EthernetClient client(data);
ret = client.write(buf, size);
}
}
return ret;
}

size_t EthernetServerPrint::write(uint8_t c)
{
return write(&c,1);
}

size_t EthernetServerPrint::write(const uint8_t *buf, size_t size)
{
return EthernetServer::writeToAllClients(buf, size);
}
19 changes: 17 additions & 2 deletions src/EthernetServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,25 @@ class EthernetServer {
void begin();
void end();
operator bool();


protected:
size_t writeToAllClients(const uint8_t *buf, size_t size);

private:
uint16_t _port;
bool listening = false;
bool listening = false;
};

class EthernetServerPrint : public EthernetServer, public Print {

public:
EthernetServerPrint(uint16_t port) : EthernetServer(port) {}

virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);

using Print::write;

};

#endif

0 comments on commit 7b06101

Please sign in to comment.