add sleep if open impedence

This commit is contained in:
2026-06-12 13:56:48 +08:00
parent b26ae2ce3c
commit 62e7cab5be
3 changed files with 13 additions and 6 deletions

View File

@@ -206,6 +206,9 @@ class Decoder_main(threading.Thread):
self.zmqServer.state_mode = 'rest'
try:
if self.zmqServer.open_Impedance:
time.sleep(0.005)
continue
if self.decoder_class == 'ssvep' or self.decoder_class == 'pvs':
self.decoder_SSVEP()
elif self.decoder_class == 'ssmvep':
@@ -215,7 +218,7 @@ class Decoder_main(threading.Thread):
else:
if self.zmqServer.paradigmBuffer.GetDataLenCount() < 25:
time.sleep(0.005)
continue;
continue
self.zmqServer.paradigmBuffer.getData(25)
except Exception as e:
algo_log(f"Decoder Loop Error: {e}")

View File

@@ -182,7 +182,7 @@ class zmqServer(threading.Thread):
# 转置为上位机需要的[50, 通道数]格式
filtered_data = filtered_data.T.astype(np.float64)
send_buf = filtered_data.tobytes()
algo_log(f"发送滤波数据,长度: {len(send_buf)}字节, filtered_data.shape: {filtered_data.shape}", level="DEBUG", record_once=True)
# algo_log(f"发送滤波数据,长度: {len(send_buf)}字节, filtered_data.shape: {filtered_data.shape}", level="DEBUG", record_once=True)
self.data_send_queue.put(send_buf)
def _process_data_send_queue(self):
@@ -228,6 +228,9 @@ class zmqServer(threading.Thread):
algo_log(f"无效JSON命令: {message_bytes.hex()}", level="ERROR")
self.broadcast_message("error", {"code": 400, "message": "无效JSON格式"})
return
except Exception as e:
algo_log(f"_handle_cmd_message exception: {e}", level="ERROR")
return
algo_log(f"收到命令: {message}", level="INFO")
method = message.get("method")
@@ -418,7 +421,8 @@ class zmqServer(threading.Thread):
break
except Exception as e:
algo_log(f"服务器主循环异常: {e}", level="ERROR")
algo_log(f"服务器主循环异常: {str(e)}", level="ERROR")
return
finally:
self.running = False
# 优雅关闭所有资源

View File

@@ -56,7 +56,7 @@ EMPTY_FRAME = b""
# 仿真信号配置
TARGET_CHANNEL = 0
SIGNAL_FREQ_LIST = [3, 13]
SIGNAL_FREQ_LIST = [13]
SIGNAL_AMP = 1.8
NOISE_GAUSSIAN_AMP = 0.4
NOISE_POWER50_AMP = 0.3
@@ -128,8 +128,8 @@ def generate_eeg_packet(pkt_idx: int) -> np.ndarray:
sig = 0.0
for freq in SIGNAL_FREQ_LIST:
sig += SIGNAL_AMP * np.sin(2 * np.pi * freq * t_arr)
sig += NOISE_POWER50_AMP * np.sin(2 * np.pi * 50 * t_arr)
sig += NOISE_GAUSSIAN_AMP * np.random.randn(n_point)
# sig += NOISE_POWER50_AMP * np.sin(2 * np.pi * 50 * t_arr)
# sig += NOISE_GAUSSIAN_AMP * np.random.randn(n_point)
data[:, ch] = sig
# 事件通道、保留通道