BLESession.matches: Check service adtypes both 16 bits and 128 bits

LEGO Boost communicates with a Scratch extension through Scratch-link.
It was reported that bluepy-scratch-link fails to connect to LEGO Boost.
LEGO Boost advertises adtype 0x7 "Complete List of 128-bit Service Class
UUIDs". However, bluepy-scratch-link checks only adtype 0x3 "Complete
List of 16-bit Service Class UUIDs" which is valid for micro:bit.

To allow bluepy-scratch-link, check both adtypes 0x7 and 0x3. Introduce
constants to note those two adtype values.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
This commit is contained in:
Shin'ichiro Kawasaki
2020-01-25 18:48:10 +09:00
parent 865c613890
commit 2240de0085

View File

@@ -109,6 +109,9 @@ class BLESession(Session):
CONNECTED = 3
DONE = 4
ADTYPE_COMP_16B = 0x3
ADTYPE_COMP_128B = 0x7
class BLEThread(threading.Thread):
"""
Separated thread to control notifications to Scratch.
@@ -208,9 +211,13 @@ class BLESession(Session):
logger.debug(f"sevice to check: {s}")
given_uuid = s
logger.debug(f"given: {given_uuid}")
service_class_uuid = dev.getValueText(0x3)
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_128B)
logger.debug(f"adtype 128b: {service_class_uuid}")
if not service_class_uuid:
continue
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_16B)
logger.debug(f"adtype 16b: {service_class_uuid}")
if not service_class_uuid:
continue
dev_uuid = UUID(service_class_uuid)
logger.debug(f"dev: {dev_uuid}")
logger.debug(given_uuid == dev_uuid)