style: remove NeuliveThreeOneDataDecoder code

This commit is contained in:
Roy
2025-05-28 14:57:10 +08:00
parent 593a2eaecb
commit 58636ed9fc
4 changed files with 0 additions and 342 deletions
-37
View File
@@ -647,43 +647,6 @@ class CC2650Device(Device):
self._master.reset(self.device_id)
break
elif device_type == 'NeuliveThreeOne':
i = 0
request_times = 0
while i < 8:
try:
# print('i', i)
# 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))
except SendInstructionTimeoutError as e:
print(e)
self._master.log_warn('device', self.device_id, 'update_calibration_info no response', i)
raise BaseException
except RuntimeError as e:
print(e)
self._master.log_warn('device', self.device_id, 'update_calibration_info no response - 2', i)
request_times += 1
if request_times > 3:
self._master.reset(self.device_id)
break
else:
# print('data success')
if len(data) > 0:
i += 1
else:
request_times += 1
if request_times > 3:
self._master.reset(self.device_id)
break
elif device_type == 'EISZeroOne':
i = 1
while i <= 24:
-264
View File
@@ -96,8 +96,6 @@ class DataDecodeFormat(Generic[T], metaclass=abc.ABCMeta):
return TDC4VAF2DataDecoder(expr[9:])
elif expr.startswith(b'TDC4VC:'):
return TDC4VCDataDecoder(expr[7:])
elif expr.startswith(b'NeuliveThreeOne:'):
return NeuliveThreeOneDataDecoder(expr[16:])
elif expr.startswith(b'EISZeroOne:'):
return EISZeroOneDataDecoder(expr[11:])
@@ -1238,268 +1236,6 @@ class TDBC4VCTHDataDecoder(RecDataDecoder):
return ret
class NeuliveThreeOneDataDecoder(RecDataDecoder):
"""
::
| | 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
-----------------------------------------------------------------
| timestamp |
|channel data # |
| delta time |
| channel data |
| x-axis acc data |
| y-axis acc data |
| z-axis acc data |
"""
NAME = 'NeuliveThreeOne'
AMP_GAIN = (100, 400, 800, 25)
CH_NUMBER = 8
GAIN_LEVEL_NUMBER = 4
__slots__ = ("_start_return_data", "_time_stamp", "_time_stamp_list", "_discard_data_counter",
"_channel", 'amp_gain', 'data_counter', 'cali_coeff', '_cali_coeff', "_cycle_start_time",
"_adc_clock", "_axis_ch", "_prev_delta_time","_prev_data", "_prev_time_stamp",
"_accelerator_sensitivity", '_prev_packet_delta_time', '_prev_packet_delta_mean')
def __init__(self, cali_coeff: bytes = None):
super().__init__()
self._start_return_data = False
self._time_stamp = 0
self._time_stamp_list = []
self._discard_data_counter = 0
self._channel = 0
self._adc_clock = 0
self._axis_ch = 0
self._accelerator_sensitivity = 0
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
self._cycle_start_time = []
if cali_coeff is not None:
self._cali_coeff = cali_coeff
self.cali_coeff = self._decode_cali_coeff(cali_coeff)
self._prev_data = None
self._prev_delta_time = None
self._prev_time_stamp = None
self._prev_packet_delta_time = []
self._prev_packet_delta_mean = None
@staticmethod
def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
if cali_coeff != b'':
cali_table = []
max_length = 4
size_of_cali_data_per_amp_gain_level = 64
for i in range(0, max_length):
for j in range(0, size_of_cali_data_per_amp_gain_level, 4):
index = i * size_of_cali_data_per_amp_gain_level + j
amp = struct.unpack('>h', cali_coeff[index: index + 2])[0]
offset = struct.unpack('>h', cali_coeff[index + 2: index + 4])[0]
cali_table.append((amp, offset))
# print('decode cali', i , j , amp , offset)
# print('cali_table', cali_table)
return cali_table
else:
print()
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
@property
def real_sample_rate(self) -> int:
result = 0
if self._adc_clock != 0:
result = (200 / self._adc_clock) * 1000
return result
def decode(self, data: bytes) -> Optional[RecordingData]:
if data is None:
return None
data_length = data[5]
# channel data & acc data number should be data_length+2
if (len(data)-8)/3 != data_length+2:
return None
axis_start_index = 8 + data_length * 3 # 239
axis_data_length = int((len(data) - axis_start_index) / 6)
time_stamp: int = struct.unpack('<I', data[1:5])[0] # unit us
time_delta: int = struct.unpack('<H', data[6:8])[0] # unit us
# print("chip id = ", data[0])
# print("data_length = ", data_length)
# print("time_stamp = ", data[1], data[2], data[3], data[4])
# print("time_delta = ", data[6], data[7])
stop = len(data)
if time_stamp != 0:
time_stamp, _, ret_get_time_stamp = self.get_time_stamp(time_stamp)
if time_stamp is None:
return None
if self._prev_time_stamp is None or len(self._prev_time_stamp) == 0:
self._prev_time_stamp.append(time_stamp)
self._prev_delta_time.append(time_delta)
return None
# is packet delta time normal?
data_packets_time_delta = time_stamp - self._prev_time_stamp[0]
# print("data_packets_time_delta = ", data_packets_time_delta, "; prev_time_stamp = ", self._prev_time_stamp[0])
if data_packets_time_delta <= 0:
return None
elif self._prev_packet_delta_mean is None or self._prev_packet_delta_mean == 0:
self._prev_packet_delta_time = []
self._prev_packet_delta_time.append(data_packets_time_delta)
self._prev_packet_delta_mean = sum(self._prev_packet_delta_time) / len(self._prev_packet_delta_time)
elif data_packets_time_delta > 3 * self._prev_packet_delta_mean:
# print("[warning] data lost time = ", time_stamp/1e6)
self._prev_packet_delta_mean = 0
self._prev_packet_delta_time = []
else:
# update packet delta standard
MAX_PREV_PACKET = 10
if len(self._prev_packet_delta_time) >= MAX_PREV_PACKET:
self._prev_packet_delta_time.pop(0)
self._prev_packet_delta_time.append(data_packets_time_delta)
self._prev_packet_delta_mean = sum(self._prev_packet_delta_time) / len(self._prev_packet_delta_time)
# get sample rate
if data_length == 1 or int(time_delta) == 0:
sample_rate = 0
acc_sample_rate = 0
else:
sample_rate = data_length * 1e6 / time_delta # unit 1/s
acc_sample_rate = sample_rate / data_length
# create record ret
ret = RecordingData(self.device, self._prev_time_stamp[0], int(sample_rate), int(acc_sample_rate), 4)
ret.cycle = self._cycle_start_time
# get user setting gain level
# and set amp_gain=0~3 => gain=25, 100, 400, 800
amp_gain = self.amp_gain
amp_gain = amp_gain + 1
if amp_gain == 4:
amp_gain = 0
# decode recording data
NUMBER_OF_CALI_CH = 16
for i in range(data_length):
# avoid index out of range
offset = 8 + 3 * i
if offset + 1 < stop:
ch = data[offset]
d1 = data[offset + 1]
d2 = data[offset + 2]
channel = ch
value = d1 << 8 | d2
if channel < NUMBER_OF_CALI_CH and self.cali_coeff is not None:
gain, offset = self.cali_coeff[NUMBER_OF_CALI_CH * amp_gain + channel]
if gain == 0:
cali_value = value - 2048
elif gain == 1 and offset == 0:
cali_value = value - 2048
else:
cali_value = int(1000 * ((value - 2048 - offset) / gain))
# print("gain = ", gain)
# print("offset = ", offset)
else:
cali_value = value - 2048
ret.append_data(channel, cali_value)
# print("\n")
# decode 3-axis acc data
x_axis_acc_ch = 256
y_axis_acc_ch = 257
z_axis_acc_ch = 258
axis_acc_ch = 259
divide_ratio = 0
if self._axis_ch > 0:
if self._accelerator_sensitivity == 0:
divide_ratio = 16384
elif self._accelerator_sensitivity == 1:
divide_ratio = 8192
elif self._accelerator_sensitivity == 2:
divide_ratio = 4096
elif self._accelerator_sensitivity == 3:
divide_ratio = 2048
axis_channel_allow = bin(self._axis_ch)[2:]
axis_channel_allow_list = [ch for ch in axis_channel_allow]
axis_channel_allow_list.reverse()
for i in range(axis_data_length):
x_axis_index: int = i*6 + axis_start_index
y_axis_index: int = i*6 + axis_start_index + 2
z_axis_index: int = i*6 + axis_start_index + 4
x_axis_data = data[x_axis_index + 1] << 8 | data[x_axis_index]
y_axis_data = data[y_axis_index + 1] << 8 | data[y_axis_index]
z_axis_data = data[z_axis_index + 1] << 8 | data[z_axis_index]
# print("x_axis_data = ", x_axis_data, "y_axis_data = ", y_axis_data, "z_axis_data", z_axis_data)
# using 2's complement
if x_axis_data >= 0x8000:
x_axis_data = x_axis_data - 0xFFFF
if y_axis_data >= 0x8000:
y_axis_data = y_axis_data - 0xFFFF
if z_axis_data >= 0x8000:
z_axis_data = z_axis_data - 0xFFFF
axis_data = int(math.sqrt(x_axis_data ** 2 + y_axis_data ** 2 + z_axis_data ** 2))
if self._axis_ch >= 1:
ret.append_data(x_axis_acc_ch, int((x_axis_data) / divide_ratio))
if self._axis_ch >= 2:
ret.append_data(y_axis_acc_ch, int((y_axis_data) / divide_ratio))
if self._axis_ch >= 4:
ret.append_data(z_axis_acc_ch, int((z_axis_data) / divide_ratio))
if self._axis_ch >= 8:
ret.append_data(axis_acc_ch, int((axis_data) / divide_ratio))
# update previous time stamp
self._prev_time_stamp.pop()
self._prev_delta_time.pop()
self._prev_time_stamp.append(time_stamp)
self._prev_delta_time.append(time_delta)
return ret
class EISZeroOneDataDecoder(RecDataDecoder):
"""
::S
-19
View File
@@ -978,31 +978,12 @@ class DeviceDataRuntime(DataRuntime):
# transmit calibration gain level to decoder
if isinstance(decoder, TDC4VAF2DataDecoder):
# get amp_gain from meta file
decoder.amp_gain = self.meta_file.configuration.amp_gain
elif isinstance(decoder, TDC4VCDataDecoder):
# get amp_gain from meta file
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')
# decoder._time_stamp_list = self._time_stamp_list
decoder._axis_ch = self.meta_file.configuration.get_parameter('AXIS_CH')
decoder._prev_data = self._prev_data
decoder._prev_delta_time = self._prev_delta_time
decoder._prev_time_stamp = self._prev_time_stamp
# elif isinstance(decoder, I4V4Z4T4DataDecoder):
# get cycle_time from meta file
# decoder._mode = self.meta_file.configuration.MODE
# decoder._cycle_start_time = self._cycle_start_time
elif isinstance(decoder, NeuliveThreeOneDataDecoder):
# get amp_gain from meta file
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')
# decoder._time_stamp_list = self._time_stamp_list
decoder._axis_ch = self.meta_file.configuration.get_parameter('AXIS_CH')
decoder._prev_data = self._prev_data
decoder._prev_delta_time = self._prev_delta_time
decoder._prev_time_stamp = self._prev_time_stamp
-22
View File
@@ -125,43 +125,21 @@ class RecordingProcess(Process):
# transmit calibration gain level to decoder
if isinstance(decoder, TDC4VAF2DataDecoder):
# get amp_gain from meta file
decoder.amp_gain = self._meta_file.configuration.amp_gain
elif isinstance(decoder, TDC4VCDataDecoder):
# get amp_gain from meta file
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')
# decoder._time_stamp_list = self._time_stamp_list
decoder._axis_ch = self._meta_file.configuration.get_parameter('AXIS_CH')
decoder._prev_data = self._prev_data
decoder._prev_delta_time = self._prev_delta_time
decoder._prev_time_stamp = self._prev_time_stamp
elif isinstance(decoder, I4V4Z4T4DataDecoder):
# get cycle_time from meta file
decoder._mode = self._meta_file.configuration.get_parameter('MODE')
# decoder._cycle_start_time = self._cycle_start_time
elif isinstance(decoder, PEL_FMT1_DataDecoder):
# get cycle_time from meta file
decoder._mode = self._meta_file.configuration.get_parameter('MODE')
# decoder._cycle_start_time = self._cycle_start_time
elif isinstance(decoder, NeuliveThreeOneDataDecoder):
# get amp_gain from meta file
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')
# decoder._time_stamp_list = self._time_stamp_list
decoder._axis_ch = self._meta_file.configuration.get_parameter('AXIS_CH')
decoder._accelerator_sensitivity = self._meta_file.configuration.get_parameter('ACCELERATOR_S')
decoder._prev_data = self._prev_data
decoder._prev_delta_time = self._prev_delta_time
decoder._prev_time_stamp = self._prev_time_stamp
elif isinstance(decoder, EISZeroOneDataDecoder):
# get amp_gain from meta file
decoder._mode = self._meta_file.configuration.get_parameter('MODE')
return decoder
def recv_data_foreach_runtime(self) -> bool: