8000 extmod/btstack: Reset pending_value_handle before calling read-done cb. by dpgeorge · Pull Request #13637 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

extmod/btstack: Reset pending_value_handle before calling read-done cb. #13637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extmod/btstack/modbluetooth_btstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,9 @@ STATIC void btstack_packet_handler_read(uint8_t packet_type, uint16_t channel, u
if (!conn) {
return;
}
mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_READ_DONE, conn_handle, conn->pending_value_handle, status);
uint16_t value_handle = conn->pending_value_handle;
conn->pending_value_handle = 0xffff;
mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_READ_DONE, conn_handle, value_handle, status);
} else if (event_type == GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT) {
DEBUG_printf(" --> gatt characteristic value query result\n");
uint16_t conn_handle = gatt_event_characteristic_value_query_result_get_handle(packet);
Expand Down
18 changes: 12 additions & 6 deletions tests/multi_bluetooth/ble_irq_calls.py
_, state_handle, _ = self._characteristic
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def __init__(self):
self.done = False
self._conn_handle = None
self._service = None
self._characteristic = None
self._characteristic_handle = None
self._cccd_handle = None
self._reads_remaining = None
ble.active(1)
ble.irq(self._ble_event_handler)
ble.gap_connect(*BDADDR)
Expand Down Expand Up @@ -101,7 +102,8 @@ def _ble_event_handler(self, event, data):
_, end_handle, value_handle, properties, uuid = data
assert uuid == STATE_UUID
print("characteristic found:", uuid)
self._characteristic = (end_handle, value_handle, properties)
assert self._characteristic_handle is None
self._characteristic_handle = value_handle

elif event == _IRQ_GATTC_CHARACTERISTIC_DONE:
start_handle, end_handle = self._service
Expand All @@ -128,17 +130,21 @@ def _ble_event_handler(self, event, data):
elif event == _IRQ_GATTC_WRITE_DONE:
conn_handle, _, result = data
print("CCCD write result:", result)
print("issue gattc_read")
ble.gattc_read(self._conn_handle, state_handle)
self._reads_remaining = 2
ble.gattc_read(self._conn_handle, self._characteristic_handle)

elif event == _IRQ_GATTC_READ_RESULT:
_, _, char_data = data
print("gattc_read result:", bytes(char_data))

elif event == _IRQ_GATTC_READ_DONE:
self.done = True
ble.gap_disconnect(self._conn_handle)
self._reads_remaining -= 1
if self._reads_remaining > 0:
ble.gattc_read(self._conn_handle, self._characteristic_handle)
else:
self.done = True
ble.gap_disconnect(self._conn_handle)


class Peripheral:
Expand Down
4 changes: 4 additions & 0 deletions tests/multi_bluetooth/ble_irq_calls.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ peripheral start
_IRQ_CENTRAL_CONNECT
_IRQ_MTU_EXCHANGED
_IRQ_GATTS_READ_REQUEST
_IRQ_GATTS_READ_REQUEST
_IRQ_CENTRAL_DISCONNECT
--- instance1 ---
central start
Expand All @@ -27,5 +28,8 @@ issue gattc_read
_IRQ_GATTC_READ_RESULT
gattc_read result: b''
_IRQ_GATTC_READ_DONE
_IRQ_GATTC_READ_RESULT
gattc_read result: b''
_IRQ_GATTC_READ_DONE
_IRQ_PERIPHERAL_DISCONNECT
connection closed
0