1
0
Fork 0

tighten up the use of time

This commit is contained in:
Kevin Matz 2022-11-23 13:49:35 -05:00
parent e157090e35
commit e12d11e62e
1 changed files with 10 additions and 11 deletions

View File

@ -444,8 +444,8 @@ void Universe::tx_loop_()
///
/// > \cite DMX Table 6 - Timing Diagram Values - output of transmitting UART
/// >
/// > Minimum Update Time for 513 slots : 22.7ms
std::chrono::milliseconds minimum_update_time(23);
/// > Minimum Update Time for 513 slots : 22.7ms = 22700µs
std::chrono::microseconds minimum_update_time(22700);
/// > \cite sACN 6.6.2 Null START Code Transmission Requirements in E1.31
/// > Data Packets
@ -469,8 +469,7 @@ void Universe::tx_loop_()
while (enable || terminated_resend >= 0)
{
// enforce strict minimum update times
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::system_clock::now() - last_sent);
auto elapsed = std::chrono::system_clock::now() - last_sent;
if (elapsed < minimum_update_time)
std::this_thread::sleep_for(minimum_update_time - elapsed);
@ -479,7 +478,6 @@ void Universe::tx_loop_()
enable = tx_enable_;
tx_control_mutex_.unlock();
if (enable)
{
if (active_data_slots)
@ -494,26 +492,27 @@ void Universe::tx_loop_()
}
// see if this is new data or re-transmitting
auto sleep = std::chrono::milliseconds(minimum_update_time);
null_start_mutex.lock();
bool new_data = (null_start_data != last_null_data);
null_start_mutex.unlock();
auto sleep = minimum_update_time;
if (new_data)
{
retransmission_count = 0;
last_null_data = null_start_data;
}
else
if (++retransmission_count >= 2)
sleep = std::chrono::milliseconds(keep_alive_interval);
else if (++retransmission_count >= 2)
{
sleep = keep_alive_interval;
retransmission_count = 3; // prevent counter from overflowing
}
// send the sACN message
sACNsend();
last_sent = std::chrono::system_clock::now();
// sleep before the next cycle
if (enable)
tx_request_.wait_for(mtx, sleep);
tx_request_.wait_for(mtx, sleep);
}
}