mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	cleanup
This commit is contained in:
		| @@ -104,16 +104,12 @@ void BluetoothConnection::send_service_for_discovery_() { | |||||||
|       esp_ble_gattc_get_attr_count(this->gattc_if_, this->conn_id_, ESP_GATT_DB_CHARACTERISTIC, |       esp_ble_gattc_get_attr_count(this->gattc_if_, this->conn_id_, ESP_GATT_DB_CHARACTERISTIC, | ||||||
|                                    service_result.start_handle, service_result.end_handle, 0, &total_char_count); |                                    service_result.start_handle, service_result.end_handle, 0, &total_char_count); | ||||||
|  |  | ||||||
|   if (char_count_status == ESP_GATT_OK && total_char_count > 0) { |   if (char_count_status != ESP_GATT_OK) { | ||||||
|     // Only reserve if we successfully got a count |  | ||||||
|     service_resp.characteristics.reserve(total_char_count); |  | ||||||
|   } else if (char_count_status != ESP_GATT_OK) { |  | ||||||
|     ESP_LOGW(TAG, "[%d] [%s] Error getting characteristic count, status=%d", this->connection_index_, |     ESP_LOGW(TAG, "[%d] [%s] Error getting characteristic count, status=%d", this->connection_index_, | ||||||
|              this->address_str().c_str(), char_count_status); |              this->address_str().c_str(), char_count_status); | ||||||
|   } |   } else if (total_char_count > 0) { | ||||||
|  |     // Reserve space and process characteristics | ||||||
|   // Now process characteristics |     service_resp.characteristics.reserve(total_char_count); | ||||||
|   if (char_count_status == ESP_GATT_OK && total_char_count > 0) { |  | ||||||
|     uint16_t char_offset = 0; |     uint16_t char_offset = 0; | ||||||
|     esp_gattc_char_elem_t char_result; |     esp_gattc_char_elem_t char_result; | ||||||
|     while (true) {  // characteristics |     while (true) {  // characteristics | ||||||
| @@ -146,20 +142,12 @@ void BluetoothConnection::send_service_for_discovery_() { | |||||||
|           esp_ble_gattc_get_attr_count(this->gattc_if_, this->conn_id_, ESP_GATT_DB_DESCRIPTOR, char_result.char_handle, |           esp_ble_gattc_get_attr_count(this->gattc_if_, this->conn_id_, ESP_GATT_DB_DESCRIPTOR, char_result.char_handle, | ||||||
|                                        service_result.end_handle, 0, &total_desc_count); |                                        service_result.end_handle, 0, &total_desc_count); | ||||||
|  |  | ||||||
|       if (desc_count_status == ESP_GATT_OK && total_desc_count > 0) { |       if (desc_count_status != ESP_GATT_OK) { | ||||||
|         // Only reserve if we successfully got a count |  | ||||||
|         characteristic_resp.descriptors.reserve(total_desc_count); |  | ||||||
|       } else if (desc_count_status != ESP_GATT_OK) { |  | ||||||
|         ESP_LOGW(TAG, "[%d] [%s] Error getting descriptor count for char handle %d, status=%d", this->connection_index_, |         ESP_LOGW(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->address_str().c_str(), char_result.char_handle, desc_count_status); | ||||||
|       } |       } else if (total_desc_count > 0) { | ||||||
|  |         // Reserve space and process descriptors | ||||||
|       // Skip descriptor processing if there are no descriptors |         characteristic_resp.descriptors.reserve(total_desc_count); | ||||||
|       if (desc_count_status != ESP_GATT_OK || total_desc_count == 0) { |  | ||||||
|         continue; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       // Now process descriptors |  | ||||||
|         uint16_t desc_offset = 0; |         uint16_t desc_offset = 0; | ||||||
|         esp_gattc_descr_elem_t desc_result; |         esp_gattc_descr_elem_t desc_result; | ||||||
|         while (true) {  // descriptors |         while (true) {  // descriptors | ||||||
| @@ -184,8 +172,9 @@ void BluetoothConnection::send_service_for_discovery_() { | |||||||
|           descriptor_resp.handle = desc_result.handle; |           descriptor_resp.handle = desc_result.handle; | ||||||
|           desc_offset++; |           desc_offset++; | ||||||
|         } |         } | ||||||
|  |       }  // end else if (total_desc_count > 0) | ||||||
|     } |     } | ||||||
|   }  // end if (char_count_status == ESP_GATT_OK && total_char_count > 0) |   }  // 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); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user