103 lines
4.2 KiB
C++
103 lines
4.2 KiB
C++
#include "lasp_daqconfig.h"
|
|
#include "lasp_deviceinfo.h"
|
|
#include <algorithm>
|
|
#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");
|
|
|
|
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);
|
|
|
|
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");
|
|
});
|
|
|
|
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<>());
|
|
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);
|
|
daqchannel.def_readwrite("qty", &DaqChannel::qty);
|
|
|
|
daqchannel.def("__eq__", [](const DaqChannel &a, const DaqChannel &b) {
|
|
return a == b;
|
|
});
|
|
|
|
/// 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);
|
|
|
|
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);
|
|
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);
|
|
}
|