unify sACN subscribers
This commit is contained in:
parent
efad085a2a
commit
7f1bd834cc
@ -28,39 +28,24 @@ ESPAsyncE131::ESPAsyncE131(uint8_t buffers) {
|
|||||||
_handler = NULL;
|
_handler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESPAsyncE131::begin(e131_listen_t type, uint16_t universe) {
|
bool ESPAsyncE131::subscribe(uint16_t universe, e131_listen_t type) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if (type == E131_UNICAST)
|
switch (type) {
|
||||||
success = initUnicast();
|
case E131_UNICAST:
|
||||||
if (type == E131_MULTICAST)
|
Serial.println("Unicasting");
|
||||||
success = initMulticast(universe);
|
success = udp.listen(E131_DEFAULT_PORT);
|
||||||
|
break;
|
||||||
|
case E131_MULTICAST:
|
||||||
|
success = udp.listenMulticast(E131MulticastAddress(universe),
|
||||||
|
E131_DEFAULT_PORT);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ESPAsyncE131::initUnicast() {
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
if (udp.listen(E131_DEFAULT_PORT)) {
|
|
||||||
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this,
|
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this,
|
||||||
std::placeholders::_1));
|
std::placeholders::_1));
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ESPAsyncE131::initMulticast(uint16_t universe) {
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
IPAddress address = IPAddress(239, 255, ((universe >> 8) & 0xff),
|
|
||||||
((universe >> 0) & 0xff));
|
|
||||||
|
|
||||||
if (udp.listenMulticast(address, E131_DEFAULT_PORT)) {
|
|
||||||
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this,
|
|
||||||
std::placeholders::_1));
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +110,10 @@ void ESPAsyncE131::dumpError(e131_packet_t *packet, e131_error_t error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPAddress ESPAsyncE131::E131MulticastAddress(uint16_t universe) {
|
||||||
|
return IPAddress(239, 255, ((universe >> 8) & 0xff), ((universe >> 0) & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
void ESPAsyncE131::onPacket(E131PacketHandlerFunction callback)
|
void ESPAsyncE131::onPacket(E131PacketHandlerFunction callback)
|
||||||
{
|
{
|
||||||
_handler = callback;
|
_handler = callback;
|
||||||
|
@ -118,8 +118,9 @@ class ESPAsyncE131 {
|
|||||||
ESPAsyncE131(uint8_t buffers = 1);
|
ESPAsyncE131(uint8_t buffers = 1);
|
||||||
|
|
||||||
void onPacket(E131PacketHandlerFunction callback);
|
void onPacket(E131PacketHandlerFunction callback);
|
||||||
bool begin(e131_listen_t type, uint16_t universe = 1);
|
bool subscribe(uint16_t universe = 1, e131_listen_t type = E131_MULTICAST);
|
||||||
static void dumpError(e131_packet_t *packet, e131_error_t error);
|
static void dumpError(e131_packet_t *packet, e131_error_t error);
|
||||||
|
static IPAddress E131MulticastAddress(uint16_t universe);
|
||||||
|
|
||||||
e131_stats_t stats; // Statistics tracker
|
e131_stats_t stats; // Statistics tracker
|
||||||
|
|
||||||
@ -136,10 +137,6 @@ class ESPAsyncE131 {
|
|||||||
e131_packet_t *sbuff; // Pointer to scratch packet buffer
|
e131_packet_t *sbuff; // Pointer to scratch packet buffer
|
||||||
AsyncUDP udp; // AsyncUDP
|
AsyncUDP udp; // AsyncUDP
|
||||||
|
|
||||||
// Internal Initializers
|
|
||||||
bool initUnicast();
|
|
||||||
bool initMulticast(uint16_t universe);
|
|
||||||
|
|
||||||
// UDP packet parser callback
|
// UDP packet parser callback
|
||||||
void parsePacket(AsyncUDPPacket _packet);
|
void parsePacket(AsyncUDPPacket _packet);
|
||||||
};
|
};
|
||||||
|
@ -120,8 +120,8 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// start sACN
|
//// start sACN
|
||||||
if (!e131->begin(sACN_mode, strobe_universe)) {
|
if (!e131->subscribe(strobe_universe, sACN_mode)) {
|
||||||
Serial.println("Failed to start E1.31");
|
Serial.println("Failed to start E1.31");
|
||||||
} else {
|
} else {
|
||||||
e131->onPacket(std::bind(&Strobe::recvData, strobe,
|
e131->onPacket(std::bind(&Strobe::recvData, strobe,
|
||||||
|
Loading…
Reference in New Issue
Block a user