LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_daqconfig.cpp
Go to the documentation of this file.
1#include "lasp_daqconfig.h"
2#include "lasp_deviceinfo.h"
3#include <algorithm>
4#include <iostream>
5#include <pybind11/numpy.h>
6#include <pybind11/stl.h>
7#include <stdint.h>
8
9using std::cerr;
10namespace py = pybind11;
11
12void init_daqconfiguration(py::module &m) {
13
15 py::class_<DataTypeDescriptor> dtype_desc(m, "DataTypeDescriptor");
16
17 dtype_desc.def_readonly("name", &DataTypeDescriptor::name);
18 dtype_desc.def_readonly("sw", &DataTypeDescriptor::sw);
19 dtype_desc.def_readonly("is_floating", &DataTypeDescriptor::is_floating);
20 dtype_desc.def_readonly("dtype", &DataTypeDescriptor::dtype);
21
22 py::enum_<DataTypeDescriptor::DataType>(dtype_desc, "DataType")
27 .value("dtype_int32", DataTypeDescriptor::DataType::dtype_int32);
28
29 dtype_desc.def_static("toStr", [](const DataTypeDescriptor::DataType d) {
30 return dtype_map.at(d).name;
31 });
32 dtype_desc.def_static("fromStr", [](const std::string &dtype_str) {
33 decltype(dtype_map.cbegin()) d = std::find_if(
34 dtype_map.cbegin(), dtype_map.cend(),
35 [&dtype_str](const auto &d) { return d.second.name == dtype_str; });
36 if (d != dtype_map.cend()) {
37 return d->first;
38 }
39 throw std::runtime_error(dtype_str + " not found in list of data types");
40 });
41
42 dtype_desc.def_readonly("dtype", &DataTypeDescriptor::dtype);
43
45 py::class_<DaqApi> daqapi(m, "DaqApi");
46 daqapi.def_readonly("apiname", &DaqApi::apiname);
47 daqapi.def_readonly("apicode", &DaqApi::apicode);
48 daqapi.def_readonly("api_specific_subcode", &DaqApi::api_specific_subcode);
49 daqapi.def("__str__", [](const DaqApi &d) { return std::string(d); });
50
52 py::class_<DaqConfiguration> daqconfig(m, "DaqConfiguration");
53
54 py::class_<DaqChannel> daqchannel(m, "DaqChannel");
55 daqchannel.def(py::init<>());
56 daqchannel.def_readwrite("enabled", &DaqChannel::enabled);
57 daqchannel.def_readwrite("name", &DaqChannel::name);
58 daqchannel.def_readwrite("sensitivity", &DaqChannel::sensitivity);
59 daqchannel.def_readwrite("ACCouplingMode", &DaqChannel::ACCouplingMode);
60 daqchannel.def_readwrite("IEPEEnabled", &DaqChannel::IEPEEnabled);
61 daqchannel.def_readwrite("digitalHighpassCutOn",
63 daqchannel.def_readwrite("rangeIndex", &DaqChannel::rangeIndex);
64
65 py::enum_<DaqChannel::Qty>(daqchannel, "Qty")
66 .value("Number", DaqChannel::Qty::Number)
67 .value("AcousticPressure", DaqChannel::Qty::AcousticPressure)
68 .value("Voltage", DaqChannel::Qty::Voltage)
69 .value("UserDefined", DaqChannel::Qty::UserDefined);
70 daqchannel.def_readwrite("qty", &DaqChannel::qty);
71
72 daqchannel.def("__eq__", [](const DaqChannel &a, const DaqChannel &b) {
73 return a == b;
74 });
75
77 daqconfig.def(py::init<>());
78 daqconfig.def(py::init<const DeviceInfo &>());
79 daqconfig.def_readwrite("api", &DaqConfiguration::api);
80 daqconfig.def_readwrite("device_name", &DaqConfiguration::device_name);
81
82 daqconfig.def_readwrite("sampleRateIndex",
84 daqconfig.def_readwrite("dataTypeIndex", &DaqConfiguration::dataTypeIndex);
85
86 daqconfig.def_readwrite("framesPerBlockIndex",
88 daqconfig.def_readwrite("monitorOutput", &DaqConfiguration::monitorOutput);
89
90 daqconfig.def("match", &DaqConfiguration::match);
91
92 daqconfig.def_static("fromTOML", &DaqConfiguration::fromTOML);
93 daqconfig.def("toTOML", &DaqConfiguration::toTOML);
94 daqconfig.def_readwrite("inchannel_config",
96 daqconfig.def_readwrite("outchannel_config",
98 daqconfig.def("setAllInputEnabled", &DaqConfiguration::setAllInputEnabled);
99 daqconfig.def("setAllOutputEnabled", &DaqConfiguration::setAllOutputEnabled);
100 daqconfig.def("enabledInChannels", &DaqConfiguration::enabledInChannels,
101 py::arg("include_monitor") = true);
102}
Class that specifies API related information. An API configuration is part of the DAQConfiguration an...
unsigned api_specific_subcode
string apiname
Stores channel configuration data for each channel. I.e. the physical quantity measured,...
double sensitivity
The conversion between recorded physical unit and stored / outputed number, i.e. Number/Volt or Numbe...
double digitalHighPassCutOn
Whether to enable a digital high pass on the signal before passing the result in case of input,...
bool IEPEEnabled
For input-only: enable IEPE constant current power supply for this channel. Only for hardware that is...
int rangeIndex
Index in possible ranges for input / output.
bool ACCouplingMode
Whether to enable HW AC-coupling for this channel.
Qty qty
The physical quantity that is inputed / outputed.
bool enabled
Whether the channel is enabled.
static DaqConfiguration fromTOML(const std::string &toml)
Load in a DAQConfiguration from TOML.
std::vector< DaqChannel > enabledInChannels(const bool include_monitor=true) const
Return list of enabled input channels.
int framesPerBlockIndex
The index in the array of frames per block that can be used for the device.
int dataTypeIndex
Required datatype for output, should be present in the list.
std::vector< DaqChannel > inchannel_config
Channel configuration for input channels.
bool monitorOutput
If set to true and if the device has this capability, the output channels are added as input channels...
string device_name
The internal device name this DAQ configuration applies to.
std::string toTOML() const
Export the class to TOML markup language.
int sampleRateIndex
Index in list of sample rates that are available for the device.
std::vector< DaqChannel > outchannel_config
Channel configuration for output channels.
void setAllInputEnabled(bool val)
Set all input channels to enabled / disabled state.
bool match(const DeviceInfo &devinfo) const
Check to see whether the DAQ configuration matches with the device. This means, some basic checks are...
void setAllOutputEnabled(bool val)
Set all output channels to enabled / disabled state.
unsigned sw
Sample width of a single sample, in bytes.
string name
Name of the datatype.
bool is_floating
Whether the datatype is a floating point Y/N.
DataType
Basic data types coming from a DAQ that we can deal with. The naming will be self-explainging.
DataType dtype
The number from the enumeration.
const std::map< DataTypeDescriptor::DataType, const DataTypeDescriptor > dtype_map
void init_daqconfiguration(py::module &m)