2020-03-05 02:34:46 +00:00
|
|
|
# Test BLE GAP advertising and scanning
|
|
|
|
|
|
|
|
from micropython import const
|
|
|
|
import time, machine, bluetooth
|
|
|
|
|
2020-05-13 05:35:32 +01:00
|
|
|
_IRQ_SCAN_RESULT = const(5)
|
|
|
|
_IRQ_SCAN_DONE = const(6)
|
2020-03-05 02:34:46 +00:00
|
|
|
|
|
|
|
ADV_TIME_S = 3
|
|
|
|
|
|
|
|
|
|
|
|
def instance0():
|
|
|
|
multitest.globals(BDADDR=ble.config("mac"))
|
|
|
|
multitest.next()
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
|
|
|
|
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)
|
2020-03-05 02:34:46 +00:00
|
|
|
time.sleep(ADV_TIME_S)
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
|
2020-03-05 02:34:46 +00:00
|
|
|
print("gap_advertise(None)")
|
|
|
|
ble.gap_advertise(None)
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
|
2020-03-05 02:34:46 +00:00
|
|
|
ble.active(0)
|
|
|
|
|
|
|
|
|
|
|
|
def instance1():
|
|
|
|
multitest.next()
|
|
|
|
finished = False
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
adv_types = set()
|
2020-03-05 02:34:46 +00:00
|
|
|
adv_data = None
|
|
|
|
|
|
|
|
def irq(ev, data):
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
nonlocal finished, adv_types, adv_data
|
2020-03-05 02:34:46 +00:00
|
|
|
if ev == _IRQ_SCAN_RESULT:
|
2020-08-14 06:16:29 +01:00
|
|
|
if data[0] == BDADDR[0] and data[1] == BDADDR[1]:
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
adv_types.add(data[2])
|
|
|
|
if adv_data is None:
|
|
|
|
adv_data = bytes(data[4])
|
|
|
|
else:
|
|
|
|
if adv_data != data[4]:
|
2020-04-07 06:59:16 +01:00
|
|
|
adv_data = b"MISMATCH"
|
2020-05-13 05:35:32 +01:00
|
|
|
elif ev == _IRQ_SCAN_DONE:
|
2020-03-05 02:34:46 +00:00
|
|
|
finished = True
|
|
|
|
|
|
|
|
ble.config(rxbuf=2000)
|
|
|
|
ble.irq(irq)
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
ble.gap_scan(2 * ADV_TIME_S * 1000, 10000, 10000)
|
2020-03-05 02:34:46 +00:00
|
|
|
while not finished:
|
|
|
|
machine.idle()
|
|
|
|
ble.active(0)
|
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.
2020-03-10 00:45:03 +00:00
|
|
|
print("adv_types:", sorted(adv_types))
|
2020-03-05 02:34:46 +00:00
|
|
|
print("adv_data:", adv_data)
|
|
|
|
|
|
|
|
|
|
|
|
ble = bluetooth.BLE()
|
|
|
|
ble.active(1)
|