Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upsteam multicast compatibility APIs #821

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template<>
WiFiUDP* SList<WiFiUDP>::_s_first = 0;

/* Constructor */
WiFiUDP::WiFiUDP() : _ctx(0) {
WiFiUDP::WiFiUDP() : _ctx(0), _multicast(false) {
WiFiUDP::_add(this);
}

Expand All @@ -48,6 +48,7 @@ WiFiUDP::WiFiUDP(const WiFiUDP& other) {
_ctx->ref();
}
WiFiUDP::_add(this);
_multicast = other._multicast;
}

WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs) {
Expand Down Expand Up @@ -97,6 +98,12 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
return 1;
}

uint8_t WiFiUDP::beginMulticast(IPAddress addr, uint16_t port) {
auto ret = beginMulticast(IP_ADDR_ANY, addr, port);
_multicast = true;
return ret;
}

/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() {
Expand Down Expand Up @@ -137,7 +144,13 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) {
_ctx = new UdpContext;
_ctx->ref();
}
return (_ctx->connect(ip, port)) ? 1 : 0;
auto ret = (_ctx->connect(ip, port)) ? 1 : 0;
if (_multicast) {
_ctx->setMulticastInterface(IP_ADDR_ANY);
_ctx->setMulticastTTL(255);
}
return ret;

}

int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
Expand Down
9 changes: 7 additions & 2 deletions libraries/WiFi/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {

// initialize, start listening on specified port.
// Returns 1 if successful, 0 if there are no sockets available to use
uint8_t begin(uint16_t port) override;
virtual uint8_t begin(uint16_t port) override;
// initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
virtual uint8_t beginMulticast(IPAddress, uint16_t) override;

// Finish with the UDP connection
void stop() override;
virtual void stop() override;
// join a multicast group and listen on the given port
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);

Expand Down Expand Up @@ -110,4 +113,6 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
static void stopAll();
static void stopAllExcept(WiFiUDP * exC);

private:
bool _multicast;
};