From f27ffda259f215b28674239a895fc22268c61b46 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Thu, 20 Jun 2024 01:53:39 +0900 Subject: [PATCH 1/2] refactor: comminize some structs --- Artnet/ArtDmx.h | 50 ----------------------------------------------- Artnet/ArtNzs.h | 3 +-- Artnet/Common.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ Artnet/Sender.h | 18 ++++++++--------- 4 files changed, 62 insertions(+), 61 deletions(-) diff --git a/Artnet/ArtDmx.h b/Artnet/ArtDmx.h index f1128b9..57b1403 100644 --- a/Artnet/ArtDmx.h +++ b/Artnet/ArtDmx.h @@ -25,48 +25,6 @@ enum Index : uint16_t DATA = 18 }; -struct Destination -{ - String ip; - uint8_t net; - uint8_t subnet; - uint8_t universe; -}; - -inline bool operator<(const Destination &rhs, const Destination &lhs) -{ - if (rhs.ip < lhs.ip) { - return true; - } - if (rhs.ip > lhs.ip) { - return false; - } - if (rhs.net < lhs.net) { - return true; - } - if (rhs.net > lhs.net) { - return false; - } - if (rhs.subnet < lhs.subnet) { - return true; - } - if (rhs.subnet > lhs.subnet) { - return false; - } - if (rhs.universe < lhs.universe) { - return true; - } - if (rhs.universe > lhs.universe) { - return false; - } - return false; -} - -inline bool operator==(const Destination &rhs, const Destination &lhs) -{ - return rhs.ip == lhs.ip && rhs.net == lhs.net && rhs.subnet == lhs.subnet && rhs.universe == lhs.universe; -} - struct Metadata { uint8_t sequence; @@ -78,16 +36,8 @@ struct Metadata using CallbackType = std::function; #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -// sender -using LastSendTimeMsMap = std::map; -using SequenceMap = std::map; -// receiver using CallbackMap = std::map; #else -// sender -using LastSendTimeMsMap = arx::stdx::map; -using SequenceMap = arx::stdx::map; -// receiver using CallbackMap = arx::stdx::map; #endif diff --git a/Artnet/ArtNzs.h b/Artnet/ArtNzs.h index 2932c64..6c52367 100644 --- a/Artnet/ArtNzs.h +++ b/Artnet/ArtNzs.h @@ -36,10 +36,8 @@ struct Metadata using CallbackType = std::function; #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -// receiver using CallbackMap = std::map; #else -// receiver using CallbackMap = arx::stdx::map; #endif @@ -84,5 +82,6 @@ inline void setDataTo(uint8_t *packet, const uint16_t ch, const uint8_t data) } // namespace art_net using ArtNzsMetadata = art_net::art_nzs::Metadata; +using ArtNzsCallback = art_net::art_nzs::CallbackType; #endif // ARTNET_ARTNZS_H diff --git a/Artnet/Common.h b/Artnet/Common.h index 0a6f66b..e5b2967 100644 --- a/Artnet/Common.h +++ b/Artnet/Common.h @@ -77,6 +77,58 @@ struct RemoteInfo uint16_t port; }; +struct Destination +{ + String ip; + uint8_t net; + uint8_t subnet; + uint8_t universe; +}; + +inline bool operator<(const Destination &rhs, const Destination &lhs) +{ + if (rhs.ip < lhs.ip) { + return true; + } + if (rhs.ip > lhs.ip) { + return false; + } + if (rhs.net < lhs.net) { + return true; + } + if (rhs.net > lhs.net) { + return false; + } + if (rhs.subnet < lhs.subnet) { + return true; + } + if (rhs.subnet > lhs.subnet) { + return false; + } + if (rhs.universe < lhs.universe) { + return true; + } + if (rhs.universe > lhs.universe) { + return false; + } + return false; +} + +inline bool operator==(const Destination &rhs, const Destination &lhs) +{ + return rhs.ip == lhs.ip && rhs.net == lhs.net && rhs.subnet == lhs.subnet && rhs.universe == lhs.universe; +} + +#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 +// sender +using LastSendTimeMsMap = std::map; +using SequenceMap = std::map; +#else +// sender +using LastSendTimeMsMap = arx::stdx::map; +using SequenceMap = arx::stdx::map; +#endif + #ifdef ARTNET_ENABLE_WIFI inline bool isNetworkReady() { diff --git a/Artnet/Sender.h b/Artnet/Sender.h index 3b82367..ea956c8 100644 --- a/Artnet/Sender.h +++ b/Artnet/Sender.h @@ -15,9 +15,9 @@ class Sender_ { S* stream; Array packet; - art_dmx::LastSendTimeMsMap last_send_times; - art_dmx::SequenceMap dmx_sequences; - art_nzs::SequenceMap nzs_sequences; + LastSendTimeMsMap last_send_times; + SequenceMap dmx_sequences; + SequenceMap nzs_sequences; public: #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 @@ -51,7 +51,7 @@ class Sender_ } void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical) { - art_dmx::Destination dest {ip, net, subnet, universe}; + Destination dest {ip, net, subnet, universe}; uint32_t now = millis(); if (this->last_send_times.find(dest) == this->last_send_times.end()) { this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); @@ -85,7 +85,7 @@ class Sender_ } void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code) { - art_dmx::Destination dest {ip, net, subnet, universe}; + Destination dest {ip, net, subnet, universe}; uint32_t now = millis(); if (this->last_send_times.find(dest) == this->last_send_times.end()) { this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); @@ -110,7 +110,7 @@ class Sender_ } void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical, const uint8_t *data, uint16_t size) { - art_dmx::Destination dest {ip, net, subnet, universe}; + Destination dest {ip, net, subnet, universe}; this->setArtDmxData(data, size); this->sendArxDmxInternal(dest, physical); } @@ -129,7 +129,7 @@ class Sender_ } void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code, const uint8_t *data, uint16_t size) { - art_dmx::Destination dest {ip, net, subnet, universe}; + Destination dest {ip, net, subnet, universe}; this->setArtNzsData(data, size); this->sendArxNzsInternal(dest, start_code); } @@ -152,7 +152,7 @@ class Sender_ this->stream = &s; } - void sendArxDmxInternal(const art_dmx::Destination &dest, uint8_t physical) + void sendArxDmxInternal(const Destination &dest, uint8_t physical) { #ifdef ARTNET_ENABLE_WIFI if (!isNetworkReady()) { @@ -167,7 +167,7 @@ class Sender_ this->dmx_sequences[dest] = (this->dmx_sequences[dest] + 1) % 256; } - void sendArxNzsInternal(const art_dmx::Destination &dest, uint8_t start_code) + void sendArxNzsInternal(const Destination &dest, uint8_t start_code) { #ifdef ARTNET_ENABLE_WIFI if (!isNetworkReady()) { From 4f91d4c981627f48143eebeb6d5e482c72b6e981 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Thu, 20 Jun 2024 01:53:49 +0900 Subject: [PATCH 2/2] docs: update README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index edb55d9..c2f6c8a 100644 --- a/README.md +++ b/README.md @@ -284,10 +284,20 @@ void setArtDmxData(uint16_t ch, uint8_t data); void streamArtDmxTo(const String& ip, uint16_t universe15bit); void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe); void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical); +// streaming artnzs packet +void setArtNzsData(const uint8_t* const data, uint16_t size); +void setArtNzsData(uint16_t ch, uint8_t data); +void streamArtNzsTo(const String& ip, uint16_t universe15bit); +void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe); +void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code); // one-line artdmx sender void sendArtDmx(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size); void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size); void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical, const uint8_t *data, uint16_t size); +// one-line artnzs sender +void sendArtNzs(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size); +void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size); +void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code, const uint8_t *data, uint16_t size); // send other packets void sendArtTrigger(const String& ip, uint16_t oem = 0, uint8_t key = 0, uint8_t subkey = 0, const uint8_t *payload = nullptr, uint16_t size = 512); void sendArtSync(const String& ip); @@ -324,6 +334,8 @@ OpCode parse() void subscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe, const ArtDmxCallback &func); // subscribe artdmx packet for specified universe (15 bit) void subscribeArtDmxUniverse(uint16_t universe, const ArtDmxCallback &func); +// subscribe artnzs packet for specified universe (15 bit) +auto subscribeArtNzsUniverse(uint16_t universe, const ArtNzsCallback &func); // subscribe artdmx packet for all universes void subscribeArtDmx(const ArtDmxCallback &func); // subscribe other packets @@ -334,6 +346,7 @@ void unsubscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe); void unsubscribeArtDmxUniverse(uint16_t universe); void unsubscribeArtDmxUniverses(); void unsubscribeArtDmx(); +void unsubscribeArtNzsUniverse(uint16_t universe); void unsubscribeArtSync(); void unsubscribeArtTrigger(); // set artdmx data to CRGB (FastLED) directly