add gatt_client_read_multiple_characteristic_values

This commit is contained in:
Matthias Ringwald 2015-10-02 14:59:23 +02:00
parent d43bd7a6fb
commit 5a93002a1d
2 changed files with 64 additions and 2 deletions

View File

@ -297,6 +297,19 @@ static void att_read_blob_request(uint16_t request_type, uint16_t peripheral_han
l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 5);
}
static void att_read_multiple_request(uint16_t peripheral_handle, uint16_t num_value_handles, uint16_t * value_handles){
l2cap_reserve_packet_buffer();
uint8_t * request = l2cap_get_outgoing_buffer();
request[0] = ATT_READ_MULTIPLE_REQUEST;
int i;
int offset = 1;
for (i=0;i<num_value_handles;i++){
bt_store_16(request, offset, value_handles[i]);
offset += 2;
}
l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, offset);
}
// precondition: can_send_packet_now == TRUE
static void att_signed_write_request(uint16_t request_type, uint16_t peripheral_handle, uint16_t attribute_handle, uint16_t value_length, uint8_t * value, uint32_t sign_counter, uint8_t sgn[8]){
l2cap_reserve_packet_buffer();
@ -414,6 +427,10 @@ static void send_gatt_read_blob_request(gatt_client_t *peripheral){
att_read_blob_request(ATT_READ_BLOB_REQUEST, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_offset);
}
static void send_gatt_read_multiple_request(gatt_client_t * peripheral){
att_read_multiple_request(peripheral->handle, peripheral->read_multiple_handle_count, peripheral->read_multiple_handles);
}
static void send_gatt_write_attribute_value_request(gatt_client_t * peripheral){
att_write_request(ATT_WRITE_REQUEST, peripheral->handle, peripheral->attribute_handle, peripheral->attribute_length, peripheral->attribute_value);
}
@ -820,6 +837,11 @@ static void gatt_client_run(void){
send_gatt_read_by_type_request(peripheral);
break;
case P_W2_SEND_READ_MULTIPLE_REQUEST:
peripheral->gatt_client_state = P_W4_READ_MULTIPLE_RESPONSE;
send_gatt_read_multiple_request(peripheral);
break;
case P_W2_SEND_WRITE_CHARACTERISTIC_VALUE:
peripheral->gatt_client_state = P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT;
send_gatt_write_attribute_value_request(peripheral);
@ -937,7 +959,7 @@ static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint8_t *p
linked_list_remove(&gatt_client_connections, (linked_item_t *) peripheral);
btstack_memory_gatt_client_free(peripheral);
// Forward event to all subclients
emit_event_to_all_subclients((le_event_t *) packet);
break;
@ -1203,6 +1225,18 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
}
break;
case ATT_READ_MULTIPLE_RESPONSE:
switch(peripheral->gatt_client_state){
case P_W4_READ_MULTIPLE_RESPONSE:
report_gatt_characteristic_value(peripheral, 0, &packet[1], size-1);
gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0);
break;
default:
break;
}
break;
case ATT_ERROR_RESPONSE:
switch (packet[4]){
@ -1500,6 +1534,20 @@ le_command_status_t gatt_client_read_long_value_of_characteristic(uint16_t gatt_
return gatt_client_read_long_value_of_characteristic_using_value_handle(gatt_client_id, handle, characteristic->value_handle);
}
le_command_status_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id, uint16_t con_handle, int num_value_handles, uint16_t * value_handles){
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
if (!peripheral) return (le_command_status_t) BTSTACK_MEMORY_ALLOC_FAILED;
if (!is_ready(peripheral)) return BLE_PERIPHERAL_IN_WRONG_STATE;
peripheral->subclient_id = gatt_client_id;
peripheral->read_multiple_handle_count = num_value_handles;
peripheral->read_multiple_handles = value_handles;
peripheral->gatt_client_state = P_W2_SEND_READ_MULTIPLE_REQUEST;
gatt_client_run();
return BLE_PERIPHERAL_OK;
}
le_command_status_t gatt_client_write_value_of_characteristic_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
gatt_client_t * peripheral = provide_context_for_conn_handle(con_handle);

View File

@ -81,6 +81,9 @@ typedef enum {
P_W2_SEND_READ_BY_TYPE_REQUEST,
P_W4_READ_BY_TYPE_RESPONSE,
P_W2_SEND_READ_MULTIPLE_REQUEST,
P_W4_READ_MULTIPLE_RESPONSE,
P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
@ -158,8 +161,12 @@ typedef struct gatt_client{
uint16_t attribute_length;
uint8_t* attribute_value;
// read multiple characteristic values
uint16_t read_multiple_handle_count;
uint16_t * read_multiple_handles;
uint16_t client_characteristic_configuration_handle;
uint8_t client_characteristic_configuration_value[2];
uint8_t client_characteristic_configuration_value[2];
uint8_t filter_with_uuid;
uint8_t send_confirmation;
@ -315,6 +322,13 @@ le_command_status_t gatt_client_read_long_value_of_characteristic(uint16_t gatt_
le_command_status_t gatt_client_read_long_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle);
le_command_status_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset);
/*
* @brief Read multiple characteristic values
* @param number handles
* @param list_of_handles list of handles
*/
le_command_status_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id, uint16_t con_handle, int num_value_handles, uint16_t * value_handles);
/**
* @brief Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
*/