LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_daq.h
Go to the documentation of this file.
1#pragma once
2#include "lasp_config.h"
3#include "lasp_daqdata.h"
4#include "lasp_deviceinfo.h"
5#include "lasp_types.h"
6#include <functional>
7#include <memory>
8#include <mutex>
9#include <atomic>
10
18using InDaqCallback = std::function<void(const DaqData &)>;
19
23using OutDaqCallback = std::function<void(DaqData &)>;
24
29class Daq : public DaqConfiguration, public DeviceInfo {
30
31protected:
32 Daq(const DeviceInfo &devinfo, const DaqConfiguration &config);
33 Daq(const Daq &) = delete;
34
35public:
40 public:
41 enum class StreamError {
42 noError,
49 };
50
54 inline static const std::map<StreamError, std::string> errorMessages{
55 {StreamError::noError, "No error"},
56 {StreamError::inputXRun, "Input buffer overrun"},
57 {StreamError::outputXRun, "Output buffer underrun"},
58 {StreamError::driverError, "Driver error"},
59 {StreamError::systemError, "System error"},
60 {StreamError::threadError, "Thread error"},
61 {StreamError::logicError, "Logic error (probably a bug)"},
62 };
63
64 bool isRunning = false;
70 bool error() const { return errorType != StreamError::noError; };
71
73
74 std::string errorMsg() const { return errorMessages.at(errorType); }
75
82 bool runningOK() const { return isRunning && !error(); }
83
84 }; // End of class StreamStatus
85
86 using rte = std::runtime_error;
90 class StreamException : public rte {
92
93 public:
96 : rte(StreamStatus::errorMessages.at(e)), e(e) {}
98 const std::string &additional_info)
99 : rte(StreamStatus::errorMessages.at(e) + ": " + additional_info),
100 e(e) {}
101 operator StreamError() { return e; }
102 };
103
112 static std::unique_ptr<Daq> createDaq(const DeviceInfo &devinfo,
113 const DaqConfiguration &config);
114
124 virtual void start(InDaqCallback inCallback, OutDaqCallback outCallback) = 0;
125
130 virtual void stop() = 0;
131
132 virtual ~Daq() = 0;
133
142 us neninchannels(bool include_monitorchannels = true) const;
143
149 us nenoutchannels() const;
150
160 boolvec eninchannels(const bool include_monitor = true) const;
161
167 boolvec enoutchannels() const;
168
174 double samplerate() const;
175
185 dvec inputRangeForEnabledChannels(const bool include_monitor = true) const;
186
194
200 const DataTypeDescriptor &dtypeDescr() const;
201
210
216 virtual StreamStatus getStreamStatus() const = 0;
217
224 bool duplexMode() const {
225 return (neninchannels() > 0 && nenoutchannels() > 0);
226 }
227};
Used for internal throwing of exceptions.
Definition lasp_daq.h:90
StreamStatus::StreamError e
Definition lasp_daq.h:94
StreamException(const StreamStatus::StreamError e, const std::string &additional_info)
Definition lasp_daq.h:97
StreamException(const StreamStatus::StreamError e)
Definition lasp_daq.h:95
Information regarding a stream.
Definition lasp_daq.h:39
bool runningOK() const
Returns true if everything is OK with a certain stream and the stream is running.
Definition lasp_daq.h:82
StreamError errorType
Definition lasp_daq.h:72
bool error() const
Check if stream has error.
Definition lasp_daq.h:70
static const std::map< StreamError, std::string > errorMessages
Map between error types and messages.
Definition lasp_daq.h:54
std::string errorMsg() const
Definition lasp_daq.h:74
Configuration of a DAQ device.
int framesPerBlockIndex
The index in the array of frames per block that can be used for the device.
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
Base cass for all DAQ (Data Acquisition) interfaces. A DAQ can be a custom device,...
Definition lasp_daq.h:29
const DataTypeDescriptor & dtypeDescr() const
More elaborate description of the datatypes.
Definition lasp_daq.cpp:86
std::runtime_error rte
Definition lasp_daq.h:86
us neninchannels(bool include_monitorchannels=true) const
Returns the number of enabled input channels.
Definition lasp_daq.cpp:99
boolvec eninchannels(const bool include_monitor=true) const
Create a vector of boolean values of the enabled input channels.
Definition lasp_daq.cpp:109
static std::unique_ptr< Daq > createDaq(const DeviceInfo &devinfo, const DaqConfiguration &config)
Create a Daq based on given device info and configuration.
Definition lasp_daq.cpp:20
bool duplexMode() const
Whether the device runs in duplex mode (both input and output), or false if only input / only output.
Definition lasp_daq.h:224
virtual ~Daq()=0
Definition lasp_daq.cpp:18
virtual void start(InDaqCallback inCallback, OutDaqCallback outCallback)=0
Start the Daq.
double samplerate() const
Returns current sample rate.
Definition lasp_daq.cpp:78
DataTypeDescriptor::DataType dataType() const
Returns datatype (enum) corresponding to the datatype of the samples.
Definition lasp_daq.cpp:83
virtual void stop()=0
Stop the Daq device. Throws an exception if the device is not running at the time this method is call...
Daq(const Daq &)=delete
boolvec enoutchannels() const
Create an array of booleans for each enabled output channel.
Definition lasp_daq.cpp:120
virtual StreamStatus getStreamStatus() const =0
Get stream status corresponding to current DAQ.
us framesPerBlock() const
The number of frames that is send in a block of DaqData.
Definition lasp_daq.h:207
dvec inputRangeForEnabledChannels(const bool include_monitor=true) const
Returns the input range for each channel. Maximum allowed absolute value of the signal that can pass ...
Definition lasp_daq.cpp:90
us nenoutchannels() const
Returns the number of enabled output channels.
Definition lasp_daq.cpp:104
Descriptor for data types containing more detailed information.
DataType
Basic data types coming from a DAQ that we can deal with. The naming will be self-explainging.
Structure containing device info parameters.
usvec availableFramesPerBlock
Available latency-setting (number of frames passed in each callback).
std::vector< double > dvec
std::function< void(DaqData &)> OutDaqCallback
Definition lasp_daq.h:23
std::function< void(const DaqData &)> InDaqCallback
Definition lasp_daq.h:18
std::vector< bool > boolvec
size_t us
We often use boolean values.
Definition lasp_types.h:29