1
0
Fork 0

bring awareness of device operating classes to the base universe class

This commit is contained in:
Kevin Matz 2023-04-16 11:05:04 -04:00
parent f1f153f09e
commit 63aef39f28
5 changed files with 29 additions and 13 deletions

View File

@ -29,6 +29,17 @@
* @brief @cite DMX The Digital Multiplex Protocol
*/
namespace DMX {
/// \cite DMX 1.4 Classes of data appropriate for transmission
///
/// DMX512 is designed to carry repetitive control data from a single controller
/// to one or more receivers.
enum DeviceClass
{
CONTROLLER, //!< 3.7 A transmitting device that originates DMX512 data.
RECEIVER, //!< 3.30 A piece of equipment that accepts a DMX512 signal.
RESPONDER, //!< 4.3 A RECEIVER capable of returning status information
};
/// \cite DMX Table D1 - Reserved START Codes
static const uint8_t E111_NULL_START = 0;
static const uint8_t E111_ASC_TEXT_ASCII = 23;

View File

@ -34,6 +34,7 @@ namespace DMX {
*/
Universe::Universe(int timeout_period)
: null_start_data({0})
, device_class_(RECEIVER)
, rx_timeout_period_(timeout_period)
, status_(DMX_NULL)
, active_data_slots_(1) // start code
@ -133,6 +134,9 @@ void Universe::setStatus(uint8_t val)
void Universe::setValue(const uint16_t start, const uint16_t footprint,
const uint8_t * const data)
{
if (!isEditable())
return;
// start and footprint valid?
if (start < 1 || start + footprint > null_start_data.size())
return;
@ -302,6 +306,17 @@ void Universe::rx_timeout_(bool add_now)
}
/**
* @brief Universe::isEditable
* @return
*/
bool Universe::isEditable() const
{
std::shared_lock lk_ctl(mtx_control);
return device_class_ == CONTROLLER;
}
/**
* @brief Universe::activeSlots
* @return

View File

@ -63,6 +63,7 @@ class Universe {
std::shared_ptr<void> onDataChange(const std::function<void(Universe*)>);
std::shared_ptr<void> onStatusChange(const std::function<void(Universe*)>);
virtual bool isEditable() const;
virtual uint16_t activeSlots() const;
/// Known states of the universe Status value
@ -79,6 +80,7 @@ class Universe {
void do_callbacks_(std::vector<std::weak_ptr<const std::function<void(Universe*)>>>&);
DimmerData null_start_data; //!< NULL Start Code data
DeviceClass device_class_; //!< operating class of the universe
mutable std::shared_mutex mtx_data; //!< memory protect Null Start data
mutable std::shared_mutex mtx_control; //!< thread protected access control
std::chrono::system_clock::time_point last_updated_; //!< time of the latest update

View File

@ -41,6 +41,7 @@ Universe::Universe(Source* src, Receiver* rsv)
, sync_data_(nullptr)
, sync_sequence_(0)
{
device_class_ = sender_ ? DMX::CONTROLLER : DMX::RECEIVER;
destination.type = ACN::SDT::SDT_ADDR_NULL;
}
@ -275,17 +276,6 @@ void Universe::setSyncData(const std::vector<uint8_t> & data)
}
/**
* @brief Universe::isEditable
* @return
*/
bool Universe::isEditable() const
{
std::shared_lock lk_ctl(mtx_control);
return sender_;
}
/**
* @brief Universe::activeSlots
* @return

View File

@ -81,8 +81,6 @@ public:
virtual void resetSynchronization();
virtual void setSyncData(const std::vector<uint8_t> &);
virtual bool isEditable() const;
virtual uint16_t activeSlots() const override;
virtual bool hasSources() const;
virtual const std::vector<DATA::data_header> sources() const;