1
0
Fork 0
OpenLCP/platform/qt/qsacnuniverse.cpp

261 lines
5.0 KiB
C++
Raw Normal View History

2021-09-02 13:18:40 -04:00
#include "qsacnuniverse.h"
/**
* @brief QSacnUniverse::QSacnUniverse
* @param parent
* @param universe
*/
2021-09-10 09:55:34 -04:00
QSacnUniverse::QSacnUniverse(QObject *parent, std::shared_ptr<sACN::Universe> universe)
2021-09-02 13:18:40 -04:00
: QObject(parent)
, universe_(universe)
, status_watchdog_(new QTimer(this))
2021-09-02 13:18:40 -04:00
{
2021-09-10 09:55:34 -04:00
if (!universe)
return;
data_change_token = universe_->onDataChange([this](DMX::Universe*){emit dataChanged();});
status_change_token = universe_->onStatusChange([this](DMX::Universe*){emit statusChanged();});
2021-09-10 12:00:50 -04:00
if (!universe->isEditable())
list_change_token = universe_->onSourceListChange([this](){syncSources();});
// set the status watchdog to update the status if the universe
// isn't showing frequent activity
2022-12-03 10:59:22 -05:00
status_watchdog_->callOnTimeout([this](){universe_->status();});
status_watchdog_->setInterval(DMX::E111_DATA_LOSS_TIMEOUT);
status_watchdog_->start();
connect(this, &QSacnUniverse::dataChanged,
this, [this](){status_watchdog_->start();});
connect(this, &QSacnUniverse::statusChanged,
this, [this](){status_watchdog_->start();});
2021-09-02 13:18:40 -04:00
};
2021-09-10 11:47:48 -04:00
/**
* @brief QSacnUniverse::~QSacnUniverse
*/
QSacnUniverse::~QSacnUniverse()
{
2021-09-10 12:00:50 -04:00
// delete QSacnUniverse sources
2022-11-28 09:22:53 -05:00
qDeleteAll(sources_);
2021-09-10 11:47:48 -04:00
}
2021-09-02 13:18:40 -04:00
/**
* @brief QSacnUniverse::description
* @return
*/
const QString QSacnUniverse::sourceName() const
2021-09-02 13:18:40 -04:00
{
auto metadata = universe_->metadata();
2022-12-04 10:36:37 -05:00
return metadata ? QString::fromUtf8(metadata->source_name.c_str()) : QString();
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::number
* @return
*/
uint16_t QSacnUniverse::number() const
{
auto metadata = universe_->metadata();
2022-12-04 10:36:37 -05:00
return metadata ? metadata->universe : 0;
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::priority
* @return
*/
uint8_t QSacnUniverse::priority() const
{
auto metadata = universe_->metadata();
2022-12-04 10:36:37 -05:00
return metadata ? metadata->priority : 0;
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::rxRate
* @return
*/
double QSacnUniverse::rxRate() const
{
2022-12-04 10:36:37 -05:00
return universe_ ? universe_->rxRate() : -1;
2021-09-02 13:18:40 -04:00
}
2022-11-28 09:25:47 -05:00
/**
* @brief QSacnUniverse::status
* @return
*/
uint8_t QSacnUniverse::status() const
{
2022-12-04 10:36:37 -05:00
return universe_ ? universe_->status() : sACN::Universe::DMX_NULL;
2022-11-28 09:25:47 -05:00
}
2021-09-02 13:18:40 -04:00
/**
* @brief QSacnUniverse::slot
* @param slot
* @return
*/
2021-09-11 14:29:17 -04:00
uint8_t QSacnUniverse::slot(const uint16_t slot) const
2021-09-02 13:18:40 -04:00
{
2022-12-04 10:36:37 -05:00
return universe_ ? universe_->slot(slot) : 0;
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::isEditable
* @return
*/
bool QSacnUniverse::isEditable() const
{
2022-12-04 10:36:37 -05:00
return universe_ ? universe_->isEditable() : false;
2021-09-02 13:18:40 -04:00
}
2021-09-10 12:00:50 -04:00
/**
* @brief QSacnUniverse::sources
* @return
*/
2022-12-04 00:32:12 -05:00
const QList<sACN::DATA::data_header> QSacnUniverse::sources() const
2021-09-10 12:00:50 -04:00
{
QList<sACN::DATA::data_header> ret;
if (!universe_)
return ret;
for (const auto & src : universe_->sources())
ret.append(src);
return ret;
}
/**
* @brief QSacnUniverse::sourceUniverse
* @param metadata
* @return
*/
2022-12-04 00:32:12 -05:00
QSacnUniverse* QSacnUniverse::sourceUniverse(const sACN::DATA::data_header& metadata) const
2021-09-10 12:00:50 -04:00
{
if (!universe_)
return nullptr;
if (!sources_.count(metadata))
return nullptr;
return sources_.value(metadata);
}
/**
* @brief QSacnUniverse::activeSlots
* @return
*/
uint16_t QSacnUniverse::activeSlots() const
{
2022-12-04 10:36:37 -05:00
return universe_ ? universe_->activeSlots() : 0;
}
2021-09-02 13:18:40 -04:00
/**
* @brief QSacnUniverse::setOptions
* @param o
*/
void QSacnUniverse::setOptions(sACN::DATA::data_options o)
{
2021-09-08 15:47:10 -04:00
if (!isEditable())
2021-09-08 10:33:54 -04:00
return;
universe_->metadata()->options = o;
2022-12-02 12:58:39 -05:00
emit dataChanged();
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::setPriority
* @param p
*/
void QSacnUniverse::setPriority(uint8_t p)
{
2021-09-08 15:47:10 -04:00
if (!isEditable())
2021-09-08 10:33:54 -04:00
return;
universe_->metadata()->priority = p;
2022-12-02 12:58:39 -05:00
emit dataChanged();
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::setSyncAddress
* @param a
*/
void QSacnUniverse::setSyncAddress(uint16_t a)
{
2021-09-08 15:47:10 -04:00
if (!isEditable())
2021-09-08 10:33:54 -04:00
return;
universe_->metadata()->sync_address = a;
2022-12-02 12:58:39 -05:00
emit dataChanged();
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::setValue
* @param addr
* @param level
*/
void QSacnUniverse::setValue (const uint16_t addr, const uint8_t level)
{
2022-12-06 18:04:19 -05:00
setValue(addr, 1, &level);
2021-09-02 13:18:40 -04:00
}
/**
* @brief QSacnUniverse::setValue
* @param addr
* @param size
* @param profile
*/
void QSacnUniverse::setValue (const uint16_t addr, const uint16_t size,
const uint8_t* profile)
{
2021-09-08 15:47:10 -04:00
if (!isEditable())
2021-09-08 10:33:54 -04:00
return;
universe_->sACN::Universe::setValue(addr, size, profile);
2022-12-02 12:58:39 -05:00
emit dataChanged();
2021-09-02 13:18:40 -04:00
}
2021-09-10 12:00:50 -04:00
/**
* @brief QSacnUniverse::syncSources
*/
void QSacnUniverse::syncSources()
{
2022-11-28 09:39:11 -05:00
// create a new list of sources
2021-09-10 12:00:50 -04:00
QMap<sACN::DATA::data_header, QSacnUniverse*> newSources;
auto headers = universe_->sources();
for (const auto & metadata : headers)
{
2022-11-28 09:39:11 -05:00
if (sources_.contains(metadata))
// move the QSacnUniverse to the new list
newSources.insert(metadata, sources_.take(metadata));
else
{ // make a new QSacnUniverse to add to the new list
2021-09-10 12:00:50 -04:00
auto universe = universe_->sourceUniverse(metadata);
newSources.insert(metadata, new QSacnUniverse(this, universe));
}
}
2022-11-28 09:39:11 -05:00
// delete any remaining sources, ie. not moved to the new list
2022-11-28 09:22:53 -05:00
qDeleteAll(sources_);
2021-09-10 12:00:50 -04:00
2022-11-28 09:39:11 -05:00
// accept the new list
2021-09-10 12:00:50 -04:00
sources_ = newSources;
emit sourceListChanged();
}