lasp/cpp_src/pybind11/lasp_daqconfig.cpp

103 lines
4.2 KiB
C++
Raw Normal View History

2022-07-20 12:58:48 +00:00
#include "lasp_daqconfig.h"
#include "lasp_deviceinfo.h"
#include <algorithm>
2022-07-20 12:58:48 +00:00
#include <iostream>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <stdint.h>
using std::cerr;
namespace py = pybind11;
void init_daqconfiguration(py::module &m) {
/// DataType
py::class_<DataTypeDescriptor> dtype_desc(m, "DataTypeDescriptor");
2022-07-20 12:58:48 +00:00
dtype_desc.def_readonly("name", &DataTypeDescriptor::name);
dtype_desc.def_readonly("sw", &DataTypeDescriptor::sw);
dtype_desc.def_readonly("is_floating", &DataTypeDescriptor::is_floating);
dtype_desc.def_readonly("dtype", &DataTypeDescriptor::dtype);
2022-07-20 12:58:48 +00:00
py::enum_<DataTypeDescriptor::DataType>(dtype_desc, "DataType")
.value("dtype_fl32", DataTypeDescriptor::DataType::dtype_fl32)
.value("dtype_fl64", DataTypeDescriptor::DataType::dtype_fl64)
.value("dtype_int8", DataTypeDescriptor::DataType::dtype_int8)
.value("dtype_int16", DataTypeDescriptor::DataType::dtype_int16)
.value("dtype_int32", DataTypeDescriptor::DataType::dtype_int32);
dtype_desc.def_static("toStr", [](const DataTypeDescriptor::DataType d) {
return dtype_map.at(d).name;
});
dtype_desc.def_static("fromStr", [](const std::string &dtype_str) {
decltype(dtype_map.cbegin()) d = std::find_if(
dtype_map.cbegin(), dtype_map.cend(),
[&dtype_str](const auto &d) { return d.second.name == dtype_str; });
if (d != dtype_map.cend()) {
return d->first;
}
throw std::runtime_error(dtype_str + " not found in list of data types");
});
2022-07-20 12:58:48 +00:00
dtype_desc.def_readonly("dtype", &DataTypeDescriptor::dtype);
/// DaqApi
py::class_<DaqApi> daqapi(m, "DaqApi");
daqapi.def_readonly("apiname", &DaqApi::apiname);
daqapi.def_readonly("apicode", &DaqApi::apicode);
daqapi.def_readonly("api_specific_subcode", &DaqApi::api_specific_subcode);
daqapi.def("__str__", [](const DaqApi &d) { return std::string(d); });
/// DaqChannel, DaqConfiguration
py::class_<DaqConfiguration> daqconfig(m, "DaqConfiguration");
py::class_<DaqChannel> daqchannel(m, "DaqChannel");
daqchannel.def(py::init<>());
2022-07-20 12:58:48 +00:00
daqchannel.def_readwrite("enabled", &DaqChannel::enabled);
daqchannel.def_readwrite("name", &DaqChannel::name);
daqchannel.def_readwrite("sensitivity", &DaqChannel::sensitivity);
daqchannel.def_readwrite("ACCouplingMode", &DaqChannel::ACCouplingMode);
daqchannel.def_readwrite("IEPEEnabled", &DaqChannel::IEPEEnabled);
daqchannel.def_readwrite("digitalHighpassCutOn",
&DaqChannel::digitalHighPassCutOn);
daqchannel.def_readwrite("rangeIndex", &DaqChannel::rangeIndex);
py::enum_<DaqChannel::Qty>(daqchannel, "Qty")
.value("Number", DaqChannel::Qty::Number)
.value("AcousticPressure", DaqChannel::Qty::AcousticPressure)
.value("Voltage", DaqChannel::Qty::Voltage)
.value("UserDefined", DaqChannel::Qty::UserDefined);
2022-07-20 12:58:48 +00:00
daqchannel.def_readwrite("qty", &DaqChannel::qty);
daqchannel.def("__eq__", [](const DaqChannel &a, const DaqChannel &b) {
return a == b;
});
2022-07-20 12:58:48 +00:00
/// DaqConfiguration
daqconfig.def(py::init<>());
daqconfig.def(py::init<const DeviceInfo &>());
daqconfig.def_readwrite("api", &DaqConfiguration::api);
daqconfig.def_readwrite("device_name", &DaqConfiguration::device_name);
2022-07-20 12:58:48 +00:00
daqconfig.def_readwrite("sampleRateIndex",
&DaqConfiguration::sampleRateIndex);
daqconfig.def_readwrite("dataTypeIndex", &DaqConfiguration::dataTypeIndex);
daqconfig.def_readwrite("framesPerBlockIndex",
&DaqConfiguration::framesPerBlockIndex);
daqconfig.def_readwrite("monitorOutput", &DaqConfiguration::monitorOutput);
daqconfig.def("match", &DaqConfiguration::match);
daqconfig.def_static("fromTOML", &DaqConfiguration::fromTOML);
2022-07-20 12:58:48 +00:00
daqconfig.def("toTOML", &DaqConfiguration::toTOML);
daqconfig.def_readwrite("inchannel_config",
&DaqConfiguration::inchannel_config);
daqconfig.def_readwrite("outchannel_config",
&DaqConfiguration::outchannel_config);
daqconfig.def("setAllInputEnabled", &DaqConfiguration::setAllInputEnabled);
daqconfig.def("setAllOutputEnabled", &DaqConfiguration::setAllOutputEnabled);
daqconfig.def("enabledInChannels", &DaqConfiguration::enabledInChannels,
py::arg("include_monitor") = true);
2022-07-20 12:58:48 +00:00
}