From 4975c7e8096e7e4d3ca8e2c76631355c647c16de Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Fri, 9 Dec 2022 15:16:03 -0500 Subject: [PATCH] rearrange in header order --- protocol/esta/sacn/universe.cpp | 288 ++++++++++++++++---------------- protocol/esta/sacn/universe.h | 3 +- 2 files changed, 145 insertions(+), 146 deletions(-) diff --git a/protocol/esta/sacn/universe.cpp b/protocol/esta/sacn/universe.cpp index 0a7ca04..121a827 100644 --- a/protocol/esta/sacn/universe.cpp +++ b/protocol/esta/sacn/universe.cpp @@ -33,10 +33,10 @@ namespace sACN { Universe::Universe(Source* src) : DMX::Universe(E131_NETWORK_DATA_LOSS_TIMEOUT) , ACN::DMP::Component(UUID::uuid(), "OpenLCP sACN Universe") + , sender_(src ? new UniverseSender(src, this) : nullptr) , metadata_(std::make_shared()) , active_data_slots_(1) // start code , sync_sequence_(0) - , sender_(src ? new UniverseSender(src, this) : nullptr) { destination.type = ACN::SDT::SDT_ADDR_NULL; } @@ -56,76 +56,13 @@ Universe::~Universe() /** - * @brief Universe::rxDmpGetProperty - * @param message + * @brief Universe::metadata + * @return */ -void Universe::rxDmpGetProperty(ACN::PDU::Message message) +std::shared_ptr Universe::metadata() { - (void)message; -} - - -/** - * @brief Universe::rxDmpSetProperty - * @param message - */ -void Universe::rxDmpSetProperty(ACN::PDU::Message message) -{ - // only act on the first property pair in the data - if (!message->data()) - return; - auto set_data = std::static_pointer_cast(message->data()); - if (set_data->properties.empty()) - return; - const auto& [range, data] = set_data->properties.front(); - - /// > \cite sACN 7.3 Address Type and Data Type - /// > - /// > Sources shall set the DMP Layer's Address Type and Data Type to 0xa1. - /// > Receivers shall discard the packet if the received value is not 0xa1. - if (range.isRelative()) return; - if (range.type() != ACN::DMP::ARRAY) return; - if (range.elementLength() != ACN::DMP::TWO) return; - - /// > \cite sACN 7.4 First Property Address - /// > - /// > Sources shall set the DMP Layer's First Property Address to 0x0000. - /// > Receivers shall discard the packet if the received value is not 0x0000. - if (range.address != 0) - return; - - /// > \cite sACN 7.5 Address Increment - /// > - /// > Sources shall set the DMP Layer's Address Increment to 0x0001. - /// > Receivers shall discard the packet if the received value is not 0x0001. - if (range.incriment != 1) - return; - - /// > \cite sACN 7.6 Property Value Count - /// > - /// > The DMP Layer's Property Value Count is used to encode the number of - /// > 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 - /// > DMX512-A [DMX] START Code and data. - DMX::Universe::setData(data); -} - - -/** - * @brief Universe::rxDmpGetProperty - * @param message - */ -void Universe::rxDmpSubscribe(ACN::PDU::Message message) -{ - (void)message; + std::shared_lock lk_ctl(mtx_control); + return metadata_; } @@ -135,8 +72,8 @@ void Universe::rxDmpSubscribe(ACN::PDU::Message message) */ void Universe::setMetadata(std::shared_ptr metadata) { - std::unique_lock lk_ctl(mtx_control); - metadata_ = metadata; + std::unique_lock lk_ctl(mtx_control); + metadata_ = metadata; } @@ -146,19 +83,85 @@ void Universe::setMetadata(std::shared_ptr metadata) */ bool Universe::isSyncronized() { - std::shared_lock lk_ctl(mtx_control); - return !sync_data_; + std::shared_lock lk_ctl(mtx_control); + return !sync_data_; }; +/** + * @brief Universe::synchronize + * @param sequence_number + */ +void Universe::synchronize(uint8_t sequence_number) +{ + std::shared_lock lk_ctl(mtx_control); + if (!sync_data_) + return; + + /// > \cite sACN 6.7.2 Sequence Numbering + /// > + /// > Having first received a packet with sequence number A, + /// > a second packet with sequence number B arrives. + /// > If, using signed 8-bit binary arithmetic, B - A + /// > is less than or equal to 0, but greater than -20, + /// > then the packet containing sequence number B shall be deemed out of + /// > sequence and discarded. + auto a = sync_sequence_; + auto b = sequence_number; + int8_t dif = b - a; + if (dif <= 0 && dif > -20) + return; + { + std::unique_lock lk_wctl(lk_ctl); + sync_sequence_ = sequence_number; + } + DMX::Universe::setData(*sync_data_); + resetSynchronization(); +} + + +/** + * @brief Universe::resetSynchronization + */ +void Universe::resetSynchronization() +{ + std::unique_lock lk_ctl(mtx_control); + delete sync_data_; + sync_data_ = nullptr; +} + + +/** + * @brief Universe::setSyncData + * @param data + */ +void Universe::setSyncData(const std::vector & data) +{ + resetSynchronization(); + std::unique_lock lk_ctl(mtx_control); + sync_data_ = new std::vector(data); +} + + /** * @brief Universe::isEditable * @return */ bool Universe::isEditable() const { - std::shared_lock lk_ctl(mtx_control); - return sender_; + std::shared_lock lk_ctl(mtx_control); + return sender_; +} + + +/** + * @brief Universe::activeSlots + * @return + */ +uint16_t Universe::activeSlots() +{ + std::shared_lock lk_ctl(mtx_control); + return active_data_slots_; } @@ -174,18 +177,6 @@ const std::vector Universe::sources() const } -/** - * @brief Add a callback to be notified when the source list changes. - * @param callback - * @return - */ -std::shared_ptr Universe::onSourceListChange(std::function callback) -{ - (void)callback; - return nullptr; -}; - - /** * @brief sourceUniverse * @param src @@ -193,11 +184,11 @@ std::shared_ptr Universe::onSourceListChange(std::function callbac */ std::shared_ptr Universe::sourceUniverse(const DATA::data_header& src) { - std::shared_lock lk_ctl(mtx_control); - if (src == *metadata_) - return shared_from_this(); + std::shared_lock lk_ctl(mtx_control); + if (src == *metadata_) + return shared_from_this(); - return nullptr; + return nullptr; } @@ -207,19 +198,20 @@ std::shared_ptr Universe::sourceUniverse(const DATA::data_header& src) */ std::shared_ptr Universe::addNewSource(const DATA::data_header&) { - return nullptr; + return nullptr; } /** - * @brief Universe::activeSlots + * @brief Add a callback to be notified when the source list changes. + * @param callback * @return */ -uint16_t Universe::activeSlots() +std::shared_ptr Universe::onSourceListChange(std::function callback) { - std::shared_lock lk_ctl(mtx_control); - return active_data_slots_; -} + (void)callback; + return nullptr; +}; void Universe::setValue (const uint16_t start, const uint16_t footprint, @@ -268,68 +260,76 @@ void Universe::setStatus(uint8_t status) /** - * @brief Universe::metadata - * @return + * @brief Universe::rxDmpGetProperty + * @param message */ -std::shared_ptr Universe::metadata() +void Universe::rxDmpGetProperty(ACN::PDU::Message message) { - std::shared_lock lk_ctl(mtx_control); - return metadata_; + (void)message; } /** - * @brief Universe::synchronize - * @param sequence_number + * @brief Universe::rxDmpSetProperty + * @param message */ -void Universe::synchronize(uint8_t sequence_number) +void Universe::rxDmpSetProperty(ACN::PDU::Message message) { - std::shared_lock lk_ctl(mtx_control); - if (!sync_data_) - return; + // only act on the first property pair in the data + if (!message->data()) + return; + auto set_data = std::static_pointer_cast(message->data()); + if (set_data->properties.empty()) + return; + const auto& [range, data] = set_data->properties.front(); - /// > \cite sACN 6.7.2 Sequence Numbering - /// > - /// > Having first received a packet with sequence number A, - /// > a second packet with sequence number B arrives. - /// > If, using signed 8-bit binary arithmetic, B - A - /// > is less than or equal to 0, but greater than -20, - /// > then the packet containing sequence number B shall be deemed out of - /// > sequence and discarded. - auto a = sync_sequence_; - auto b = sequence_number; - int8_t dif = b - a; - if (dif <= 0 && dif > -20) - return; - { - std::unique_lock lk_wctl(lk_ctl); - sync_sequence_ = sequence_number; - } - DMX::Universe::setData(*sync_data_); - resetSynchronization(); + /// > \cite sACN 7.3 Address Type and Data Type + /// > + /// > Sources shall set the DMP Layer's Address Type and Data Type to 0xa1. + /// > Receivers shall discard the packet if the received value is not 0xa1. + if (range.isRelative()) return; + if (range.type() != ACN::DMP::ARRAY) return; + if (range.elementLength() != ACN::DMP::TWO) return; + + /// > \cite sACN 7.4 First Property Address + /// > + /// > Sources shall set the DMP Layer's First Property Address to 0x0000. + /// > Receivers shall discard the packet if the received value is not 0x0000. + if (range.address != 0) + return; + + /// > \cite sACN 7.5 Address Increment + /// > + /// > Sources shall set the DMP Layer's Address Increment to 0x0001. + /// > Receivers shall discard the packet if the received value is not 0x0001. + if (range.incriment != 1) + return; + + /// > \cite sACN 7.6 Property Value Count + /// > + /// > The DMP Layer's Property Value Count is used to encode the number of + /// > 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 + /// > DMX512-A [DMX] START Code and data. + DMX::Universe::setData(data); } /** - * @brief Universe::resetSynchronization + * @brief Universe::rxDmpGetProperty + * @param message */ -void Universe::resetSynchronization() +void Universe::rxDmpSubscribe(ACN::PDU::Message message) { - std::unique_lock lk_ctl(mtx_control); - delete sync_data_; - sync_data_ = nullptr; -} - - -/** - * @brief Universe::setSyncData - * @param data - */ -void Universe::setSyncData(const std::vector & data) -{ - resetSynchronization(); - std::unique_lock lk_ctl(mtx_control); - sync_data_ = new std::vector(data); + (void)message; } }; // namespace SACN diff --git a/protocol/esta/sacn/universe.h b/protocol/esta/sacn/universe.h index a7becef..14a76da 100644 --- a/protocol/esta/sacn/universe.h +++ b/protocol/esta/sacn/universe.h @@ -99,6 +99,7 @@ protected: virtual void rxDmpSubscribe(ACN::PDU::Message) override; private: + UniverseSender * sender_; std::shared_ptr metadata_; std::vector * sync_data_ = nullptr; @@ -125,8 +126,6 @@ private: * > the sequence number of an E1.31 Data Packet on that same universe. */ uint8_t sync_sequence_; - - UniverseSender * sender_; }; } // SACN namespace