sensor-sdk 0.0.13__py3-none-any.whl → 0.0.15__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.
Potentially problematic release.
This version of sensor-sdk might be problematic. Click here for more details.
- sensor/gforce.py +4 -4
- sensor/sensor_data_context.py +34 -20
- sensor/sensor_profile.py +57 -11
- {sensor_sdk-0.0.13.dist-info → sensor_sdk-0.0.15.dist-info}/METADATA +1 -1
- sensor_sdk-0.0.15.dist-info/RECORD +14 -0
- sensor_sdk-0.0.13.dist-info/RECORD +0 -14
- {sensor_sdk-0.0.13.dist-info → sensor_sdk-0.0.15.dist-info}/LICENSE.txt +0 -0
- {sensor_sdk-0.0.13.dist-info → sensor_sdk-0.0.15.dist-info}/WHEEL +0 -0
- {sensor_sdk-0.0.13.dist-info → sensor_sdk-0.0.15.dist-info}/top_level.txt +0 -0
- {sensor_sdk-0.0.13.dist-info → sensor_sdk-0.0.15.dist-info}/zip-safe +0 -0
sensor/gforce.py
CHANGED
|
@@ -853,10 +853,10 @@ class GForce:
|
|
|
853
853
|
|
|
854
854
|
async def stop_streaming(self):
|
|
855
855
|
exceptions = []
|
|
856
|
-
try:
|
|
857
|
-
|
|
858
|
-
except Exception as e:
|
|
859
|
-
|
|
856
|
+
# try:
|
|
857
|
+
# await asyncio.wait_for(self.set_subscription(DataSubscription.OFF), utils._TIMEOUT)
|
|
858
|
+
# except Exception as e:
|
|
859
|
+
# exceptions.append(e)
|
|
860
860
|
try:
|
|
861
861
|
await asyncio.wait_for(self.client.stop_notify(self.data_char), utils._TIMEOUT)
|
|
862
862
|
except Exception as e:
|
sensor/sensor_data_context.py
CHANGED
|
@@ -274,12 +274,15 @@ class SensorProfileDataCtx:
|
|
|
274
274
|
return True
|
|
275
275
|
self._is_data_transfering = True
|
|
276
276
|
self._rawDataBuffer.queue.clear()
|
|
277
|
+
self._concatDataBuffer.clear()
|
|
278
|
+
self.clear()
|
|
279
|
+
|
|
277
280
|
if not self.isUniversalStream:
|
|
278
281
|
await self.gForce.start_streaming(self._rawDataBuffer)
|
|
279
|
-
return True
|
|
280
282
|
else:
|
|
281
283
|
await self.gForce.set_subscription(self.notifyDataFlag)
|
|
282
|
-
|
|
284
|
+
|
|
285
|
+
return True
|
|
283
286
|
|
|
284
287
|
async def stop_streaming(self) -> bool:
|
|
285
288
|
if not self._is_data_transfering:
|
|
@@ -287,12 +290,21 @@ class SensorProfileDataCtx:
|
|
|
287
290
|
|
|
288
291
|
self._is_data_transfering = False
|
|
289
292
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
try:
|
|
294
|
+
|
|
295
|
+
if not self.isUniversalStream:
|
|
296
|
+
await self.gForce.stop_streaming()
|
|
297
|
+
else:
|
|
298
|
+
await self.gForce.set_subscription(0)
|
|
299
|
+
|
|
300
|
+
while self._is_running and not self._rawDataBuffer.empty():
|
|
301
|
+
await asyncio.sleep(0.1)
|
|
302
|
+
|
|
303
|
+
except Exception as e:
|
|
304
|
+
print(e)
|
|
305
|
+
return False
|
|
306
|
+
|
|
307
|
+
return True
|
|
296
308
|
|
|
297
309
|
async def setFilter(self, filter: str, value: str) -> str:
|
|
298
310
|
self.filter_map[filter] = value
|
|
@@ -313,6 +325,7 @@ class SensorProfileDataCtx:
|
|
|
313
325
|
switch |= 8
|
|
314
326
|
try:
|
|
315
327
|
await self.gForce.set_firmware_filter_switch(switch)
|
|
328
|
+
await asyncio.sleep(0.1)
|
|
316
329
|
return "OK"
|
|
317
330
|
except Exception as e:
|
|
318
331
|
return "ERROR: " + str(e)
|
|
@@ -342,22 +355,23 @@ class SensorProfileDataCtx:
|
|
|
342
355
|
except Exception as e:
|
|
343
356
|
continue
|
|
344
357
|
|
|
345
|
-
self.
|
|
358
|
+
if self.isDataTransfering:
|
|
359
|
+
self._processDataPackage(data, buf, sensor)
|
|
346
360
|
self._rawDataBuffer.task_done()
|
|
347
361
|
|
|
348
|
-
|
|
349
|
-
|
|
362
|
+
while self._is_running and self.isDataTransfering and not buf.empty():
|
|
363
|
+
sensorData: SensorData = None
|
|
364
|
+
try:
|
|
365
|
+
sensorData = buf.get_nowait()
|
|
366
|
+
except Exception as e:
|
|
367
|
+
break
|
|
368
|
+
if sensorData != None and callback != None:
|
|
350
369
|
try:
|
|
351
|
-
|
|
370
|
+
asyncio.get_event_loop().run_in_executor(self.dataPool, callback, sensor, sensorData)
|
|
352
371
|
except Exception as e:
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
asyncio.get_event_loop().run_in_executor(self.dataPool, callback, sensor, sensorData)
|
|
357
|
-
except Exception as e:
|
|
358
|
-
print(e)
|
|
359
|
-
|
|
360
|
-
buf.task_done()
|
|
372
|
+
print(e)
|
|
373
|
+
|
|
374
|
+
buf.task_done()
|
|
361
375
|
|
|
362
376
|
def _processDataPackage(self, data: bytes, buf: Queue[SensorData], sensor):
|
|
363
377
|
v = data[0]
|
sensor/sensor_profile.py
CHANGED
|
@@ -61,6 +61,8 @@ class SensorProfile:
|
|
|
61
61
|
self._gforce: GForce = None
|
|
62
62
|
self._data_event_loop: asyncio.AbstractEventLoop = None
|
|
63
63
|
self._event_loop: asyncio.AbstractEventLoop = None
|
|
64
|
+
self._is_starting = False
|
|
65
|
+
self._is_setting_param = False
|
|
64
66
|
|
|
65
67
|
def __del__(self) -> None:
|
|
66
68
|
"""
|
|
@@ -239,6 +241,8 @@ class SensorProfile:
|
|
|
239
241
|
self._data_ctx = SensorProfileDataCtx(self._gforce, self._device.Address, self._raw_data_buf)
|
|
240
242
|
if self._data_ctx.isUniversalStream:
|
|
241
243
|
async_exec(self._process_universal_data())
|
|
244
|
+
else:
|
|
245
|
+
async_exec(self._process_data())
|
|
242
246
|
|
|
243
247
|
if self.deviceState == DeviceStateEx.Connected or self.deviceState == DeviceStateEx.Ready:
|
|
244
248
|
return True
|
|
@@ -288,7 +292,7 @@ class SensorProfile:
|
|
|
288
292
|
return await async_call(self._connect())
|
|
289
293
|
|
|
290
294
|
async def _waitForDisconnect(self) -> bool:
|
|
291
|
-
while self.deviceState != DeviceStateEx.Disconnected:
|
|
295
|
+
while not utils._terminated and self.deviceState != DeviceStateEx.Disconnected:
|
|
292
296
|
await asyncio.sleep(1)
|
|
293
297
|
return True
|
|
294
298
|
|
|
@@ -341,11 +345,13 @@ class SensorProfile:
|
|
|
341
345
|
if self._data_event_loop == None:
|
|
342
346
|
self._data_event_loop = asyncio.new_event_loop()
|
|
343
347
|
|
|
344
|
-
|
|
348
|
+
self._raw_data_buf.queue.clear()
|
|
345
349
|
self._data_buffer.queue.clear()
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
|
|
351
|
+
result = await self._data_ctx.start_streaming()
|
|
352
|
+
await asyncio.sleep(0.2)
|
|
353
|
+
|
|
354
|
+
self._is_starting = False
|
|
349
355
|
return result
|
|
350
356
|
|
|
351
357
|
def startDataNotification(self) -> bool:
|
|
@@ -355,6 +361,10 @@ class SensorProfile:
|
|
|
355
361
|
:return: bool: 如果开始数据通知成功,返回 True;否则返回 False。
|
|
356
362
|
|
|
357
363
|
"""
|
|
364
|
+
if self._is_starting:
|
|
365
|
+
return False
|
|
366
|
+
|
|
367
|
+
self._is_starting = True
|
|
358
368
|
return sync_call(self._startDataNotification())
|
|
359
369
|
|
|
360
370
|
async def asyncStartDataNotification(self) -> bool:
|
|
@@ -364,6 +374,10 @@ class SensorProfile:
|
|
|
364
374
|
:return: bool: 如果开始数据通知成功,返回 True;否则返回 False。
|
|
365
375
|
|
|
366
376
|
"""
|
|
377
|
+
if self._is_starting:
|
|
378
|
+
return False
|
|
379
|
+
|
|
380
|
+
self._is_starting = True
|
|
367
381
|
return await async_call(self._startDataNotification())
|
|
368
382
|
|
|
369
383
|
async def _stopDataNotification(self) -> bool:
|
|
@@ -377,7 +391,9 @@ class SensorProfile:
|
|
|
377
391
|
if not self._data_ctx.isDataTransfering:
|
|
378
392
|
return True
|
|
379
393
|
|
|
380
|
-
|
|
394
|
+
result = await self._data_ctx.stop_streaming()
|
|
395
|
+
self._is_starting = False
|
|
396
|
+
return not result
|
|
381
397
|
|
|
382
398
|
def stopDataNotification(self) -> bool:
|
|
383
399
|
"""
|
|
@@ -386,6 +402,10 @@ class SensorProfile:
|
|
|
386
402
|
:return: bool: 如果停止数据通知成功,返回 True;否则返回 False。
|
|
387
403
|
|
|
388
404
|
"""
|
|
405
|
+
if self._is_starting:
|
|
406
|
+
return False
|
|
407
|
+
|
|
408
|
+
self._is_starting = True
|
|
389
409
|
return sync_call(self._stopDataNotification())
|
|
390
410
|
|
|
391
411
|
async def asyncStopDataNotification(self) -> bool:
|
|
@@ -395,6 +415,10 @@ class SensorProfile:
|
|
|
395
415
|
:return: bool: 如果停止数据通知成功,返回 True;否则返回 False。
|
|
396
416
|
|
|
397
417
|
"""
|
|
418
|
+
if self._is_starting:
|
|
419
|
+
return False
|
|
420
|
+
|
|
421
|
+
self._is_starting = True
|
|
398
422
|
return await async_call(self._stopDataNotification())
|
|
399
423
|
|
|
400
424
|
async def _refresh_power(self):
|
|
@@ -474,21 +498,35 @@ class SensorProfile:
|
|
|
474
498
|
return None
|
|
475
499
|
|
|
476
500
|
async def _setParam(self, key: str, value: str) -> str:
|
|
501
|
+
result = "Error: Not supported"
|
|
477
502
|
if self.deviceState != DeviceStateEx.Ready:
|
|
478
|
-
|
|
503
|
+
result = "Error: Please connect first"
|
|
479
504
|
|
|
480
505
|
if key in ["NTF_EMG", "NTF_EEG", "NTF_ECG", "NTF_IMU", "NTF_BRTH"]:
|
|
481
506
|
if value in ["ON", "OFF"]:
|
|
482
507
|
self._data_ctx.init_map[key] = value
|
|
483
|
-
|
|
508
|
+
result = "OK"
|
|
484
509
|
|
|
485
510
|
if key in ["FILTER_50Hz", "FILTER_60Hz", "FILTER_HPF", "FILTER_LPF"]:
|
|
486
511
|
if value in ["ON", "OFF"]:
|
|
487
|
-
|
|
512
|
+
needPauseTransfer = self.isDataTransfering
|
|
513
|
+
if needPauseTransfer:
|
|
514
|
+
if self._is_starting:
|
|
515
|
+
self._is_setting_param = False
|
|
516
|
+
return "Error: Please pause data transfer first"
|
|
517
|
+
|
|
518
|
+
self._is_starting = True
|
|
519
|
+
await self._stopDataNotification()
|
|
520
|
+
result = await self._data_ctx.setFilter(key, value)
|
|
521
|
+
if needPauseTransfer:
|
|
522
|
+
self._is_starting = True
|
|
523
|
+
await self._startDataNotification()
|
|
488
524
|
|
|
489
525
|
if key == "DEBUG_BLE_DATA_PATH":
|
|
490
|
-
|
|
491
|
-
|
|
526
|
+
result = await self._data_ctx.setDebugCSV(value)
|
|
527
|
+
|
|
528
|
+
self._is_setting_param = False
|
|
529
|
+
return result
|
|
492
530
|
|
|
493
531
|
def setParam(self, key: str, value: str) -> str:
|
|
494
532
|
"""
|
|
@@ -500,6 +538,10 @@ class SensorProfile:
|
|
|
500
538
|
:return: str: 设置参数的结果。
|
|
501
539
|
|
|
502
540
|
"""
|
|
541
|
+
if self._is_setting_param:
|
|
542
|
+
return "Error: Please wait for the previous operation to complete"
|
|
543
|
+
|
|
544
|
+
self._is_setting_param = True
|
|
503
545
|
return sync_call(
|
|
504
546
|
self._setParam(key, value),
|
|
505
547
|
20,
|
|
@@ -515,6 +557,10 @@ class SensorProfile:
|
|
|
515
557
|
:return: str: 设置参数的结果。
|
|
516
558
|
|
|
517
559
|
"""
|
|
560
|
+
if self._is_setting_param:
|
|
561
|
+
return "Error: Please wait for the previous operation to complete"
|
|
562
|
+
|
|
563
|
+
self._is_setting_param = True
|
|
518
564
|
return await async_call(
|
|
519
565
|
self._setParam(key, value),
|
|
520
566
|
20,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
sensor/__init__.py,sha256=L1VyAP0EDEnJIMeMTzp4iXHSRUUHyHScF_GIl3iYKRI,123
|
|
2
|
+
sensor/gforce.py,sha256=wZ4aEFtrgeR8LsL7tm6VSsjvIVcWbfQhwAVfADveNkg,25761
|
|
3
|
+
sensor/sensor_controller.py,sha256=qnM9mVwpJn9PCnxlvbgWFeaLktqVnmaquZgasYGEHqs,9451
|
|
4
|
+
sensor/sensor_data.py,sha256=Hu7Ql0LgQ7V24xYZhaLrKPwU4KWZeWE655v8Gy8xphY,3934
|
|
5
|
+
sensor/sensor_data_context.py,sha256=rxttt7f1BQOM2lUFys_po4BICdVl-NmIHKfnqGKs5XE,28815
|
|
6
|
+
sensor/sensor_device.py,sha256=eO1vaqjxCc2UCPBoKXqlk6o498uRyWt6IYs7r7wXSD0,3042
|
|
7
|
+
sensor/sensor_profile.py,sha256=NJsPr9l4VB9zAjfkaD28chGnJiSCnYAGFdkkN9Wyky0,19669
|
|
8
|
+
sensor/utils.py,sha256=BudTD083ucGxcTXfmksF-2gLRi_i-k7tMytruLUUKJc,6503
|
|
9
|
+
sensor_sdk-0.0.15.dist-info/LICENSE.txt,sha256=8CSivOpub3IuXODTyqBRI91AxouJZk02YrcKuOAkWu8,1111
|
|
10
|
+
sensor_sdk-0.0.15.dist-info/METADATA,sha256=D2Zk6zQPs3XrYYVdt_ROBT-PNZaIi_EhCgFZ9iqtwb4,9825
|
|
11
|
+
sensor_sdk-0.0.15.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
12
|
+
sensor_sdk-0.0.15.dist-info/top_level.txt,sha256=Ftq49B6bH0Ffdc7c8LkcyakHo6lsg_snlBbpEUoILSk,7
|
|
13
|
+
sensor_sdk-0.0.15.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
14
|
+
sensor_sdk-0.0.15.dist-info/RECORD,,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
sensor/__init__.py,sha256=L1VyAP0EDEnJIMeMTzp4iXHSRUUHyHScF_GIl3iYKRI,123
|
|
2
|
-
sensor/gforce.py,sha256=QsbHhTieVKMJ_KHn7nEchh7sChZWL-iSP0LmfxhYYXw,25753
|
|
3
|
-
sensor/sensor_controller.py,sha256=qnM9mVwpJn9PCnxlvbgWFeaLktqVnmaquZgasYGEHqs,9451
|
|
4
|
-
sensor/sensor_data.py,sha256=Hu7Ql0LgQ7V24xYZhaLrKPwU4KWZeWE655v8Gy8xphY,3934
|
|
5
|
-
sensor/sensor_data_context.py,sha256=a45WJPE-8-CzzMn9BlCjjC39fiIxkjV-UQw2Rok-OyM,28536
|
|
6
|
-
sensor/sensor_device.py,sha256=eO1vaqjxCc2UCPBoKXqlk6o498uRyWt6IYs7r7wXSD0,3042
|
|
7
|
-
sensor/sensor_profile.py,sha256=qxjTYt7X45rmVcapI93ynB4dTFLLt0M-WKCp-cpqKrM,18167
|
|
8
|
-
sensor/utils.py,sha256=BudTD083ucGxcTXfmksF-2gLRi_i-k7tMytruLUUKJc,6503
|
|
9
|
-
sensor_sdk-0.0.13.dist-info/LICENSE.txt,sha256=8CSivOpub3IuXODTyqBRI91AxouJZk02YrcKuOAkWu8,1111
|
|
10
|
-
sensor_sdk-0.0.13.dist-info/METADATA,sha256=6hKH69-rbvoswQ9LGvPVcGiY0v8qKKN9rfiVXjX0hLs,9825
|
|
11
|
-
sensor_sdk-0.0.13.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
12
|
-
sensor_sdk-0.0.13.dist-info/top_level.txt,sha256=Ftq49B6bH0Ffdc7c8LkcyakHo6lsg_snlBbpEUoILSk,7
|
|
13
|
-
sensor_sdk-0.0.13.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
14
|
-
sensor_sdk-0.0.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|