Merge branch 'feature/ota_image_size' into 'master'

esp_https_ota: Added esp_https_ota_get_image_size() to retrieve total size of OTA update

Closes IDFGH-5096

See merge request espressif/esp-idf!13496
This commit is contained in:
Mahavir Jain 2021-05-17 05:31:58 +00:00
commit fe02ef0fed
2 changed files with 31 additions and 0 deletions

View File

@ -201,6 +201,21 @@ esp_err_t esp_https_ota_get_img_desc(esp_https_ota_handle_t https_ota_handle, es
*/
int esp_https_ota_get_image_len_read(esp_https_ota_handle_t https_ota_handle);
/**
* @brief This function returns OTA image total size.
*
* @note This API should be called after esp_https_ota_begin() has been already called.
* This can be used to create some sort of progress indication
* (in combination with esp_https_ota_get_image_len_read())
*
* @param[in] https_ota_handle pointer to esp_https_ota_handle_t structure
*
* @return
* - -1 On failure or chunked encoding
* - total bytes of image
*/
int esp_https_ota_get_image_size(esp_https_ota_handle_t https_ota_handle);
#ifdef __cplusplus
}
#endif

View File

@ -246,6 +246,10 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_
goto http_cleanup;
}
if (!https_ota_handle->partial_http_download) {
https_ota_handle->image_length = esp_http_client_get_content_length(https_ota_handle->http_client);
}
https_ota_handle->update_partition = NULL;
ESP_LOGI(TAG, "Starting OTA...");
https_ota_handle->update_partition = esp_ota_get_next_update_partition(NULL);
@ -521,6 +525,18 @@ int esp_https_ota_get_image_len_read(esp_https_ota_handle_t https_ota_handle)
return handle->binary_file_len;
}
int esp_https_ota_get_image_size(esp_https_ota_handle_t https_ota_handle)
{
esp_https_ota_t *handle = (esp_https_ota_t *)https_ota_handle;
if (handle == NULL) {
return -1;
}
if (handle->state < ESP_HTTPS_OTA_BEGIN) {
return -1;
}
return handle->image_length;
}
esp_err_t esp_https_ota(const esp_http_client_config_t *config)
{
if (!config) {