Merge branch 'ble_chars' into integration

This commit is contained in:
J. Nick Koston 2025-07-25 17:22:40 -10:00
commit 15806fb95d
No known key found for this signature in database

View File

@ -105,7 +105,12 @@ void BluetoothConnection::send_service_for_discovery_() {
return; return;
} }
if (total_char_count > 0) { if (total_char_count == 0) {
// No characteristics, just send the service response
api_conn->send_message(resp, api::BluetoothGATTGetServicesResponse::MESSAGE_TYPE);
return
}
// Reserve space and process characteristics // Reserve space and process characteristics
service_resp.characteristics.reserve(total_char_count); service_resp.characteristics.reserve(total_char_count);
uint16_t char_offset = 0; uint16_t char_offset = 0;
@ -117,11 +122,13 @@ void BluetoothConnection::send_service_for_discovery_() {
service_result.end_handle, &char_result, &char_count, char_offset); service_result.end_handle, &char_result, &char_count, char_offset);
if (char_status == ESP_GATT_INVALID_OFFSET || char_status == ESP_GATT_NOT_FOUND) { if (char_status == ESP_GATT_INVALID_OFFSET || char_status == ESP_GATT_NOT_FOUND) {
break; break;
} else if (char_status != ESP_GATT_OK) { }
if (char_status != ESP_GATT_OK) {
ESP_LOGE(TAG, "[%d] [%s] esp_ble_gattc_get_all_char error, status=%d", this->connection_index_, ESP_LOGE(TAG, "[%d] [%s] esp_ble_gattc_get_all_char error, status=%d", this->connection_index_,
this->address_str().c_str(), char_status); this->address_str().c_str(), char_status);
return; return;
} else if (char_count == 0) { }
if (char_count == 0) {
break; break;
} }
@ -158,11 +165,13 @@ void BluetoothConnection::send_service_for_discovery_() {
this->gattc_if_, this->conn_id_, char_result.char_handle, &desc_result, &desc_count, desc_offset); this->gattc_if_, this->conn_id_, char_result.char_handle, &desc_result, &desc_count, desc_offset);
if (desc_status == ESP_GATT_INVALID_OFFSET || desc_status == ESP_GATT_NOT_FOUND) { if (desc_status == ESP_GATT_INVALID_OFFSET || desc_status == ESP_GATT_NOT_FOUND) {
break; break;
} else if (desc_status != ESP_GATT_OK) { }
if (desc_status != ESP_GATT_OK) {
ESP_LOGE(TAG, "[%d] [%s] esp_ble_gattc_get_all_descr error, status=%d", this->connection_index_, ESP_LOGE(TAG, "[%d] [%s] esp_ble_gattc_get_all_descr error, status=%d", this->connection_index_,
this->address_str().c_str(), desc_status); this->address_str().c_str(), desc_status);
return; return;
} else if (desc_count == 0) { }
if (desc_count == 0) {
break; // No more descriptors break; // No more descriptors
} }
@ -173,7 +182,6 @@ void BluetoothConnection::send_service_for_discovery_() {
desc_offset++; desc_offset++;
} }
} }
} // end else if (total_char_count > 0)
// Send the message (we already checked api_conn is not null at the beginning) // Send the message (we already checked api_conn is not null at the beginning)
api_conn->send_message(resp, api::BluetoothGATTGetServicesResponse::MESSAGE_TYPE); api_conn->send_message(resp, api::BluetoothGATTGetServicesResponse::MESSAGE_TYPE);