v1.8.0: Audio 代码重构与低功耗优化 (#943)

* Reconstruct Audio Code

* Remove old IoT implementation

* Add MQTT-UDP documentation

* OTA升级失败时,可以继续使用
This commit is contained in:
Xiaoxia
2025-07-19 22:45:22 +08:00
committed by GitHub
parent 0621578f55
commit 3c71558a5f
173 changed files with 2099 additions and 3265 deletions

View File

@@ -260,13 +260,13 @@ void Ota::MarkCurrentVersionValid() {
}
}
void Ota::Upgrade(const std::string& firmware_url) {
bool Ota::Upgrade(const std::string& firmware_url) {
ESP_LOGI(TAG, "Upgrading firmware from %s", firmware_url.c_str());
esp_ota_handle_t update_handle = 0;
auto update_partition = esp_ota_get_next_update_partition(NULL);
if (update_partition == NULL) {
ESP_LOGE(TAG, "Failed to get update partition");
return;
return false;
}
ESP_LOGI(TAG, "Writing to partition %s at offset 0x%lx", update_partition->label, update_partition->address);
@@ -277,18 +277,18 @@ void Ota::Upgrade(const std::string& firmware_url) {
auto http = std::unique_ptr<Http>(network->CreateHttp(0));
if (!http->Open("GET", firmware_url)) {
ESP_LOGE(TAG, "Failed to open HTTP connection");
return;
return false;
}
if (http->GetStatusCode() != 200) {
ESP_LOGE(TAG, "Failed to get firmware, status code: %d", http->GetStatusCode());
return;
return false;
}
size_t content_length = http->GetBodyLength();
if (content_length == 0) {
ESP_LOGE(TAG, "Failed to get content length");
return;
return false;
}
char buffer[512];
@@ -298,7 +298,7 @@ void Ota::Upgrade(const std::string& firmware_url) {
int ret = http->Read(buffer, sizeof(buffer));
if (ret < 0) {
ESP_LOGE(TAG, "Failed to read HTTP data: %s", esp_err_to_name(ret));
return;
return false;
}
// Calculate speed and progress every second
@@ -328,13 +328,13 @@ void Ota::Upgrade(const std::string& firmware_url) {
auto current_version = esp_app_get_description()->version;
if (memcmp(new_app_info.version, current_version, sizeof(new_app_info.version)) == 0) {
ESP_LOGE(TAG, "Firmware version is the same, skipping upgrade");
return;
return false;
}
if (esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle)) {
esp_ota_abort(update_handle);
ESP_LOGE(TAG, "Failed to begin OTA");
return;
return false;
}
image_header_checked = true;
@@ -345,7 +345,7 @@ void Ota::Upgrade(const std::string& firmware_url) {
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to write OTA data: %s", esp_err_to_name(err));
esp_ota_abort(update_handle);
return;
return false;
}
}
http->Close();
@@ -357,23 +357,22 @@ void Ota::Upgrade(const std::string& firmware_url) {
} else {
ESP_LOGE(TAG, "Failed to end OTA: %s", esp_err_to_name(err));
}
return;
return false;
}
err = esp_ota_set_boot_partition(update_partition);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to set boot partition: %s", esp_err_to_name(err));
return;
return false;
}
ESP_LOGI(TAG, "Firmware upgrade successful, rebooting in 3 seconds...");
vTaskDelay(pdMS_TO_TICKS(3000));
esp_restart();
ESP_LOGI(TAG, "Firmware upgrade successful");
return true;
}
void Ota::StartUpgrade(std::function<void(int progress, size_t speed)> callback) {
bool Ota::StartUpgrade(std::function<void(int progress, size_t speed)> callback) {
upgrade_callback_ = callback;
Upgrade(firmware_url_);
return Upgrade(firmware_url_);
}
std::vector<int> Ota::ParseVersion(const std::string& version) {