Merge pull request #6513 from dhalbert/7.3.x-6495-backport-ble-disconnect-check

Test for a BLE disconnect while reading
This commit is contained in:
Scott Shawcroft 2022-06-22 09:38:24 -07:00 committed by GitHub
commit 25206a8aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -185,7 +185,12 @@ STATIC bool _on_gattc_read_rsp_evt(ble_evt_t *ble_evt, void *param) {
} }
break; break;
} }
case BLE_GAP_EVT_DISCONNECTED: {
read->conn_handle = BLE_CONN_HANDLE_INVALID;
read->done = true;
return false;
break;
}
default: default:
// For debugging. // For debugging.
// mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id);
@ -219,6 +224,8 @@ size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_
while (!read_info.done) { while (!read_info.done) {
RUN_BACKGROUND_TASKS; RUN_BACKGROUND_TASKS;
} }
// Test if we were disconnected while reading
common_hal_bleio_check_connected(read_info.conn_handle);
ble_drv_remove_event_handler(_on_gattc_read_rsp_evt, &read_info); ble_drv_remove_event_handler(_on_gattc_read_rsp_evt, &read_info);
check_gatt_status(read_info.status); check_gatt_status(read_info.status);