This commit is contained in:
2026-06-06 17:08:09 +08:00
parent 9c9b522443
commit d576cae3c0
5 changed files with 34 additions and 13 deletions

View File

@@ -5,6 +5,7 @@
import numpy as np
from scipy import signal
import threading
from logs.log import algo_log
class ParadigmRingBuffer:
def __init__(self, n_chan, n_points):
@@ -19,7 +20,8 @@ class ParadigmRingBuffer:
## append buffer and update current pointer
def appendBuffer(self, data):
if self.nUpdate == self.n_points:
raise Exception("Buffer is full")
# raise Exception("Buffer is full")
algo_log("Buffer is full", record_once=True)
n = data.shape[1]

View File

@@ -24,7 +24,7 @@ class zmqServer(threading.Thread):
# 原有业务状态变量
# self.get_Impedance = False # 是否返回阻抗值
# self.open_Impedance = None # 是否开启阻抗检测功能
self.open_Impedance = False # 是否开启阻抗检测功能
self.StartDecode = False # false 停止解码true=开始解码
self.StartTrain = False # False未进入训练状态True处于训练状态
self.state_mode = None # 'train'为训练状态rest'为休息状态,'test'为测试状态
@@ -36,6 +36,7 @@ class zmqServer(threading.Thread):
# 范式数据缓存
self.paradigmBuffer = ParadigmRingBuffer(self.device_info['channel_nums'], self.device_info['sample_rate'] * 10)
self.filterBuffer = FilterRingBuffer(self.device_info['channel_nums'], self.device_info['sample_rate'] * 10)
self.paradigmBufferLock= threading.Lock()
# 命令与数据通信
@@ -111,6 +112,17 @@ class zmqServer(threading.Thread):
with self._event_lock:
self._event_inner_idx = value
def reset_state(self):
"""清空采集器状态和缓存数据"""
with self.paradigmBufferLock:
self.paradigmBuffer.resetAllPara()
self.count_events = {}
self.epoch_finished = False
self.pack_contain_event = False
self.event_inner_idx = -1
self.interval_inited = False
def interval_init(self, decoder_class):
if decoder_class == 'ssmvep':
interval_epoch = ast.literal_eval(IniRead('system', 'SSMVEP_IntervalEpoch'))
@@ -199,15 +211,18 @@ class zmqServer(threading.Thread):
self.running = False
elif method == "rest": #休息状态
self.state_mode = 'rest'
elif method == "impedance":
if params == 1:
self.open_Impedance = True # 开启阻抗
# self.get_Impedance = True # 返回阻抗
elif params == 2:
self.open_Impedance = False # 关闭阻抗
else:
algo_log(f"未知命令:{method}", level="WARNING")
# elif method == "getReport":
# self.getReport = True
# elif method == "impedance":
# if params == 1:
# self.open_Impedance = True # 开启阻抗
# self.get_Impedance = True # 返回阻抗
# elif params == 2:
# self.open_Impedance = False # 关闭阻抗
# self.get_Impedance = False # 停止返回阻抗
@@ -251,7 +266,7 @@ class zmqServer(threading.Thread):
self.paradigmBuffer.appendBuffer(data_np)
self.filterBuffer.appendBuffer(data_np)
algo_log(f"数据写入成功shape={data_np.shape}, 范围=[{data_np.min():.2f}, {data_np.max():.2f}] μV", level="DEBUG")
# algo_log(f"数据写入成功shape={data_np.shape}, 范围=[{data_np.min():.2f}, {data_np.max():.2f}] μV", level="DEBUG")
except Exception as e:
algo_log(f"数据处理失败:{str(e)}", level="ERROR")