qlsdk2 0.1.5__tar.gz → 0.1.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: qlsdk2
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: SDK for quanlan device
5
5
  Home-page: https://github.com/hehuajun/qlsdk
6
6
  Author: hehuajun
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
6
6
 
7
7
  setuptools.setup(
8
8
  name="qlsdk2",
9
- version="0.1.5",
9
+ version="0.1.7",
10
10
  author="hehuajun",
11
11
  author_email="hehuajun@eegion.com",
12
12
  description="SDK for quanlan device",
@@ -33,15 +33,17 @@ class AR4M(object):
33
33
  def _search_ar4(self):
34
34
  try:
35
35
  devices = AR4SDK.enum_devices()
36
- logger.debug(f"_search_ar4 devices size: {len(devices)}")
36
+ # logger.debug(f"_search_ar4 devices size: {len(devices)}")
37
37
  for dev in devices:
38
- logger.debug(f"slot: {dev.slot}, mac: {dev.mac}-{hex(dev.mac)}, hub_name: {dev.hub_name.str}")
38
+ # logger.debug(f"slot: {dev.slot}, mac: {dev.mac}-{hex(dev.mac)}, hub_name: {dev.hub_name.str}")
39
39
  if dev.mac in list(self._devices.keys()):
40
40
  ar4 = self._devices[dev.mac]
41
41
  ar4.update_info()
42
- ar4 = AR4(hex(dev.mac), dev.slot, dev.hub_name.str)
43
- if ar4.init():
44
- self._devices[dev.mac] = ar4
42
+ else:
43
+ ar4 = AR4(hex(dev.mac), dev.slot, dev.hub_name.str.decode("utf-8"))
44
+ if ar4.init():
45
+ self._devices[dev.mac] = ar4
46
+ logger.info(f"add device mac: {ar4.box_mac} slot: {ar4.slot} hub_name: {ar4.hub_name}")
45
47
  except Exception as e:
46
48
  logger.error(f"_search_ar4 异常: {str(e)}")
47
49
  finally:
@@ -108,13 +108,19 @@ class AR4SDK:
108
108
  """枚举可用设备"""
109
109
  devices = []
110
110
  ptr = _dll.ar4_sdk_enum_device()
111
+ if not ptr:
112
+ logger.info("没有找到ar4设备")
113
+ return devices
111
114
 
112
- while ptr and ptr.contents.mac != 0:
113
- devices.append(ptr.contents)
114
- ptr = ptr[1]
115
- if isinstance(ptr, Ar4Device):
116
- logger.debug(f"enum_devices break with {ptr}")
115
+ index = 0
116
+ while True:
117
+ device = ptr[index]
118
+ if not device or device.mac == 0:
117
119
  break
120
+ # logger.debug(f"get device: {device.slot}, mac: {hex(device.mac)}, hub_name: {device.hub_name.str}")
121
+ devices.append(device)
122
+ index += 1
123
+
118
124
  return devices
119
125
 
120
126
  @classmethod
@@ -140,7 +146,7 @@ def _get_time():
140
146
 
141
147
  # ar4设备对象
142
148
  class AR4(object):
143
- def __init__(self, box_mac, slot, hub_name):
149
+ def __init__(self, box_mac:str, slot:int, hub_name:str):
144
150
  self._handle = None
145
151
  self._box_type = None
146
152
  self._box_mac = box_mac
@@ -159,9 +165,11 @@ class AR4(object):
159
165
  self._connected = False
160
166
  self._conn_time = None
161
167
  self._last_time = None
168
+
169
+ self._acq_info = {}
162
170
  # 回调函数
163
171
  self._data_callback = FuncAr4DataNotify(self._wrap_data_accept())
164
- self._trigger_callback = FuncAr4TriggerNotify(self._trigger_accept)
172
+ self._trigger_callback = FuncAr4TriggerNotify(self._wrap_trigger_accept())
165
173
 
166
174
  # 消息订阅
167
175
  self._consumers: dict[str, Queue] = {}
@@ -169,7 +177,14 @@ class AR4(object):
169
177
  @property
170
178
  def box_mac(self):
171
179
  return self._box_mac
180
+ @property
181
+ def slot(self):
182
+ return self._slot
183
+ @property
184
+ def hub_name(self):
185
+ return self._hub_name
172
186
  def init(self):
187
+ # logger.info(f"init ar4 {self.box_mac}")
173
188
  if not self._handle:
174
189
  self._connected = self.connect()
175
190
  if self._connected:
@@ -226,6 +241,8 @@ class AR4(object):
226
241
  logger.info(f"ar4 {self._box_mac} 启动数据采集...")
227
242
  """启动数据采集"""
228
243
 
244
+ self._acq_info["start_time"] = _get_time()
245
+
229
246
  if self._handle:
230
247
  # 设置信号数据回调
231
248
  try:
@@ -234,10 +251,10 @@ class AR4(object):
234
251
  logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
235
252
 
236
253
  # 设置trigger数据回调
237
- try:
238
- _dll.ar4_sdk_register_trigger_notify(self._handle, self._trigger_callback)
239
- except Exception as e:
240
- logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
254
+ # try:
255
+ # _dll.ar4_sdk_register_trigger_notify(self._handle, self._trigger_callback)
256
+ # except Exception as e:
257
+ # logger.error(f"ar4 {self._box_mac} 停止采集异常: {str(e)}")
241
258
  # 启动采集
242
259
  try:
243
260
  logger.debug(f"ar4 {self._box_mac} 启动采集: {self._handle}")
@@ -254,6 +271,10 @@ class AR4(object):
254
271
  def stop_acquisition(self):
255
272
  """停止采集"""
256
273
  if self._handle:
274
+ try:
275
+ self.get_acq_start_time()
276
+ except Exception as e:
277
+ logger.error(f"ar4 {self._box_mac} 获取开始采集时间异常: {str(e)}")
257
278
  try:
258
279
  return _dll.ar4_sdk_stop_acq(self._handle) == 0
259
280
  except Exception as e:
@@ -276,6 +297,9 @@ class AR4(object):
276
297
  def get_acq_start_time(self):
277
298
  try:
278
299
  ret = _dll.ar4_sdk_get_acq_start_time(self._handle)
300
+ # 更新采样开始时间
301
+ if ret:
302
+ self._acq_info["start_time"] = ret
279
303
  logger.debug(f"ar4 {self._box_mac} 获取采样开始时间: {ret}")
280
304
  except Exception as e:
281
305
  logger.error(f"ar4 {self._box_mac} 获取采样开始时间异常: {str(e)}")
@@ -308,6 +332,14 @@ class AR4(object):
308
332
  for consumer in self._consumers.values():
309
333
  consumer.put(packet)
310
334
  # logger.debug(f"EEG数据: {packet}")
335
+
336
+ def _wrap_trigger_accept(self):
337
+
338
+ @FuncAr4DataNotify
339
+ def trigger_accept(handle, time_ms, trigger_type, trigger_value):
340
+ self._trigger_accept(time_ms, trigger_type, trigger_value)
341
+
342
+ return trigger_accept
311
343
 
312
344
  def _trigger_accept(self, time_ms, trigger_type, trigger_value):
313
345
  logger.info(f"_trigger_accept 被调用")
@@ -351,9 +383,12 @@ class AR4Packet(Packet):
351
383
  self.acc_count = data.acc_count
352
384
  # 读eeg数据
353
385
  if self.eeg_ch_count and self.eeg_count:
354
- self.eeg = [[] for _ in range(self.eeg_ch_count)]
355
- for i in range(self.eeg_ch_count):
356
- self.eeg[i] = [data.eeg[j + (i * self.eeg_count)] for j in range(self.eeg_count)]
386
+ # self.eeg = [[] for _ in range(self.eeg_ch_count)]
387
+ # for i in range(self.eeg_ch_count):
388
+ # self.eeg[i] = [data.eeg[j + (i * self.eeg_count)] for j in range(self.eeg_count)]
389
+ # tmp = data.eeg[:self.eeg_ch_count * self.eeg_count]
390
+ # logger.info(tmp)
391
+ self.eeg = [data.eeg[i:self.eeg_count*self.eeg_ch_count:self.eeg_ch_count] for i in range(self.eeg_ch_count)]
357
392
  # 读acc数据
358
393
  if self.acc_ch_count and self.acc_count:
359
394
  self.acc = [[] for _ in range(self.acc_ch_count)]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: qlsdk2
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: SDK for quanlan device
5
5
  Home-page: https://github.com/hehuajun/qlsdk
6
6
  Author: hehuajun
File without changes
File without changes
File without changes
File without changes