Skip to content

Commit dcb863e

Browse files
committed
tests/multi_bluetooth: Use time.sleep_ms instead of time.sleep.
On unix, time.sleep is implemented as select(timeout=<time>) which means that it does not run the poll hook during sleeping. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent a6aa739 commit dcb863e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

tests/multi_bluetooth/ble_gap_advertise.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
_IRQ_SCAN_RESULT = const(5)
77
_IRQ_SCAN_DONE = const(6)
88

9-
ADV_TIME_S = 3
9+
ADV_TIME_MS = 3000
1010

1111

1212
def instance0():
1313
multitest.globals(BDADDR=ble.config("mac"))
1414
multitest.next()
1515

16+
adv_data = b"\x02\x01\x06\x04\xffMPY"
17+
1618
print("gap_advertise(100_000, connectable=False)")
17-
ble.gap_advertise(100_000, b"\x02\x01\x06\x04\xffMPY", connectable=False)
18-
time.sleep(ADV_TIME_S)
19+
ble.gap_advertise(100_000, adv_data, connectable=False)
20+
time.sleep_ms(ADV_TIME_MS)
1921

2022
print("gap_advertise(20_000, connectable=True)")
21-
ble.gap_advertise(20_000, b"\x02\x01\x06\x04\xffMPY", connectable=True)
22-
time.sleep(ADV_TIME_S)
23+
ble.gap_advertise(20_000, adv_data, connectable=True)
24+
time.sleep_ms(ADV_TIME_MS)
2325

2426
print("gap_advertise(None)")
2527
ble.gap_advertise(None)
@@ -30,19 +32,20 @@ def instance0():
3032
def instance1():
3133
multitest.next()
3234
finished = False
33-
adv_types = {}
34-
adv_data = None
35+
matched_adv_types = {}
36+
matched_adv_data = None
3537

3638
def irq(ev, data):
37-
nonlocal finished, adv_types, adv_data
39+
nonlocal finished, matched_adv_types, matched_adv_data
3840
if ev == _IRQ_SCAN_RESULT:
39-
if data[0] == BDADDR[0] and data[1] == BDADDR[1]:
40-
adv_types[data[2]] = True
41-
if adv_data is None:
42-
adv_data = bytes(data[4])
41+
addr_type, addr, adv_type, rssi, adv_data = data
42+
if addr_type == BDADDR[0] and addr == BDADDR[1]:
43+
matched_adv_types[adv_type] = True
44+
if matched_adv_data is None:
45+
matched_adv_data = bytes(adv_data)
4346
else:
44-
if adv_data != data[4]:
45-
adv_data = b"MISMATCH"
47+
if adv_data != matched_adv_data:
48+
matched_adv_data = b"MISMATCH"
4649
elif ev == _IRQ_SCAN_DONE:
4750
finished = True
4851

@@ -51,12 +54,12 @@ def irq(ev, data):
5154
except:
5255
pass
5356
ble.irq(irq)
54-
ble.gap_scan(2 * ADV_TIME_S * 1000, 10000, 10000)
57+
ble.gap_scan(2 * ADV_TIME_MS, 30000, 30000)
5558
while not finished:
5659
machine.idle()
5760
ble.active(0)
58-
print("adv_types:", sorted(adv_types))
59-
print("adv_data:", adv_data)
61+
print("adv_types:", sorted(matched_adv_types))
62+
print("adv_data:", matched_adv_data)
6063

6164

6265
ble = bluetooth.BLE()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy