Bugfix in changing measurement channelConfig afterwards. Was not correctly fixed, as to store the enum index corresponding to the quantity

This commit is contained in:
Anne de Jong 2022-10-20 12:28:46 +02:00
parent 142a161283
commit 6758655eaa
3 changed files with 15 additions and 5 deletions

View File

@ -82,6 +82,12 @@ class Qty:
return (self.name == other.name and return (self.name == other.name and
self.unit_name == other.unit_name) self.unit_name == other.unit_name)
def toInt(self):
"""
Convert quantity to its specific enum integer value
"""
return self.cpp_enum.value
@unique @unique

View File

@ -51,6 +51,7 @@ from scipy.io import wavfile
import os, time, wave, logging import os, time, wave, logging
from .lasp_common import SIQtys, Qty, getFreq from .lasp_common import SIQtys, Qty, getFreq
from .lasp_cpp import Window, DaqChannel, LASP_VERSION_MAJOR from .lasp_cpp import Window, DaqChannel, LASP_VERSION_MAJOR
from typing import List
def getSampWidth(dtype): def getSampWidth(dtype):
@ -311,14 +312,14 @@ class Measurement:
return chcfg return chcfg
@channelConfig.setter @channelConfig.setter
def channelConfig(self, chcfg): def channelConfig(self, chcfg: List[DaqChannel]):
chname = [] chname = []
sens = [] sens = []
qtys = [] qtys = []
for ch in chcfg: for ch in chcfg:
chname.append(ch.name) chname.append(ch.name)
sens.append(ch.sensitivity) sens.append(ch.sensitivity)
qtys.append(SIQtys.fromInt(ch.qty)) qtys.append(SIQtys.fromCppEnum(ch.qty))
self.channelNames = chname self.channelNames = chname
self.sensitivity = sens self.sensitivity = sens
@ -332,11 +333,14 @@ class Measurement:
def qtys(self, newqtys): def qtys(self, newqtys):
if not len(newqtys) == len(self._qtys): if not len(newqtys) == len(self._qtys):
raise ValueError('Invalid number of quantities') raise ValueError('Invalid number of quantities')
qtys_json = [qty.to_json() for qty in newqtys] qtys_int = [qty.toInt() for qty in newqtys]
# Use setAttribute here, but thos store the jsonified version as well, # Use setAttribute here, but thos store the jsonified version as well,
# which we have to overwrite again with the deserialized ones. This is # which we have to overwrite again with the deserialized ones. This is
# actually not a very nice way of coding. # actually not a very nice way of coding.
self.setAttribute('qtys', qtys_json) with self.file('r+') as f:
# Update comment attribute in the file
f.attrs['qtys_enum_idx'] = qtys_int
self._qtys = newqtys self._qtys = newqtys
@contextmanager @contextmanager

View File

@ -1,5 +1,5 @@
/* #define DEBUGTRACE_ENABLED */
#include <armadillo> #include <armadillo>
#define DEBUGTRACE_ENABLED
#include "arma_npy.h" #include "arma_npy.h"
#include "debugtrace.hpp" #include "debugtrace.hpp"
#include "lasp_ppm.h" #include "lasp_ppm.h"