6
6
_IRQ_SCAN_RESULT = const (5 )
7
7
_IRQ_SCAN_DONE = const (6 )
8
8
9
- ADV_TIME_S = 3
9
+ ADV_TIME_MS = 3000
10
10
11
11
12
12
def instance0 ():
13
13
multitest .globals (BDADDR = ble .config ("mac" ))
14
14
multitest .next ()
15
15
16
+ adv_data = b"\x02 \x01 \x06 \x04 \xff MPY"
17
+
16
18
print ("gap_advertise(100_000, connectable=False)" )
17
- ble .gap_advertise (100_000 , b" \x02 \x01 \x06 \x04 \xff MPY" , 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 )
19
21
20
22
print ("gap_advertise(20_000, connectable=True)" )
21
- ble .gap_advertise (20_000 , b" \x02 \x01 \x06 \x04 \xff MPY" , 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 )
23
25
24
26
print ("gap_advertise(None)" )
25
27
ble .gap_advertise (None )
@@ -30,19 +32,20 @@ def instance0():
30
32
def instance1 ():
31
33
multitest .next ()
32
34
finished = False
33
- adv_types = {}
34
- adv_data = None
35
+ matched_adv_types = {}
36
+ matched_adv_data = None
35
37
36
38
def irq (ev , data ):
37
- nonlocal finished , adv_types , adv_data
39
+ nonlocal finished , matched_adv_types , matched_adv_data
38
40
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 )
43
46
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"
46
49
elif ev == _IRQ_SCAN_DONE :
47
50
finished = True
48
51
@@ -51,12 +54,12 @@ def irq(ev, data):
51
54
except :
52
55
pass
53
56
ble .irq (irq )
54
- ble .gap_scan (2 * ADV_TIME_S * 1000 , 10000 , 10000 )
57
+ ble .gap_scan (2 * ADV_TIME_MS , 30000 , 30000 )
55
58
while not finished :
56
59
machine .idle ()
57
60
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 )
60
63
61
64
62
65
ble = bluetooth .BLE ()
0 commit comments