diff options
| author | Damien George <damien.p.george@gmail.com> | 2020-03-10 11:45:03 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2020-03-11 14:00:44 +1100 |
| commit | dd0bc26e65734b8a4fafa3769008e92e2ec6645d (patch) | |
| tree | 9312f74c625e65ddf6c44e5a5e9264ee667190e5 /tests | |
| parent | bd746a46309efc261d6124b546b5bf6775d47460 (diff) | |
extmod/modbluetooth: Change scan result's "connectable" to "adv_type".
This commit changes the BLE _IRQ_SCAN_RESULT data from:
addr_type, addr, connectable, rssi, adv_data
to:
addr_type, addr, adv_type, rssi, adv_data
This allows _IRQ_SCAN_RESULT to handle all scan result types (not just
connectable and non-connectable passive scans), and to distinguish between
them using adv_type which is an integer taking values 0x00-0x04 per the BT
specification.
This is a breaking change to the API, albeit a very minor one: the existing
connectable value was a boolean and True now becomes 0x00, False becomes
0x02.
Documentation is updated and a test added.
Fixes #5738.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/multi_bluetooth/ble_gap_advertise.py | 24 | ||||
| -rw-r--r-- | tests/multi_bluetooth/ble_gap_advertise.py.exp | 4 |
2 files changed, 22 insertions, 6 deletions
diff --git a/tests/multi_bluetooth/ble_gap_advertise.py b/tests/multi_bluetooth/ble_gap_advertise.py index 6b43f275f..dacb43133 100644 --- a/tests/multi_bluetooth/ble_gap_advertise.py +++ b/tests/multi_bluetooth/ble_gap_advertise.py @@ -11,34 +11,48 @@ ADV_TIME_S = 3 def instance0(): multitest.globals(BDADDR=ble.config("mac")) - print("gap_advertise(20_000)") - ble.gap_advertise(20_000, b"\x02\x01\x06\x04\xffMPY") multitest.next() + + print("gap_advertise(100_000, connectable=False)") + ble.gap_advertise(100_000, b"\x02\x01\x06\x04\xffMPY", connectable=False) + time.sleep(ADV_TIME_S) + + print("gap_advertise(20_000, connectable=True)") + ble.gap_advertise(20_000, b"\x02\x01\x06\x04\xffMPY", connectable=True) time.sleep(ADV_TIME_S) + print("gap_advertise(None)") ble.gap_advertise(None) + ble.active(0) def instance1(): multitest.next() finished = False + adv_types = set() adv_data = None def irq(ev, data): - nonlocal finished, adv_data + nonlocal finished, adv_types, adv_data if ev == _IRQ_SCAN_RESULT: if data[1] == BDADDR: - adv_data = bytes(data[4]) + adv_types.add(data[2]) + if adv_data is None: + adv_data = bytes(data[4]) + else: + if adv_data != data[4]: + adv_data = "MISMATCH" elif ev == _IRQ_SCAN_COMPLETE: finished = True ble.config(rxbuf=2000) ble.irq(irq) - ble.gap_scan(ADV_TIME_S * 1000, 10000, 10000) + ble.gap_scan(2 * ADV_TIME_S * 1000, 10000, 10000) while not finished: machine.idle() ble.active(0) + print("adv_types:", sorted(adv_types)) print("adv_data:", adv_data) diff --git a/tests/multi_bluetooth/ble_gap_advertise.py.exp b/tests/multi_bluetooth/ble_gap_advertise.py.exp index b2ac61eb1..2eb2a4484 100644 --- a/tests/multi_bluetooth/ble_gap_advertise.py.exp +++ b/tests/multi_bluetooth/ble_gap_advertise.py.exp @@ -1,5 +1,7 @@ --- instance0 --- -gap_advertise(20_000) +gap_advertise(100_000, connectable=False) +gap_advertise(20_000, connectable=True) gap_advertise(None) --- instance1 --- +adv_types: [0, 2] adv_data: b'\x02\x01\x06\x04\xffMPY' |
