DMX::Universe calculates it's rx rate
This commit is contained in:
parent
dd1f4ff4ff
commit
31108b7499
|
@ -47,15 +47,31 @@ const uint8_t Universe::slot (const uint16_t address) const
|
|||
|
||||
|
||||
/**
|
||||
accept new data from receiver
|
||||
* @brief Universe::rxRate Rate (in Hz) at which the universe is being recv'd.
|
||||
* @return Hz
|
||||
*
|
||||
* Calculated as the rolling mean of (the number of frames in
|
||||
* the last 2.5 seconds) / 2.5 seconds.
|
||||
*/
|
||||
const double Universe::rxRate()
|
||||
{
|
||||
rx_timeout_();
|
||||
return rx_times_.size() / 2.5;
|
||||
}
|
||||
|
||||
@param vector<uint8_t> varaibly sized data, beginning with a start code.
|
||||
*/
|
||||
void Universe::setData(vector<uint8_t> vect) {
|
||||
|
||||
/**
|
||||
* @brief Universe::setData Accept new data from receiver
|
||||
* @param vect varaibly sized data, beginning with a start code.
|
||||
*
|
||||
* The only setData method used to establish rx rate.
|
||||
*/
|
||||
void Universe::setData(std::vector<uint8_t> vect) {
|
||||
switch (vect.front()) { // start code
|
||||
case E111_NULL_START:
|
||||
vect.resize(null_start_data_.size(), 0); // pad shorter, truncate larger
|
||||
std::copy(vect.begin(), vect.end(), null_start_data_.begin());
|
||||
rx_timeout_(true);
|
||||
for (const auto &cb : callbacks_)
|
||||
cb(this);
|
||||
break;
|
||||
|
@ -103,4 +119,24 @@ void Universe::onData(const DataHandler callback)
|
|||
callbacks_.push_back(callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Universe::rx_timeout_
|
||||
* @param add_now
|
||||
*/
|
||||
void Universe::rx_timeout_(bool add_now)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto elapsed = [](auto& a, auto& b) {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(a - b);
|
||||
};
|
||||
|
||||
if (add_now)
|
||||
rx_times_.push(now);
|
||||
|
||||
while (rx_times_.size() > 0 &&
|
||||
elapsed(now, rx_times_.front()).count() > 2500)
|
||||
rx_times_.pop();
|
||||
}
|
||||
|
||||
} // DMX
|
||||
|
|
|
@ -23,18 +23,14 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
namespace DMX {
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
using std::array;
|
||||
using std::function;
|
||||
using std::vector;
|
||||
|
||||
// Table D1 - Reserved START Codes
|
||||
static const uint8_t E111_NULL_START = 0;
|
||||
static const uint8_t E111_ASC_TEXT_ASCII = 23;
|
||||
|
@ -45,32 +41,36 @@ static const uint8_t E111_ASC_SIP = 207;
|
|||
|
||||
|
||||
class Universe; // forward declare the Univserse class
|
||||
using DataHandler = function<void(Universe *)>;
|
||||
using DimmerData = array<uint8_t, 513>;
|
||||
using DataHandler = std::function<void(Universe *)>;
|
||||
using DimmerData = std::array<uint8_t, 513>;
|
||||
|
||||
/*
|
||||
The Universe class
|
||||
|
||||
ANSI E1.11 describes may things about moving data over
|
||||
serial EIA-485-A links. This class encapselates that data,
|
||||
regardless of how it was transmitted.
|
||||
*/
|
||||
/**
|
||||
* @brief The Universe class
|
||||
*
|
||||
* ANSI E1.11 describes may things about moving data over serial EIA-485-A
|
||||
* links. This class encapselates that data, regardless of how it was
|
||||
* transmitted.
|
||||
*/
|
||||
class Universe {
|
||||
public:
|
||||
Universe ();
|
||||
|
||||
const DimmerData * data() const { return &null_start_data_; }
|
||||
const uint8_t slot (const uint16_t) const;
|
||||
const double rxRate();
|
||||
|
||||
void setValue (const uint16_t, const uint8_t);
|
||||
void setValue (const uint16_t, const uint16_t, const uint8_t*);
|
||||
|
||||
void setData (vector<uint8_t>);
|
||||
void setData (std::vector<uint8_t>);
|
||||
void onData (const DataHandler);
|
||||
|
||||
private:
|
||||
DimmerData null_start_data_;
|
||||
vector<DataHandler> callbacks_;
|
||||
std::vector<DataHandler> callbacks_;
|
||||
std::queue<std::chrono::time_point<std::chrono::system_clock>> rx_times_;
|
||||
|
||||
void rx_timeout_(bool add_now = false);
|
||||
};
|
||||
|
||||
} // DMX
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../../sacn/universe.h"
|
||||
|
||||
|
@ -19,14 +17,32 @@ public:
|
|||
SACN::Universe *universe = nullptr)
|
||||
: QObject(parent)
|
||||
, universe_(universe)
|
||||
, refreshTimer_(new QTimer(this))
|
||||
, lastRecieved_(QTime())
|
||||
{
|
||||
universe_->onData(std::bind(&QSacnUniverse::dataChangedNotifier,
|
||||
this, std::placeholders::_1));
|
||||
};
|
||||
|
||||
uint8_t value(const u_int16_t slot)
|
||||
const QString description() const
|
||||
{
|
||||
return QString::fromUtf8(universe_->source()->description().c_str());
|
||||
}
|
||||
|
||||
const uint16_t number() const
|
||||
{
|
||||
return universe_->source()->universe();
|
||||
}
|
||||
|
||||
const uint8_t priority() const
|
||||
{
|
||||
return universe_->source()->priority();
|
||||
}
|
||||
|
||||
const double rxRate() const
|
||||
{
|
||||
return universe_->rxRate();
|
||||
}
|
||||
|
||||
uint8_t value(const u_int16_t slot) const
|
||||
{
|
||||
return universe_->slot(slot);
|
||||
}
|
||||
|
@ -66,12 +82,9 @@ protected:
|
|||
void dataChangedNotifier(DMX::Universe* universe = nullptr)
|
||||
{
|
||||
Q_UNUSED(universe)
|
||||
lastRecieved_ = QTime::currentTime();
|
||||
emit changed(universe_);
|
||||
};
|
||||
|
||||
private:
|
||||
SACN::Universe *universe_;
|
||||
QTimer *refreshTimer_;
|
||||
QTime lastRecieved_;
|
||||
};
|
||||
|
|
|
@ -145,6 +145,7 @@ Qt::ItemFlags UniverseModel::flags(const QModelIndex &index) const
|
|||
*/
|
||||
void UniverseModel::universeRefreshed() {
|
||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||
emit recievedUpdate(universe_);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@ public:
|
|||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
void setUniverse(QSacnUniverse *universe);
|
||||
QSacnUniverse * universe() const { return universe_; }
|
||||
|
||||
signals:
|
||||
void recievedUpdate(const QSacnUniverse*);
|
||||
|
||||
public slots:
|
||||
void universeRefreshed();
|
||||
|
|
Loading…
Reference in New Issue