From 47181045ae9215f49690e10089ba60e5edd64fbd Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 1 Feb 2018 15:17:03 +0100 Subject: [PATCH] gatt_client: add gatt_client_request_can_write_without_response_event() --- src/ble/gatt_client.c | 23 ++++++++++++++++++++++- src/ble/gatt_client.h | 14 +++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 93167bf3f..661e58702 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -998,10 +998,22 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){ return 1; } #endif - default: break; } + + // requested can send snow? + if (peripheral->write_without_response_callback){ + btstack_packet_handler_t packet_handler = peripheral->write_without_response_callback; + peripheral->write_without_response_callback = NULL; + uint8_t event[4]; + event[0] = GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE; + event[1] = sizeof(event) - 2; + little_endian_store_16(event, 2, peripheral->con_handle); + packet_handler(HCI_EVENT_PACKET, peripheral->con_handle, event, sizeof(event)); + return 1; // to trigger requeueing (even if higher layer didn't sent) + } + return 0; } @@ -1915,3 +1927,12 @@ void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con gatt_client_run(); } } + +uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle){ + gatt_client_t * context = provide_context_for_conn_handle(con_handle); + if (!context) return BTSTACK_MEMORY_ALLOC_FAILED; + if (context->write_without_response_callback) return GATT_CLIENT_IN_WRONG_STATE; + context->write_without_response_callback = callback; + att_dispatch_client_request_can_send_now_event(context->con_handle); + return 0; +} diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index 654309773..ff201699b 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -138,6 +138,9 @@ typedef struct gatt_client{ // user callback btstack_packet_handler_t callback; + // can write without response callback + btstack_packet_handler_t write_without_response_callback; + hci_con_handle_t con_handle; uint8_t address_type; @@ -358,6 +361,14 @@ void gatt_client_listen_for_characteristic_value_updates(gatt_client_notificatio */ void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); +/** + * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees a single successful gatt_client_write_value_of_characteristic_without_response + * @param packet_handler + * @param con_handle + * @returns status + */ +uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); + /** * @brief -> gatt complete event */ @@ -381,9 +392,6 @@ void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_cli void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); -// only used for testing -void gatt_client_pts_suppress_mtu_exchange(void); - #if defined __cplusplus } #endif