From f9aa487d5f557a2d3aa73c918615284890c1cbac Mon Sep 17 00:00:00 2001 From: mxklb Date: Sat, 28 Jan 2023 00:16:40 +0100 Subject: [PATCH] Highest priority package first handling --- wled00/e131.cpp | 9 +++++-- wled00/src/dependencies/e131/ESPAsyncE131.h | 26 +++++++++++++++++++++ wled00/wled.h | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/wled00/e131.cpp b/wled00/e131.cpp index 49440931..7f98c09d 100644 --- a/wled00/e131.cpp +++ b/wled00/e131.cpp @@ -74,8 +74,13 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){ dmxChannels = htons(p->property_value_count) -1; e131_data = p->property_values; seq = p->sequence_number; - // skip packages != e131 config priority - if (e131Priority != 0 && p->priority != e131Priority) return; + if (e131Priority != 0) { + // track lastest e131 package priority .. + if (p->priority >= lastPriority.get()) lastPriority.set(p->priority); + // skip packages < lastest priority or < e131 config priority + if (p->priority < lastPriority.get() || p->priority < e131Priority) return; + // Note: HTP for multiple senders with same priority is not implemented! + } } else { //DDP realtimeIP = clientIP; handleDDPPacket(p); diff --git a/wled00/src/dependencies/e131/ESPAsyncE131.h b/wled00/src/dependencies/e131/ESPAsyncE131.h index 36486a6e..5bc6128f 100644 --- a/wled00/src/dependencies/e131/ESPAsyncE131.h +++ b/wled00/src/dependencies/e131/ESPAsyncE131.h @@ -228,4 +228,30 @@ class ESPAsyncE131 { bool begin(bool multicast, uint16_t port = E131_DEFAULT_PORT, uint16_t universe = 1, uint8_t n = 1); }; +// Class to track e131 package priority +class E131Priority { + private: + uint8_t priority; + time_t setupTime; + uint16_t seconds; + + public: + E131Priority(uint16_t timeout=3) { + seconds = timeout; + set(0); + }; + + // Set priority (+ remember time) + void set(uint8_t prio) { + setupTime = time(0); + priority = prio; + } + + // Get priority (+ reset to default if older timeout) + uint8_t get(uint8_t defaultPrio=0) { + if (time(0) > setupTime + seconds) priority = defaultPrio; + return priority; + } +}; + #endif // ESPASYNCE131_H_ \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index 3c6d7b5f..578fa14a 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -403,7 +403,8 @@ WLED_GLOBAL uint16_t e131ProxyUniverse _INIT(0); // output this #endif WLED_GLOBAL uint16_t e131Universe _INIT(1); // settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes) WLED_GLOBAL uint16_t e131Port _INIT(5568); // DMX in port. E1.31 default is 5568, Art-Net is 6454 -WLED_GLOBAL byte e131Priority _INIT(0); // E1.31 port priority (if != 0 any data.priority != will be skipped) +WLED_GLOBAL byte e131Priority _INIT(0); // E1.31 port priority (if != 0 priority handling is active) +WLED_GLOBAL E131Priority lastPriority _INIT(3); // E1.31 priority tracking timeout, init value = timeout in seconds WLED_GLOBAL byte DMXMode _INIT(DMX_MODE_MULTIPLE_RGB); // DMX mode (s.a.) WLED_GLOBAL uint16_t DMXAddress _INIT(1); // DMX start address of fixture, a.k.a. first Channel [for E1.31 (sACN) protocol] WLED_GLOBAL uint16_t DMXSegmentSpacing _INIT(0); // Number of void/unused channels between each segments DMX channels