lasp/lasp/device/lasp_daq.cpp

95 lines
2.7 KiB
C++
Raw Normal View History

#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;
std::unique_ptr<Daq> Daq::createDaq(const DeviceInfo &devinfo,
const DaqConfiguration &config) {
DEBUGTRACE_ENTER;
if (!config.match(devinfo)) {
throw std::runtime_error("DaqConfiguration does not match device info");
}
// Some basic sanity checks
if ((devinfo.ninchannels != config.eninchannels.size())) {
/* cerr << "devinfo.ninchannels: " << devinfo.ninchannels << endl; */
/* cerr << "config.eninchannels.size(): " << config.eninchannels.size() <<
* endl; */
throw runtime_error("Invalid length of enabled input channels specified");
}
if ((devinfo.noutchannels != config.enoutchannels.size())) {
throw runtime_error("outvalid length of enabled output channels specified");
}
int apicode = devinfo.api.apicode;
if (devinfo.api == DaqApi()) {
throw std::runtime_error(string("Unable to match API: ") +
devinfo.api.apiname);
}
#if LASP_HAS_ULDAQ == 1
else 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 (monitorOutput && !(nenoutchannels() > 0)) {
throw runtime_error(
"Output monitoring only possible when at least one output channel is "
"enabled. Please make sure to enable at least one output channel, or "
"disable monitoring output.");
}
}
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(inputRangeIndices.at(ch));
}
us Daq::neninchannels(bool include_monitorchannel) const {
us inch = std::count(eninchannels.begin(), eninchannels.end(), true);
if (monitorOutput && include_monitorchannel) {
inch += nenoutchannels();
}
return inch;
}
us Daq::nenoutchannels() const {
return std::count(enoutchannels.begin(), enoutchannels.end(), true);
}