Skip to content

Commit a9b038a

Browse files
committed
examples/bluetooth/ble_advertising.py: Fix decoding UUIDs.
The UUID32 case was incorrect: first, the "<d" should have been "<I", and second, the UUID constructor treats integer arguments as UUID16. So this UUID32 case needs to pass in the actual data bytes. And then it's simpler to just make all cases pass in the data bytes. Signed-off-by: Damien George <[email protected]>
1 parent 6a8c45b commit a9b038a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

examples/bluetooth/ble_advertising.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,9 @@ def decode_name(payload):
7979

8080
def decode_services(payload):
8181
services = []
82-
for u in decode_field(payload, _ADV_TYPE_UUID16_COMPLETE):
83-
services.append(bluetooth.UUID(struct.unpack("<h", u)[0]))
84-
for u in decode_field(payload, _ADV_TYPE_UUID32_COMPLETE):
85-
services.append(bluetooth.UUID(struct.unpack("<d", u)[0]))
86-
for u in decode_field(payload, _ADV_TYPE_UUID128_COMPLETE):
87-
services.append(bluetooth.UUID(u))
82+
for code in (_ADV_TYPE_UUID16_COMPLETE, _ADV_TYPE_UUID32_COMPLETE, _ADV_TYPE_UUID128_COMPLETE):
83+
for u in decode_field(payload, code):
84+
services.append(bluetooth.UUID(u))
8885
return services
8986

9087

0 commit comments

Comments
 (0)