Skip to content

Commit 46e243c

Browse files
committed
aioble/central.py: Fix ScanResult.services when decoding UUIDs.
Fixes are needed to support the cases of: - There may be more than one UUID per advertising field. - The UUID advertising field may be empty (no UUIDs). - Constructing 32-bit `bluetooth.UUID()` entities, which must be done by passing in a 4-byte bytes object, not an integer. Signed-off-by: Damien George <damien@micropython.org>
1 parent e5389eb commit 46e243c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

‎micropython/bluetooth/aioble-central/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.1")
1+
metadata(version="0.2.2")
22

33
require("aioble-core")
44

‎micropython/bluetooth/aioble/aioble/central.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ def name(self):
195195

196196
# Generator that enumerates the service UUIDs that are advertised.
197197
def services(self):
198-
for u in self._decode_field(_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE):
199-
yield bluetooth.UUID(struct.unpack("<H", u)[0])
200-
for u in self._decode_field(_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE):
201-
yield bluetooth.UUID(struct.unpack("<I", u)[0])
202-
for u in self._decode_field(_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE):
203-
yield bluetooth.UUID(u)
198+
for uuid_len, codes in (
199+
(2, (_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE)),
200+
(4, (_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE)),
201+
(16, (_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE)),
202+
):
203+
for u in self._decode_field(*codes):
204+
for i in range(0, len(u), uuid_len):
205+
yield bluetooth.UUID(u[i : i + uuid_len])
204206

205207
# Generator that returns (manufacturer_id, data) tuples.
206208
def manufacturer(self, filter=None):

‎micropython/bluetooth/aioble/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# code. This allows (for development purposes) all the files to live in the
44
# one directory.
55

6-
metadata(version="0.5.1")
6+
metadata(version="0.5.2")
77

88
# Default installation gives you everything. Install the individual
99
# components (or a combination of them) if you want a more minimal install.

0 commit comments

Comments
 (0)