sensor-sdk 0.0.6__tar.gz → 0.0.8__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sensor-sdk
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: Python sdk for Synchroni
5
5
  Home-page: https://github.com/oymotion/SynchroniSDKPython
6
6
  Author: Martin Ye
@@ -370,9 +370,7 @@ class Response:
370
370
 
371
371
 
372
372
  class GForce:
373
- def __init__(
374
- self, device: BLEDevice, cmd_char: str, data_char: str, isUniversalStream: bool
375
- ):
373
+ def __init__(self, device: BLEDevice, cmd_char: str, data_char: str, isUniversalStream: bool):
376
374
  self.device_name = ""
377
375
  self.client = None
378
376
  self.cmd_char = cmd_char
@@ -412,6 +410,7 @@ class GForce:
412
410
 
413
411
  def _on_data_response(self, q: Queue[bytes], bs: bytearray):
414
412
  bs = bytes(bs)
413
+
415
414
  full_packet = []
416
415
 
417
416
  is_partial_data = bs[0] == ResponseCode.PARTIAL_PACKET
@@ -500,9 +499,7 @@ class GForce:
500
499
  def _convert_acceleration_to_g(data: bytes) -> np.ndarray[np.float32]:
501
500
  normalizing_factor = 65536.0
502
501
 
503
- acceleration_data = (
504
- np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
505
- )
502
+ acceleration_data = np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
506
503
  num_channels = 3
507
504
 
508
505
  return acceleration_data.reshape(-1, num_channels)
@@ -511,9 +508,7 @@ class GForce:
511
508
  def _convert_gyro_to_dps(data: bytes) -> np.ndarray[np.float32]:
512
509
  normalizing_factor = 65536.0
513
510
 
514
- gyro_data = (
515
- np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
516
- )
511
+ gyro_data = np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
517
512
  num_channels = 3
518
513
 
519
514
  return gyro_data.reshape(-1, num_channels)
@@ -522,9 +517,7 @@ class GForce:
522
517
  def _convert_magnetometer_to_ut(data: bytes) -> np.ndarray[np.float32]:
523
518
  normalizing_factor = 65536.0
524
519
 
525
- magnetometer_data = (
526
- np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
527
- )
520
+ magnetometer_data = np.frombuffer(data, dtype=np.int32).astype(np.float32) / normalizing_factor
528
521
  num_channels = 3
529
522
 
530
523
  return magnetometer_data.reshape(-1, num_channels)
@@ -846,15 +839,11 @@ class GForce:
846
839
  async def stop_streaming(self):
847
840
  exceptions = []
848
841
  try:
849
- await asyncio.wait_for(
850
- self.set_subscription(DataSubscription.OFF), utils._TIMEOUT
851
- )
842
+ await asyncio.wait_for(self.set_subscription(DataSubscription.OFF), utils._TIMEOUT)
852
843
  except Exception as e:
853
844
  exceptions.append(e)
854
845
  try:
855
- await asyncio.wait_for(
856
- self.client.stop_notify(self.data_char), utils._TIMEOUT
857
- )
846
+ await asyncio.wait_for(self.client.stop_notify(self.data_char), utils._TIMEOUT)
858
847
  except Exception as e:
859
848
  exceptions.append(e)
860
849
 
@@ -881,9 +870,7 @@ class GForce:
881
870
  bs = bytes([req.cmd])
882
871
  if req.body is not None:
883
872
  bs += req.body
884
- await asyncio.wait_for(
885
- self.client.write_gatt_char(self.cmd_char, bs), utils._TIMEOUT
886
- )
873
+ await asyncio.wait_for(self.client.write_gatt_char(self.cmd_char, bs), utils._TIMEOUT)
887
874
 
888
875
  if not req.has_res:
889
876
  return None
@@ -11,7 +11,6 @@ from sensor.sensor_data import DataType, Sample, SensorData
11
11
  from enum import Enum, IntEnum
12
12
 
13
13
  from sensor.sensor_device import DeviceInfo
14
- from sensor.utils import timer
15
14
 
16
15
 
17
16
  class SensorDataType(IntEnum):
@@ -205,13 +204,13 @@ class SensorProfileDataCtx:
205
204
  info.MTUSize = self.gForce.client.mtu_size
206
205
  else:
207
206
  info.MTUSize = 0
208
- print("get_device_name")
207
+ # print("get_device_name")
209
208
  info.DeviceName = await self.gForce.get_device_name()
210
- print("get_model_number")
209
+ # print("get_model_number")
211
210
  info.ModelName = await self.gForce.get_model_number()
212
- print("get_hardware_revision")
211
+ # print("get_hardware_revision")
213
212
  info.HardwareVersion = await self.gForce.get_hardware_revision()
214
- print("get_firmware_revision")
213
+ # print("get_firmware_revision")
215
214
  info.FirmwareVersion = await self.gForce.get_firmware_revision()
216
215
  return info
217
216
 
@@ -226,22 +225,27 @@ class SensorProfileDataCtx:
226
225
  self.notifyDataFlag |= DataSubscription.DNF_IMPEDANCE
227
226
 
228
227
  if self.hasEEG():
229
- print("initEEG")
228
+ # print("initEEG")
230
229
  info.EegChannelCount = await self.initEEG(packageCount)
230
+ info.EegSampleRate = self.sensorDatas[SensorDataType.DATA_TYPE_EEG].sampleRate
231
231
 
232
232
  if self.hasECG():
233
- print("initECG")
233
+ # print("initECG")
234
234
  info.EcgChannelCount = await self.initECG(packageCount)
235
+ info.EcgSampleRate = self.sensorDatas[SensorDataType.DATA_TYPE_ECG].sampleRate
235
236
 
236
237
  if self.hasBrth():
237
- print("initBrth")
238
+ # print("initBrth")
238
239
  info.BrthChannelCount = await self.initBrth(packageCount)
240
+ info.BrthSampleRate = self.sensorDatas[SensorDataType.DATA_TYPE_BRTH].sampleRate
239
241
 
240
242
  if self.hasIMU():
241
- print("initIMU")
243
+ # print("initIMU")
242
244
  imuChannelCount = await self.initIMU(packageCount)
243
245
  info.AccChannelCount = imuChannelCount
244
246
  info.GyroChannelCount = imuChannelCount
247
+ info.AccSampleRate = self.sensorDatas[SensorDataType.DATA_TYPE_ACC].sampleRate
248
+ info.GyroSampleRate = self.sensorDatas[SensorDataType.DATA_TYPE_GYRO].sampleRate
245
249
 
246
250
  self._device_info = info
247
251
 
@@ -786,9 +790,15 @@ class SensorProfileDataCtx:
786
790
 
787
791
  return crc8
788
792
 
789
- def processUniversalData(self, buf: Queue[SensorData], loop: asyncio.AbstractEventLoop, sensor, callback):
793
+ async def processUniversalData(
794
+ self, buf: Queue[SensorData], event_loop: asyncio.AbstractEventLoop, cmd_loop: asyncio.AbstractEventLoop, sensor, callback
795
+ ):
790
796
 
791
797
  while self._is_running:
798
+ while self._is_running and self._rawDataBuffer.empty():
799
+ await asyncio.sleep(0.01)
800
+ continue
801
+
792
802
  try:
793
803
  while self._is_running and not self._rawDataBuffer.empty():
794
804
  data = self._rawDataBuffer.get_nowait()
@@ -821,21 +831,21 @@ class SensorProfileDataCtx:
821
831
  if self._is_data_transfering:
822
832
  data_package = bytes(self._concatDataBuffer[index + 2 : index + 2 + n])
823
833
  self._processDataPackage(data_package, buf, sensor)
824
- while self._is_running and self.isDataTransfering:
834
+ while self._is_running and self.isDataTransfering and not buf.empty():
825
835
  sensorData: SensorData = None
826
836
  try:
827
837
  sensorData = buf.get_nowait()
828
838
  except Exception as e:
829
839
  break
830
- if loop != None and sensorData != None and callback != None:
840
+ if event_loop != None and sensorData != None and callback != None:
831
841
  try:
832
- loop.call_soon_threadsafe(callback, sensor, sensorData)
842
+ event_loop.call_soon_threadsafe(callback, sensor, sensorData)
833
843
  except Exception as e:
834
844
  print(e)
835
845
 
836
846
  buf.task_done()
837
-
838
847
  last_cut = index = index + 2 + n
848
+
839
849
  elif self._concatDataBuffer[index] == 0xAA:
840
850
  if (index + 1) >= data_size:
841
851
  index += 1
@@ -850,11 +860,14 @@ class SensorProfileDataCtx:
850
860
  index += 1
851
861
  continue
852
862
  data_package = bytes(self._concatDataBuffer[index + 2 : index + 2 + n])
853
- if loop != None:
854
- loop.call_soon_threadsafe(self.gForce._on_cmd_response, None, data_package)
863
+ if cmd_loop != None:
864
+ cmd_loop.call_soon_threadsafe(self.gForce._on_cmd_response, None, data_package)
855
865
  last_cut = index = index + 2 + n
866
+
856
867
  else:
857
868
  index += 1
858
869
 
859
- if last_cut > 0:
860
- self._concatDataBuffer = self._concatDataBuffer[last_cut + 1 :]
870
+ if last_cut > 0:
871
+ self._concatDataBuffer = self._concatDataBuffer[last_cut + 1 :]
872
+ last_cut = -1
873
+ index = 0
@@ -40,11 +40,17 @@ class DeviceInfo:
40
40
  self.HardwareVersion = ""
41
41
  self.FirmwareVersion = ""
42
42
  self.EmgChannelCount = 0
43
+ self.EmgSampleRate = 0
43
44
  self.EegChannelCount = 0
45
+ self.EegSampleRate = 0
44
46
  self.EcgChannelCount = 0
47
+ self.EcgSampleRate = 0
45
48
  self.AccChannelCount = 0
49
+ self.AccSampleRate = 0
46
50
  self.GyroChannelCount = 0
51
+ self.GyroSampleRate = 0
47
52
  self.BrthChannelCount = 0
53
+ self.BrthSampleRate = 0
48
54
  self.MTUSize = 0
49
55
 
50
56
 
@@ -351,7 +351,9 @@ class SensorProfile:
351
351
  self._data_buffer.task_done()
352
352
 
353
353
  async def _process_universal_data(self):
354
- self._data_ctx.processUniversalData(self._data_buffer, self._event_loop, self, self._on_data_callback)
354
+ await self._data_ctx.processUniversalData(
355
+ self._data_buffer, self._event_loop, self._gforce_event_loop, self, self._on_data_callback
356
+ )
355
357
 
356
358
  async def _startDataNotification(self) -> bool:
357
359
  if self.deviceState != DeviceStateEx.Ready:
@@ -474,7 +476,7 @@ class SensorProfile:
474
476
  return sync_call(
475
477
  self._gforce_event_loop,
476
478
  self._init(packageSampleCount, powerRefreshInterval),
477
- 120,
479
+ 20,
478
480
  )
479
481
 
480
482
  async def asyncInit(self, packageSampleCount: int, powerRefreshInterval: int) -> bool:
@@ -490,7 +492,7 @@ class SensorProfile:
490
492
  return await async_call(
491
493
  self._gforce_event_loop,
492
494
  self._init(packageSampleCount, powerRefreshInterval),
493
- 120,
495
+ 20,
494
496
  )
495
497
 
496
498
  def getBatteryLevel(self) -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sensor-sdk
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: Python sdk for Synchroni
5
5
  Home-page: https://github.com/oymotion/SynchroniSDKPython
6
6
  Author: Martin Ye
@@ -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.6",
11
+ version="0.0.8",
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