Bugfixes of Python/C++ interaction layer, first tests for DaqConfiguration code
This commit is contained in:
parent
6b8abb878a
commit
fa32e9eac3
@ -3,4 +3,5 @@ from .lasp_device_common import *
|
||||
from .lasp_daq import *
|
||||
from .lasp_deviceinfo import *
|
||||
from .lasp_daqconfig import *
|
||||
from .lasp_daq import *
|
||||
|
||||
|
@ -117,7 +117,8 @@ cdef extern from "lasp_cppdaq.h" nogil:
|
||||
|
||||
usvec inputRangeIndices
|
||||
|
||||
DaqConfiguration()
|
||||
cppDaqConfiguration()
|
||||
cppDaqConfiguration(cppDeviceInfo& devinfo)
|
||||
|
||||
int getHighestInChannel()
|
||||
int getHighestOutChannel()
|
||||
|
@ -277,7 +277,7 @@ int mycallback(
|
||||
if(inputBuffer) {
|
||||
us j=0; // OUR buffer channel counter
|
||||
us i=0; // RtAudio channel counter
|
||||
for(us ch=daq->getLowestInChannel();ch<=daq->getHighestInChannel();ch++) {
|
||||
for(int ch=daq->getLowestInChannel();ch<=daq->getHighestInChannel();ch++) {
|
||||
if(eninchannels[ch]) {
|
||||
memcpy(
|
||||
&(inbuffercpy[monitorOffset+j*bytesperchan]),
|
||||
|
@ -1,4 +1,5 @@
|
||||
include "lasp_common_decls.pxd"
|
||||
from .lasp_deviceinfo cimport DeviceInfo
|
||||
|
||||
cdef class DaqConfiguration:
|
||||
cdef:
|
||||
|
@ -8,43 +8,31 @@ Description:
|
||||
Data Acquistiion (DAQ) device descriptors, and the DAQ devices themselves
|
||||
|
||||
"""
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
from dataclasses_json import dataclass_json
|
||||
__all__ = ['DaqChannel', 'DaqConfiguration']
|
||||
from ..lasp_common import lasp_shelve, SIQtys, Qty
|
||||
|
||||
from .lasp_device_common import DaqChannel
|
||||
import json
|
||||
|
||||
|
||||
class CouplingMode:
|
||||
ac = 'AC'
|
||||
dc = 'DC'
|
||||
undefined = 'Undefined'
|
||||
|
||||
class Range:
|
||||
oneV = '+/- 1 V'
|
||||
tenV = '+/- 10 V'
|
||||
undefined = 'Undefined'
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass
|
||||
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
|
||||
|
||||
|
||||
cdef class DaqConfiguration:
|
||||
"""
|
||||
Initialize a device descriptor
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def from_json(self, jsonstring):
|
||||
def fromDeviceInfo(DeviceInfo devinfo):
|
||||
cdef:
|
||||
cppDaqConfiguration cconfig
|
||||
|
||||
d = DaqConfiguration()
|
||||
cconfig = cppDaqConfiguration(devinfo.devinfo)
|
||||
d.config = cconfig
|
||||
return d
|
||||
|
||||
@staticmethod
|
||||
def from_json(jsonstring):
|
||||
config_dict = json.loads(jsonstring)
|
||||
return DaqConfiguration.from_dict(config_dict)
|
||||
|
||||
@ -58,8 +46,13 @@ cdef class DaqConfiguration:
|
||||
config.device_name = pydict['device_name'].encode('utf-8')
|
||||
config.eninchannels = pydict['eninchannels']
|
||||
config.enoutchannels = pydict['enoutchannels']
|
||||
config.inchannel_names = pydict['inchannel_names']
|
||||
config.outchannel_names = pydict['outchannel_names']
|
||||
|
||||
config.inchannel_names = [inchname.encode('utf-8') for inchname in
|
||||
pydict['inchannel_names']]
|
||||
|
||||
config.outchannel_names = [outchname.encode('utf-8') for outchname in
|
||||
pydict['outchannel_names']]
|
||||
|
||||
config.sampleRateIndex = pydict['sampleRateIndex']
|
||||
config.framesPerBlockIndex = pydict['framesPerBlockIndex']
|
||||
config.dataTypeIndex = pydict['dataTypeIndex']
|
||||
@ -75,7 +68,7 @@ cdef class DaqConfiguration:
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(dict(
|
||||
apicode = self.api.apicode,
|
||||
apicode = self.config.api.apicode,
|
||||
device_name = self.config.device_name.decode('utf-8'),
|
||||
|
||||
eninchannels = self.eninchannels(),
|
||||
@ -87,7 +80,7 @@ cdef class DaqConfiguration:
|
||||
self.config.outchannel_names],
|
||||
sampleRateIndex = self.config.sampleRateIndex,
|
||||
dataTypeIndex = self.config.dataTypeIndex,
|
||||
nFramesPerBlockIndex = self.config.framesPerBlockIndex,
|
||||
framesPerBlockIndex = self.config.framesPerBlockIndex,
|
||||
monitorOutput = self.config.monitorOutput,
|
||||
|
||||
inputIEPEEnabled = self.config.inputIEPEEnabled,
|
||||
@ -111,7 +104,7 @@ cdef class DaqConfiguration:
|
||||
)
|
||||
def setInChannel(self, i:int, daqchannel: DaqChannel):
|
||||
self.config.eninchannels[i] = daqchannel.channel_enabled
|
||||
self.config.inchannel_names[i] = daqchannel.channel_name
|
||||
self.config.inchannel_names[i] = daqchannel.channel_name.encode('utf-8')
|
||||
self.config.inchannel_sensitivities[i] = daqchannel.sensitivity
|
||||
self.config.inputRangeIndices[i] = daqchannel.range_index
|
||||
self.config.inputACCouplingMode[i] = daqchannel.ACCoupling_enabled
|
||||
|
@ -1,5 +1,7 @@
|
||||
|
||||
__all__ = ['AvType']
|
||||
__all__ = ['AvType', 'DaqChannel']
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses_json import dataclass_json
|
||||
from typing import List
|
||||
|
||||
class AvType:
|
||||
"""Specificying the type of data, for adding and removing callbacks from
|
||||
@ -7,3 +9,26 @@ class AvType:
|
||||
audio_input = 1
|
||||
audio_output = 2
|
||||
video = 4
|
||||
|
||||
@dataclass_json
|
||||
@dataclass
|
||||
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
|
||||
|
||||
class CouplingMode:
|
||||
ac = 'AC'
|
||||
dc = 'DC'
|
||||
undefined = 'Undefined'
|
||||
|
||||
class Range:
|
||||
oneV = '+/- 1 V'
|
||||
tenV = '+/- 10 V'
|
||||
undefined = 'Undefined'
|
||||
|
||||
|
||||
|
||||
|
@ -21,9 +21,9 @@ args = parser.parse_args()
|
||||
|
||||
from lasp.lasp_avstream import AvStream, AvType
|
||||
from lasp.lasp_record import Recording
|
||||
from lasp.device import DAQConfiguration, RtAudio, UlDaq
|
||||
from lasp.device import DaqConfiguration, Daq, DaqChannel
|
||||
|
||||
configs = DAQConfiguration.loadConfigs()
|
||||
configs = DaqConfiguration.loadConfigs()
|
||||
|
||||
for i, (key, val) in enumerate(configs.items()):
|
||||
print(f'{i:2} : {key}')
|
||||
@ -45,8 +45,7 @@ config = configs[key]
|
||||
|
||||
print(config)
|
||||
# daq = RtAudio()
|
||||
daq = UlDaq()
|
||||
devices = daq.getDeviceInfo()
|
||||
devices = Daq.getDeviceInfo()
|
||||
|
||||
input_devices = {}
|
||||
for device in devices:
|
||||
|
@ -40,7 +40,7 @@ int main() {
|
||||
cout << "Inchannnels size: " << config.eninchannels.size() << endl;
|
||||
|
||||
|
||||
Daq* daq = Daq::createDevice(config, devinfos);
|
||||
Daq* daq = Daq::createDaq(devinfo, config);
|
||||
|
||||
SafeQueue<void*> inqueue;
|
||||
SafeQueue<void*> outqueue;
|
||||
|
Loading…
Reference in New Issue
Block a user