Skip to content

Commit

Permalink
mgmt: hawkbit: delay autohandler
Browse files Browse the repository at this point in the history
Be able to delay the next run of
the hawkbit autohandler.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Apr 29, 2024
1 parent 62b4604 commit f946939
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/zephyr/mgmt/hawkbit.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ void hawkbit_autohandler(bool auto_reschedule);
*/
enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t timeout);

/**
* @brief Cancel the run of the hawkBit autohandler.
*
* @return a value from k_work_cancel_delayable().
*/
int hawkbit_autohandler_cancel(void);

/**
* @brief Set the delay for the next run of the autohandler.
*
* @details This function will only delay the next run of the autohandler. The delay will not
* persist after the autohandler runs.
*
* @param timeout The delay to set.
* @param if_bigger If true, the delay will be set only if the new delay is bigger than the current
* one.
*
* @retval 0 if @a if_bigger was true and the current delay was bigger than the new one.
* @retval otherwise, a value from k_work_reschedule().
*/
int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger);

/**
* @brief The hawkBit probe verify if there is some update to be performed.
*
Expand Down
18 changes: 18 additions & 0 deletions subsys/mgmt/hawkbit/hawkbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,24 @@ enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t time
return HAWKBIT_NO_RESPONSE;
}

int hawkbit_autohandler_cancel(void)
{
return k_work_cancel_delayable(&hawkbit_work_handle);
}

int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger)
{
if (!if_bigger || timeout.ticks > k_work_delayable_remaining_get(&hawkbit_work_handle)) {
hawkbit_autohandler_cancel();
LOG_INF("Setting new delay for next run: %02u:%02u:%02u",
(uint32_t)(timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) / 3600,
(uint32_t)((timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) % 3600) / 60,
(uint32_t)(timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) % 60);
return k_work_reschedule(&hawkbit_work_handle, timeout);
}
return 0;
}

void hawkbit_autohandler(bool auto_reschedule)
{
if (auto_reschedule) {
Expand Down

0 comments on commit f946939

Please sign in to comment.