Skip to content

Commit

Permalink
feat: send one ArtPollReply per subscribed universe
Browse files Browse the repository at this point in the history
  • Loading branch information
hideakitai committed Jan 31, 2024
1 parent 5a3f14d commit 1e5efa4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 8 additions & 11 deletions Artnet/ArtPollReply.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ArtPollReply
String node_report {""};

public:
Packet generate_reply(const IPAddress &my_ip, const uint8_t my_mac[6], const CallbackMap &callbacks, uint8_t net_switch, uint8_t sub_switch)
Packet generate_reply(const IPAddress &my_ip, const uint8_t my_mac[6], uint32_t universe, uint8_t net_switch, uint8_t sub_switch)
{
Packet r;
for (size_t i = 0; i < ID_LENGTH; i++) r.id[i] = static_cast<uint8_t>(ARTNET_ID[i]);
Expand All @@ -84,23 +84,20 @@ class ArtPollReply
memcpy(r.long_name, long_name.c_str(), long_name.length());
memcpy(r.node_report, node_report.c_str(), node_report.length());
r.num_ports_h = 0; // Reserved
r.num_ports_l = (callbacks.size() > NUM_POLLREPLY_PUBLIC_PORT_LIMIT) ? NUM_POLLREPLY_PUBLIC_PORT_LIMIT : callbacks.size();
r.num_ports_l = 1;
memset(r.sw_in, 0, 4);
memset(r.sw_out, 0, 4);
memset(r.port_types, 0, 4);
memset(r.good_input, 0, 4);
memset(r.good_output, 0, 4);
r.net_sw = net_switch & 0x7F;
r.sub_sw = sub_switch & 0x0F;
size_t i = 0;
for (const auto& pair : callbacks) {
r.sw_in[i] = pair.first & 0x0F;
r.sw_out[i] = i; // dummy: output port is flexible
r.port_types[i] = 0xC0; // I/O available by DMX512
r.good_input[i] = 0x80; // Data received without error
r.good_output[i] = 0x80; // Data transmitted without error
if (++i >= NUM_POLLREPLY_PUBLIC_PORT_LIMIT) break;
}
// https://github.com/hideakitai/ArtNet/issues/81
r.sw_in[0] = universe & 0x0F;
r.sw_out[0] = 0; // dummy: output port is flexible
r.port_types[0] = 0xC0; // I/O available by DMX512
r.good_input[0] = 0x80; // Data received without error
r.good_output[0] = 0x80; // Data transmitted without error
r.sw_video = 0; // Video display shows local data
r.sw_macro = 0; // No support for macro key inputs
r.sw_remote = 0; // No support for remote trigger inputs
Expand Down
12 changes: 7 additions & 5 deletions Artnet/Receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ class Receiver_ {
const IPAddress my_subnet = subnetMask();
uint8_t my_mac[6];
macAddress(my_mac);
artpollreply::Packet r = artpollreply_ctx.generate_reply(my_ip, my_mac, callbacks, net_switch, sub_switch);
static const IPAddress local_broadcast_addr = IPAddress((uint32_t)my_ip | ~(uint32_t)my_subnet);
stream->beginPacket(local_broadcast_addr, DEFAULT_PORT);
stream->write(r.b, sizeof(artpollreply::Packet));
stream->endPacket();
for (const auto &cb_pair : callbacks) {
artpollreply::Packet r = artpollreply_ctx.generate_reply(my_ip, my_mac, cb_pair.first, net_switch, sub_switch);
static const IPAddress local_broadcast_addr = IPAddress((uint32_t)my_ip | ~(uint32_t)my_subnet);
stream->beginPacket(local_broadcast_addr, DEFAULT_PORT);
stream->write(r.b, sizeof(artpollreply::Packet));
stream->endPacket();
}
}

#ifdef ARTNET_ENABLE_WIFI
Expand Down

0 comments on commit 1e5efa4

Please sign in to comment.