From f1f153f09ed34b97ccbaef19830dcd5ad6f88b3f Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Sun, 16 Apr 2023 11:03:53 -0400 Subject: [PATCH] bring active slot awareness down to the base universe class --- protocol/esta/dmx/universe.cpp | 24 ++++++++++++++++++++++++ protocol/esta/dmx/universe.h | 11 +++++++++++ protocol/esta/sacn/universe.cpp | 18 +++--------------- protocol/esta/sacn/universe.h | 15 +-------------- protocol/esta/sacn/universesender.cpp | 4 ++-- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/protocol/esta/dmx/universe.cpp b/protocol/esta/dmx/universe.cpp index 683caa2..70b6acd 100644 --- a/protocol/esta/dmx/universe.cpp +++ b/protocol/esta/dmx/universe.cpp @@ -36,6 +36,7 @@ Universe::Universe(int timeout_period) : null_start_data({0}) , rx_timeout_period_(timeout_period) , status_(DMX_NULL) + , active_data_slots_(1) // start code { } @@ -144,6 +145,14 @@ void Universe::setValue(const uint16_t start, const uint16_t footprint, std::unique_lock lk_ctl(mtx_control); last_updated_ = std::chrono::system_clock::now(); } + + // set active_data_slots to at least end of footprint + if (start + footprint > active_data_slots_) + { + std::unique_lock lk_ctl(mtx_control); + active_data_slots_ = start + footprint; + } + setStatus(DMX_ACTIVE); do_callbacks_(cb_dataChange); } @@ -183,6 +192,10 @@ void Universe::setData(const std::vector& data) null_start_data.fill(0); // wipe old data std::copy_n(data.cbegin(), length, null_start_data.begin()); // copy new data } + { + std::unique_lock lk_ctl(mtx_control); + active_data_slots_ = length; + } rx_timeout_(true); // update rx times do_callbacks_(cb_dataChange); // run callbacks } @@ -289,6 +302,17 @@ void Universe::rx_timeout_(bool add_now) } +/** + * @brief Universe::activeSlots + * @return + */ +uint16_t Universe::activeSlots() const +{ + std::shared_lock lk_ctl(mtx_control); + return active_data_slots_; +} + + /** * @brief Universe::doCallbacks * @param callbacks diff --git a/protocol/esta/dmx/universe.h b/protocol/esta/dmx/universe.h index 6455ff6..b6ef90c 100644 --- a/protocol/esta/dmx/universe.h +++ b/protocol/esta/dmx/universe.h @@ -63,6 +63,8 @@ class Universe { std::shared_ptr onDataChange(const std::function); std::shared_ptr onStatusChange(const std::function); + virtual uint16_t activeSlots() const; + /// Known states of the universe Status value enum Status : uint8_t { DMX_NULL = 0, //!< uninitialized @@ -89,6 +91,15 @@ class Universe { std::queue> rx_times_; std::vector>> cb_dataChange; std::vector>> cb_statusChange; + + /** + * @brief \cite DMX 8.7 Minimum number of data slots + * + * > There shall be no minimum number of data slots on the data link. DMX512 data packets + * > with fewer than 512 slots may be transmitted, subject to the minimum timing requirements + * > of this Standard – see clause 8.10 and figure 5. + */ + uint16_t active_data_slots_; }; } // namespace DMX diff --git a/protocol/esta/sacn/universe.cpp b/protocol/esta/sacn/universe.cpp index 398fcd5..877a55e 100644 --- a/protocol/esta/sacn/universe.cpp +++ b/protocol/esta/sacn/universe.cpp @@ -39,7 +39,6 @@ Universe::Universe(Source* src, Receiver* rsv) , sender_(src ? new UniverseSender(src, this) : nullptr) , metadata_(std::make_shared()) , sync_data_(nullptr) - , active_data_slots_(1) // start code , sync_sequence_(0) { destination.type = ACN::SDT::SDT_ADDR_NULL; @@ -129,7 +128,7 @@ void Universe::setStatus(uint8_t status) * @param footprint * @param data */ -void Universe::setValue (const uint16_t start, const uint16_t footprint, +void Universe::setValue(const uint16_t start, const uint16_t footprint, const uint8_t* data) { if (!isEditable()) @@ -142,13 +141,6 @@ void Universe::setValue (const uint16_t start, const uint16_t footprint, if (start < 1 || start + footprint > null_start_data.size()) return; - // set active_data_slots to at least end of footprint - if (start + footprint > active_data_slots_) - { - std::unique_lock lk_ctl(mtx_control); - active_data_slots_ = start + footprint; - } - // get a copy of the current values uint8_t og[footprint]; { @@ -303,8 +295,7 @@ uint16_t Universe::activeSlots() const if (arbitrator_) return arbitrator_->activeSlots(); - std::shared_lock lk_ctl(mtx_control); - return active_data_slots_; + return DMX::Universe::activeSlots(); } @@ -401,10 +392,7 @@ void Universe::rxDmpSetProperty(ACN::PDU::Message message) /// > DMX512-A [DMX] Slots (including the START Code slot). if (range.count < 1 || range.count > null_start_data.size()) return; - { - std::unique_lock lk_ctl(mtx_control); - active_data_slots_ = range.address + range.count; - } + /// > \cite sACN 7.7 Property Values (DMX512-A Data) /// > /// > The DMP Layer's Property values field is used to encode the diff --git a/protocol/esta/sacn/universe.h b/protocol/esta/sacn/universe.h index a9f369a..33da019 100644 --- a/protocol/esta/sacn/universe.h +++ b/protocol/esta/sacn/universe.h @@ -83,7 +83,7 @@ public: virtual bool isEditable() const; - virtual uint16_t activeSlots() const; + virtual uint16_t activeSlots() const override; virtual bool hasSources() const; virtual const std::vector sources() const; UniverseArbitrator* arbitrator() const; @@ -118,19 +118,6 @@ private: std::shared_ptr metadata_; std::vector * sync_data_; - /** - * @brief \cite sACN 3.7 Active Data Slots - * - * > When translating ANSI E1.11 DMX512-A \cite DMX to E1.31, the active data - * > slots are defined as ranging from data slot 1 to the maximum data slot in - * > the most recently received packet with the corresponding START Code. - * > - * > Devices originating E1.31 shall define their active data slots using - * > the DMP First Property Address and DMP Property Count fields shown in - * > Table 4-1. - */ - uint16_t active_data_slots_; - /** * > \cite sACN 6.3.2 E1.31 Synchronization Packet: Sequence Number * > diff --git a/protocol/esta/sacn/universesender.cpp b/protocol/esta/sacn/universesender.cpp index 8891cfa..50fdbd7 100644 --- a/protocol/esta/sacn/universesender.cpp +++ b/protocol/esta/sacn/universesender.cpp @@ -205,8 +205,8 @@ void UniverseSender::update_dmp_() ACN::DMP::Range pr(*addrtyp); pr.address = 0; pr.incriment = 1; - pr.count = mUniverse->active_data_slots_ < mUniverse->null_start_data.size() - ? mUniverse->active_data_slots_ + pr.count = mUniverse->activeSlots() < mUniverse->null_start_data.size() + ? mUniverse->activeSlots() : mUniverse->null_start_data.size(); // property data