qlsdk2 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qlsdk/__init__.py +15 -0
- qlsdk/ar4m/__init__.py +4 -0
- qlsdk/ar4m/ar4m.py +44 -0
- qlsdk/ar4m/ar4sdk.py +372 -0
- qlsdk/ar4m/example.py +51 -0
- qlsdk2-0.1.0.dist-info/METADATA +110 -0
- qlsdk2-0.1.0.dist-info/RECORD +9 -0
- qlsdk2-0.1.0.dist-info/WHEEL +5 -0
- qlsdk2-0.1.0.dist-info/top_level.txt +1 -0
qlsdk/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
2
|
+
|
|
3
|
+
# 暴露公共接口
|
|
4
|
+
from .ar4m.ar4m import AR4M
|
|
5
|
+
from .ar4m.ar4sdk import AR4SDK, AR4, Packet, AR4Packet
|
|
6
|
+
|
|
7
|
+
__all__ = ['AR4M', 'AR4', 'AR4Packet']
|
|
8
|
+
|
|
9
|
+
# from importlib import import_module
|
|
10
|
+
# from pathlib import Path
|
|
11
|
+
|
|
12
|
+
# _MODULES = [p.stem for p in Path(__file__).parent.glob("*.py") if p.stem != "__init__"]
|
|
13
|
+
|
|
14
|
+
# for module in _MODULES:
|
|
15
|
+
# import_module(f".{module}", package="qlsdk")
|
qlsdk/ar4m/__init__.py
ADDED
qlsdk/ar4m/ar4m.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from ar4sdk import AR4SDK, AR4
|
|
2
|
+
from time import sleep, time
|
|
3
|
+
from threading import Lock, Timer
|
|
4
|
+
from loguru import logger
|
|
5
|
+
|
|
6
|
+
class AR4M(object):
|
|
7
|
+
def __init__(self):
|
|
8
|
+
self._lock = Lock()
|
|
9
|
+
self._search_timer = None
|
|
10
|
+
self._search_running = False
|
|
11
|
+
self._devices: dict[str, AR4] = {}
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def devices(self):
|
|
15
|
+
return self._devices
|
|
16
|
+
def search(self):
|
|
17
|
+
if not self._search_running:
|
|
18
|
+
self._search_running = True
|
|
19
|
+
self._search()
|
|
20
|
+
|
|
21
|
+
def _search(self):
|
|
22
|
+
if self._search_running:
|
|
23
|
+
|
|
24
|
+
self._search_timer = Timer(2, self._search_ar4)
|
|
25
|
+
self._search_timer.daemon = True
|
|
26
|
+
self._search_timer.start()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _search_ar4(self):
|
|
30
|
+
try:
|
|
31
|
+
devices = AR4SDK.enum_devices()
|
|
32
|
+
logger.debug(f"_search_ar4 devices size: {len(devices)}")
|
|
33
|
+
for dev in devices:
|
|
34
|
+
logger.debug(f"slot: {dev.slot}, mac: {dev.mac}-{hex(dev.mac)}, hub_name: {dev.hub_name.str}")
|
|
35
|
+
if dev.mac in list(self._devices.keys()):
|
|
36
|
+
ar4 = self._devices[dev.mac]
|
|
37
|
+
ar4.update_info()
|
|
38
|
+
ar4 = AR4(hex(dev.mac), dev.slot, dev.hub_name.str)
|
|
39
|
+
if ar4.init():
|
|
40
|
+
self._devices[dev.mac] = ar4
|
|
41
|
+
except Exception as e:
|
|
42
|
+
logger.error(f"_search_ar4 异常: {str(e)}")
|
|
43
|
+
finally:
|
|
44
|
+
self._search()
|
qlsdk/ar4m/ar4sdk.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
from multiprocessing import Queue
|
|
3
|
+
import platform
|
|
4
|
+
from ctypes import (
|
|
5
|
+
c_int, c_int32, c_int64, c_uint32, c_uint64,
|
|
6
|
+
c_char, c_char_p, c_void_p,
|
|
7
|
+
Structure, POINTER, CFUNCTYPE
|
|
8
|
+
)
|
|
9
|
+
from loguru import logger
|
|
10
|
+
from time import sleep, time
|
|
11
|
+
|
|
12
|
+
# 加载 DLL
|
|
13
|
+
if platform.system() == 'Windows':
|
|
14
|
+
_dll = ctypes.CDLL('./libs/libAr4SDK.dll')
|
|
15
|
+
else:
|
|
16
|
+
raise NotImplementedError(f"不支持非Windows平台:{platform.system()}")
|
|
17
|
+
|
|
18
|
+
#------------------------------------------------------------------
|
|
19
|
+
# 基础类型定义
|
|
20
|
+
#------------------------------------------------------------------
|
|
21
|
+
class Ar4MacStr(Structure):
|
|
22
|
+
_fields_ = [("str", c_char * 17)]
|
|
23
|
+
|
|
24
|
+
class Ar4Name(Structure):
|
|
25
|
+
_fields_ = [("str", c_char * 21)]
|
|
26
|
+
|
|
27
|
+
class Ar4Device(Structure):
|
|
28
|
+
_fields_ = [
|
|
29
|
+
("slot", c_int32),
|
|
30
|
+
("mac", c_uint64),
|
|
31
|
+
("hub_name", Ar4Name)
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
class Ar4NotifyData(Structure):
|
|
35
|
+
_fields_ = [
|
|
36
|
+
("time_stamp", c_int64),
|
|
37
|
+
("pkg_id", c_int64),
|
|
38
|
+
("notify_id", c_int64),
|
|
39
|
+
("eeg", POINTER(c_int32)),
|
|
40
|
+
("eeg_ch_count", c_int32),
|
|
41
|
+
("eeg_count", c_int32),
|
|
42
|
+
("acc", POINTER(c_int32)),
|
|
43
|
+
("acc_ch_count", c_int32),
|
|
44
|
+
("acc_count", c_int32)
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
#------------------------------------------------------------------
|
|
48
|
+
# 回调函数类型
|
|
49
|
+
#------------------------------------------------------------------
|
|
50
|
+
FuncAr4DataNotify = CFUNCTYPE(None, c_void_p, POINTER(Ar4NotifyData))
|
|
51
|
+
FuncAr4TriggerNotify = CFUNCTYPE(None, c_void_p, c_int64, c_int32, c_uint32)
|
|
52
|
+
FuncAr4RecorderDisconnected = CFUNCTYPE(None, c_void_p)
|
|
53
|
+
FuncAr4RecorderConnected = CFUNCTYPE(None, c_void_p)
|
|
54
|
+
FuncAr4RecorderTimeout = CFUNCTYPE(None, c_void_p, c_int64)
|
|
55
|
+
FuncAr4RecorderPkgLost = CFUNCTYPE(c_int, c_void_p, c_int64, c_int64, c_int64)
|
|
56
|
+
FuncAr4GetTime = CFUNCTYPE(c_int64)
|
|
57
|
+
FuncAr4SDKPrint = CFUNCTYPE(None, c_char_p, ctypes.c_size_t)
|
|
58
|
+
|
|
59
|
+
#------------------------------------------------------------------
|
|
60
|
+
# SDK 函数定义
|
|
61
|
+
#------------------------------------------------------------------
|
|
62
|
+
# 设备枚举
|
|
63
|
+
_dll.ar4_sdk_enum_device.restype = POINTER(Ar4Device)
|
|
64
|
+
_dll.ar4_sdk_enum_hub.restype = POINTER(Ar4Name)
|
|
65
|
+
_dll.ar4_sdk_enum_in_hub.argtypes = [Ar4Name]
|
|
66
|
+
|
|
67
|
+
# MAC地址转换
|
|
68
|
+
_dll.ar4_mac_to_str.argtypes = [c_uint64]
|
|
69
|
+
_dll.ar4_mac_to_str.restype = Ar4MacStr
|
|
70
|
+
_dll.ar4_str_to_mac.argtypes = [Ar4MacStr]
|
|
71
|
+
_dll.ar4_str_to_mac.restype = c_uint64
|
|
72
|
+
|
|
73
|
+
# 连接管理
|
|
74
|
+
_dll.ar4_sdk_connect.argtypes = [c_uint64, c_void_p]
|
|
75
|
+
_dll.ar4_sdk_connect.restype = c_void_p
|
|
76
|
+
_dll.ar4_sdk_disconnect.argtypes = [c_void_p]
|
|
77
|
+
|
|
78
|
+
# AR4信息查询
|
|
79
|
+
_dll.ar4_sdk_get_box_name.argtypes = [c_void_p]
|
|
80
|
+
_dll.ar4_sdk_get_box_name.restype = c_uint64
|
|
81
|
+
|
|
82
|
+
# 数据采集控制
|
|
83
|
+
_dll.ar4_sdk_start_acq.argtypes = [c_void_p]
|
|
84
|
+
_dll.ar4_sdk_start_acq.restype = c_int
|
|
85
|
+
_dll.ar4_sdk_stop_acq.argtypes = [c_void_p]
|
|
86
|
+
_dll.ar4_sdk_stop_acq.restype = c_int
|
|
87
|
+
_dll.ar4_sdk_get_record_sample_rate.argtypes = [c_void_p]
|
|
88
|
+
_dll.ar4_sdk_get_record_sample_rate.restype = c_char_p
|
|
89
|
+
_dll.ar4_sdk_get_acq_start_time.argtypes = [c_void_p]
|
|
90
|
+
_dll.ar4_sdk_get_acq_start_time.restype = c_int64
|
|
91
|
+
|
|
92
|
+
# 回调注册
|
|
93
|
+
_dll.ar4_sdk_register_data_notify.argtypes = [c_void_p, FuncAr4DataNotify]
|
|
94
|
+
_dll.ar4_sdk_register_data_notify.restype = None
|
|
95
|
+
_dll.ar4_sdk_register_trigger_notify.argtypes = [c_void_p, c_void_p]
|
|
96
|
+
_dll.ar4_sdk_register_conn_notify.argtypes = [c_void_p, FuncAr4RecorderConnected, FuncAr4RecorderDisconnected]
|
|
97
|
+
_dll.ar4_sdk_register_record_state_notify.argtypes = [c_void_p, FuncAr4RecorderConnected, FuncAr4RecorderDisconnected]
|
|
98
|
+
_dll.ar4_sdk_register_box_conn_notify.argtypes = [c_void_p, FuncAr4RecorderConnected, FuncAr4RecorderDisconnected]
|
|
99
|
+
|
|
100
|
+
# _dll对外封装类
|
|
101
|
+
class AR4SDK:
|
|
102
|
+
@classmethod
|
|
103
|
+
def enum_devices(cls):
|
|
104
|
+
"""枚举可用设备"""
|
|
105
|
+
devices = []
|
|
106
|
+
ptr = _dll.ar4_sdk_enum_device()
|
|
107
|
+
|
|
108
|
+
while ptr and ptr.contents.mac != 0:
|
|
109
|
+
devices.append(ptr.contents)
|
|
110
|
+
ptr = ptr[1]
|
|
111
|
+
if isinstance(ptr, Ar4Device):
|
|
112
|
+
logger.debug(f"enum_devices break with {ptr}")
|
|
113
|
+
break
|
|
114
|
+
return devices
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def enum_hubs(cls):
|
|
118
|
+
"""枚举可用设备"""
|
|
119
|
+
devices = []
|
|
120
|
+
ptr = _dll.ar4_sdk_enum_hub()
|
|
121
|
+
sleep(5)
|
|
122
|
+
logger.debug(f"enum_hubs: {ptr}")
|
|
123
|
+
|
|
124
|
+
def __enter__(self):
|
|
125
|
+
return self
|
|
126
|
+
|
|
127
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# 读取系统当前时间(ms)
|
|
132
|
+
def _get_time():
|
|
133
|
+
cur_time = int(round(time()) * 1000)
|
|
134
|
+
logger.debug(f"_get_time is {cur_time}")
|
|
135
|
+
return cur_time
|
|
136
|
+
|
|
137
|
+
# ar4设备对象
|
|
138
|
+
class AR4(object):
|
|
139
|
+
def __init__(self, box_mac, slot, hub_name):
|
|
140
|
+
self._handle = None
|
|
141
|
+
self._box_type = None
|
|
142
|
+
self._box_mac = box_mac
|
|
143
|
+
self._box_id = None
|
|
144
|
+
self._box_soc = None
|
|
145
|
+
self._box_name = None
|
|
146
|
+
self._box_version = None
|
|
147
|
+
self._head_type = None
|
|
148
|
+
self._head_mac = None
|
|
149
|
+
self._head_version = None
|
|
150
|
+
self._head_conn_state = None
|
|
151
|
+
self._head_soc = None
|
|
152
|
+
self._net_state = None
|
|
153
|
+
self._hub_name = hub_name
|
|
154
|
+
self._slot = slot
|
|
155
|
+
self._connected = False
|
|
156
|
+
self._conn_time = None
|
|
157
|
+
self._last_time = None
|
|
158
|
+
# 回调函数
|
|
159
|
+
self._data_callback = FuncAr4DataNotify(self._wrap_data_accept())
|
|
160
|
+
self._trigger_callback = FuncAr4TriggerNotify(self._trigger_accept)
|
|
161
|
+
|
|
162
|
+
# 消息订阅
|
|
163
|
+
self._consumers: dict[str, Queue] = {}
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def box_mac(self):
|
|
167
|
+
return self._box_mac
|
|
168
|
+
def init(self):
|
|
169
|
+
if not self._handle:
|
|
170
|
+
self._connected = self.connect()
|
|
171
|
+
if self._connected:
|
|
172
|
+
self._conn_time = _get_time()
|
|
173
|
+
self.get_box_name()
|
|
174
|
+
self.get_head_mac()
|
|
175
|
+
self.get_record_conn_state()
|
|
176
|
+
self._last_time = _get_time()
|
|
177
|
+
logger.debug(self)
|
|
178
|
+
return True
|
|
179
|
+
|
|
180
|
+
def update_info(self):
|
|
181
|
+
self._last_time = _get_time()
|
|
182
|
+
|
|
183
|
+
# 设备连接
|
|
184
|
+
def connect(self)-> bool:
|
|
185
|
+
|
|
186
|
+
if self._box_mac:
|
|
187
|
+
"""连接设备"""
|
|
188
|
+
# callback = FuncAr4GetTime(self._get_time)
|
|
189
|
+
try:
|
|
190
|
+
self._handle = _dll.ar4_sdk_connect(int(self._box_mac, 16), c_void_p(0))
|
|
191
|
+
# logger.info(f"conn handle is {self._handle}")
|
|
192
|
+
self._handle = c_void_p(self._handle)
|
|
193
|
+
logger.debug(f"ar4 {self._box_mac} 连接: {self._handle}")
|
|
194
|
+
except Exception as e:
|
|
195
|
+
logger.error(f"ar4 {self._box_mac} 连接异常: {str(e)}")
|
|
196
|
+
return self._handle is not None
|
|
197
|
+
|
|
198
|
+
# 读取盒子名称
|
|
199
|
+
def get_box_name(self):
|
|
200
|
+
if self._handle:
|
|
201
|
+
try:
|
|
202
|
+
self._head_mac = _dll.ar4_sdk_get_recoder_mac(self._handle)
|
|
203
|
+
except Exception as e:
|
|
204
|
+
logger.error(f"ar4 {self._box_mac} 获取盒子记录子mac异常: {str(e)}")
|
|
205
|
+
# 读取记录子mac
|
|
206
|
+
def get_head_mac(self):
|
|
207
|
+
if self._handle:
|
|
208
|
+
try:
|
|
209
|
+
self._box_name = _dll.ar4_sdk_get_record_conn_state(self._handle)
|
|
210
|
+
except Exception as e:
|
|
211
|
+
logger.error(f"ar4 {self._box_mac} 获取盒子名称异常: {str(e)}")
|
|
212
|
+
# 读取记录子连接状态
|
|
213
|
+
def get_record_conn_state(self):
|
|
214
|
+
if self._handle:
|
|
215
|
+
try:
|
|
216
|
+
self._head_conn_state = _dll.ar4_sdk_get_record_conn_state(self._handle)
|
|
217
|
+
except Exception as e:
|
|
218
|
+
logger.error(f"ar4 {self._box_mac} 获取盒子记录子连接状态异常: {str(e)}")
|
|
219
|
+
|
|
220
|
+
# 数据采集启动
|
|
221
|
+
def start_acquisition(self):
|
|
222
|
+
logger.info(f"ar4 {self._box_mac} 启动数据采集...")
|
|
223
|
+
"""启动数据采集"""
|
|
224
|
+
|
|
225
|
+
if self._handle:
|
|
226
|
+
# 设置信号数据回调
|
|
227
|
+
try:
|
|
228
|
+
_dll.ar4_sdk_register_data_notify(self._handle, self._data_callback)
|
|
229
|
+
except Exception as e:
|
|
230
|
+
logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
|
|
231
|
+
|
|
232
|
+
# 设置trigger数据回调
|
|
233
|
+
try:
|
|
234
|
+
_dll.ar4_sdk_register_trigger_notify(self._handle, self._trigger_callback)
|
|
235
|
+
except Exception as e:
|
|
236
|
+
logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
|
|
237
|
+
# 启动采集
|
|
238
|
+
try:
|
|
239
|
+
logger.debug(f"ar4 {self._box_mac} 启动采集: {self._handle}")
|
|
240
|
+
ret = _dll.ar4_sdk_start_acq(self._handle)
|
|
241
|
+
logger.debug(f"ar4 {self._box_mac} 启动采集结果: {ret}")
|
|
242
|
+
|
|
243
|
+
return ret == 0
|
|
244
|
+
except Exception as e:
|
|
245
|
+
logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
|
|
246
|
+
else:
|
|
247
|
+
logger.info(f"ar4 {self._box_mac} 启动数据采集失败, 设备未连接")
|
|
248
|
+
return False
|
|
249
|
+
|
|
250
|
+
def stop_acquisition(self):
|
|
251
|
+
"""停止采集"""
|
|
252
|
+
if self._handle:
|
|
253
|
+
try:
|
|
254
|
+
return _dll.ar4_sdk_stop_acq(self._handle) == 0
|
|
255
|
+
except Exception as e:
|
|
256
|
+
logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
|
|
257
|
+
else:
|
|
258
|
+
return False
|
|
259
|
+
|
|
260
|
+
def disconnect(self):
|
|
261
|
+
"""断开连接"""
|
|
262
|
+
if self._handle:
|
|
263
|
+
_dll.ar4_sdk_disconnect(self._handle)
|
|
264
|
+
|
|
265
|
+
def get_sample_rate(self):
|
|
266
|
+
try:
|
|
267
|
+
ret = _dll.ar4_sdk_get_record_sample_rate(self._handle)
|
|
268
|
+
logger.debug(f"ar4 {self._box_mac} 获取采样率: {ret.contents.decode('utf-8')}")
|
|
269
|
+
except Exception as e:
|
|
270
|
+
logger.error(f"ar4 {self._box_mac} 获取采样率异常: {str(e)}")
|
|
271
|
+
|
|
272
|
+
def get_acq_start_time(self):
|
|
273
|
+
try:
|
|
274
|
+
ret = _dll.ar4_sdk_get_acq_start_time(self._handle)
|
|
275
|
+
logger.debug(f"ar4 {self._box_mac} 获取采样开始时间: {ret}")
|
|
276
|
+
except Exception as e:
|
|
277
|
+
logger.error(f"ar4 {self._box_mac} 获取采样开始时间异常: {str(e)}")
|
|
278
|
+
|
|
279
|
+
# 订阅推送消息
|
|
280
|
+
def subscribe(self, topic: str = None, q: Queue = Queue()):
|
|
281
|
+
if topic is None:
|
|
282
|
+
topic = f"msg_{_get_time()}"
|
|
283
|
+
if topic in list(self._consumers.keys()):
|
|
284
|
+
logger.warning(f"ar4 {self._box_mac} 订阅主题已存在: {topic}")
|
|
285
|
+
return topic, self._consumers[topic]
|
|
286
|
+
self._consumers[topic] = q
|
|
287
|
+
|
|
288
|
+
return topic, self._consumers[topic]
|
|
289
|
+
|
|
290
|
+
def _wrap_data_accept(self):
|
|
291
|
+
|
|
292
|
+
@FuncAr4DataNotify
|
|
293
|
+
def data_accept(handle, data_ptr):
|
|
294
|
+
self._data_accept(data_ptr)
|
|
295
|
+
|
|
296
|
+
return data_accept
|
|
297
|
+
|
|
298
|
+
def _data_accept(self, data_ptr):
|
|
299
|
+
# logger.info(f"_eeg_accept 被调用")
|
|
300
|
+
# logger.debug(f'handle:{self}, data_ptr:{data_ptr}')
|
|
301
|
+
# data = cast(data_ptr, POINTER(Ar4NotifyData)).contents
|
|
302
|
+
if len(self._consumers) > 0:
|
|
303
|
+
packet = AR4Packet().transfer(data_ptr.contents)
|
|
304
|
+
for consumer in self._consumers.values():
|
|
305
|
+
consumer.put(packet)
|
|
306
|
+
# logger.debug(f"EEG数据: {packet}")
|
|
307
|
+
|
|
308
|
+
def _trigger_accept(self, time_ms, trigger_type, trigger_value):
|
|
309
|
+
logger.info(f"_trigger_accept 被调用")
|
|
310
|
+
logger.info(f"触发时间: {time_ms}, 触发类型: {trigger_type}, 触发值: {trigger_value}")
|
|
311
|
+
|
|
312
|
+
def __str__(self):
|
|
313
|
+
return f"""
|
|
314
|
+
box mac: {self._box_mac},
|
|
315
|
+
box name: {self._box_name},
|
|
316
|
+
box soc: {self._box_soc}
|
|
317
|
+
head conn state: {self._head_conn_state}
|
|
318
|
+
head mac: {self._head_mac},
|
|
319
|
+
head soc: {self._head_soc}
|
|
320
|
+
connected: {self._connected}
|
|
321
|
+
connect time: {self._conn_time}
|
|
322
|
+
last time: {self._last_time}
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
class Packet(object):
|
|
326
|
+
pass
|
|
327
|
+
|
|
328
|
+
class AR4Packet(Packet):
|
|
329
|
+
def __init__(self):
|
|
330
|
+
self.time_stamp = None
|
|
331
|
+
self.pkg_id = None
|
|
332
|
+
self.notify_id = None
|
|
333
|
+
self.eeg_ch_count = None
|
|
334
|
+
self.eeg_count = None
|
|
335
|
+
self.eeg = None
|
|
336
|
+
self.acc_ch_count = None
|
|
337
|
+
self.acc_count = None
|
|
338
|
+
self.acc = None
|
|
339
|
+
|
|
340
|
+
def transfer(self, data: Ar4NotifyData):
|
|
341
|
+
self.time_stamp = data.time_stamp
|
|
342
|
+
self.pkg_id = data.pkg_id
|
|
343
|
+
self.notify_id = data.notify_id
|
|
344
|
+
self.eeg_ch_count = data.eeg_ch_count
|
|
345
|
+
self.eeg_count = data.eeg_count
|
|
346
|
+
self.acc_ch_count = data.acc_ch_count
|
|
347
|
+
self.acc_count = data.acc_count
|
|
348
|
+
# 读eeg数据
|
|
349
|
+
if self.eeg_ch_count and self.eeg_count:
|
|
350
|
+
self.eeg = [[] for _ in range(self.eeg_ch_count)]
|
|
351
|
+
for i in range(self.eeg_ch_count):
|
|
352
|
+
self.eeg[i] = [data.eeg[j + (i * self.eeg_count)] for j in range(self.eeg_count)]
|
|
353
|
+
# 读acc数据
|
|
354
|
+
if self.acc_ch_count and self.acc_count:
|
|
355
|
+
self.acc = [[] for _ in range(self.acc_ch_count)]
|
|
356
|
+
for i in range(self.acc_ch_count):
|
|
357
|
+
self.acc[i] = [data.acc[j + (i * self.acc_count)] for j in range(self.acc_count)]
|
|
358
|
+
|
|
359
|
+
return self
|
|
360
|
+
|
|
361
|
+
def __str__(self):
|
|
362
|
+
return f"""
|
|
363
|
+
time_stamp: {self.time_stamp}
|
|
364
|
+
pkg_id: {self.pkg_id}
|
|
365
|
+
notify_id: {self.notify_id}
|
|
366
|
+
eeg_ch_count: {self.eeg_ch_count}
|
|
367
|
+
eeg_count: {self.eeg_count}
|
|
368
|
+
acc_ch_count: {self.acc_ch_count}
|
|
369
|
+
acc_count: {self.acc_count}
|
|
370
|
+
eeg: {self.eeg}
|
|
371
|
+
acc: {self.acc}
|
|
372
|
+
"""
|
qlsdk/ar4m/example.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from time import sleep
|
|
2
|
+
from loguru import logger
|
|
3
|
+
import os
|
|
4
|
+
from threading import Thread
|
|
5
|
+
|
|
6
|
+
from ar4m import AR4M
|
|
7
|
+
|
|
8
|
+
#------------------------------------------------------------------
|
|
9
|
+
# 日志文件配置
|
|
10
|
+
#------------------------------------------------------------------
|
|
11
|
+
LOG_DIR = os.path.expanduser("./logs")
|
|
12
|
+
LOG_FILE = os.path.join(LOG_DIR, "app_{time}.log")
|
|
13
|
+
if not os.path.exists(LOG_DIR):
|
|
14
|
+
os.mkdir(LOG_DIR)
|
|
15
|
+
|
|
16
|
+
logger.add(LOG_FILE, rotation = "50MB")
|
|
17
|
+
|
|
18
|
+
def consumer(q):
|
|
19
|
+
t = Thread(target=deal_data, args=(q,))
|
|
20
|
+
t.daemon = True
|
|
21
|
+
t.start()
|
|
22
|
+
|
|
23
|
+
def deal_data(q):
|
|
24
|
+
while True:
|
|
25
|
+
data = q.get()
|
|
26
|
+
if data is None:
|
|
27
|
+
break
|
|
28
|
+
logger.info(data)
|
|
29
|
+
|
|
30
|
+
# 主函数
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
try:
|
|
33
|
+
ar4m = AR4M()
|
|
34
|
+
ar4m.search()
|
|
35
|
+
sleep(6)
|
|
36
|
+
for dev in list( ar4m.devices.values()):
|
|
37
|
+
ret = dev.start_acquisition()
|
|
38
|
+
topic, queue = dev.subscribe()
|
|
39
|
+
logger.info(f"启动{dev.box_mac}的数据采集{'成功' if ret else '失败'}")
|
|
40
|
+
|
|
41
|
+
sleep(60)
|
|
42
|
+
|
|
43
|
+
for dev in list( ar4m.devices.values()):
|
|
44
|
+
ret = dev.stop_acquisition()
|
|
45
|
+
dev.get_acq_start_time()
|
|
46
|
+
logger.info(f"关闭{dev.box_mac}的数据采集{'成功' if ret else '失败'}")
|
|
47
|
+
sleep(1)
|
|
48
|
+
except Exception as e:
|
|
49
|
+
logger.error(f"程序运行异常: {str(e)}")
|
|
50
|
+
finally:
|
|
51
|
+
logger.info("程序结束。")
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: qlsdk2
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SDK for quanlan device
|
|
5
|
+
Home-page: https://github.com/hehuajun/qlsdk
|
|
6
|
+
Author: hehuajun
|
|
7
|
+
Author-email: hehuajun@eegion.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: loguru (>=0.6.0)
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest (>=6.0) ; extra == 'dev'
|
|
16
|
+
Requires-Dist: twine (>=3.0) ; extra == 'dev'
|
|
17
|
+
|
|
18
|
+
# qlsdk project
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Getting started
|
|
23
|
+
|
|
24
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
25
|
+
|
|
26
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
27
|
+
|
|
28
|
+
## Add your files
|
|
29
|
+
|
|
30
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
31
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
cd existing_repo
|
|
35
|
+
git remote add origin http://10.60.170.104/sw/qlsdk-project.git
|
|
36
|
+
git branch -M main
|
|
37
|
+
git push -uf origin main
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Integrate with your tools
|
|
41
|
+
|
|
42
|
+
- [ ] [Set up project integrations](http://10.60.170.104/sw/qlsdk-project/-/settings/integrations)
|
|
43
|
+
|
|
44
|
+
## Collaborate with your team
|
|
45
|
+
|
|
46
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
47
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
48
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
49
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
50
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
51
|
+
|
|
52
|
+
## Test and Deploy
|
|
53
|
+
|
|
54
|
+
Use the built-in continuous integration in GitLab.
|
|
55
|
+
|
|
56
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
|
57
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
58
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
59
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
60
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
61
|
+
|
|
62
|
+
***
|
|
63
|
+
|
|
64
|
+
# Editing this README
|
|
65
|
+
|
|
66
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
67
|
+
|
|
68
|
+
## Suggestions for a good README
|
|
69
|
+
|
|
70
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
71
|
+
|
|
72
|
+
## Name
|
|
73
|
+
Choose a self-explaining name for your project.
|
|
74
|
+
|
|
75
|
+
## Description
|
|
76
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
77
|
+
|
|
78
|
+
## Badges
|
|
79
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
80
|
+
|
|
81
|
+
## Visuals
|
|
82
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
86
|
+
|
|
87
|
+
## Usage
|
|
88
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
89
|
+
|
|
90
|
+
## Support
|
|
91
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
92
|
+
|
|
93
|
+
## Roadmap
|
|
94
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
98
|
+
|
|
99
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
100
|
+
|
|
101
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
102
|
+
|
|
103
|
+
## Authors and acknowledgment
|
|
104
|
+
Show your appreciation to those who have contributed to the project.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
For open source projects, say how it is licensed.
|
|
108
|
+
|
|
109
|
+
## Project status
|
|
110
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
qlsdk/__init__.py,sha256=XZgk2wAPmXoV-gxwOcGzOB9n9ZzY24GZ34a-eEDCgPk,416
|
|
2
|
+
qlsdk/ar4m/__init__.py,sha256=-vJiKDRJZKvl3cefwsdtRRYobvpuwdLuMhc669pmZvo,142
|
|
3
|
+
qlsdk/ar4m/ar4m.py,sha256=AOYvvo04dD0W4EMrKDCx63pUzwL1f_CVcM_N4rebhQc,1524
|
|
4
|
+
qlsdk/ar4m/ar4sdk.py,sha256=N79P-92qjxPvLN4iYjxQIz-Fe18YP6bGLsXLbDY4eIg,13933
|
|
5
|
+
qlsdk/ar4m/example.py,sha256=cm0HeRb53roKw5HYZ4uqnDZ6suaSUdqOW_hCTcGY8lo,1501
|
|
6
|
+
qlsdk2-0.1.0.dist-info/METADATA,sha256=fPaRevTP6tp4O708DlVBrZ5p-e5SoMGXrB_03R8Et6g,6806
|
|
7
|
+
qlsdk2-0.1.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
8
|
+
qlsdk2-0.1.0.dist-info/top_level.txt,sha256=2CHzn0SY-NIBVyBl07Suh-Eo8oBAQfyNPtqQ_aDatBg,6
|
|
9
|
+
qlsdk2-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
qlsdk
|