Compare commits

...

12 Commits

Author SHA1 Message Date
peterlu14 35912f614e [update] EIS Mini vt mode add 2022-10-12 17:18:14 +08:00
Roy e3c252f204 [update] FREQ 133333 2022-10-05 11:58:37 +08:00
Roy c2164da48b [update] new vt mode on EIS 2022-10-05 11:16:09 +08:00
Roy ab2d746afb Merge branch 'release/v1.6.7/scheduler_cycle' into release/v1.6.7/scheduler_debug 2022-10-05 10:57:53 +08:00
Roy 4243a13536 Merge remote-tracking branch 'origin/dev/fix_no_data' into release/v1.6.7/scheduler_debug 2022-09-30 10:58:41 +08:00
Roy bbde653a8e [update] update cali value 2022-09-28 14:50:22 +08:00
Roy 6c0cef7925 [update] test function: print mem board info 2022-09-27 14:38:00 +08:00
Roy 3bbf0c912a [update] test function: print mem board info 2022-09-27 13:41:32 +08:00
Roy 4333958ebe [update] fix eis's FREQ default value 2022-09-16 17:49:28 +08:00
Roy 3239a691e3 [update] test function: print ram info 2022-09-16 13:12:40 +08:00
Roy 30183788d8 [update] test function: print ram info 2022-09-14 18:12:53 +08:00
Roy 13df921b1c [update] test function: print ram info 2022-09-14 17:14:47 +08:00
7 changed files with 185 additions and 42 deletions
+1 -1
View File
@@ -662,7 +662,7 @@ class CC2650Device(Device):
elif device_type == 'EISZeroOne':
i = 0
request_times = 0
while i < 7:
while i < 13:
try:
# send
code = self._encode_instruction(DeviceInstruction.TYP_CIS, DeviceInstruction.CIS_CALI, i)
+85 -25
View File
@@ -1,6 +1,7 @@
import abc
import struct
import math
import numpy
from typing import Optional, TypeVar, Generic, Tuple, Dict, List, AnyStr
from datetime import datetime
@@ -1380,12 +1381,27 @@ class EISZeroOneDataDecoder(RecDataDecoder):
def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
if cali_coeff != b'':
cali_table = []
phase_para_a = []
phase_para_b = []
hsrtia_a = []
hsrtia_b = []
hsrtia_c = []
hsrtia_d = []
phase_coeff = []
phase_offset = []
# phase_coeff = [[0]*4 for i in range(4)]
# phase_offset = [[0]*4 for i in range(4)]
phase_coeff = numpy.zeros([4, 4], dtype = int)
phase_offset = numpy.zeros([4, 4], dtype = int)
########################################
# phase_coeff
# [[gain0, g1, g2, g3] ----->最高頻
# [gain0, g1, g2, g3] ----->中頻
# [gain0, g1, g2, g3] ----->低頻
# [gain0, g1, g2, g3] ----->最低頻
# ]
#######################################
# print('cali_coeff', cali_coeff)
cutoff_freq = struct.unpack('>I', cali_coeff[1:5])[0] * 100 #4
@@ -1396,15 +1412,19 @@ class EISZeroOneDataDecoder(RecDataDecoder):
# hsrtia_160k = struct.unpack('>I', cali_coeff[8:12])[0] #4
index = 20
for i in range(index, index+16, 8):
phase_para_a.append(struct.unpack('>i', cali_coeff[i+1:i+5])[0])
phase_para_b.append(struct.unpack('>i', cali_coeff[i+5:i+9])[0])
g = 0
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 40
for i in range(index, index+16, 8):
phase_para_a.append(struct.unpack('>i', cali_coeff[i+1:i+5])[0])
phase_para_b.append(struct.unpack('>i', cali_coeff[i+5:i+9])[0])
g = 0
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#Lv[0] 160k
index = 60
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0]/1e8)
@@ -1429,18 +1449,58 @@ class EISZeroOneDataDecoder(RecDataDecoder):
hsrtia_b.append(struct.unpack('>i', cali_coeff[index+5:index+9])[0]/1e8)
hsrtia_c.append(struct.unpack('>i', cali_coeff[index+9:index+13])[0]/1e4)
# hsrtia_a.append(struct.unpack('>I', cali_coeff[index+1:index+5])[0])
# hsrtia_b.append(struct.unpack('>I', cali_coeff[index+5:index+9])[0]/1e6)
# hsrtia_c.append(struct.unpack('>I', cali_coeff[index+9:index+13])[0]/1e5)
index = 140
g = 1
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 160
g = 1
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 180
g = 2
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 200
g = 2
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 220
g = 3
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 240
g = 3
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
# print('cutoff_freq', cutoff_freq)
# print('hsrtia_a', hsrtia_a)
# print('hsrtia_b', hsrtia_b)
# print('hsrtia_c', hsrtia_c)
# print('phase_para_a', phase_para_a)
# print('phase_para_b', phase_para_b)
# print('phase_coeff')
# print(phase_coeff)
# print('phase_offset')
# print(phase_offset)
cali_table.append((cutoff_freq, phase_para_a, phase_para_b, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d))
cali_table.append((cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d))
return cali_table
else:
@@ -1490,13 +1550,12 @@ class EISZeroOneDataDecoder(RecDataDecoder):
return None
else:
if self.cali_coeff is not None and self._mode == 0:
phase_para_a = []
phase_para_b = []
hsrtia_a = []
hsrtia_b = []
hsrtia_c = []
hsrtia_d = []
cutoff_freq, phase_para_a, phase_para_b, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d = self.cali_coeff[0]
cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d = self.cali_coeff[0]
voltage_amp = round(self._ac_amp * 800 / 2047) # use UI value
if (self._freq_start > self._freq_stop):
self._freq_direction = 0
@@ -1507,6 +1566,7 @@ class EISZeroOneDataDecoder(RecDataDecoder):
img = ch1
real = ch2
freq = ch3
fre_idx = 0
voltage_mag = math.sqrt(img ** 2 + real ** 2) * (1 + freq ** 2 / cutoff_freq ** 2)
@@ -1534,22 +1594,22 @@ class EISZeroOneDataDecoder(RecDataDecoder):
raw_phase = math.atan(img / real) * 180 / math.pi + 180
if (freq >= 1000000): # 10000 Hz
i = 0
fre_idx = 0
elif (freq >= 10000): # 100 Hz
i = 1
fre_idx = 1
elif (freq >= 1000): # 10 Hz
i = 2
fre_idx = 2
elif (freq >= 1): # 0.01 Hz
i = 3
fre_idx = 3
ideal_raw_phase = phase_para_a[i] /1e10 * freq + phase_para_b[i] / 1e6
ideal_raw_phase = phase_coeff[fre_idx][gain] /1e10 * freq + phase_offset[fre_idx][gain] / 1e6
phase = raw_phase - ideal_raw_phase
if (self._first_phase_flag):
self._last_phase = phase
self._first_phase_flag = 0
elif (abs(phase - self._last_phase) >= 200):
elif (abs(phase - self._last_phase) >= 90):
phase -= 360
self._last_phase = phase
+21 -7
View File
@@ -35,7 +35,7 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
'_pin_ram_sel_value', '_pin_mem_sel_value', '_pin_mem_req_value',
'_read_green_times','_read_red_times',
'_elite_data_len', '_mem_header_len', '_mem_tailer_len', '_single_data_len',
'_head_wrong_cnt')
'_head_wrong_cnt', '_pin_busy_value')
def __init__(self,
select: Selector,
@@ -50,11 +50,11 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
self._single_data_len = self._elite_data_len + self._mem_header_len + self._mem_tailer_len
# buffer
self._tx_buffer_header = [0] * 19
self._tx_buffer_header = [0] * 64
self._tx_buffer_data = [0] * (self._single_data_len * 10 + 3)
# memory control pin
self.pin_busy = OutputPin.get_used(P3Pin.MEM_BZY, True)
self.pin_busy: Optional[InputPin] = InputPin.get_used(P3Pin.MEM_BZY)
self.pin_mem_req = OutputPin.get_used(P3Pin.MEM_REQ, False)
self.pin_mem_sel = OutputPin.get_used(P3Pin.MEM_RST, True) # MEM_RST -> actually which memory board is assign
self.pin_ram_sel: Optional[InputPin] = InputPin.get_used(P3Pin.MEM_SEL) # MEM_SEL -> actually is RAM_SEL, which RAM is assign
@@ -62,6 +62,7 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
self._pin_ram_sel_value = [bool(self.pin_ram_sel) for _ in range(Selector.SIZE)]
self._pin_mem_sel_value = [bool(self.pin_mem_sel) for _ in range(Selector.SIZE)]
self._pin_mem_req_value = [bool(self.pin_mem_req) for _ in range(Selector.SIZE)]
self._pin_busy_value = [bool(self.pin_busy) for _ in range(Selector.SIZE)]
self._read_green_times = 0
self._read_red_times = 0
@@ -98,6 +99,14 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
self._pin_ram_sel_value[channel] = True
return self._pin_ram_sel_value[channel]
def get_pin_busy(self):
channel = self.select
if self.pin_busy.input() == 0:
self._pin_busy_value[channel] = False
else:
self._pin_busy_value[channel] = True
return self._pin_busy_value[channel]
@property
def select(self) -> int:
return self._selector.channel
@@ -216,7 +225,9 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
return
def recv_memory(self, device: int) -> Optional[bytes]:
self.pin_busy.output(False)
# self.pin_busy.output(False)
print('mem_req==ram_sel,[', self._pin_mem_req_value[device], ',', self._pin_ram_sel_value[device], ']')
rx = []
@@ -300,6 +311,9 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
print("green data print:", data, device, datetime.now())
return None
# print('data=', list(data))
print('Ram:', data[62])
if (length >= 4000):
flag_print = True
print("green data: big length:", length)
@@ -415,9 +429,9 @@ class MultiExtMemSpiInterface(LowLevelHardwareInterface):
except BaseException as e:
print(e)
finally:
# print("\n")
self.pin_busy.output(True)
# finally:
# # print("\n")
# self.pin_busy.output(True)
return bytes(rx)
+5
View File
@@ -646,6 +646,7 @@ class DataServer(SocketServer, DataAPI):
def whether_to_record(self, device):
# if user click "start", return True; if user click "stop", return False;
if device in self._configurations.keys() and self._configurations[device] is not None:
# print(self._configurations.keys(), ',', device, datetime.now())
return True
else:
return False
@@ -654,6 +655,9 @@ class DataServer(SocketServer, DataAPI):
ret = False
sync = self.get_spi_obj()
busy = sync.get_pin_busy()
print('pin_busy=', busy, device, datetime.now())
if sync.get_pin_mem_req() == sync.get_pin_ram_sel():
spi_data = sync.recv_memory(device)
signal = sync.get_pin_mem_req()
@@ -662,6 +666,7 @@ class DataServer(SocketServer, DataAPI):
else:
data = None
print('data=None, mem_req!=ram_sel, [', sync.get_pin_mem_req(), ', ', sync.get_pin_ram_sel(), ']', device, datetime.now())
if data is not None:
if self._configurations.get(device, None) != None:
@@ -70,7 +70,7 @@
"description": "DPV current recording period start",
"record_meta": true,
"initial": [
13422819,
13333333,
7
],
"domain": {
@@ -63,6 +63,7 @@
"EIS CURVE",
"Cyclic Voltammetry",
"Chronoamperometric",
"V-T Graph",
"Dev Mode"
]
},
@@ -70,7 +71,7 @@
"description": "DPV current recording period start",
"record_meta": true,
"initial": [
13422819,
13333333,
7
],
"domain": {
@@ -277,6 +278,17 @@
"expression": "VALUE"
}
},
"MEASURE_VIN_RANGE": {
"description": "measure range of Vin",
"record_meta": true,
"initial": 0,
"value": [
"0",
"1",
"2",
"auto"
]
},
"BLE_WRITE": {
"description": "send msg to elite",
"domain": {
@@ -308,14 +320,16 @@
"expression": "MODE",
"when": {
"1": "set_adc_gain_I",
"2": "set_adc_gain_I"
"2": "set_adc_gain_I",
"3": "set_adc_gain_I"
}
},
{
"expression": "MODE",
"when": {
"1": "set_adc_gain_Vin",
"2": "set_adc_gain_Vin"
"2": "set_adc_gain_Vin",
"3": "set_adc_gain_Vin"
}
},
{
@@ -323,7 +337,8 @@
"when": {
"0": "curve_eis",
"1": "curve_cv3",
"2": "curve_const_vscan"
"2": "curve_const_vscan",
"3": "curve_vt"
}
},
{
@@ -456,6 +471,23 @@
"2B>pe"
]
},
"curve_vt": {
"type": "RIS",
"parameter": {
"pa": "ADC_LEVEL_I_15",
"pb": "ADC_LEVEL_V_IN_15",
"pd": "CTRL_HIGH_Z_15",
"pe": "SAMPLE_RATE",
"va": "MEASURE_VIN_RANGE"
},
"data": [
"X05;",
"4b>pa;4b>pb;",
"4b>0;4b>pd;",
"2B>pe;",
"1B>va"
]
},
"ble_instru_send": [
"ble_write",
"_cdr('20X>ADC_VALUE_I')"
@@ -63,6 +63,7 @@
"EIS CURVE",
"Cyclic Voltammetry",
"Chronoamperometric",
"V-T Graph",
"Dev Mode"
]
},
@@ -70,7 +71,7 @@
"description": "DPV current recording period start",
"record_meta": true,
"initial": [
13422819,
13333333,
7
],
"domain": {
@@ -277,6 +278,17 @@
"expression": "VALUE"
}
},
"MEASURE_VIN_RANGE": {
"description": "measure range of Vin",
"record_meta": true,
"initial": 0,
"value": [
"0",
"1",
"2",
"auto"
]
},
"BLE_WRITE": {
"description": "send msg to elite",
"domain": {
@@ -308,14 +320,16 @@
"expression": "MODE",
"when": {
"1": "set_adc_gain_I",
"2": "set_adc_gain_I"
"2": "set_adc_gain_I",
"3": "set_adc_gain_I"
}
},
{
"expression": "MODE",
"when": {
"1": "set_adc_gain_Vin",
"2": "set_adc_gain_Vin"
"2": "set_adc_gain_Vin",
"3": "set_adc_gain_Vin"
}
},
{
@@ -323,7 +337,8 @@
"when": {
"0": "curve_eis",
"1": "curve_cv3",
"2": "curve_const_vscan"
"2": "curve_const_vscan",
"3": "curve_vt"
}
},
{
@@ -456,6 +471,23 @@
"2B>pe"
]
},
"curve_vt": {
"type": "RIS",
"parameter": {
"pa": "ADC_LEVEL_I_15",
"pb": "ADC_LEVEL_V_IN_15",
"pd": "CTRL_HIGH_Z_15",
"pe": "SAMPLE_RATE",
"va": "MEASURE_VIN_RANGE"
},
"data": [
"X05;",
"4b>pa;4b>pb;",
"4b>0;4b>pd;",
"2B>pe;",
"1B>va"
]
},
"ble_instru_send": [
"ble_write",
"_cdr('20X>ADC_VALUE_I')"