diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/multi_bluetooth/ble_characteristic.py | 24 | ||||
| -rw-r--r-- | tests/multi_bluetooth/ble_characteristic.py.exp | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/multi_bluetooth/ble_characteristic.py b/tests/multi_bluetooth/ble_characteristic.py index 33d92b823..fd6fd4672 100644 --- a/tests/multi_bluetooth/ble_characteristic.py +++ b/tests/multi_bluetooth/ble_characteristic.py @@ -16,6 +16,7 @@ _IRQ_GATTC_READ_RESULT = const(15) _IRQ_GATTC_READ_DONE = const(16) _IRQ_GATTC_WRITE_DONE = const(17) _IRQ_GATTC_NOTIFY = const(18) +_IRQ_GATTC_INDICATE = const(19) SERVICE_UUID = bluetooth.UUID("A5A5A5A5-FFFF-9999-1111-5A5A5A5A5A5A") CHAR_UUID = bluetooth.UUID("00000000-1111-2222-3333-444444444444") @@ -59,6 +60,8 @@ def irq(event, data): print("_IRQ_GATTC_WRITE_DONE", data[-1]) elif event == _IRQ_GATTC_NOTIFY: print("_IRQ_GATTC_NOTIFY", data[-1]) + elif event == _IRQ_GATTC_INDICATE: + print("_IRQ_GATTC_INDICATE", data[-1]) if waiting_event is not None: if (isinstance(waiting_event, int) and event == waiting_event) or ( @@ -115,6 +118,16 @@ def instance0(): print("gatts_notify") ble.gatts_notify(conn_handle, char_handle, "periph2") + # Wait for a write to the characteristic from the central. + wait_for_event(_IRQ_GATTS_WRITE, TIMEOUT_MS) + + # Wait a bit, then notify a new value on the characteristic. + time.sleep_ms(1000) + print("gatts_write") + ble.gatts_write(char_handle, "periph3") + print("gatts_indicate") + ble.gatts_indicate(conn_handle, char_handle) + # Wait for the central to disconnect. wait_for_event(_IRQ_CENTRAL_DISCONNECT, TIMEOUT_MS) finally: @@ -163,6 +176,17 @@ def instance1(): ble.gattc_read(conn_handle, value_handle) wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS) + # Write to the characteristic, and ask for a response. + print("gattc_write") + ble.gattc_write(conn_handle, value_handle, "central2", 1) + wait_for_event(_IRQ_GATTC_WRITE_DONE, TIMEOUT_MS) + + # Wait for a indicate (should have new data), then read new value. + wait_for_event(_IRQ_GATTC_INDICATE, TIMEOUT_MS) + print("gattc_read") + ble.gattc_read(conn_handle, value_handle) + wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS) + # Disconnect from peripheral. print("gap_disconnect:", ble.gap_disconnect(conn_handle)) wait_for_event(_IRQ_PERIPHERAL_DISCONNECT, TIMEOUT_MS) diff --git a/tests/multi_bluetooth/ble_characteristic.py.exp b/tests/multi_bluetooth/ble_characteristic.py.exp index d89842ef7..7f66a4d90 100644 --- a/tests/multi_bluetooth/ble_characteristic.py.exp +++ b/tests/multi_bluetooth/ble_characteristic.py.exp @@ -6,6 +6,9 @@ gatts_write gatts_notify _IRQ_GATTS_WRITE b'central1' gatts_notify +_IRQ_GATTS_WRITE b'central2' +gatts_write +gatts_indicate _IRQ_CENTRAL_DISCONNECT --- instance1 --- gap_connect @@ -26,5 +29,11 @@ _IRQ_GATTC_NOTIFY b'periph2' gattc_read _IRQ_GATTC_READ_RESULT b'central1' _IRQ_GATTC_READ_DONE 0 +gattc_write +_IRQ_GATTC_WRITE_DONE 0 +_IRQ_GATTC_INDICATE b'periph3' +gattc_read +_IRQ_GATTC_READ_RESULT b'periph3' +_IRQ_GATTC_READ_DONE 0 gap_disconnect: True _IRQ_PERIPHERAL_DISCONNECT |
