Skip to content

Commit 3c88970

Browse files
maass-hamburgkartben
authored andcommitted
mgmt: hawkbit: add CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL
add CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL, to be able to set a interval, how often the progress is saved. Signed-off-by: Fin Maaß <[email protected]>
1 parent 4cd44e7 commit 3c88970

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

subsys/mgmt/hawkbit/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ config HAWKBIT_SAVE_PROGRESS
199199
This is especially useful for large updates over unreliable networks or in
200200
resource-constrained environments.
201201

202+
config HAWKBIT_SAVE_PROGRESS_INTERVAL
203+
int "Save the hawkBit update download progress interval"
204+
default 5
205+
range 0 100
206+
depends on HAWKBIT_SAVE_PROGRESS
207+
help
208+
Set the interval (in percent) that the hawkBit update download progress will be saved.
209+
0 means that the progress will be saved every time a new chunk is downloaded.
210+
202211
module = HAWKBIT
203212
module-str = Log Level for hawkbit
204213
module-help = Enables logging for hawkBit code.

subsys/mgmt/hawkbit/hawkbit.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -953,28 +953,37 @@ static void response_download_cb(struct http_response *rsp, enum http_final_call
953953
}
954954
}
955955

956-
if (rsp->body_found) {
957-
body_data = rsp->body_frag_start;
958-
body_len = rsp->body_frag_len;
956+
if (!rsp->body_found) {
957+
return;
958+
}
959959

960-
ret = flash_img_buffered_write(&hb_context->flash_ctx, body_data, body_len,
961-
final_data == HTTP_DATA_FINAL);
962-
if (ret < 0) {
963-
LOG_ERR("Failed to write flash: %d", ret);
964-
hb_context->code_status = HAWKBIT_DOWNLOAD_ERROR;
965-
return;
966-
}
960+
body_data = rsp->body_frag_start;
961+
body_len = rsp->body_frag_len;
967962

968-
#ifdef CONFIG_HAWKBIT_SAVE_PROGRESS
969-
stream_flash_progress_save(&hb_context->flash_ctx.stream, "hawkbit/flash_progress");
970-
#endif
963+
ret = flash_img_buffered_write(&hb_context->flash_ctx, body_data, body_len,
964+
final_data == HTTP_DATA_FINAL);
965+
if (ret < 0) {
966+
LOG_ERR("Failed to write flash: %d", ret);
967+
hb_context->code_status = HAWKBIT_DOWNLOAD_ERROR;
968+
return;
971969
}
972970

971+
#if defined CONFIG_HAWKBIT_SAVE_PROGRESS && IS_EQ(CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL, 0)
972+
stream_flash_progress_save(&hb_context->flash_ctx.stream, "hawkbit/flash_progress");
973+
#endif
974+
973975
hb_context->dl.downloaded_size = flash_img_bytes_written(&hb_context->flash_ctx);
974976

975977
downloaded = hb_context->dl.downloaded_size * 100 / hb_context->dl.file_size;
976978

977979
if (downloaded != download_progress) {
980+
#if defined CONFIG_HAWKBIT_SAVE_PROGRESS && !IS_EQ(CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL, 0)
981+
if ((downloaded / CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL) >
982+
(download_progress / CONFIG_HAWKBIT_SAVE_PROGRESS_INTERVAL)) {
983+
stream_flash_progress_save(&hb_context->flash_ctx.stream,
984+
"hawkbit/flash_progress");
985+
}
986+
#endif
978987
download_progress = downloaded;
979988
LOG_DBG("Downloaded: %u%% (%u / %u)", download_progress,
980989
hb_context->dl.downloaded_size, hb_context->dl.file_size);

0 commit comments

Comments
 (0)