feat: add manual upgrade firmware

This commit is contained in:
Terrence
2025-09-12 08:45:29 +08:00
parent 469ee2d92a
commit f79506d58b
9 changed files with 169 additions and 66 deletions

View File

@@ -325,13 +325,9 @@ bool Ota::Upgrade(const std::string& firmware_url) {
if (image_header.size() >= sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) {
esp_app_desc_t new_app_info;
memcpy(&new_app_info, image_header.data() + sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t), sizeof(esp_app_desc_t));
ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version);
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 false;
}
ESP_LOGI(TAG, "Current version: %s, New version: %s", current_version, new_app_info.version);
if (esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle)) {
esp_ota_abort(update_handle);
@@ -377,6 +373,11 @@ bool Ota::StartUpgrade(std::function<void(int progress, size_t speed)> callback)
return Upgrade(firmware_url_);
}
bool Ota::StartUpgradeFromUrl(const std::string& url, std::function<void(int progress, size_t speed)> callback) {
upgrade_callback_ = callback;
return Upgrade(url);
}
std::vector<int> Ota::ParseVersion(const std::string& version) {
std::vector<int> versionNumbers;
std::stringstream ss(version);