Skip to content

Commit 421ab50

Browse files
maass-hamburgfabiobaltieri
authored andcommitted
mgmt: hawkbit: delay autohandler
Be able to delay the next run of the hawkbit autohandler. Signed-off-by: Fin Maaß <[email protected]>
1 parent f5a3d7d commit 421ab50

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

include/zephyr/mgmt/hawkbit.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ void hawkbit_autohandler(bool auto_reschedule);
122122
*/
123123
enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t timeout);
124124

125+
/**
126+
* @brief Cancel the run of the hawkBit autohandler.
127+
*
128+
* @return a value from k_work_cancel_delayable().
129+
*/
130+
int hawkbit_autohandler_cancel(void);
131+
132+
/**
133+
* @brief Set the delay for the next run of the autohandler.
134+
*
135+
* @details This function will only delay the next run of the autohandler. The delay will not
136+
* persist after the autohandler runs.
137+
*
138+
* @param timeout The delay to set.
139+
* @param if_bigger If true, the delay will be set only if the new delay is bigger than the current
140+
* one.
141+
*
142+
* @retval 0 if @a if_bigger was true and the current delay was bigger than the new one.
143+
* @retval otherwise, a value from k_work_reschedule().
144+
*/
145+
int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger);
146+
125147
/**
126148
* @brief The hawkBit probe verify if there is some update to be performed.
127149
*

subsys/mgmt/hawkbit/hawkbit.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,24 @@ enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t time
15561556
return HAWKBIT_NO_RESPONSE;
15571557
}
15581558

1559+
int hawkbit_autohandler_cancel(void)
1560+
{
1561+
return k_work_cancel_delayable(&hawkbit_work_handle);
1562+
}
1563+
1564+
int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger)
1565+
{
1566+
if (!if_bigger || timeout.ticks > k_work_delayable_remaining_get(&hawkbit_work_handle)) {
1567+
hawkbit_autohandler_cancel();
1568+
LOG_INF("Setting new delay for next run: %02u:%02u:%02u",
1569+
(uint32_t)(timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) / 3600,
1570+
(uint32_t)((timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) % 3600) / 60,
1571+
(uint32_t)(timeout.ticks / CONFIG_SYS_CLOCK_TICKS_PER_SEC) % 60);
1572+
return k_work_reschedule(&hawkbit_work_handle, timeout);
1573+
}
1574+
return 0;
1575+
}
1576+
15591577
void hawkbit_autohandler(bool auto_reschedule)
15601578
{
15611579
if (auto_reschedule) {

0 commit comments

Comments
 (0)