Skip to content

Commit

Permalink
release 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sstaub committed Jun 9, 2017
1 parent 1f780e6 commit 3da591d
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 32 deletions.
16 changes: 16 additions & 0 deletions src/Ethernet3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ const char* EthernetClass::duplexReport() {
else return "NO LINK";
}

void EthernetClass::setRtTimeOut(uint16_t _time) {
w5500.setRetransmissionTime(_time);
}

uint16_t EthernetClass::getRtTimeOut() {
return w5500.getRetransmissionTime();
}

void EthernetClass::setRtCount(uint8_t _count) {
w5500.setRetransmissionCount(_count);
}

uint8_t EthernetClass::getRtCount() {
return w5500.getRetransmissionCount();
}

void EthernetClass::macAddress(uint8_t mac[]) {
w5500.getMACAddress(mac);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Ethernet3.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class EthernetClass {
uint8_t duplex(); // returns duplex mode 0 = no link, 1 = Half Duplex, 2 = Full Duplex
const char* duplexReport(); // returns duplex mode as a string

void setRtTimeOut(uint16_t _time = 2000); // set the retransmission timout *100us
uint16_t getRtTimeOut(); // get the retransmission timout
void setRtCount(uint8_t _count = 8); // set the retransmission count
uint8_t getRtCount(); // get the retransmission count

void macAddress(uint8_t mac[]); // get the MAC Address
const char* macAddressReport(); // returns the the MAC Address as a string

Expand Down
27 changes: 26 additions & 1 deletion src/EthernetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,29 @@ bool EthernetClient::operator==(const EthernetClient& rhs) {

uint8_t EthernetClient::getSocketNumber() {
return _sock;
}
}

void EthernetClient::remoteIP(uint8_t *ip) {
w5500.readSnDIPR(_sock, ip);
}

void EthernetClient::remoteMAC(uint8_t *mac) {
w5500.readSnDHAR(_sock, mac);
}

uint8_t EthernetClient::getSocketMode() {
return w5500.readSnMR(_sock);
}

void EthernetClient::setNoDelayedACK(bool ack) {
uint8_t value;
value = w5500.readSnMR(_sock);
bitWrite(value, 5, ack);
w5500.writeSnMR(_sock, value);
}

bool EthernetClient::getNoDelayedACK() {
uint8_t value;
value = w5500.readSnMR(_sock);
return bitRead(value, 5);
}
12 changes: 12 additions & 0 deletions src/EthernetClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class EthernetClient : public Client {
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
uint8_t getSocketNumber();

// Return the IP address of the host who sent the current incoming packet
virtual void remoteIP(uint8_t *ip);
// Return the MAC address of the host who sent the current incoming packet
virtual void remoteMAC(uint8_t *mac);

// get the value of the socket mode register
virtual uint8_t getSocketMode();
// set the 'no Delayed ACK' option
virtual void setNoDelayedACK(bool ack = false);
// get the state of 'no Delayed ACK' option
virtual bool getNoDelayedACK();

friend class EthernetServer;

using Print::write;
Expand Down
100 changes: 69 additions & 31 deletions src/EthernetUdp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ uint8_t EthernetUDP::begin(uint16_t port) {
return 1;
}

/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::beginMulticast(IPAddress ip, uint16_t port)
{
if (_sock != MAX_SOCK_NUM)
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = w5500.readSnSR(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
}
}

if (_sock == MAX_SOCK_NUM)
return 0;

// Calculate MAC address from Multicast IP Address
byte mac[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };

mac[3] = ip[1] & 0x7F;
mac[4] = ip[2];
mac[5] = ip[3];

w5500.writeSnDIPR(_sock, rawIPAddress(ip)); //239.255.0.1
w5500.writeSnDPORT(_sock, port);
w5500.writeSnDHAR(_sock,mac);

_remaining = 0;
socket(_sock, SnMR::UDP, port, SnMR::MULTI);
return 1;
}

/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int EthernetUDP::available() {
Expand Down Expand Up @@ -220,36 +253,41 @@ void EthernetUDP::flush()
}
}

/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::beginMulticast(IPAddress ip, uint16_t port)
{
if (_sock != MAX_SOCK_NUM)
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = w5500.readSnSR(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
}
}

if (_sock == MAX_SOCK_NUM)
return 0;

// Calculate MAC address from Multicast IP Address
byte mac[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };

mac[3] = ip[1] & 0x7F;
mac[4] = ip[2];
mac[5] = ip[3];

w5500.writeSnDIPR(_sock, rawIPAddress(ip)); //239.255.0.1
w5500.writeSnDPORT(_sock, port);
w5500.writeSnDHAR(_sock,mac);

_remaining = 0;
socket(_sock, SnMR::UDP, port, SnMR::MULTI);
return 1;
void EthernetUDP::remoteIP(uint8_t *ip) {
w5500.readSnDIPR(_sock, ip);
}

void EthernetUDP::remoteMAC(uint8_t *mac) {
w5500.readSnDHAR(_sock, mac);
}

uint8_t EthernetUDP::getSocketMode() {
return w5500.readSnMR(_sock);
}

void EthernetUDP::setBroadcastBlock(bool block) {
uint8_t value;
value = w5500.readSnMR(_sock);
bitWrite(value, 6, block);
w5500.writeSnMR(_sock, value);
}

bool EthernetUDP::getBroadcastBlock() {
uint8_t value;
value = w5500.readSnMR(_sock);
return bitRead(value, 6);
}

void EthernetUDP::setUnicastBlock(bool block) {
uint8_t value;
value = w5500.readSnMR(_sock);
bitWrite(value, 4, block);
w5500.writeSnMR(_sock, value);
}

bool EthernetUDP::getUnicastBlock() {
uint8_t value;
value = w5500.readSnMR(_sock);
return bitRead(value, 4);
}

10 changes: 10 additions & 0 deletions src/EthernetUdp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,18 @@ class EthernetUDP : public UDP {

// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() { return _remoteIP; };
virtual void remoteIP(uint8_t *ip);
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() { return _remotePort; };
// Return the MAC address of the host who sent the current incoming packet
virtual void remoteMAC(uint8_t *mac);

virtual uint8_t getSocketMode();
virtual void setBroadcastBlock(bool block = false); // set Broadcast blocking
virtual bool getBroadcastBlock(); // get Broadcast blocking state
virtual void setUnicastBlock(bool block = false); // set Unicast blocking, only when socketin Multicast mode
virtual bool getUnicastBlock(); // get Unicast blocking state

};

#endif
8 changes: 8 additions & 0 deletions src/utility/w5500.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,18 @@ void W5500Class::setRetransmissionTime(uint16_t _timeout) {
writeRTR(_timeout);
}

uint16_t W5500Class::getRetransmissionTime() {
return readRTR();
}

void W5500Class::setRetransmissionCount(uint8_t _retry) {
writeRCR(_retry);
}

uint8_t W5500Class::getRetransmissionCount() {
return readRCR();
}

void W5500Class::setPHYCFGR(uint8_t _val) {
writePHYCFGR(_val);
}
Expand Down

0 comments on commit 3da591d

Please sign in to comment.