Skip to content

Commit

Permalink
Added Multicast UDP support
Browse files Browse the repository at this point in the history
  • Loading branch information
aallan committed Aug 3, 2013
1 parent 293e46b commit 3811729
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions libraries/Ethernet/EthernetUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,41 @@ void EthernetUDP::flush()
}
}


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

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.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];

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

_remaining = 0;

socket(_sock, SnMR::UDP, port, SnMR::MULTI);

return 1;
}


1 change: 1 addition & 0 deletions libraries/Ethernet/EthernetUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class EthernetUDP : public UDP {
public:
EthernetUDP(); // Constructor
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual uint8_t beginMulti(IPAddress, uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual void stop(); // Finish with the UDP socket

// Sending UDP packets
Expand Down

0 comments on commit 3811729

Please sign in to comment.