Added comment. Made sure reset() of indatahandlers is called prior to starting stream. Other order could result in bugs

This commit is contained in:
Anne de Jong 2022-10-17 19:51:10 +02:00
parent b29f004f23
commit 8429dfa4e8
2 changed files with 15 additions and 20 deletions

View File

@ -11,7 +11,6 @@ using std::cerr;
using std::endl;
using rte = std::runtime_error;
InDataHandler::InDataHandler(StreamMgr &mgr) : _mgr(mgr) { DEBUGTRACE_ENTER; }
void InDataHandler::start() {
DEBUGTRACE_ENTER;
@ -270,10 +269,14 @@ void StreamMgr::startStream(const DaqConfiguration &config) {
using namespace std::placeholders;
std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config);
std::unique_ptr<Daq> *stream_placeholder;
if (isInput) {
inCallback = std::bind(&StreamMgr::inCallback, this, _1);
stream_placeholder = std::addressof(_inputStream);
for (auto &handler : _inDataHandlers) {
handler->reset(daq.get());
}
}
if (isOutput) {
if (_siggen) {
DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of ");
@ -281,24 +284,13 @@ void StreamMgr::startStream(const DaqConfiguration &config) {
_siggen->reset(daq->samplerate());
}
outCallback = std::bind(&StreamMgr::outCallback, this, _1);
stream_placeholder = std::addressof(_outputStream);
}
DEBUGTRACE_PRINT(isInput);
DEBUGTRACE_PRINT(isOutput);
daq->start(inCallback, outCallback);
if (isInput) {
_inputStream = std::move(daq);
for (auto &handler : _inDataHandlers) {
handler->reset(_inputStream.get());
}
if (_inputStream->duplexMode()) {
assert(!_outputStream);
}
} else {
assert(isOutput);
_outputStream = std::move(daq);
}
// Move daq ptr to right place
*stream_placeholder = std::move(daq);
}
void StreamMgr::stopStream(const StreamType t) {
DEBUGTRACE_ENTER;
@ -341,8 +333,10 @@ void StreamMgr::addInDataHandler(InDataHandler &handler) {
} else {
handler.reset(nullptr);
}
if(std::find(_inDataHandlers.cbegin(),_inDataHandlers.cend(), &handler) != _inDataHandlers.cend()) {
throw std::runtime_error("Error: handler already added. Probably start() is called more than once on a handler object");
if (std::find(_inDataHandlers.cbegin(), _inDataHandlers.cend(), &handler) !=
_inDataHandlers.cend()) {
throw std::runtime_error("Error: handler already added. Probably start() "
"is called more than once on a handler object");
}
_inDataHandlers.push_back(&handler);
}

View File

@ -34,7 +34,8 @@ bool PPMHandler::inCallback_threaded(const DaqData &d) {
assert(_clip_time.size() == _cur_max.size());
/// Obtain max abs values, and scale with range for each channel
/// Obtain max abs values for each column, convert this row-vec to a column
/// vector, and scale with the max-range for each channel
vd maxabs = arma::max(arma::abs(data), 0).as_col() / _max_range;
/// Find indices for channels that have a clip