Skip to content

Commit

Permalink
net: fota_download: fix reported download progress
Browse files Browse the repository at this point in the history
The progress used to be the written data offset instead of
the size of the downloaded data, and would in case of modem delta
update block at 23% while the download was approaching 100%.

Signed-off-by: Tomi Fontanilles <[email protected]>
  • Loading branch information
tomi-font authored and anangl committed Nov 15, 2023
1 parent cfa7efb commit 7c05a1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions include/net/download_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ int download_client_set_host(struct download_client *client, const char *host,
*/
__deprecated int download_client_connect(struct download_client *client, const char *host,
const struct download_client_cfg *config);

/**
* @brief Download a file.
*
Expand All @@ -279,6 +280,7 @@ __deprecated int download_client_connect(struct download_client *client, const c
*/
int download_client_start(struct download_client *client, const char *file,
size_t from);

/**
* @brief Retrieve the size of the file being downloaded, in bytes.
*
Expand All @@ -291,6 +293,18 @@ int download_client_start(struct download_client *client, const char *file,
*/
int download_client_file_size_get(struct download_client *client, size_t *size);

/**
* @brief Retrieve the number of bytes downloaded so far.
*
* The progress is only available after the download has begun.
*
* @param[in] client Client instance.
* @param[out] size Number of bytes downloaded so far.
*
* @retval int Zero on success, a negative error code otherwise.
*/
int download_client_downloaded_size_get(struct download_client *client, size_t *size);

/**
* @brief Initiate disconnection.
*
Expand Down
13 changes: 13 additions & 0 deletions subsys/net/lib/download_client/src/download_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,16 @@ int download_client_file_size_get(struct download_client *client, size_t *size)

return 0;
}

int download_client_downloaded_size_get(struct download_client *client, size_t *size)
{
if (!client || !size) {
return -EINVAL;
}

k_mutex_lock(&client->mutex, K_FOREVER);
*size = client->progress;
k_mutex_unlock(&client->mutex);

return 0;
}
6 changes: 2 additions & 4 deletions subsys/net/lib/fota_download/src/fota_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,9 @@ static int download_client_callback(const struct download_client_evt *event)
}

if (IS_ENABLED(CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT)) {
err = dfu_target_offset_get(&offset);
err = download_client_downloaded_size_get(&dlc, &offset);
if (err != 0) {
LOG_DBG("unable to get dfu target "
"offset err: %d",
err);
LOG_DBG("unable to get downloaded size err: %d", err);
set_error_state(FOTA_DOWNLOAD_ERROR_CAUSE_INTERNAL);
goto error_and_close;
}
Expand Down

0 comments on commit 7c05a1b

Please sign in to comment.