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);
78 while ((
len = this->
read_(buf,
sizeof(buf))) > 0) {
80 ESP_LOGV(TAG,
"Invalid packet received of size %d.", (
int)
len);
84 if (!this->
process_(universe, packet)) {
85 ESP_LOGV(TAG,
"Ignored packet for %d universe of size %d.",
universe, packet.
count);
95 auto effect_name = light_effect->
get_name();
96 ESP_LOGD(TAG,
"Registering '%.*s' for universes %d-%d.", (
int) effect_name.size(), effect_name.c_str(),
112 auto effect_name = light_effect->
get_name();
113 ESP_LOGD(TAG,
"Unregistering '%.*s' for universes %d-%d.", (
int) effect_name.size(), effect_name.c_str(),
126 bool handled =
false;
128 ESP_LOGV(TAG,
"Received E1.31 packet for %d universe, with %d bytes",
universe, packet.
count);
131 handled = light_effect->process_(
universe, packet) || handled;
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_
ssize_t read_(uint8_t *buf, size_t len)
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.