Skip to content

Commit 64e752c

Browse files
committed
aioble/client.py: Use characteristic end handle (when available).
The `bluetooth` module replaced the def_handle field with end_handle in the characteristic result IRQ. Use this when querying for descriptors. In the case where this is not available (older versions of micropython) continue the existing behavior of searching just past the value handle, although decrease this to +2 to avoid finding other characteristic's descriptors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 58f8bec commit 64e752c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

micropython/bluetooth/aioble/aioble/client.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def _client_irq(event, data):
4848
conn_handle, status = data
4949
ClientDiscover._discover_done(conn_handle, status)
5050
elif event == _IRQ_GATTC_CHARACTERISTIC_RESULT:
51-
conn_handle, def_handle, value_handle, properties, uuid = data
51+
conn_handle, end_handle, value_handle, properties, uuid = data
5252
ClientDiscover._discover_result(
53-
conn_handle, def_handle, value_handle, properties, bluetooth.UUID(uuid)
53+
conn_handle, end_handle, value_handle, properties, bluetooth.UUID(uuid)
5454
)
5555
elif event == _IRQ_GATTC_CHARACTERISTIC_DONE:
5656
conn_handle, status = data
@@ -284,12 +284,15 @@ def _write_done(conn_handle, value_handle, status):
284284
# this class directly, instead use `async for characteristic in
285285
# service.characteristics([uuid])` or `await service.characteristic(uuid)`.
286286
class ClientCharacteristic(BaseClientCharacteristic):
287-
def __init__(self, service, def_handle, value_handle, properties, uuid):
287+
def __init__(self, service, end_handle, value_handle, properties, uuid):
288288
self.service = service
289289
self.connection = service.connection
290290

291+
# Used for descriptor discovery. If available, otherwise assume just
292+
# past the value handle (enough for two descriptors without risking
293+
# going into the next characteristic).
294+
self._end_handle = end_handle if end_handle > value_handle else value_handle + 2
291295
# Used for read/write/notify ops.
292-
self._def_handle = def_handle
293296
self._value_handle = value_handle
294297

295298
# Which operations are supported.
@@ -323,7 +326,7 @@ def __init__(self, service, def_handle, value_handle, properties, uuid):
323326

324327
def __str__(self):
325328
return "Characteristic: {} {} {} {}".format(
326-
self._def_handle, self._value_handle, self.properties, self.uuid
329+
self._end_handle, self._value_handle, self.properties, self.uuid
327330
)
328331

329332
def _connection(self):
@@ -444,9 +447,7 @@ def __init__(self, characteristic, dsc_handle, uuid):
444447
self.properties = _FLAG_READ | _FLAG_WRITE_NO_RESPONSE
445448

446449
def __str__(self):
447-
return "Descriptor: {} {} {} {}".format(
448-
self._def_handle, self._value_handle, self.properties, self.uuid
449-
)
450+
return "Descriptor: {} {} {}".format(self._value_handle, self.properties, self.uuid)
450451

451452
def _connection(self):
452453
return self.characteristic.service.connection
@@ -456,5 +457,5 @@ def _start_discovery(characteristic, uuid=None):
456457
ble.gattc_discover_descriptors(
457458
characteristic._connection()._conn_handle,
458459
characteristic._value_handle,
459-
characteristic._value_handle + 5,
460+
characteristic._end_handle,
460461
)

0 commit comments

Comments
 (0)