From dd2bbb5973967f147c7a0182cb8e743ed828e5e9 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Tue, 6 Jun 2023 15:57:20 +0200 Subject: [PATCH] Some improvements in the clearyness of meaning in uldaq code. No bugs found. --- src/lasp/device/lasp_uldaq.cpp | 54 ++++++++++++++--------------- src/lasp/device/lasp_uldaq_impl.cpp | 48 +++++++++++++++---------- src/lasp/device/lasp_uldaq_impl.h | 4 ++- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/src/lasp/device/lasp_uldaq.cpp b/src/lasp/device/lasp_uldaq.cpp index 34e1f8e..a7252c3 100644 --- a/src/lasp/device/lasp_uldaq.cpp +++ b/src/lasp/device/lasp_uldaq.cpp @@ -6,13 +6,10 @@ #include "lasp_uldaq_impl.h" #include - - 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( diff --git a/src/lasp/device/lasp_uldaq_impl.cpp b/src/lasp/device/lasp_uldaq_impl.cpp index 6177b89..e91f63e 100644 --- a/src/lasp/device/lasp_uldaq_impl.cpp +++ b/src/lasp/device/lasp_uldaq_impl.cpp @@ -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(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(&(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(&(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"; - */ } } diff --git a/src/lasp/device/lasp_uldaq_impl.h b/src/lasp/device/lasp_uldaq_impl.h index 90c308a..cc2cade 100644 --- a/src/lasp/device/lasp_uldaq_impl.h +++ b/src/lasp/device/lasp_uldaq_impl.h @@ -1,4 +1,5 @@ #pragma once +#include "debugtrace.hpp" #include "lasp_daq.h" #include #include @@ -30,7 +31,8 @@ class UlDaqDeviceInfo : public DeviceInfo { public: DaqDeviceDescriptor _uldaqDescriptor; - virtual std::unique_ptr clone() const { + virtual std::unique_ptr clone() const override { + DEBUGTRACE_ENTER; return std::make_unique(*this); } };