Created
March 31, 2014 16:14
-
-
Save aallan/9895961 to your computer and use it in GitHub Desktop.
Mulitcast UDP patch for the EthernetUdp.c source code in Arduino Ethernet library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Add the following decleration to EthernetUdp.h directly after line 55 | |
virtual uint8_t beginMulti(IPAddress, uint16_t); | |
then add the following code to the end of EthernetUdp.c | |
*/ | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment