mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	preen
This commit is contained in:
		| @@ -1495,9 +1495,7 @@ void APIConnection::execute_service(const ExecuteServiceRequest &msg) { | ||||
| NoiseEncryptionSetKeyResponse APIConnection::noise_encryption_set_key(const NoiseEncryptionSetKeyRequest &msg) { | ||||
|   psk_t psk{}; | ||||
|   NoiseEncryptionSetKeyResponse resp; | ||||
|   // Create temporary string from pointer/length for base64_decode | ||||
|   std::string key_str(reinterpret_cast<const char *>(msg.key_ptr_), msg.key_len_); | ||||
|   if (base64_decode(key_str, psk.data(), key_str.size()) != psk.size()) { | ||||
|   if (base64_decode(msg.key, psk.data(), msg.key.size()) != psk.size()) { | ||||
|     ESP_LOGW(TAG, "Invalid encryption key length"); | ||||
|     resp.success = false; | ||||
|     return resp; | ||||
|   | ||||
| @@ -333,8 +333,7 @@ esp_err_t BluetoothConnection::read_characteristic(uint16_t handle) { | ||||
|   return ESP_OK; | ||||
| } | ||||
|  | ||||
| esp_err_t BluetoothConnection::write_characteristic(uint16_t handle, const uint8_t *data, size_t data_len, | ||||
|                                                     bool response) { | ||||
| esp_err_t BluetoothConnection::write_characteristic(uint16_t handle, const std::string &data, bool response) { | ||||
|   if (!this->connected()) { | ||||
|     ESP_LOGW(TAG, "[%d] [%s] Cannot write GATT characteristic, not connected.", this->connection_index_, | ||||
|              this->address_str_.c_str()); | ||||
| @@ -344,7 +343,7 @@ esp_err_t BluetoothConnection::write_characteristic(uint16_t handle, const uint8 | ||||
|            handle); | ||||
|  | ||||
|   esp_err_t err = | ||||
|       esp_ble_gattc_write_char(this->gattc_if_, this->conn_id_, handle, data_len, const_cast<uint8_t *>(data), | ||||
|       esp_ble_gattc_write_char(this->gattc_if_, this->conn_id_, handle, data.size(), (uint8_t *) data.data(), | ||||
|                                response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); | ||||
|   if (err != ERR_OK) { | ||||
|     ESP_LOGW(TAG, "[%d] [%s] esp_ble_gattc_write_char error, err=%d", this->connection_index_, | ||||
| @@ -372,7 +371,7 @@ esp_err_t BluetoothConnection::read_descriptor(uint16_t handle) { | ||||
|   return ESP_OK; | ||||
| } | ||||
|  | ||||
| esp_err_t BluetoothConnection::write_descriptor(uint16_t handle, const uint8_t *data, size_t data_len, bool response) { | ||||
| esp_err_t BluetoothConnection::write_descriptor(uint16_t handle, const std::string &data, bool response) { | ||||
|   if (!this->connected()) { | ||||
|     ESP_LOGW(TAG, "[%d] [%s] Cannot write GATT descriptor, not connected.", this->connection_index_, | ||||
|              this->address_str_.c_str()); | ||||
| @@ -382,7 +381,7 @@ esp_err_t BluetoothConnection::write_descriptor(uint16_t handle, const uint8_t * | ||||
|            handle); | ||||
|  | ||||
|   esp_err_t err = esp_ble_gattc_write_char_descr( | ||||
|       this->gattc_if_, this->conn_id_, handle, data_len, const_cast<uint8_t *>(data), | ||||
|       this->gattc_if_, this->conn_id_, handle, data.size(), (uint8_t *) data.data(), | ||||
|       response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); | ||||
|   if (err != ERR_OK) { | ||||
|     ESP_LOGW(TAG, "[%d] [%s] esp_ble_gattc_write_char_descr error, err=%d", this->connection_index_, | ||||
|   | ||||
| @@ -19,9 +19,9 @@ class BluetoothConnection : public esp32_ble_client::BLEClientBase { | ||||
|   esp32_ble_tracker::AdvertisementParserType get_advertisement_parser_type() override; | ||||
|  | ||||
|   esp_err_t read_characteristic(uint16_t handle); | ||||
|   esp_err_t write_characteristic(uint16_t handle, const uint8_t *data, size_t data_len, bool response); | ||||
|   esp_err_t write_characteristic(uint16_t handle, const std::string &data, bool response); | ||||
|   esp_err_t read_descriptor(uint16_t handle); | ||||
|   esp_err_t write_descriptor(uint16_t handle, const uint8_t *data, size_t data_len, bool response); | ||||
|   esp_err_t write_descriptor(uint16_t handle, const std::string &data, bool response); | ||||
|  | ||||
|   esp_err_t notify_characteristic(uint16_t handle, bool enable); | ||||
|  | ||||
|   | ||||
| @@ -344,8 +344,7 @@ void BluetoothProxy::bluetooth_gatt_write(const api::BluetoothGATTWriteRequest & | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   auto err = connection->write_characteristic(msg.handle, reinterpret_cast<const uint8_t *>(msg.data.data()), | ||||
|                                               msg.data.size(), msg.response); | ||||
|   auto err = connection->write_characteristic(msg.handle, msg.data, msg.response); | ||||
|   if (err != ESP_OK) { | ||||
|     this->send_gatt_error(msg.address, msg.handle, err); | ||||
|   } | ||||
| @@ -373,8 +372,7 @@ void BluetoothProxy::bluetooth_gatt_write_descriptor(const api::BluetoothGATTWri | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   auto err = connection->write_descriptor(msg.handle, reinterpret_cast<const uint8_t *>(msg.data.data()), | ||||
|                                           msg.data.size(), true); | ||||
|   auto err = connection->write_descriptor(msg.handle, msg.data, true); | ||||
|   if (err != ESP_OK) { | ||||
|     this->send_gatt_error(msg.address, msg.handle, err); | ||||
|   } | ||||
|   | ||||
| @@ -839,12 +839,12 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) { | ||||
| void VoiceAssistant::on_audio(const api::VoiceAssistantAudio &msg) { | ||||
| #ifdef USE_SPEAKER  // We should never get to this function if there is no speaker anyway | ||||
|   if ((this->speaker_ != nullptr) && (this->speaker_buffer_ != nullptr)) { | ||||
|     if (this->speaker_buffer_index_ + msg.data_len_ < SPEAKER_BUFFER_SIZE) { | ||||
|       memcpy(this->speaker_buffer_ + this->speaker_buffer_index_, msg.data_ptr_, msg.data_len_); | ||||
|       this->speaker_buffer_index_ += msg.data_len_; | ||||
|       this->speaker_buffer_size_ += msg.data_len_; | ||||
|       this->speaker_bytes_received_ += msg.data_len_; | ||||
|       ESP_LOGV(TAG, "Received audio: %u bytes from API", msg.data_len_); | ||||
|     if (this->speaker_buffer_index_ + msg.data.size() < SPEAKER_BUFFER_SIZE) { | ||||
|       memcpy(this->speaker_buffer_ + this->speaker_buffer_index_, msg.data.data(), msg.data.size()); | ||||
|       this->speaker_buffer_index_ += msg.data.size(); | ||||
|       this->speaker_buffer_size_ += msg.data.size(); | ||||
|       this->speaker_bytes_received_ += msg.data.size(); | ||||
|       ESP_LOGV(TAG, "Received audio: %u bytes from API", msg.data.size()); | ||||
|     } else { | ||||
|       ESP_LOGE(TAG, "Cannot receive audio, buffer is full"); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user