Bugfix and code formatting.
This commit is contained in:
parent
8befe4afc8
commit
24b9a24b04
@ -67,7 +67,7 @@ public:
|
|||||||
DaqData(const DaqData &);
|
DaqData(const DaqData &);
|
||||||
DaqData(DaqData &&);
|
DaqData(DaqData &&);
|
||||||
DaqData &operator=(const DaqData &) = delete;
|
DaqData &operator=(const DaqData &) = delete;
|
||||||
virtual ~DaqData();
|
~DaqData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return pointer to the raw data corresponding to a certain sample
|
* @brief Return pointer to the raw data corresponding to a certain sample
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
__all__ = ['DaqChannel']
|
|
||||||
import json, logging
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import List
|
|
||||||
import numpy as np
|
|
||||||
from dataclasses_json import dataclass_json
|
|
||||||
from ..lasp_common import Qty, SIQtys
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
|
||||||
@dataclass(eq=False)
|
|
||||||
class DaqChannel:
|
|
||||||
channel_enabled: bool
|
|
||||||
channel_name: str = 'Unnamed channel'
|
|
||||||
sensitivity: float = 1.0
|
|
||||||
range_index: int = 0
|
|
||||||
ACCoupling_enabled: bool = False
|
|
||||||
IEPE_enabled: bool = False
|
|
||||||
channel_metadata: str = ''
|
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
# logging.debug(f'__post_init__({self.channel_name})')
|
|
||||||
self._qty = SIQtys.default()
|
|
||||||
|
|
||||||
# Whether a digital high-pass filter should be used on input data.
|
|
||||||
# Negative means disabled. A positive number corresponds to the cut-on
|
|
||||||
# frequency of the installed highpass filter.
|
|
||||||
self._highpass = -1.0
|
|
||||||
try:
|
|
||||||
meta = json.loads(self.channel_metadata)
|
|
||||||
if 'qty' in meta:
|
|
||||||
# The quantity itself is stored as a JSON string, in the JSON
|
|
||||||
# object called channel_metadata.
|
|
||||||
self._qty = Qty.from_json(meta['qty'])
|
|
||||||
if 'highpass' in meta:
|
|
||||||
self._highpass = meta['highpass']
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
logging.debug(f'No JSON data found in DaqChannel {self.channel_name}')
|
|
||||||
|
|
||||||
@property
|
|
||||||
def qty(self):
|
|
||||||
return self._qty
|
|
||||||
|
|
||||||
@qty.setter
|
|
||||||
def qty(self, newqty):
|
|
||||||
self._qty = newqty
|
|
||||||
self._store('qty', newqty.to_json())
|
|
||||||
|
|
||||||
@property
|
|
||||||
def highpass(self):
|
|
||||||
return self._highpass
|
|
||||||
|
|
||||||
@highpass.setter
|
|
||||||
def highpass(self, newvalue: float):
|
|
||||||
newvalue = float(newvalue)
|
|
||||||
self._highpass = newvalue
|
|
||||||
self._store('highpass', newvalue)
|
|
||||||
|
|
||||||
def _store(self, name, val):
|
|
||||||
try:
|
|
||||||
meta = json.loads(self.channel_metadata)
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
meta = {}
|
|
||||||
|
|
||||||
meta[name] = val
|
|
||||||
self.channel_metadata = json.dumps(meta)
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
"""
|
|
||||||
We overwrite the default equal-check as the floating point values
|
|
||||||
cannot be exactly checked due to conversion from/to JSON
|
|
||||||
"""
|
|
||||||
return (self.channel_enabled == other.channel_enabled and
|
|
||||||
self.channel_name == other.channel_name and
|
|
||||||
self.range_index == other.range_index and
|
|
||||||
self.ACCoupling_enabled == other.ACCoupling_enabled and
|
|
||||||
self.IEPE_enabled == other.IEPE_enabled and
|
|
||||||
self.channel_metadata == other.channel_metadata and
|
|
||||||
np.isclose(self.highpass,other.highpass))
|
|
||||||
|
|
@ -231,7 +231,7 @@ public:
|
|||||||
|
|
||||||
if (nFramesPerBlock_copy != nFramesPerBlock) {
|
if (nFramesPerBlock_copy != nFramesPerBlock) {
|
||||||
throw rte("Got different number of frames per block back from RtAudio "
|
throw rte("Got different number of frames per block back from RtAudio "
|
||||||
"backend. Do not know what to do");
|
"backend. I do not know what to do.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,8 +410,10 @@ std::unique_ptr<Daq> createRtAudioDevice(const DeviceInfo &devinfo,
|
|||||||
void myerrorcallback(RtAudioError::Type, const string &errorText) {
|
void myerrorcallback(RtAudioError::Type, const string &errorText) {
|
||||||
cerr << "RtAudio backend stream error: " << errorText << endl;
|
cerr << "RtAudio backend stream error: " << errorText << endl;
|
||||||
}
|
}
|
||||||
int mycallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames,
|
int mycallback(
|
||||||
double streamTime, RtAudioStreamStatus status, void *userData) {
|
void *outputBuffer, void *inputBuffer, unsigned int nFrames,
|
||||||
|
__attribute__((unused)) double streamTime, // Not used parameter streamTime
|
||||||
|
RtAudioStreamStatus status, void *userData) {
|
||||||
|
|
||||||
return static_cast<RtAudioDaq *>(userData)->streamCallback(
|
return static_cast<RtAudioDaq *>(userData)->streamCallback(
|
||||||
outputBuffer, inputBuffer, nFrames, status);
|
outputBuffer, inputBuffer, nFrames, status);
|
||||||
|
@ -2,16 +2,17 @@
|
|||||||
#include "debugtrace.hpp"
|
#include "debugtrace.hpp"
|
||||||
#include "lasp_config.h"
|
#include "lasp_config.h"
|
||||||
#if LASP_HAS_ULDAQ == 1
|
#if LASP_HAS_ULDAQ == 1
|
||||||
#include <uldaq.h>
|
|
||||||
#include "lasp_uldaq.h"
|
#include "lasp_uldaq.h"
|
||||||
#include "lasp_uldaq_impl.h"
|
#include "lasp_uldaq_impl.h"
|
||||||
|
#include <uldaq.h>
|
||||||
|
|
||||||
|
void fillUlDaqDeviceInfo(std::vector<DeviceInfo> &devinfolist,
|
||||||
void fillUlDaqDeviceInfo(std::vector<DeviceInfo> &devinfolist,void* vDescriptors) {
|
void *vDescriptors) {
|
||||||
|
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
|
||||||
DaqDeviceDescriptor* descriptors_copy = static_cast<DaqDeviceDescriptor*>(vDescriptors);
|
DaqDeviceDescriptor *descriptors_copy =
|
||||||
|
static_cast<DaqDeviceDescriptor *>(vDescriptors);
|
||||||
|
|
||||||
UlError err;
|
UlError err;
|
||||||
unsigned int numdevs = MAX_ULDAQ_DEV_COUNT_PER_API;
|
unsigned int numdevs = MAX_ULDAQ_DEV_COUNT_PER_API;
|
||||||
@ -100,5 +101,4 @@ std::unique_ptr<Daq> createUlDaqDevice(const DeviceInfo &devinfo,
|
|||||||
return std::make_unique<DT9837A>(devinfo, config);
|
return std::make_unique<DT9837A>(devinfo, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // LASP_HAS_ULDAQ
|
#endif // LASP_HAS_ULDAQ
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "lasp_daq.h"
|
#include "lasp_daq.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The maximum number of devices that can be enumerated when calling
|
* @brief The maximum number of devices that can be enumerated when calling
|
||||||
* ulGetDaqDeviceInventory()
|
* ulGetDaqDeviceInventory()
|
||||||
@ -20,5 +19,4 @@ std::unique_ptr<Daq> createUlDaqDevice(const DeviceInfo& devinfo,
|
|||||||
* copy of the device descriptors is set to the memory of this pointer. We use
|
* copy of the device descriptors is set to the memory of this pointer. We use
|
||||||
* a void* pointer here to not expose the implementation of UlDaq.
|
* a void* pointer here to not expose the implementation of UlDaq.
|
||||||
*/
|
*/
|
||||||
void fillUlDaqDeviceInfo(std::vector<DeviceInfo>, void* descriptors=nullptr);
|
void fillUlDaqDeviceInfo(std::vector<DeviceInfo>&, void *descriptors = nullptr);
|
||||||
|
|
||||||
|
@ -149,8 +149,10 @@ void DT9837A::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Throws an exception in case it happens. Does nothing in case of no
|
* @brief Throws an appropriate stream exception based on the UlError number.
|
||||||
* error.
|
* The mapping is based on the error numbers as given in uldaq.h. There are a
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
@ -161,13 +163,7 @@ inline void throwUlException(UlError err) {
|
|||||||
string errstr = getErrMsg(err);
|
string errstr = getErrMsg(err);
|
||||||
showErr(errstr);
|
showErr(errstr);
|
||||||
Daq::StreamStatus::StreamError serr;
|
Daq::StreamStatus::StreamError serr;
|
||||||
if ((int)err < 5) {
|
if ((int)err == 18) {
|
||||||
serr = Daq::StreamStatus::StreamError::logicError;
|
|
||||||
} else if ((int)err < 9) {
|
|
||||||
serr = Daq::StreamStatus::StreamError::systemError;
|
|
||||||
} else if ((int)err < 18) {
|
|
||||||
serr = Daq::StreamStatus::StreamError::logicError;
|
|
||||||
} else if ((int)err == 18) {
|
|
||||||
serr = Daq::StreamStatus::StreamError::inputXRun;
|
serr = Daq::StreamStatus::StreamError::inputXRun;
|
||||||
} else if ((int)err == 19) {
|
} else if ((int)err == 19) {
|
||||||
serr = Daq::StreamStatus::StreamError::outputXRun;
|
serr = Daq::StreamStatus::StreamError::outputXRun;
|
||||||
@ -276,8 +272,7 @@ bool InBufHandler::operator()() {
|
|||||||
auto runCallback = ([&](us totalOffset) {
|
auto runCallback = ([&](us totalOffset) {
|
||||||
/* DEBUGTRACE_ENTER; */
|
/* DEBUGTRACE_ENTER; */
|
||||||
|
|
||||||
DaqData data(nFramesPerBlock, nchannels,
|
DaqData data(nFramesPerBlock, nchannels, dtype_descr.dtype);
|
||||||
DataTypeDescriptor::DataType::dtype_fl64);
|
|
||||||
|
|
||||||
us monitorOffset = monitorOutput ? 1 : 0;
|
us monitorOffset = monitorOutput ? 1 : 0;
|
||||||
/* /// Put the output monitor in front */
|
/* /// Put the output monitor in front */
|
||||||
@ -304,7 +299,7 @@ bool InBufHandler::operator()() {
|
|||||||
UlError err = ulDaqInScanStatus(daq.getHandle(), &status, &transferStatus);
|
UlError err = ulDaqInScanStatus(daq.getHandle(), &status, &transferStatus);
|
||||||
throwUlException(err);
|
throwUlException(err);
|
||||||
|
|
||||||
increment = transferStatus.currentTotalCount - totalFramesCount;
|
us increment = transferStatus.currentTotalCount - totalFramesCount;
|
||||||
totalFramesCount += increment;
|
totalFramesCount += increment;
|
||||||
|
|
||||||
if (increment > nFramesPerBlock) {
|
if (increment > nFramesPerBlock) {
|
||||||
@ -382,7 +377,7 @@ bool OutBufHandler::operator()() {
|
|||||||
if (status != SS_RUNNING) {
|
if (status != SS_RUNNING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
increment = transferStatus.currentTotalCount - totalFramesCount;
|
us increment = transferStatus.currentTotalCount - totalFramesCount;
|
||||||
totalFramesCount += increment;
|
totalFramesCount += increment;
|
||||||
|
|
||||||
if (increment > nFramesPerBlock) {
|
if (increment > nFramesPerBlock) {
|
||||||
@ -392,7 +387,7 @@ 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, DataTypeDescriptor::DataType::dtype_fl64);
|
DaqData d(nFramesPerBlock, 1, dtype_descr.dtype);
|
||||||
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])));
|
||||||
|
|
||||||
@ -401,7 +396,7 @@ bool OutBufHandler::operator()() {
|
|||||||
} else {
|
} else {
|
||||||
botenqueued = false;
|
botenqueued = false;
|
||||||
if (!topenqueued) {
|
if (!topenqueued) {
|
||||||
DaqData d(nFramesPerBlock, 1, DataTypeDescriptor::DataType::dtype_fl64);
|
DaqData d(nFramesPerBlock, 1, dtype_descr.dtype);
|
||||||
res = cb(d);
|
res = cb(d);
|
||||||
d.copyToRaw(0, reinterpret_cast<byte_t *>(&(buf[0])));
|
d.copyToRaw(0, reinterpret_cast<byte_t *>(&(buf[0])));
|
||||||
|
|
||||||
@ -453,11 +448,13 @@ void DT9837A::threadFcn(InDaqCallback inCallback, OutDaqCallback outCallback) {
|
|||||||
if (ibh) {
|
if (ibh) {
|
||||||
if (!(*ibh)()) {
|
if (!(*ibh)()) {
|
||||||
_stopThread = true;
|
_stopThread = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obh) {
|
if (obh) {
|
||||||
if (!(*obh)()) {
|
if (!(*obh)()) {
|
||||||
_stopThread = true;
|
_stopThread = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(sleeptime_us));
|
std::this_thread::sleep_for(std::chrono::microseconds(sleeptime_us));
|
||||||
|
@ -59,19 +59,43 @@ public:
|
|||||||
*/
|
*/
|
||||||
class BufHandler {
|
class BufHandler {
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Reference to underlying Daq
|
||||||
|
*/
|
||||||
DT9837A &daq;
|
DT9837A &daq;
|
||||||
const DataTypeDescriptor dtype_descr;
|
/**
|
||||||
|
* @brief The type of data, in this case always double precision floats
|
||||||
|
*/
|
||||||
|
const DataTypeDescriptor dtype_descr = dtype_desc_fl64;
|
||||||
|
/**
|
||||||
|
* @brief The number of channels, number of frames per callback (block).
|
||||||
|
*/
|
||||||
us nchannels, nFramesPerBlock;
|
us nchannels, nFramesPerBlock;
|
||||||
|
/**
|
||||||
|
* @brief Sampling frequency in Hz
|
||||||
|
*/
|
||||||
double samplerate;
|
double samplerate;
|
||||||
std::vector<double> buf;
|
std::vector<double> buf;
|
||||||
|
/**
|
||||||
|
* @brief Whether the top / bottom part of the buffer are ready to be
|
||||||
|
* enqueued
|
||||||
|
*/
|
||||||
bool topenqueued, botenqueued;
|
bool topenqueued, botenqueued;
|
||||||
|
|
||||||
us increment = 0;
|
/**
|
||||||
|
* @brief Counter for the total number of frames acquired / sent since the
|
||||||
|
* start of the stream.
|
||||||
|
*/
|
||||||
us totalFramesCount = 0;
|
us totalFramesCount = 0;
|
||||||
long long buffer_mid_idx;
|
long long buffer_mid_idx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Initialize bufhandler
|
||||||
|
*
|
||||||
|
* @param daq
|
||||||
|
* @param nchannels
|
||||||
|
*/
|
||||||
BufHandler(DT9837A &daq, const us nchannels)
|
BufHandler(DT9837A &daq, const us nchannels)
|
||||||
: daq(daq), dtype_descr(daq.dtypeDescr()), nchannels(nchannels),
|
: daq(daq), dtype_descr(daq.dtypeDescr()), nchannels(nchannels),
|
||||||
nFramesPerBlock(daq.framesPerBlock()), samplerate(daq.samplerate()),
|
nFramesPerBlock(daq.framesPerBlock()), samplerate(daq.samplerate()),
|
||||||
|
Loading…
Reference in New Issue
Block a user