sensor-sdk 0.0.16__tar.gz → 0.0.18__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.
Potentially problematic release.
This version of sensor-sdk might be problematic. Click here for more details.
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/PKG-INFO +3 -3
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/README.md +2 -2
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/gforce.py +10 -10
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/sensor_controller.py +7 -7
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/sensor_data_context.py +10 -7
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/sensor_profile.py +9 -9
- sensor-sdk-0.0.16/sensor/utils.py → sensor-sdk-0.0.18/sensor/sensor_utils.py +10 -1
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/PKG-INFO +3 -3
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/SOURCES.txt +1 -1
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/setup.py +1 -1
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/LICENSE.txt +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/__init__.py +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/sensor_data.py +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor/sensor_device.py +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/dependency_links.txt +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/requires.txt +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/top_level.txt +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/sensor_sdk.egg-info/zip-safe +0 -0
- {sensor-sdk-0.0.16 → sensor-sdk-0.0.18}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sensor-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.18
|
|
4
4
|
Summary: Python sdk for Synchroni
|
|
5
5
|
Home-page: https://github.com/oymotion/SynchroniSDKPython
|
|
6
6
|
Author: Martin Ye
|
|
@@ -92,10 +92,10 @@ isScanning = SensorControllerInstance.isScanning
|
|
|
92
92
|
|
|
93
93
|
### 5. Check if bluetooth is enabled
|
|
94
94
|
|
|
95
|
-
Use `property
|
|
95
|
+
Use `property isEnable: bool` to check if bluetooth is enable
|
|
96
96
|
|
|
97
97
|
```python
|
|
98
|
-
|
|
98
|
+
isEnable = SensorControllerInstance.isEnable
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
### 6. Create SensorProfile
|
|
@@ -81,10 +81,10 @@ isScanning = SensorControllerInstance.isScanning
|
|
|
81
81
|
|
|
82
82
|
### 5. Check if bluetooth is enabled
|
|
83
83
|
|
|
84
|
-
Use `property
|
|
84
|
+
Use `property isEnable: bool` to check if bluetooth is enable
|
|
85
85
|
|
|
86
86
|
```python
|
|
87
|
-
|
|
87
|
+
isEnable = SensorControllerInstance.isEnable
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
### 6. Create SensorProfile
|
|
@@ -16,7 +16,7 @@ from bleak import (
|
|
|
16
16
|
BleakGATTCharacteristic,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
-
from sensor import
|
|
19
|
+
from sensor import sensor_utils
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
@dataclass
|
|
@@ -393,7 +393,7 @@ class GForce:
|
|
|
393
393
|
self._raw_data_buf = buf
|
|
394
394
|
|
|
395
395
|
try:
|
|
396
|
-
await asyncio.wait_for(client.connect(),
|
|
396
|
+
await asyncio.wait_for(client.connect(), sensor_utils._TIMEOUT)
|
|
397
397
|
except Exception as e:
|
|
398
398
|
return
|
|
399
399
|
|
|
@@ -404,12 +404,12 @@ class GForce:
|
|
|
404
404
|
if not self._is_universal_stream:
|
|
405
405
|
await asyncio.wait_for(
|
|
406
406
|
client.start_notify(self.cmd_char, self._on_cmd_response),
|
|
407
|
-
|
|
407
|
+
sensor_utils._TIMEOUT,
|
|
408
408
|
)
|
|
409
409
|
else:
|
|
410
410
|
await asyncio.wait_for(
|
|
411
411
|
client.start_notify(self.data_char, self._on_universal_response),
|
|
412
|
-
|
|
412
|
+
sensor_utils._TIMEOUT,
|
|
413
413
|
)
|
|
414
414
|
except Exception as e:
|
|
415
415
|
return
|
|
@@ -859,17 +859,17 @@ class GForce:
|
|
|
859
859
|
self.data_char,
|
|
860
860
|
lambda _, data: self._on_data_response(q, data),
|
|
861
861
|
),
|
|
862
|
-
|
|
862
|
+
sensor_utils._TIMEOUT,
|
|
863
863
|
)
|
|
864
864
|
|
|
865
865
|
async def stop_streaming(self):
|
|
866
866
|
exceptions = []
|
|
867
867
|
# try:
|
|
868
|
-
# await asyncio.wait_for(self.set_subscription(DataSubscription.OFF),
|
|
868
|
+
# await asyncio.wait_for(self.set_subscription(DataSubscription.OFF), sensor_utils._TIMEOUT)
|
|
869
869
|
# except Exception as e:
|
|
870
870
|
# exceptions.append(e)
|
|
871
871
|
try:
|
|
872
|
-
await asyncio.wait_for(self.client.stop_notify(self.data_char),
|
|
872
|
+
await asyncio.wait_for(self.client.stop_notify(self.data_char), sensor_utils._TIMEOUT)
|
|
873
873
|
except Exception as e:
|
|
874
874
|
exceptions.append(e)
|
|
875
875
|
|
|
@@ -879,7 +879,7 @@ class GForce:
|
|
|
879
879
|
async def disconnect(self):
|
|
880
880
|
with suppress(asyncio.CancelledError):
|
|
881
881
|
try:
|
|
882
|
-
await asyncio.wait_for(self.client.disconnect(),
|
|
882
|
+
await asyncio.wait_for(self.client.disconnect(), sensor_utils._TIMEOUT)
|
|
883
883
|
except Exception as e:
|
|
884
884
|
pass
|
|
885
885
|
|
|
@@ -896,12 +896,12 @@ class GForce:
|
|
|
896
896
|
bs = bytes([req.cmd])
|
|
897
897
|
if req.body is not None:
|
|
898
898
|
bs += req.body
|
|
899
|
-
await asyncio.wait_for(self.client.write_gatt_char(self.cmd_char, bs),
|
|
899
|
+
await asyncio.wait_for(self.client.write_gatt_char(self.cmd_char, bs), sensor_utils._TIMEOUT)
|
|
900
900
|
|
|
901
901
|
if not req.has_res:
|
|
902
902
|
return None
|
|
903
903
|
|
|
904
904
|
try:
|
|
905
|
-
return await asyncio.wait_for(q.get(),
|
|
905
|
+
return await asyncio.wait_for(q.get(), sensor_utils._TIMEOUT)
|
|
906
906
|
except Exception as e:
|
|
907
907
|
return None
|
|
@@ -6,10 +6,10 @@ from typing import Callable, Dict, List, Optional, Tuple
|
|
|
6
6
|
import bleak
|
|
7
7
|
|
|
8
8
|
from sensor import sensor_profile
|
|
9
|
-
from sensor import
|
|
9
|
+
from sensor import sensor_utils
|
|
10
10
|
from sensor.sensor_profile import DeviceStateEx, SensorProfile
|
|
11
11
|
|
|
12
|
-
from sensor.
|
|
12
|
+
from sensor.sensor_utils import async_call, sync_call, async_exec
|
|
13
13
|
from bleak import (
|
|
14
14
|
BleakScanner,
|
|
15
15
|
AdvertisementData,
|
|
@@ -52,13 +52,13 @@ class SensorController:
|
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
def terminate(self):
|
|
55
|
-
|
|
55
|
+
sensor_utils._terminated = True
|
|
56
56
|
|
|
57
57
|
for sensor in self._sensor_profiles.values():
|
|
58
58
|
if sensor.deviceState == DeviceStateEx.Connected or sensor.deviceState == DeviceStateEx.Ready:
|
|
59
59
|
sensor._destroy()
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
sensor_utils.Terminate()
|
|
62
62
|
|
|
63
63
|
def _match_device(self, _device: bleak.BLEDevice, adv: AdvertisementData):
|
|
64
64
|
if _device.name == None:
|
|
@@ -71,7 +71,7 @@ class SensorController:
|
|
|
71
71
|
return False
|
|
72
72
|
|
|
73
73
|
@property
|
|
74
|
-
def
|
|
74
|
+
def isScanning(self) -> bool:
|
|
75
75
|
"""
|
|
76
76
|
检查是否正在扫描。
|
|
77
77
|
|
|
@@ -181,13 +181,13 @@ class SensorController:
|
|
|
181
181
|
return await async_call(self._async_scan(period))
|
|
182
182
|
|
|
183
183
|
async def _device_scan_callback(self, devices: List[sensor_profile.BLEDevice]):
|
|
184
|
-
if self._device_callback:
|
|
184
|
+
if not sensor_utils._terminated and self._device_callback:
|
|
185
185
|
try:
|
|
186
186
|
asyncio.get_event_loop().run_in_executor(None, self._device_callback, devices)
|
|
187
187
|
except Exception as e:
|
|
188
188
|
print(e)
|
|
189
189
|
|
|
190
|
-
if self._is_scanning:
|
|
190
|
+
if not sensor_utils._terminated and self._is_scanning:
|
|
191
191
|
async_exec(self._startScan())
|
|
192
192
|
|
|
193
193
|
async def _startScan(self) -> bool:
|
|
@@ -7,7 +7,7 @@ import struct
|
|
|
7
7
|
from typing import Deque, List
|
|
8
8
|
from concurrent.futures import ThreadPoolExecutor
|
|
9
9
|
import csv
|
|
10
|
-
from sensor import
|
|
10
|
+
from sensor import sensor_utils
|
|
11
11
|
from sensor.gforce import DataSubscription, GForce, SamplingRate
|
|
12
12
|
from sensor.sensor_data import DataType, Sample, SensorData
|
|
13
13
|
|
|
@@ -391,7 +391,7 @@ class SensorProfileDataCtx:
|
|
|
391
391
|
sensorData = buf.get_nowait()
|
|
392
392
|
except Exception as e:
|
|
393
393
|
break
|
|
394
|
-
if sensorData != None and callback != None:
|
|
394
|
+
if not sensor_utils._terminated and sensorData != None and callback != None:
|
|
395
395
|
try:
|
|
396
396
|
asyncio.get_event_loop().run_in_executor(self.dataPool, callback, sensor, sensorData)
|
|
397
397
|
except Exception as e:
|
|
@@ -459,6 +459,8 @@ class SensorProfileDataCtx:
|
|
|
459
459
|
offset += 2
|
|
460
460
|
newPackageIndex = packageIndex
|
|
461
461
|
lastPackageIndex = sensorData.lastPackageIndex
|
|
462
|
+
if sensorData.lastPackageCounter == 0 and sensorData.lastPackageIndex == 0 and packageIndex > 1:
|
|
463
|
+
return False
|
|
462
464
|
|
|
463
465
|
if packageIndex < lastPackageIndex:
|
|
464
466
|
packageIndex += 65536 # 包索引是 U16 类型
|
|
@@ -477,7 +479,7 @@ class SensorProfileDataCtx:
|
|
|
477
479
|
+ str(lostSampleCount)
|
|
478
480
|
)
|
|
479
481
|
# print(lostLog)
|
|
480
|
-
if sensor._event_loop != None and sensor._on_error_callback != None:
|
|
482
|
+
if not sensor_utils._terminated and sensor._event_loop != None and sensor._on_error_callback != None:
|
|
481
483
|
try:
|
|
482
484
|
asyncio.get_event_loop().run_in_executor(None, sensor._on_error_callback, sensor, lostLog)
|
|
483
485
|
except Exception as e:
|
|
@@ -699,7 +701,7 @@ class SensorProfileDataCtx:
|
|
|
699
701
|
index += 1
|
|
700
702
|
continue
|
|
701
703
|
crc = self._concatDataBuffer[index + 1 + n + 1]
|
|
702
|
-
calc_crc =
|
|
704
|
+
calc_crc = sensor_utils.calc_crc8(self._concatDataBuffer[index + 2 : index + 2 + n])
|
|
703
705
|
if crc != calc_crc:
|
|
704
706
|
index += 1
|
|
705
707
|
continue
|
|
@@ -712,7 +714,7 @@ class SensorProfileDataCtx:
|
|
|
712
714
|
sensorData = buf.get_nowait()
|
|
713
715
|
except Exception as e:
|
|
714
716
|
break
|
|
715
|
-
if sensorData != None and callback != None:
|
|
717
|
+
if not sensor_utils._terminated and sensorData != None and callback != None:
|
|
716
718
|
try:
|
|
717
719
|
asyncio.get_event_loop().run_in_executor(self.dataPool, callback, sensor, sensorData)
|
|
718
720
|
except Exception as e:
|
|
@@ -730,12 +732,13 @@ class SensorProfileDataCtx:
|
|
|
730
732
|
index += 1
|
|
731
733
|
continue
|
|
732
734
|
crc = self._concatDataBuffer[index + 1 + n + 1]
|
|
733
|
-
calc_crc =
|
|
735
|
+
calc_crc = sensor_utils.calc_crc8(self._concatDataBuffer[index + 2 : index + 2 + n])
|
|
734
736
|
if crc != calc_crc:
|
|
735
737
|
index += 1
|
|
736
738
|
continue
|
|
737
739
|
data_package = bytes(self._concatDataBuffer[index + 2 : index + 2 + n])
|
|
738
|
-
|
|
740
|
+
if not sensor_utils._terminated:
|
|
741
|
+
asyncio.get_event_loop().run_in_executor(None, self.gForce._on_cmd_response, None, data_package)
|
|
739
742
|
last_cut = index = index + 2 + n
|
|
740
743
|
|
|
741
744
|
else:
|
|
@@ -10,7 +10,7 @@ from bleak import (
|
|
|
10
10
|
BleakClient,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
-
from sensor import
|
|
13
|
+
from sensor import sensor_utils
|
|
14
14
|
from sensor.gforce import GForce
|
|
15
15
|
from sensor.sensor_data import SensorData
|
|
16
16
|
import asyncio
|
|
@@ -18,7 +18,7 @@ import asyncio
|
|
|
18
18
|
|
|
19
19
|
from sensor.sensor_data_context import SensorProfileDataCtx
|
|
20
20
|
from sensor.sensor_device import BLEDevice, DeviceInfo, DeviceStateEx
|
|
21
|
-
from sensor.
|
|
21
|
+
from sensor.sensor_utils import async_call, sync_call, async_exec
|
|
22
22
|
|
|
23
23
|
SERVICE_GUID = "0000ffd0-0000-1000-8000-00805f9b34fb"
|
|
24
24
|
OYM_CMD_NOTIFY_CHAR_UUID = "f000ffe1-0451-4000-b000-000000000000"
|
|
@@ -212,7 +212,7 @@ class SensorProfile:
|
|
|
212
212
|
self._on_power_changed = callback
|
|
213
213
|
|
|
214
214
|
async def _connect(self) -> bool:
|
|
215
|
-
if
|
|
215
|
+
if sensor_utils._terminated:
|
|
216
216
|
return False
|
|
217
217
|
|
|
218
218
|
if self._event_loop == None:
|
|
@@ -292,7 +292,7 @@ class SensorProfile:
|
|
|
292
292
|
return await async_call(self._connect())
|
|
293
293
|
|
|
294
294
|
async def _waitForDisconnect(self) -> bool:
|
|
295
|
-
while not
|
|
295
|
+
while not sensor_utils._terminated and self.deviceState != DeviceStateEx.Disconnected:
|
|
296
296
|
await asyncio.sleep(1)
|
|
297
297
|
return True
|
|
298
298
|
|
|
@@ -303,7 +303,7 @@ class SensorProfile:
|
|
|
303
303
|
return False
|
|
304
304
|
self._set_device_state(DeviceStateEx.Disconnecting)
|
|
305
305
|
await self._gforce.disconnect()
|
|
306
|
-
await asyncio.wait_for(self._waitForDisconnect(),
|
|
306
|
+
await asyncio.wait_for(self._waitForDisconnect(), sensor_utils._TIMEOUT)
|
|
307
307
|
|
|
308
308
|
return True
|
|
309
309
|
|
|
@@ -393,7 +393,7 @@ class SensorProfile:
|
|
|
393
393
|
|
|
394
394
|
result = await self._data_ctx.stop_streaming()
|
|
395
395
|
self._is_starting = False
|
|
396
|
-
return
|
|
396
|
+
return result
|
|
397
397
|
|
|
398
398
|
def stopDataNotification(self) -> bool:
|
|
399
399
|
"""
|
|
@@ -422,12 +422,12 @@ class SensorProfile:
|
|
|
422
422
|
return await async_call(self._stopDataNotification())
|
|
423
423
|
|
|
424
424
|
async def _refresh_power(self):
|
|
425
|
-
while not
|
|
425
|
+
while not sensor_utils._terminated and self.deviceState == DeviceStateEx.Ready:
|
|
426
426
|
await asyncio.sleep(self._power_interval / 1000)
|
|
427
427
|
|
|
428
428
|
self._power = await self._gforce.get_battery_level()
|
|
429
429
|
|
|
430
|
-
if self._event_loop != None and self._on_power_changed != None:
|
|
430
|
+
if not sensor_utils._terminated and self._event_loop != None and self._on_power_changed != None:
|
|
431
431
|
try:
|
|
432
432
|
asyncio.get_event_loop().run_in_executor(None, self._on_power_changed, self, self._power)
|
|
433
433
|
except Exception as e:
|
|
@@ -443,7 +443,7 @@ class SensorProfile:
|
|
|
443
443
|
|
|
444
444
|
if await self._data_ctx.init(packageSampleCount):
|
|
445
445
|
self._power_interval = powerRefreshInterval
|
|
446
|
-
|
|
446
|
+
sensor_utils.async_exec(self._refresh_power())
|
|
447
447
|
|
|
448
448
|
return self._data_ctx.hasInit()
|
|
449
449
|
|
|
@@ -25,10 +25,18 @@ def checkRunLoop():
|
|
|
25
25
|
_event_thread.daemon = True
|
|
26
26
|
_event_thread.name = "SensorController event"
|
|
27
27
|
_event_thread.start()
|
|
28
|
+
time.sleep(0.1)
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
def Terminate():
|
|
31
|
-
global _runloop, _needCloseRunloop, _event_thread
|
|
32
|
+
global _runloop, _needCloseRunloop, _event_thread, _terminated
|
|
33
|
+
_terminated = True
|
|
34
|
+
try:
|
|
35
|
+
for task in asyncio.all_tasks():
|
|
36
|
+
task.cancel()
|
|
37
|
+
except Exception as e:
|
|
38
|
+
pass
|
|
39
|
+
|
|
32
40
|
if _needCloseRunloop:
|
|
33
41
|
try:
|
|
34
42
|
_runloop.stop()
|
|
@@ -85,6 +93,7 @@ async def async_call(function, _timeout=_TIMEOUT) -> any:
|
|
|
85
93
|
|
|
86
94
|
|
|
87
95
|
def start_loop(loop: asyncio.BaseEventLoop):
|
|
96
|
+
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
88
97
|
asyncio.set_event_loop(loop)
|
|
89
98
|
loop.run_forever()
|
|
90
99
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sensor-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.18
|
|
4
4
|
Summary: Python sdk for Synchroni
|
|
5
5
|
Home-page: https://github.com/oymotion/SynchroniSDKPython
|
|
6
6
|
Author: Martin Ye
|
|
@@ -92,10 +92,10 @@ isScanning = SensorControllerInstance.isScanning
|
|
|
92
92
|
|
|
93
93
|
### 5. Check if bluetooth is enabled
|
|
94
94
|
|
|
95
|
-
Use `property
|
|
95
|
+
Use `property isEnable: bool` to check if bluetooth is enable
|
|
96
96
|
|
|
97
97
|
```python
|
|
98
|
-
|
|
98
|
+
isEnable = SensorControllerInstance.isEnable
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
### 6. Create SensorProfile
|
|
@@ -8,7 +8,7 @@ with open(os.path.join(this_directory, "README.md"), "r", encoding="utf-8") as f
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="sensor-sdk",
|
|
11
|
-
version="0.0.
|
|
11
|
+
version="0.0.18",
|
|
12
12
|
description="Python sdk for Synchroni",
|
|
13
13
|
long_description=long_description,
|
|
14
14
|
long_description_content_type="text/markdown",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|