lasp/src/lasp/device/lasp_daq.cpp

102 lines
2.7 KiB
C++

#include "debugtrace.hpp"
DEBUGTRACE_VARIABLES;
#include "lasp_daq.h"
#if LASP_HAS_ULDAQ == 1
#include "lasp_uldaq.h"
#endif
#if LASP_HAS_RTAUDIO == 1
#include "lasp_rtaudiodaq.h"
#endif
using std::runtime_error;
Daq::~Daq() {}
std::unique_ptr<Daq> Daq::createDaq(const DeviceInfo &devinfo,
const DaqConfiguration &config) {
DEBUGTRACE_ENTER;
int apicode = devinfo.api.apicode;
#if LASP_HAS_ULDAQ == 1
if (devinfo.api == uldaqapi) {
return createUlDaqDevice(devinfo, config);
}
#endif
#if LASP_HAS_RTAUDIO == 1
else if (apicode >= 1 && apicode <= 5) {
return createRtAudioDevice(devinfo, config);
}
#endif
else {
throw std::runtime_error(string("Unable to match API: ") +
devinfo.api.apiname);
}
}
Daq::Daq(const DeviceInfo &devinfo, const DaqConfiguration &config)
: DaqConfiguration(config), DeviceInfo(devinfo) {
DEBUGTRACE_ENTER;
if (!hasInternalOutputMonitor && monitorOutput) {
throw std::runtime_error(
"Output monitor flag set, but device does not have output monitor");
}
if (!config.match(devinfo)) {
throw std::runtime_error("DaqConfiguration does not match device info");
}
if(neninchannels(false) > ninchannels) {
throw std::runtime_error("Number of enabled input channels is higher than device capability");
}
if(nenoutchannels() > noutchannels) {
throw std::runtime_error("Number of enabled output channels is higher than device capability");
}
}
double Daq::samplerate() const {
return availableSampleRates.at(sampleRateIndex);
}
DataTypeDescriptor::DataType Daq::dataType() const {
return availableDataTypes.at(dataTypeIndex);
}
DataTypeDescriptor Daq::dtypeDescr() const { return dtype_map.at(dataType()); }
double Daq::inputRangeForChannel(us ch) const {
if (!(ch < ninchannels)) {
throw runtime_error("Invalid channel number");
}
return availableInputRanges.at(inchannel_config[ch].rangeIndex);
}
us Daq::neninchannels(bool include_monitorchannel) const {
boolvec eninchannels = this->eninchannels(include_monitorchannel);
return std::count(eninchannels.cbegin(), eninchannels.cend(), true);
}
us Daq::nenoutchannels() const {
boolvec enchannels = this->enoutchannels();
return std::count(enchannels.cbegin(), enchannels.cend(), true);
}
boolvec Daq::eninchannels(bool include_monitor) const {
boolvec res;
if (hasInternalOutputMonitor && include_monitor) {
res.push_back(monitorOutput);
}
for (auto &ch : inchannel_config) {
res.push_back(ch.enabled);
}
return res;
}
boolvec Daq::enoutchannels() const {
boolvec res;
for (auto &ch : outchannel_config) {
res.push_back(ch.enabled);
}
return res;
}