From b538fb896cf758dc72c832737a354d24cd953730 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 27 Aug 2024 14:12:39 +0200 Subject: [PATCH] gatt_client: add gatt_client_write_long_value_of_characteristic_with_context --- src/ble/gatt_client.c | 14 +++++++++++++- src/ble/gatt_client.h | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index c79df6cbf..417199f42 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -2867,8 +2867,20 @@ uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packe return ERROR_CODE_SUCCESS; } +uint8_t gatt_client_write_long_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id){ + // TODO: move into gatt_client_write_long_value_of_characteristic_with_offset once gatt_client_write_long_value_of_characteristic_with_offset_with_context exists + gatt_client_t * gatt_client; + uint8_t status = gatt_client_provide_context_for_request(con_handle, &gatt_client); + if (status != ERROR_CODE_SUCCESS){ + return status; + } + gatt_client->service_id = service_id; + gatt_client->connection_id = connection_id; + return gatt_client_write_long_value_of_characteristic_with_offset(callback, con_handle, value_handle, 0, value_length, value); +} + uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){ - return gatt_client_write_long_value_of_characteristic_with_offset(callback, con_handle, value_handle, 0, value_length, value); + return gatt_client_write_long_value_of_characteristic_with_context(callback, con_handle, value_handle, value_length, value, 0, 0); } uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){ diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index 42df8c46d..b86f03742 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -857,7 +857,26 @@ uint8_t gatt_client_write_value_of_characteristic_with_context(btstack_packet_ha */ uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); -/** +/** + * @brief Writes the characteristic value using the characteristic's value handle. + * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. + * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). + * @param callback + * @param con_handle + * @param value_handle + * @param value_length + * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received + * @param service_id - context provided to callback in events + * @param connection_id - contest provided to callback in events + * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found + * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated + * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready + * ERROR_CODE_SUCCESS if query is successfully registered + */ +uint8_t gatt_client_write_long_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, + uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); + +/** * @brief Writes the characteristic value using the characteristic's value handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).