Skip to content

Commit

Permalink
fw_update: only report state/reason for first failed block
Browse files Browse the repository at this point in the history
When a block failure occurs, report the status/reason to the server. If
further failures occur there is no need to report as the download is
continuing to progress.

This approach was adopted after discussion in
#696

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed Dec 11, 2024
1 parent 7459507 commit be31140
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/fw_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ static void fw_update_thread(void *arg)

block_retries.idx = 0;
block_retries.count = 0;
bool block_retries_reported = false;

while (1)
{
Expand Down Expand Up @@ -401,21 +402,29 @@ static void fw_update_thread(void *arg)
next_block,
golioth_status_to_str(err));

golioth_fw_update_report_state_sync(&_component_ctx,
GOLIOTH_OTA_STATE_DOWNLOADING,
GOLIOTH_OTA_REASON_CONNECTION_LOST,
FW_REPORT_COMPONENT_NAME
| FW_REPORT_CURRENT_VERSION
| FW_REPORT_TARGET_VERSION);
if (!block_retries_reported)
{
golioth_fw_update_report_state_sync(&_component_ctx,
GOLIOTH_OTA_STATE_DOWNLOADING,
GOLIOTH_OTA_REASON_CONNECTION_LOST,
FW_REPORT_COMPONENT_NAME
| FW_REPORT_CURRENT_VERSION
| FW_REPORT_TARGET_VERSION);
}

golioth_sys_msleep(FW_UPDATE_RESUME_DELAY_S * 1000);

golioth_fw_update_report_state_sync(&_component_ctx,
GOLIOTH_OTA_STATE_DOWNLOADING,
GOLIOTH_OTA_REASON_READY,
FW_REPORT_COMPONENT_NAME
| FW_REPORT_CURRENT_VERSION
| FW_REPORT_TARGET_VERSION);
if (!block_retries_reported)
{
golioth_fw_update_report_state_sync(&_component_ctx,
GOLIOTH_OTA_STATE_DOWNLOADING,
GOLIOTH_OTA_REASON_READY,
FW_REPORT_COMPONENT_NAME
| FW_REPORT_CURRENT_VERSION
| FW_REPORT_TARGET_VERSION);

block_retries_reported = true;
}
}
}

Expand Down

0 comments on commit be31140

Please sign in to comment.