From 8429dfa4e8b6f34454c018b6ddee55299379f0f1 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Mon, 17 Oct 2022 19:51:10 +0200 Subject: [PATCH] Added comment. Made sure reset() of indatahandlers is called prior to starting stream. Other order could result in bugs --- src/lasp/device/lasp_streammgr.cpp | 32 ++++++++++++------------------ src/lasp/dsp/lasp_ppm.cpp | 3 ++- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/lasp/device/lasp_streammgr.cpp b/src/lasp/device/lasp_streammgr.cpp index f9c2384..4209e97 100644 --- a/src/lasp/device/lasp_streammgr.cpp +++ b/src/lasp/device/lasp_streammgr.cpp @@ -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; @@ -60,7 +59,7 @@ void StreamMgr::checkRightThread() const { void StreamMgr::rescanDAQDevices(bool background, std::function callback) { DEBUGTRACE_ENTER; - auto& pool = getPool(); + auto &pool = getPool(); checkRightThread(); if (!_devices_mtx.try_lock()) { @@ -270,10 +269,14 @@ void StreamMgr::startStream(const DaqConfiguration &config) { using namespace std::placeholders; std::unique_ptr daq = Daq::createDaq(devinfo, config); + std::unique_ptr *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); } diff --git a/src/lasp/dsp/lasp_ppm.cpp b/src/lasp/dsp/lasp_ppm.cpp index cfe2b10..12bcd2b 100644 --- a/src/lasp/dsp/lasp_ppm.cpp +++ b/src/lasp/dsp/lasp_ppm.cpp @@ -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