Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e580592

Browse files
aallancmaglie
authored andcommitted
Added Multicast UDP support
Fix #1531
1 parent 59b5311 commit e580592

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

‎libraries/Ethernet/src/EthernetUdp.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,37 @@ void EthernetUDP::flush()
216216
}
217217
}
218218

219+
/* Start EthernetUDP socket, listening at local port PORT */
220+
uint8_t EthernetUDP::beginMulticast(IPAddress ip, uint16_t port)
221+
{
222+
if (_sock != MAX_SOCK_NUM)
223+
return 0;
224+
225+
for (int i = 0; i < MAX_SOCK_NUM; i++) {
226+
uint8_t s = W5100.readSnSR(i);
227+
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
228+
_sock = i;
229+
break;
230+
}
231+
}
232+
233+
if (_sock == MAX_SOCK_NUM)
234+
return 0;
235+
236+
// Calculate MAC address from Multicast IP Address
237+
byte mac[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };
238+
239+
mac[3] = ip[1] & 0x7F;
240+
mac[4] = ip[2];
241+
mac[5] = ip[3];
242+
243+
W5100.writeSnDIPR(_sock, rawIPAddress(ip)); //239.255.0.1
244+
W5100.writeSnDPORT(_sock, port);
245+
W5100.writeSnDHAR(_sock,mac);
246+
247+
_remaining = 0;
248+
socket(_sock, SnMR::UDP, port, SnMR::MULTI);
249+
return 1;
250+
}
251+
252+

‎libraries/Ethernet/src/EthernetUdp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class EthernetUDP : public UDP {
5353
public:
5454
EthernetUDP(); // Constructor
5555
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
56+
virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
5657
virtual void stop(); // Finish with the UDP socket
5758

5859
// Sending UDP packets

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /