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 "lasp_uldaq_impl.h"
#include <uldaq.h> #include <uldaq.h>
void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) { void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) {
DEBUGTRACE_ENTER; DEBUGTRACE_ENTER;
UlError err; UlError err;
unsigned int numdevs = MAX_ULDAQ_DEV_COUNT_PER_API; unsigned int numdevs = MAX_ULDAQ_DEV_COUNT_PER_API;
@ -35,6 +32,7 @@ void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) {
devinfo._uldaqDescriptor = descriptor; devinfo._uldaqDescriptor = descriptor;
devinfo.api = uldaqapi; devinfo.api = uldaqapi;
{
string name, interface; string name, interface;
string productname = descriptor.productName; string productname = descriptor.productName;
if (productname != "DT9837A") { if (productname != "DT9837A") {
@ -58,8 +56,10 @@ void fillUlDaqDeviceInfo(DeviceInfoList &devinfolist) {
name = "Uknown interface = "; name = "Uknown interface = ";
} }
name += string(descriptor.productName) + " " + string(descriptor.uniqueId); name +=
string(descriptor.productName) + " " + string(descriptor.uniqueId);
devinfo.device_name = std::move(name); devinfo.device_name = std::move(name);
}
devinfo.physicalOutputQty = DaqChannel::Qty::Voltage; devinfo.physicalOutputQty = DaqChannel::Qty::Voltage;

View File

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

View File

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