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>
pull/863/head
Damien George 2024-05-25 17:37:41 +10:00
rodzic e5389eb26a
commit 46e243c592
3 zmienionych plików z 10 dodań i 8 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
metadata(version="0.2.1")
metadata(version="0.2.2")
require("aioble-core")

Wyświetl plik

@ -195,12 +195,14 @@ class ScanResult:
# Generator that enumerates the service UUIDs that are advertised.
def services(self):
for u in self._decode_field(_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE):
yield bluetooth.UUID(struct.unpack("<H", u)[0])
for u in self._decode_field(_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE):
yield bluetooth.UUID(struct.unpack("<I", u)[0])
for u in self._decode_field(_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE):
yield bluetooth.UUID(u)
for uuid_len, codes in (
(2, (_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE)),
(4, (_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE)),
(16, (_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE)),
):
for u in self._decode_field(*codes):
for i in range(0, len(u), uuid_len):
yield bluetooth.UUID(u[i : i + uuid_len])
# Generator that returns (manufacturer_id, data) tuples.
def manufacturer(self, filter=None):

Wyświetl plik

@ -3,7 +3,7 @@
# code. This allows (for development purposes) all the files to live in the
# one directory.
metadata(version="0.5.1")
metadata(version="0.5.2")
# Default installation gives you everything. Install the individual
# components (or a combination of them) if you want a more minimal install.