1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 05:42:20 +01:00
This commit is contained in:
J. Nick Koston
2025-07-31 06:47:31 -10:00
parent 3a80aac6e8
commit 551bff33c2

View File

@@ -56,6 +56,13 @@ static size_t estimate_service_size(uint16_t char_count, bool use_efficient_uuid
return service_overhead + (char_size + desc_size) * char_count;
}
// Helper to calculate actual service size
static size_t get_service_size(api::BluetoothGATTService &service) {
api::ProtoSize service_size;
service.calculate_size(service_size);
return service_size.get_size();
}
bool BluetoothConnection::supports_efficient_uuids_() const {
auto *api_conn = this->proxy_->get_api_connection();
return api_conn && api_conn->client_supports_api_version(1, 12);
@@ -169,12 +176,7 @@ void BluetoothConnection::send_service_for_discovery_() {
break;
}
if (total_char_count == 0) {
// No characteristics, increment and continue to next service
this->send_service_++;
continue;
}
if (total_char_count > 0) {
// Reserve space and process characteristics
service_resp.characteristics.reserve(total_char_count);
uint16_t char_offset = 0;
@@ -212,8 +214,8 @@ void BluetoothConnection::send_service_for_discovery_() {
this->gattc_if_, this->conn_id_, ESP_GATT_DB_DESCRIPTOR, 0, 0, char_result.char_handle, &total_desc_count);
if (desc_count_status != ESP_GATT_OK) {
ESP_LOGE(TAG, "[%d] [%s] Error getting descriptor count for char handle %d, status=%d", this->connection_index_,
this->address_str().c_str(), char_result.char_handle, desc_count_status);
ESP_LOGE(TAG, "[%d] [%s] Error getting descriptor count for char handle %d, status=%d",
this->connection_index_, this->address_str().c_str(), char_result.char_handle, desc_count_status);
this->send_service_ = DONE_SENDING_SERVICES;
return;
}
@@ -252,13 +254,10 @@ void BluetoothConnection::send_service_for_discovery_() {
desc_offset++;
}
}
} // end if (total_char_count > 0)
// Calculate the actual size of just this service
api::ProtoSize service_size;
service_resp.calculate_size(service_size);
// Update running total
current_size += service_size.get_size() + 1; // +1 for field tag
current_size += get_service_size(service_resp) + 1; // +1 for field tag
// Check if we've exceeded the limit (worst case scenario)
// Our estimation above should have caught this, but if we're here it means