Added comment. Made sure reset() of indatahandlers is called prior to starting stream. Other order could result in bugs
This commit is contained in:
parent
b29f004f23
commit
8429dfa4e8
@ -11,7 +11,6 @@ using std::cerr;
|
|||||||
using std::endl;
|
using std::endl;
|
||||||
using rte = std::runtime_error;
|
using rte = std::runtime_error;
|
||||||
|
|
||||||
|
|
||||||
InDataHandler::InDataHandler(StreamMgr &mgr) : _mgr(mgr) { DEBUGTRACE_ENTER; }
|
InDataHandler::InDataHandler(StreamMgr &mgr) : _mgr(mgr) { DEBUGTRACE_ENTER; }
|
||||||
void InDataHandler::start() {
|
void InDataHandler::start() {
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
@ -60,7 +59,7 @@ void StreamMgr::checkRightThread() const {
|
|||||||
void StreamMgr::rescanDAQDevices(bool background,
|
void StreamMgr::rescanDAQDevices(bool background,
|
||||||
std::function<void()> callback) {
|
std::function<void()> callback) {
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
auto& pool = getPool();
|
auto &pool = getPool();
|
||||||
|
|
||||||
checkRightThread();
|
checkRightThread();
|
||||||
if (!_devices_mtx.try_lock()) {
|
if (!_devices_mtx.try_lock()) {
|
||||||
@ -270,10 +269,14 @@ void StreamMgr::startStream(const DaqConfiguration &config) {
|
|||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config);
|
std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config);
|
||||||
|
|
||||||
|
std::unique_ptr<Daq> *stream_placeholder;
|
||||||
if (isInput) {
|
if (isInput) {
|
||||||
inCallback = std::bind(&StreamMgr::inCallback, this, _1);
|
inCallback = std::bind(&StreamMgr::inCallback, this, _1);
|
||||||
|
stream_placeholder = std::addressof(_inputStream);
|
||||||
|
for (auto &handler : _inDataHandlers) {
|
||||||
|
handler->reset(daq.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOutput) {
|
if (isOutput) {
|
||||||
if (_siggen) {
|
if (_siggen) {
|
||||||
DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of ");
|
DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of ");
|
||||||
@ -281,24 +284,13 @@ void StreamMgr::startStream(const DaqConfiguration &config) {
|
|||||||
_siggen->reset(daq->samplerate());
|
_siggen->reset(daq->samplerate());
|
||||||
}
|
}
|
||||||
outCallback = std::bind(&StreamMgr::outCallback, this, _1);
|
outCallback = std::bind(&StreamMgr::outCallback, this, _1);
|
||||||
|
stream_placeholder = std::addressof(_outputStream);
|
||||||
}
|
}
|
||||||
DEBUGTRACE_PRINT(isInput);
|
|
||||||
DEBUGTRACE_PRINT(isOutput);
|
|
||||||
|
|
||||||
daq->start(inCallback, outCallback);
|
daq->start(inCallback, outCallback);
|
||||||
|
|
||||||
if (isInput) {
|
// Move daq ptr to right place
|
||||||
_inputStream = std::move(daq);
|
*stream_placeholder = std::move(daq);
|
||||||
for (auto &handler : _inDataHandlers) {
|
|
||||||
handler->reset(_inputStream.get());
|
|
||||||
}
|
|
||||||
if (_inputStream->duplexMode()) {
|
|
||||||
assert(!_outputStream);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
assert(isOutput);
|
|
||||||
_outputStream = std::move(daq);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void StreamMgr::stopStream(const StreamType t) {
|
void StreamMgr::stopStream(const StreamType t) {
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
@ -341,8 +333,10 @@ void StreamMgr::addInDataHandler(InDataHandler &handler) {
|
|||||||
} else {
|
} else {
|
||||||
handler.reset(nullptr);
|
handler.reset(nullptr);
|
||||||
}
|
}
|
||||||
if(std::find(_inDataHandlers.cbegin(),_inDataHandlers.cend(), &handler) != _inDataHandlers.cend()) {
|
if (std::find(_inDataHandlers.cbegin(), _inDataHandlers.cend(), &handler) !=
|
||||||
throw std::runtime_error("Error: handler already added. Probably start() is called more than once on a handler object");
|
_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);
|
_inDataHandlers.push_back(&handler);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ bool PPMHandler::inCallback_threaded(const DaqData &d) {
|
|||||||
|
|
||||||
assert(_clip_time.size() == _cur_max.size());
|
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;
|
vd maxabs = arma::max(arma::abs(data), 0).as_col() / _max_range;
|
||||||
|
|
||||||
/// Find indices for channels that have a clip
|
/// Find indices for channels that have a clip
|
||||||
|
Loading…
Reference in New Issue
Block a user