11static const char *
const TAG =
"e131";
12static const int PORT = 5568;
17#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
21#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
27#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
31 int err = this->
socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable,
sizeof(
int));
33 ESP_LOGW(TAG,
"Socket unable to set reuseaddr: errno %d", err);
36 err = this->
socket_->setblocking(
false);
38 ESP_LOGW(TAG,
"Socket unable to set nonblocking mode: errno %d", err);
47 ESP_LOGW(TAG,
"Socket unable to set sockaddr: errno %d", errno);
54 ESP_LOGW(TAG,
"Socket unable to bind: errno %d", errno);
58#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
59 if (!this->
udp_.begin(PORT)) {
60 ESP_LOGW(TAG,
"Cannot bind E1.31 to port %d.", PORT);
74#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
81 ESP_LOGV(TAG,
"Invalid packet received of size %d.", (
int)
len);
85 if (!this->
process_(universe, packet)) {
86 ESP_LOGV(TAG,
"Ignored packet for %d universe of size %d.",
universe, packet.
count);
88#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
89 while (
auto packet_size = this->
udp_.parsePacket()) {
90 auto len = this->
udp_.read(buf,
sizeof(buf));
95 ESP_LOGV(TAG,
"Invalid packet received of size %d.", (
int)
len);
99 if (!this->
process_(universe, packet)) {
100 ESP_LOGV(TAG,
"Ignored packet for %d universe of size %d.",
universe, packet.
count);
111 auto effect_name = light_effect->
get_name();
112 ESP_LOGD(TAG,
"Registering '%.*s' for universes %d-%d.", (
int) effect_name.size(), effect_name.c_str(),
128 auto effect_name = light_effect->
get_name();
129 ESP_LOGD(TAG,
"Unregistering '%.*s' for universes %d-%d.", (
int) effect_name.size(), effect_name.c_str(),
142 bool handled =
false;
144 ESP_LOGV(TAG,
"Received E1.31 packet for %d universe, with %d bytes",
universe, packet.
count);
147 handled = light_effect->process_(
universe, packet) || handled;
virtual void mark_failed()
Mark this component as failed.
int get_first_universe() const
int get_last_universe() const
std::vector< E131AddressableLightEffect * > light_effects_
void leave_(int universe)
void add_effect(E131AddressableLightEffect *light_effect)
void remove_effect(E131AddressableLightEffect *light_effect)
bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet)
bool process_(int universe, const E131Packet &packet)
std::unique_ptr< socket::Socket > socket_
StringRef get_name() const
Returns the name of this effect.
std::unique_ptr< Socket > socket_ip(int type, int protocol)
Create a socket in the newest available IP domain (IPv6 or IPv4) of the given type and protocol.
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port)
Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
Providing packet encoding functions for exchanging data with a remote host.