Sitelet https://github.com/forkineye/ESPAsyncE131/commit/11bf2769bc35e6737857cba7b2ddc997736b5fa6
Skip to content

Commit 11bf276

Browse files
Added the ability to set the UDP Port number at begin time.
1 parent 1f5d4ed commit 11bf276

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎ESPAsyncE131.cpp‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ ESPAsyncE131::ESPAsyncE131(uint8_t buffers) {
4242
//
4343
/////////////////////////////////////////////////////////
4444

45-
bool ESPAsyncE131::begin(e131_listen_t type, uint16_t universe, uint8_t n) {
45+
bool ESPAsyncE131::begin(e131_listen_t type, uint16_t universe, uint8_t n)
46+
{
47+
begin (type, E131_ListenPort, universe, n);
48+
}
49+
50+
bool ESPAsyncE131::begin (e131_listen_t type, ESPAsyncE131PortId UdpPortId, uint16_t universe, uint8_t n)
51+
{
4652
bool success = false;
4753

54+
E131_ListenPort = UdpPortId;
55+
4856
if (type == E131_UNICAST)
49-
success = initUnicast();
57+
success = initUnicast ();
5058
if (type == E131_MULTICAST)
51-
success = initMulticast(universe, n);
59+
success = initMulticast (universe, n);
5260

5361
return success;
5462
}
@@ -63,7 +71,7 @@ bool ESPAsyncE131::initUnicast() {
6371
bool success = false;
6472
delay(100);
6573

66-
if (udp.listen(E131_DEFAULT_PORT)) {
74+
if (udp.listen(E131_ListenPort)) {
6775
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this,
6876
std::placeholders::_1));
6977
success = true;
@@ -78,7 +86,7 @@ bool ESPAsyncE131::initMulticast(uint16_t universe, uint8_t n) {
7886
IPAddress address = IPAddress(239, 255, ((universe >> 8) & 0xff),
7987
((universe >> 0) & 0xff));
8088

81-
if (udp.listenMulticast(address, E131_DEFAULT_PORT)) {
89+
if (udp.listenMulticast(address, E131_ListenPort)) {
8290
ip4_addr_t ifaddr;
8391
ip4_addr_t multicast_addr;
8492

‎ESPAsyncE131.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ typedef struct {
128128
unsigned long last_seen;
129129
} e131_stats_t;
130130

131+
typedef uint16_t ESPAsyncE131PortId;
132+
131133
class ESPAsyncE131 {
132134
private:
133135
// Constants for packet validation
@@ -149,14 +151,15 @@ class ESPAsyncE131 {
149151
void parsePacket(AsyncUDPPacket _packet);
150152

151153
void (*PacketCallback)(e131_packet_t* ReceivedData, void* UserInfo) = nullptr;
154+
ESPAsyncE131PortId E131_ListenPort = E131_DEFAULT_PORT;
152155

153156
public:
154157
e131_stats_t stats; // Statistics tracker
155-
156158
ESPAsyncE131(uint8_t buffers = 1);
157159

158160
// Generic UDP listener, no physical or IP configuration
159-
bool begin(e131_listen_t type, uint16_t universe = 1, uint8_t n = 1);
161+
bool begin (e131_listen_t type, uint16_t universe = 1, uint8_t n = 1);
162+
bool begin (e131_listen_t type, ESPAsyncE131PortId UdpPortId, uint16_t universe, uint8_t n);
160163

161164
// Ring buffer access
162165
inline bool isEmpty() { return pbuff->isEmpty(pbuff); }

0 commit comments

Comments
 (0)