1
0
Fork 0

accept the front of over-length data

This commit is contained in:
Kevin Matz 2022-11-28 11:36:01 -05:00
parent fdb2980d0e
commit a81bc5b1fd
1 changed files with 8 additions and 11 deletions

View File

@ -113,17 +113,14 @@ void Universe::setData(const std::vector<uint8_t>& data)
if (data.front() != E111_NULL_START)
return altSCdata(data);
// too many slots!
if (data.size() > null_start_data.size())
return;
// copy data
null_start_mutex.lock();
if (data.size() < null_start_data.size())
null_start_data.fill(0);
std::copy(data.begin(), data.end(), null_start_data.begin());
null_start_mutex.unlock();
// accept variable lenth input, but never more than the limit
const auto max_length = null_start_data.size();
const auto length = data.size() < max_length ? data.size() : max_length;
null_start_mutex.lock(); // take the lock
if (length < max_length)
null_start_data.fill(0); // wipe old data
std::copy_n(data.cbegin(), length, null_start_data.begin()); // copy new data
null_start_mutex.unlock(); // free the lock
rx_timeout_(true); // update rx times
doDataCallbacks(); // notify callbacks