buffer v1

This commit is contained in:
2026-06-08 17:06:27 +08:00
parent 509fc5a1d7
commit d741e3548f
3 changed files with 21 additions and 20 deletions

View File

@@ -185,7 +185,7 @@ class Decoder_main(threading.Thread):
def run(self): def run(self):
while self.Runing: while self.Runing:
# 当滤波数据大于5秒时启动滤波线程 # 当滤波数据大于5秒时启动滤波线程
if self.zmqServer.filterBuffer.GetDataLenCount() > self.device_info['sample_rate'] * 5: if not self.sliding_filter.is_alive() and self.zmqServer.filterBuffer.GetDataLenCount() > self.device_info['sample_rate'] * 5:
algo_log("启动滤波线程", level="DEBUG") algo_log("启动滤波线程", level="DEBUG")
self.sliding_filter.start() self.sliding_filter.start()

View File

@@ -53,7 +53,7 @@ class FilterRingBuffer:
:param count: 读取点数 :param count: 读取点数
:return: np.ndarray, shape=(n_chan, count) :return: np.ndarray, shape=(n_chan, count)
""" """
with self.lock: # with self.lock:
count = min(count, self.total_samples) count = min(count, self.total_samples)
if count == 0: if count == 0:
return np.zeros((self.n_chan, 0)) return np.zeros((self.n_chan, 0))
@@ -75,7 +75,6 @@ class FilterRingBuffer:
:param n: 点数 :param n: 点数
:return: np.ndarray, shape=(n_chan, n) | None数据不足时 :return: np.ndarray, shape=(n_chan, n) | None数据不足时
""" """
with self.lock:
if self.total_samples < n: if self.total_samples < n:
return None return None
return self.getData(n) return self.getData(n)
@@ -173,12 +172,14 @@ class SlidingFilter(threading.Thread):
try: try:
# 获取最新的3秒窗口数据 # 获取最新的3秒窗口数据
window_data = self.ring_buffer.get_latest_n_points(self.window_size) window_data = self.ring_buffer.get_latest_n_points(self.window_size)
algo_log(f"获取到{window_data.shape}数据", level='debug')
if window_data is None: if window_data is None:
algo_log(f"缓存数据不足,当前缓存{self.ring_buffer.GetDataLenCount()}点,需{self.window_size}", level='debug') algo_log(f"缓存数据不足,当前缓存{self.ring_buffer.GetDataLenCount()}点,需{self.window_size}", level='debug')
continue continue
# 滤波并提取无边界效应的200ms数据 # 滤波并提取无边界效应的200ms数据
filtered_data = self._filter_window_data(window_data) filtered_data = self._filter_window_data(window_data)
algo_log(f"滤波后{filtered_data.shape}数据", level='debug')
# 回调返回结果(外部可处理) # 回调返回结果(外部可处理)
if self.filter_result_callback is not None: if self.filter_result_callback is not None:

View File

@@ -268,7 +268,7 @@ class zmqServer(threading.Thread):
# -------------------------- 数据端口消息处理 -------------------------- # -------------------------- 数据端口消息处理 --------------------------
def _handle_data_message(self, frames): def _handle_data_message(self, frames):
"""处理8100端口二进制脑电数据消息""" """处理8100端口二进制脑电数据消息"""
algo_log(f"收到数据帧,总帧数:{len(frames)}", level="DEBUG", record_once=False) algo_log(f"收到数据帧,总帧数:{len(frames)}", level="DEBUG", record_once=True)
# 然后再进行解析 # 然后再进行解析
if len(frames) == 4: if len(frames) == 4:
# 你的上位机格式 # 你的上位机格式