2#include "debugtrace.hpp"
11using Lck = std::scoped_lock<std::mutex>;
12using rte = std::runtime_error;
15 const us resolution,
const us channel)
17 _resolution(resolution), _channel(channel) {
21 if (approx_time_hist <= 0) {
22 throw rte(
"Invalid time history. Should be > 0");
24 if (resolution <= 1) {
25 throw rte(
"Invalid resolution. Should be > 1");
39 _dat.col(0) += _nsamples_per_point / _fs;
41 while (_tb.
size() > _nsamples_per_point) {
43 _dat.col(0) += _nsamples_per_point / _fs;
44 vd newvals = _tb.
pop(_nsamples_per_point);
45 d newmax = newvals.max();
46 d newmin = newvals.min();
48 vd mincol = _dat.col(1);
49 vd maxcol = _dat.col(2);
50 _dat(arma::span(0, _resolution-2),1) = mincol(arma::span(1, _resolution-1));
51 _dat(arma::span(0, _resolution-2),2) = maxcol(arma::span(1, _resolution-1));
52 _dat(_resolution-1, 1) = newmin;
53 _dat(_resolution-1, 2) = newmax;
75 _sens[i] = ch.sensitivity;
81 std::max<us>(
static_cast<us>(_approx_time_hist / _resolution * _fs), 1);
83 const d dt_points = _nsamples_per_point / _fs;
84 const d tend = dt_points * _resolution;
87 _dat.resize(_resolution, 3);
88 _dat.col(0) = arma::linspace(0, tend, _resolution);
std::vector< DaqChannel > enabledInChannels(const bool include_monitor=true) const
Return list of enabled input channels.
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
arma::Mat< d > toFloat() const
Convert samples to floating point values and return a nframes x nchannels array of floats....
Base cass for all DAQ (Data Acquisition) interfaces. A DAQ can be a custom device,...
us neninchannels(bool include_monitorchannels=true) const
Returns the number of enabled input channels.
double samplerate() const
Returns current sample rate.
void inCallback(const DaqData &)
dmat getCurrentValue() const
Returns a 2D array, with:
RtSignalViewer(SmgrHandle mgr, const d approx_time_hist, const us resolution, const us channel)
void startThread()
This method should be called from the derived class' constructor, to start the thread and data is inc...
void stopThread()
This method SHOULD be called from all classes that derive on ThreadedInDataHandler....
A bit of curiously recurring template pattern, to connect the specific handlers and connect the prope...
dmat pop(const us nframes, const us keep=0)
Pop frames from the buffer. Throws a runtime error if more frames are requested than actually stored.
us size() const
Returns current size of stored amount of frames.
void reset()
Reset (empties) the time buffer.
void push(const dmat &mat)
Put samples in the buffer. Number of channels should match other frames, otherwise things go wrong.
std::scoped_lock< std::mutex > Lck
std::shared_ptr< StreamMgr > SmgrHandle
std::scoped_lock< std::mutex > lck
size_t us
We often use boolean values.