diff --git a/protocol/sacn/universe.cpp b/protocol/sacn/universe.cpp index 9266012..2b18606 100644 --- a/protocol/sacn/universe.cpp +++ b/protocol/sacn/universe.cpp @@ -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::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); } }