110 lines
2.3 KiB
C++
110 lines
2.3 KiB
C++
#pragma once
|
|
#include <uldaq.h>
|
|
#include "lasp_types.h"
|
|
#include "lasp_uldaq_impl.h"
|
|
#include "lasp_uldaq_common.h"
|
|
|
|
|
|
|
|
/** \addtogroup device
|
|
* @{
|
|
* \addtogroup uldaq
|
|
*/
|
|
/**
|
|
* @brief Helper class for managing input and output samples of the DAQ device.
|
|
*/
|
|
|
|
class DT9837A;
|
|
class BufHandler {
|
|
protected:
|
|
/**
|
|
* @brief Reference to underlying Daq
|
|
*/
|
|
DT9837A &daq;
|
|
/**
|
|
* @brief The type of data, in this case always double precision floats
|
|
*/
|
|
const DataTypeDescriptor dtype_descr = dtype_desc_fl64;
|
|
/**
|
|
* @brief The number of channels, number of frames per callback (block).
|
|
*/
|
|
us nchannels, nFramesPerBlock;
|
|
/**
|
|
* @brief Sampling frequency in Hz
|
|
*/
|
|
double samplerate;
|
|
/**
|
|
* @brief Storage capacity for the DAQ I/O.
|
|
*/
|
|
std::vector<double> buf;
|
|
/**
|
|
* @brief Whether the top part of the buffer is enqueued
|
|
*/
|
|
bool topenqueued = false;
|
|
/**
|
|
* @brief Whether the bottom part of the buffer is enqueued
|
|
* enqueued
|
|
*/
|
|
bool botenqueued = false;
|
|
|
|
/**
|
|
* @brief Counter for the total number of frames acquired / sent since the
|
|
* start of the stream.
|
|
*/
|
|
us totalFramesCount = 0;
|
|
long long buffer_mid_idx;
|
|
|
|
public:
|
|
/**
|
|
* @brief Initialize bufhandler
|
|
*
|
|
* @param daq
|
|
* @param nchannels
|
|
*/
|
|
BufHandler(DT9837A &daq, const us nchannels)
|
|
: daq(daq), dtype_descr(daq.dtypeDescr()), nchannels(nchannels),
|
|
nFramesPerBlock(daq.framesPerBlock()), samplerate(daq.samplerate()),
|
|
buf(2 * nchannels *
|
|
nFramesPerBlock, // Watch the two here, the top and the bottom!
|
|
0),
|
|
buffer_mid_idx(nchannels * nFramesPerBlock) {
|
|
assert(nchannels > 0);
|
|
assert(nFramesPerBlock > 0);
|
|
}
|
|
};
|
|
/**
|
|
* @brief Specific helper for the input buffer
|
|
*/
|
|
class InBufHandler : public BufHandler {
|
|
bool monitorOutput;
|
|
InDaqCallback cb;
|
|
|
|
public:
|
|
InBufHandler(DT9837A &daq, InDaqCallback cb);
|
|
void start();
|
|
/**
|
|
* @brief InBufHandler::operator()()
|
|
*
|
|
* @return true on success
|
|
*/
|
|
bool operator()();
|
|
~InBufHandler();
|
|
};
|
|
class OutBufHandler : public BufHandler {
|
|
OutDaqCallback cb;
|
|
|
|
public:
|
|
OutBufHandler(DT9837A &daq, OutDaqCallback cb);
|
|
void start();
|
|
/**
|
|
* @brief OutBufHandler::operator()
|
|
*
|
|
* @return true on success
|
|
*/
|
|
bool operator()();
|
|
|
|
~OutBufHandler();
|
|
};
|
|
/** @} */
|
|
/** @} */
|