1
0
Fork 0

don't modify data being set

This commit is contained in:
Kevin Matz 2021-08-31 13:24:32 -04:00
parent 337a8a650d
commit 740bd851c0
2 changed files with 25 additions and 17 deletions

View File

@ -84,25 +84,33 @@ double Universe::rxRate()
/**
* @brief Universe::setData Accept new data from receiver
* @param vect varaibly sized data, beginning with a start code.
* @param data 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
null_start_mutex.lock();
std::copy(vect.begin(), vect.end(), null_start_data.begin());
null_start_mutex.unlock();
rx_timeout_(true);
for (const auto &cb : callbacks_)
cb(this);
break;
default:
break;
}
void Universe::setData(const std::vector<uint8_t>& data)
{
// no data?
if (data.empty())
return;
// 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();
// update rx times
rx_timeout_(true);
// notify callbacks
for (const auto &cb : callbacks_)
cb(this);
}

View File

@ -56,7 +56,7 @@ class Universe {
void setValue (const uint16_t, const uint8_t);
void setValue (const uint16_t, const uint16_t, const uint8_t*);
void setData (std::vector<uint8_t>);
void setData (const std::vector<uint8_t> &);
void onData (const DataHandler);
protected: