style: remove TDC4VAF2DataDecoder code
This commit is contained in:
@@ -596,18 +596,7 @@ class CC2650Device(Device):
|
||||
|
||||
coeff = []
|
||||
|
||||
if device_type == 'TDC4VAF2':
|
||||
# neulive 1.3, 1.6
|
||||
for i in range(24):
|
||||
# send
|
||||
code = self._encode_instruction(DeviceInstruction.TYP_CIS, DeviceInstruction.CIS_CALI, i)
|
||||
self._master.write_characteristic(self.device_id, CC2650MasterDevice.COMMAND_HANDLE, code)
|
||||
|
||||
# receive
|
||||
data = self._master.read_characteristic(self.device_id, CC2650MasterDevice.RETURN_HANDLE)
|
||||
coeff.append(self._decode_data(DeviceInstruction.CIS_CALI, data))
|
||||
|
||||
elif device_type == 'TDC4VC':
|
||||
if device_type == 'TDC4VC':
|
||||
i = 0
|
||||
request_times = 0
|
||||
while i < 4:
|
||||
|
||||
@@ -70,9 +70,6 @@ class DataDecodeFormat(Generic[T], metaclass=abc.ABCMeta):
|
||||
if expr == RawDataDecoder.NAME:
|
||||
return RawDataDecoder.INSTANCE
|
||||
|
||||
elif expr == TDC4VAF2DataDecoder.NAME:
|
||||
return TDC4VAF2DataDecoder()
|
||||
|
||||
elif expr == TDC4VCDataDecoder.NAME:
|
||||
return TDC4VCDataDecoder()
|
||||
|
||||
@@ -86,9 +83,7 @@ class DataDecodeFormat(Generic[T], metaclass=abc.ABCMeta):
|
||||
raise RuntimeError('current not support custom data decode format : ' + expr)
|
||||
|
||||
elif isinstance(expr, bytes):
|
||||
if expr.startswith(b'TDC4VAF2:'):
|
||||
return TDC4VAF2DataDecoder(expr[9:])
|
||||
elif expr.startswith(b'TDC4VC:'):
|
||||
if expr.startswith(b'TDC4VC:'):
|
||||
return TDC4VCDataDecoder(expr[7:])
|
||||
elif expr.startswith(b'EISZeroOne:'):
|
||||
return EISZeroOneDataDecoder(expr[11:])
|
||||
@@ -313,163 +308,6 @@ class RecDataDecoder(DataDecodeFormat[RecordingData], metaclass=abc.ABCMeta):
|
||||
def decode(self, data: bytes) -> Optional[RecordingData]:
|
||||
pass
|
||||
|
||||
class TDC4VAF2DataDecoder(RecDataDecoder):
|
||||
"""
|
||||
|
||||
data format
|
||||
-----------
|
||||
|
||||
::
|
||||
|
||||
| | 1 | 2 | 3 |
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
|
||||
-----------------------------------------------------------------
|
||||
| header | length = N |
|
||||
| timestamp |
|
||||
| time delta |
|
||||
| data [0] | data[1] |
|
||||
| ............................ | data[N] |
|
||||
|
||||
*data*
|
||||
|
||||
::
|
||||
|
||||
| | 1 |
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
|
||||
---------------------------------
|
||||
|channel| value | F |
|
||||
|
||||
cali coeff table format
|
||||
-----------------------
|
||||
|
||||
TODO cali coeff table format
|
||||
|
||||
::
|
||||
| | 1 | 2 | 3 | 4 | 5 | 6 |
|
||||
01234567890123456789012345678901234567890123456789012345678901234
|
||||
-----------------------------------------------------------------
|
||||
| | c0 g0 amp | c0 g1 amp | c0 g2..
|
||||
.. amp | | c0 g0 off | c0 g1..
|
||||
.. off | c0 g2 off | | c1 g0..
|
||||
| ............................................................. |
|
||||
| cN g0 amp | cN g1 amp | cN g2 amp |.. (4 bytes) ..|
|
||||
| cN g0 off | cN g1 off | cN g2 off |.. (4 bytes) ..|
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
NAME = 'TDC4VAF2'
|
||||
|
||||
AMP_GAIN = (35, 75, 325)
|
||||
|
||||
__slots__ = 'amp_gain', 'data_counter', 'cali_coeff', '_cali_coeff'
|
||||
|
||||
def __init__(self, cali_coeff: bytes = None):
|
||||
super().__init__()
|
||||
|
||||
self.amp_gain: int = 0
|
||||
self.data_counter: int = 0
|
||||
|
||||
self._cali_coeff: Optional[bytes] = None
|
||||
self.cali_coeff: Optional[List[Tuple[int, int]]] = None
|
||||
|
||||
if cali_coeff is not None:
|
||||
self._cali_coeff = cali_coeff
|
||||
self.cali_coeff = self._decode_cali_coeff(cali_coeff)
|
||||
|
||||
@staticmethod
|
||||
def _decode_cali_coeff(self, cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
|
||||
if cali_coeff != b'':
|
||||
cali_table = []
|
||||
|
||||
for i in range(0, 12): # foreach channel
|
||||
for j in range(20 * i + 3, 20 * i + 9, 2):
|
||||
amp = struct.unpack('>h', cali_coeff[j:j + 2])[0]
|
||||
offset = struct.unpack('>h', cali_coeff[j + 10:j + 12])[0]
|
||||
cali_table.append((amp, offset))
|
||||
|
||||
return cali_table
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def name(self) -> AnyStr:
|
||||
if self._cali_coeff is None:
|
||||
return self.NAME
|
||||
else:
|
||||
return self.NAME.encode() + b':' + self._cali_coeff
|
||||
|
||||
def decode(self, data: bytes) -> Optional[RecordingData]:
|
||||
"""
|
||||
data_counter is used for excluding data which were send from the beginning ( < 15 )with the wrong timestamp,
|
||||
and these data will cause error while recording.
|
||||
"""
|
||||
|
||||
if self.data_counter < 15:
|
||||
self.data_counter += 1
|
||||
else:
|
||||
if len(data) < 8:
|
||||
return None
|
||||
|
||||
# print(hex_line(data))
|
||||
|
||||
data_length = int(data[1])
|
||||
|
||||
if data_length == 0:
|
||||
return None
|
||||
|
||||
time_stamp: float = struct.unpack('<I', data[2:6])[0] # unit: 1/32K sec, 1/32 ms
|
||||
time_delta: float = struct.unpack('<H', data[6:8])[0] # unit: as above
|
||||
|
||||
time_stamp, _, ret_get_time_stamp = self.get_time_stamp(time_stamp)
|
||||
|
||||
if time_stamp is None:
|
||||
return None
|
||||
|
||||
if data_length == 1 or int(time_delta) == 0:
|
||||
sample_rate = 0
|
||||
|
||||
else:
|
||||
# recalculate sample rate
|
||||
sample_rate = 32769 * (data_length - 1) / time_delta # unit 1/s
|
||||
|
||||
ret = RecordingData(self.device, time_stamp / 32.769, int(sample_rate))
|
||||
|
||||
amp_gain = self.AMP_GAIN.index(self.amp_gain)
|
||||
stop = len(data)
|
||||
|
||||
for i in range(data_length):
|
||||
# avoid index out of range
|
||||
offset = 8 + 2 * i
|
||||
if offset + 1 < stop:
|
||||
d1 = data[offset]
|
||||
d2 = data[offset + 1]
|
||||
|
||||
channel = (d1 & 0xF0) >> 4
|
||||
value = ((d1 & 0x0F) << 6) | ((d2 & 0xFC) >> 2)
|
||||
flag = d2 & 0b0011
|
||||
|
||||
if flag != 0:
|
||||
ret.append_data(channel, None)
|
||||
|
||||
else:
|
||||
if channel < 12 and self.cali_coeff is not None:
|
||||
gain, offset = self.cali_coeff[channel * 3 + amp_gain]
|
||||
gain /= 2
|
||||
|
||||
if gain == 0:
|
||||
cali_value = value - 512
|
||||
else:
|
||||
cali_value = int(1000 * ((value - 512 - offset) / gain))
|
||||
else:
|
||||
cali_value = value - 512
|
||||
|
||||
ret.append_data(channel, cali_value)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
class TDC4VCDataDecoder(RecDataDecoder):
|
||||
"""
|
||||
::
|
||||
|
||||
@@ -740,7 +740,7 @@ class DeviceCommonInstruction:
|
||||
if instruction == cls.RESET:
|
||||
return '_sync(False)', '_notify(False)', 'VIS_RST'
|
||||
elif instruction == cls.START:
|
||||
return '_data_format("TDC4VAF2")', '_notify(True)', 'VIS_STI', '_sync(True)'
|
||||
return '_notify(True)', 'VIS_STI', '_sync(True)'
|
||||
elif instruction == cls.INTERRUPT:
|
||||
return '_notify(False)', 'VIS_INT', '_sync(False)'
|
||||
elif instruction == cls.CLOSE:
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
from .library import *
|
||||
|
||||
DEVLIB_GENERATOR_NAME = 'GENERATOR'
|
||||
|
||||
REC_CHANNEL_COUNT = 16
|
||||
|
||||
MODE_LIST = [
|
||||
"zero",
|
||||
"sin",
|
||||
"ramp"
|
||||
]
|
||||
|
||||
ADC_SAMPLE_RATE_LIST = [
|
||||
100,
|
||||
500,
|
||||
1000,
|
||||
2500,
|
||||
4000,
|
||||
5000
|
||||
]
|
||||
|
||||
AMP_GAIN_LIST = [
|
||||
0.5,
|
||||
1,
|
||||
10,
|
||||
100,
|
||||
1000
|
||||
]
|
||||
|
||||
NOISE_LIST = [
|
||||
0,
|
||||
0.1,
|
||||
0.5,
|
||||
1.0
|
||||
]
|
||||
|
||||
DEVLIB_GENERATOR = DeviceLibrary(DEVLIB_GENERATOR_NAME, DeviceLibraryVersion(0, 6))
|
||||
|
||||
DEVLIB_GENERATOR._file = ''
|
||||
|
||||
_constant = ConstantScope({
|
||||
'REC_CHANNEL_COUNT': REC_CHANNEL_COUNT,
|
||||
'ADC_SAMPLE_RATE_LIST': ADC_SAMPLE_RATE_LIST
|
||||
})
|
||||
|
||||
DEVLIB_GENERATOR._constant = _constant
|
||||
|
||||
DEVLIB_GENERATOR._para = ParameterTable({
|
||||
'MODE': ParameterInfo('MODE',
|
||||
ParameterConstantRangeDomain(0, 3),
|
||||
initial=1,
|
||||
value=ArrayExpression(MODE_LIST),
|
||||
description='working mode',
|
||||
record_meta=True),
|
||||
'CHANNEL': ParameterInfo('CHANNEL',
|
||||
ParameterSetDomain(ParameterConstantRangeDomain(0, REC_CHANNEL_COUNT)),
|
||||
initial=[0],
|
||||
description='record channels',
|
||||
record_meta=True),
|
||||
'SAMPLE_RATE': ParameterInfo('SAMPLE_RATE',
|
||||
ParameterConstantRangeDomain(0, len(ADC_SAMPLE_RATE_LIST)),
|
||||
value=Expression.parse('ADC_SAMPLE_RATE_LIST[VALUE]'),
|
||||
description='sampling rate',
|
||||
alias=['ADC_RATE'],
|
||||
record_meta=True),
|
||||
'AMP_GAIN': ParameterInfo('AMP_GAIN',
|
||||
ParameterConstantRangeDomain(0, len(AMP_GAIN_LIST)),
|
||||
initial=1,
|
||||
value=ArrayExpression(AMP_GAIN_LIST),
|
||||
description='amp gain',
|
||||
record_meta=True),
|
||||
'NOISE': ParameterInfo('NOISE',
|
||||
ParameterConstantRangeDomain(0, len(NOISE_LIST)),
|
||||
description='signal noise factor',
|
||||
record_meta=True),
|
||||
})
|
||||
|
||||
DEVLIB_GENERATOR._inst = InstructionTable({
|
||||
'start': ListInstruction('start', [
|
||||
GuardExpression('len(CHANNEL) > 0', 'no recording channel'),
|
||||
"_data_format('TDC4VAF2')",
|
||||
"_sync(True)"
|
||||
])
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ cli options
|
||||
ramp : ramp
|
||||
(Elite, Neulive serial)
|
||||
Elite_Legacy
|
||||
TDC4VAF2 Elite Neulive
|
||||
Elite Neulive
|
||||
(NeuliveSTI serial)
|
||||
NeuliveSTI NeuliveSTI1.0
|
||||
(EliteZM serial)
|
||||
@@ -318,7 +318,6 @@ class RampGenerator(Generator):
|
||||
class DeviceGenerator(Generator):
|
||||
SUPPORT = {
|
||||
'Elite_Legacy': ('Elite_Legacy', '0.0.0'),
|
||||
'TDC4VAF2': ('Elite', '0.1.0'),
|
||||
'Elite': ('Elite', '0.1.0'),
|
||||
'Neulive': ('Neulive', '1.2.0'),
|
||||
}
|
||||
@@ -645,7 +644,7 @@ class GeneratorOptions(CliOptions):
|
||||
ramp : ramp
|
||||
(Elite, Neulive serial)
|
||||
Elite_Legacy
|
||||
TDC4VAF2 Elite Neulive
|
||||
Elite Neulive
|
||||
(NeuliveSTI serial)
|
||||
NeuliveSTI NeuliveSTI1.0
|
||||
(EliteZM serial)
|
||||
|
||||
@@ -977,9 +977,7 @@ class DeviceDataRuntime(DataRuntime):
|
||||
decoder = super().data_format
|
||||
|
||||
# transmit calibration gain level to decoder
|
||||
if isinstance(decoder, TDC4VAF2DataDecoder):
|
||||
decoder.amp_gain = self.meta_file.configuration.amp_gain
|
||||
elif isinstance(decoder, TDC4VCDataDecoder):
|
||||
if isinstance(decoder, TDC4VCDataDecoder):
|
||||
decoder.amp_gain = self.meta_file.configuration.amp_gain
|
||||
decoder._channel = self.meta_file.configuration.channel
|
||||
decoder._adc_clock = self.meta_file.configuration.get_parameter('ADC_CLOCK')
|
||||
|
||||
@@ -124,9 +124,7 @@ class RecordingProcess(Process):
|
||||
decoder = self.ensure_data_format()
|
||||
|
||||
# transmit calibration gain level to decoder
|
||||
if isinstance(decoder, TDC4VAF2DataDecoder):
|
||||
decoder.amp_gain = self._meta_file.configuration.amp_gain
|
||||
elif isinstance(decoder, TDC4VCDataDecoder):
|
||||
if isinstance(decoder, TDC4VCDataDecoder):
|
||||
decoder.amp_gain = self._meta_file.configuration.amp_gain
|
||||
decoder._channel = self._meta_file.configuration.channel
|
||||
decoder._adc_clock = self._meta_file.configuration.get_parameter('ADC_CLOCK')
|
||||
|
||||
Reference in New Issue
Block a user