Some improvements in the clearyness of meaning in uldaq code. No bugs found.

This commit is contained in:
Anne de Jong 2023-06-06 15:57:20 +02:00
parent ae3f8043e0
commit dd2bbb5973
3 changed files with 59 additions and 47 deletions

View File

@ -6,13 +6,10 @@
#include "lasp_uldaq_impl.h"
#include <uldaq.h>
void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) {
DEBUGTRACE_ENTER;
UlError err;
unsigned int numdevs = MAX_ULDAQ_DEV_COUNT_PER_API;
@ -35,32 +32,35 @@ void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) {
devinfo._uldaqDescriptor = descriptor;
devinfo.api = uldaqapi;
string name, interface;
string productname = descriptor.productName;
if (productname != "DT9837A") {
throw rte("Unknown UlDAQ type: " + productname);
{
string name, interface;
string productname = descriptor.productName;
if (productname != "DT9837A") {
throw rte("Unknown UlDAQ type: " + productname);
}
switch (descriptor.devInterface) {
case USB_IFC:
name = "USB - ";
break;
case BLUETOOTH_IFC:
/* devinfo. */
name = "Bluetooth - ";
break;
case ETHERNET_IFC:
/* devinfo. */
name = "Ethernet - ";
break;
default:
name = "Uknown interface = ";
}
name +=
string(descriptor.productName) + " " + string(descriptor.uniqueId);
devinfo.device_name = std::move(name);
}
switch (descriptor.devInterface) {
case USB_IFC:
name = "USB - ";
break;
case BLUETOOTH_IFC:
/* devinfo. */
name = "Bluetooth - ";
break;
case ETHERNET_IFC:
/* devinfo. */
name = "Ethernet - ";
break;
default:
name = "Uknown interface = ";
}
name += string(descriptor.productName) + " " + string(descriptor.uniqueId);
devinfo.device_name = std::move(name);
devinfo.physicalOutputQty = DaqChannel::Qty::Voltage;
devinfo.availableDataTypes.push_back(

View File

@ -70,7 +70,8 @@ DT9837A::DT9837A(const DeviceInfo &devinfo, const DaqConfiguration &config)
throw rte("Unsensible number of samples per block chosen");
}
if (samplerate() < ULDAQ_SAMPLERATES.at(0) || samplerate() > ULDAQ_SAMPLERATES.at(ULDAQ_SAMPLERATES.size()-1)) {
if (samplerate() < ULDAQ_SAMPLERATES.at(0) ||
samplerate() > ULDAQ_SAMPLERATES.at(ULDAQ_SAMPLERATES.size() - 1)) {
throw rte("Invalid sample rate");
}
@ -135,11 +136,13 @@ void DT9837A::stop() {
throw rte("No data acquisition running");
}
// Stop the thread and join it
_stopThread = true;
if (_thread.joinable()) {
_thread.join();
}
assert(_thread.joinable());
_thread.join();
_stopThread = false;
// Update stream status
status.isRunning = false;
_streamStatus = status;
}
@ -150,9 +153,9 @@ void DT9837A::stop() {
* log of errors definded here (109 in total). Except for some, we will map
* most of them to a driver error.
*
* @param e
* @param e The backend error code.
*/
inline void throwUlException(UlError err) {
inline void throwOnPossibleUlException(UlError err) {
if (err == ERR_NO_ERROR) {
return;
}
@ -207,14 +210,14 @@ InBufHandler::InBufHandler(DT9837A &daq, InDaqCallback cb)
// monitor channel (hence the false flag).
dvec ranges = daq.inputRangeForEnabledChannels(false);
us enabled_ch_count = 0;
us enabled_ch_counter = 0;
for (us chin = 0; chin < 4; chin++) {
if (eninchannels_without_mon[chin] == true) {
DaqInChanDescriptor indesc;
indesc.type = DAQI_ANALOG_SE;
indesc.channel = chin;
double rangeval = ranges.at(enabled_ch_count);
double rangeval = ranges.at(enabled_ch_counter);
Range rangenum;
if (fabs(rangeval - 1.0) < 1e-8) {
rangenum = BIP1VOLTS;
@ -227,7 +230,7 @@ InBufHandler::InBufHandler(DT9837A &daq, InDaqCallback cb)
}
indesc.range = rangenum;
indescs.push_back(indesc);
enabled_ch_count++;
enabled_ch_counter++;
}
}
@ -248,7 +251,7 @@ InBufHandler::InBufHandler(DT9837A &daq, InDaqCallback cb)
err = ulDaqInScan(daq.getHandle(), indescs.data(), nchannels,
2 * nFramesPerBlock, // Watch the 2 here!
&samplerate, scanoptions, inscanflags, buf.data());
throwUlException(err);
throwOnPossibleUlException(err);
}
void InBufHandler::start() {
@ -256,7 +259,7 @@ void InBufHandler::start() {
ScanStatus status;
TransferStatus transferStatus;
UlError err = ulDaqInScanStatus(daq.getHandle(), &status, &transferStatus);
throwUlException(err);
throwOnPossibleUlException(err);
totalFramesCount = transferStatus.currentTotalCount;
topenqueued = true;
@ -279,10 +282,15 @@ bool InBufHandler::operator()() {
if (monitorOutput) {
for (us frame = 0; frame < nFramesPerBlock; frame++) {
data.value<double>(frame, 0) =
buf[totalOffset + (frame * nchannels) + (nchannels - 1)];
buf[totalOffset // Offset to lowest part of the buffer, or not
+ (frame * nchannels) // Data is interleaved, so skip each
+ (nchannels - 1)] // Monitor comes as last in the channel list,
// but we want it first in the output data.
;
}
}
// Now, all normal channels
for (us channel = 0; channel < nchannels - monitorOffset; channel++) {
/* DEBUGTRACE_PRINT(channel); */
for (us frame = 0; frame < nFramesPerBlock; frame++) {
@ -297,7 +305,7 @@ bool InBufHandler::operator()() {
TransferStatus transferStatus;
UlError err = ulDaqInScanStatus(daq.getHandle(), &status, &transferStatus);
throwUlException(err);
throwOnPossibleUlException(err);
us increment = transferStatus.currentTotalCount - totalFramesCount;
totalFramesCount += increment;
@ -342,7 +350,7 @@ OutBufHandler::OutBufHandler(DT9837A &daq, OutDaqCallback cb)
2 * nFramesPerBlock, // Watch the 2 here!
&samplerate, scanoptions, outscanflags, buf.data());
throwUlException(err);
throwOnPossibleUlException(err);
}
void OutBufHandler::start() {
@ -373,7 +381,7 @@ bool OutBufHandler::operator()() {
TransferStatus transferStatus;
err = ulAOutScanStatus(daq.getHandle(), &status, &transferStatus);
throwUlException(err);
throwOnPossibleUlException(err);
if (status != SS_RUNNING) {
return false;
}
@ -387,7 +395,9 @@ bool OutBufHandler::operator()() {
if (transferStatus.currentIndex < buffer_mid_idx) {
topenqueued = false;
if (!botenqueued) {
DaqData d(nFramesPerBlock, 1, dtype_descr.dtype);
DaqData d(nFramesPerBlock, 1,// Only one output channel
dtype_descr.dtype);
// Receive data
res = cb(d);
d.copyToRaw(0, reinterpret_cast<byte_t *>(&(buf[buffer_mid_idx])));
@ -396,7 +406,9 @@ bool OutBufHandler::operator()() {
} else {
botenqueued = false;
if (!topenqueued) {
DaqData d(nFramesPerBlock, 1, dtype_descr.dtype);
DaqData d(nFramesPerBlock, 1,// Only one output channel
dtype_descr.dtype);
// Receive
res = cb(d);
d.copyToRaw(0, reinterpret_cast<byte_t *>(&(buf[0])));
@ -473,11 +485,9 @@ void DT9837A::threadFcn(InDaqCallback inCallback, OutDaqCallback outCallback) {
status.errorType = e.e;
_streamStatus = status;
/*
cerr << "\n******************\n";
cerr << "Catched error in UlDAQ thread: " << e.what() << endl;
cerr << "\n******************\n";
*/
}
}

View File

@ -1,4 +1,5 @@
#pragma once
#include "debugtrace.hpp"
#include "lasp_daq.h"
#include <algorithm>
#include <cassert>
@ -30,7 +31,8 @@ class UlDaqDeviceInfo : public DeviceInfo {
public:
DaqDeviceDescriptor _uldaqDescriptor;
virtual std::unique_ptr<DeviceInfo> clone() const {
virtual std::unique_ptr<DeviceInfo> clone() const override {
DEBUGTRACE_ENTER;
return std::make_unique<UlDaqDeviceInfo>(*this);
}
};