From e862db5bb2d611ad1b6059fd6ed78ca4d3b4f6d9 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 16 Jun 2023 17:34:43 +0200 Subject: [PATCH] measure gain --- ble_interface.py | 27 ++++++++++++++++++++++++--- myUUIDs.py | 3 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ble_interface.py b/ble_interface.py index 70a086e..05a2fa1 100644 --- a/ble_interface.py +++ b/ble_interface.py @@ -1,6 +1,6 @@ from asyncio import AbstractEventLoop import asyncio -from typing import Dict +from typing import Dict, dataclass_transform from bleak import BleakClient, BleakScanner from bleak.backends.characteristic import BleakGATTCharacteristic @@ -31,6 +31,7 @@ class ble_interface: self.CURRENT: self.__current_meas_handler, self.RANGE: self.__range_handler, } + self.characteristics_gain: Dict[str, Dict[int, int]] = {} # for every service, links handle with gain async def __connect(self): device = await BleakScanner.find_device_by_address(self.address, cb=dict(use_bdaddr=False)) @@ -48,8 +49,28 @@ class ble_interface: self.parse_services(services) + await self.get_associated_gains(self.CURRENT) + await asyncio.Event().wait() + async def get_associated_gains(self, id: str): + s = self.services[id] + for c in s.characteristics: + self.log.info(c.descriptors) + descr = c.get_descriptor(normalize_uuid_str(myUUIDs.SOURCE_GAIN_DESCR)) + if(not descr): + self.log.info("descr not found") + continue + + data = await self.client.read_gatt_descriptor(descr.handle); + gain = struct.unpack("