1
0
Fork 0

protocol specific timeout periods

This commit is contained in:
Kevin Matz 2021-08-06 12:36:31 -04:00
parent 7ad1962d3b
commit cfd0aa647d
3 changed files with 13 additions and 6 deletions

View File

@ -30,7 +30,8 @@ namespace DMX {
/**
* @brief Universe::Universe
*/
Universe::Universe()
Universe::Universe(int timeout_period)
: rx_timeout_period_(timeout_period)
{
null_start_data_.fill(0);
}
@ -63,12 +64,12 @@ uint8_t Universe::slot(const uint16_t address)
* @return Hz
*
* Calculated as the rolling mean of (the number of frames in
* the last 2.5 seconds) / 2.5 seconds.
* the last rx_timeout_peroid ms) / rx_timeout_period seconds.
*/
double Universe::rxRate()
{
rx_timeout_();
return rx_times_.size() / 2.5;
return rx_times_.size() / (rx_timeout_period_ / 1000.0);
}
@ -147,7 +148,7 @@ void Universe::rx_timeout_(bool add_now)
rx_times_.push(now);
while (rx_times_.size() > 0 &&
elapsed(now, rx_times_.front()).count() > 2500)
elapsed(now, rx_times_.front()).count() > rx_timeout_period_)
rx_times_.pop();
}

View File

@ -39,6 +39,11 @@ static const uint8_t E111_ASC_TEXT_UTF8 = 144;
static const uint8_t E111_ASC_MANUFACTURER = 145;
static const uint8_t E111_ASC_SIP = 207;
// 8.5.3.1 Alternate START code refresh interval
// A DMX512 transmitter interleaving NULL START Code packets with
// Alternate START Code packets shall send a NULL START Code packet at least
// once per second.
static const int E111_DATA_LOSS_TIMEOUT = 1000;
class Universe; // forward declare the Univserse class
using DataHandler = std::function<void(Universe *)>;
@ -53,7 +58,7 @@ using DimmerData = std::array<uint8_t, 513>;
*/
class Universe {
public:
Universe ();
Universe (int timeout_period = E111_DATA_LOSS_TIMEOUT);
virtual ~Universe ();
virtual const DimmerData * data() const { return &null_start_data_; }
@ -74,6 +79,7 @@ class Universe {
std::queue<std::chrono::time_point<std::chrono::system_clock>> rx_times_;
void rx_timeout_(bool add_now = false);
const int rx_timeout_period_;
};
} // DMX

View File

@ -81,7 +81,7 @@ bool operator== (const UniverseSource& a, const UniverseSource& b)
* @brief Universe::Universe
*/
Universe::Universe()
: DMX::Universe()
: DMX::Universe(E131_NETWORK_DATA_LOSS_TIMEOUT)
{
sync_data_.clear();
};