Skip to content

Commit

Permalink
mgmt: hawkbit: also use workqueue for shell run
Browse files Browse the repository at this point in the history
Also use a workqueue, when execution of
hawkBit is requested via shell.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Apr 4, 2024
1 parent 823fb64 commit 839b1c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
8 changes: 8 additions & 0 deletions include/zephyr/mgmt/hawkbit.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ int hawkbit_init(void);
*/
void hawkbit_autohandler(void);

/**
* @brief Runs hawkBit probe and hawkBit update automatically
*
* @details It does the same as hawkbit_autohandler, but only once.
*/
void hawkbit_autohandler_once(void);

/**
* @brief The hawkBit probe verify if there is some update to be performed.
*
Expand All @@ -63,6 +70,7 @@ void hawkbit_autohandler(void);
*/
enum hawkbit_response hawkbit_probe(void);


/**
* @}
*/
Expand Down
15 changes: 14 additions & 1 deletion subsys/mgmt/hawkbit/hawkbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ static union {
} hawkbit_results;

static void autohandler(struct k_work *work);
static void autohandler_once(struct k_work *work);

static K_WORK_DELAYABLE_DEFINE(hawkbit_work_handle, autohandler);
static K_WORK_DELAYABLE_DEFINE(hawkbit_work_handle_once, autohandler_once);

static struct k_sem probe_sem;

Expand Down Expand Up @@ -1191,8 +1193,10 @@ enum hawkbit_response hawkbit_probe(void)
return hb_context.code_status;
}

static void autohandler(struct k_work *work)
static void autohandler_once(struct k_work *work)
{
ARG_UNUSED(work);

switch (hawkbit_probe()) {
case HAWKBIT_UNCONFIRMED_IMAGE:
LOG_ERR("Current image is not confirmed");
Expand Down Expand Up @@ -1239,7 +1243,16 @@ static void autohandler(struct k_work *work)
LOG_INF("hawkBit is already running");
break;
}
}

void hawkbit_autohandler_once(void)
{
k_work_reschedule(&hawkbit_work_handle_once, K_NO_WAIT);
}

static void autohandler(struct k_work *work)
{
autohandler_once(work);
k_work_reschedule(&hawkbit_work_handle, K_MSEC(poll_sleep));
}

Expand Down
43 changes: 1 addition & 42 deletions subsys/mgmt/hawkbit/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,7 @@ static void cmd_run(const struct shell *sh, size_t argc, char **argv)
ARG_UNUSED(argv);

shell_fprintf(sh, SHELL_INFO, "Starting hawkBit run...\n");
switch (hawkbit_probe()) {
case HAWKBIT_UNCONFIRMED_IMAGE:
shell_fprintf(
sh, SHELL_ERROR,
"Image is unconfirmed."
"Rebooting to revert back to previous confirmed image\n");
sys_reboot(SYS_REBOOT_WARM);
break;

case HAWKBIT_CANCEL_UPDATE:
shell_fprintf(sh, SHELL_INFO,
"hawkBit update Cancelled from server\n");
break;

case HAWKBIT_NO_UPDATE:
shell_fprintf(sh, SHELL_INFO, "No update found\n");
break;

case HAWKBIT_OK:
shell_fprintf(sh, SHELL_INFO, "Image Already updated\n");
break;

case HAWKBIT_UPDATE_INSTALLED:
shell_fprintf(sh, SHELL_INFO, "Update Installed\n");
break;

case HAWKBIT_DOWNLOAD_ERROR:
shell_fprintf(sh, SHELL_INFO, "Download Error\n");
break;

case HAWKBIT_NETWORKING_ERROR:
shell_fprintf(sh, SHELL_INFO, "Networking Error\n");
break;

case HAWKBIT_METADATA_ERROR:
shell_fprintf(sh, SHELL_INFO, "Metadata Error\n");
break;

default:
shell_fprintf(sh, SHELL_ERROR, "Invalid response\n");
break;
}
hawkbit_autohandler_once();
k_sleep(K_MSEC(1));
}

Expand Down

0 comments on commit 839b1c2

Please sign in to comment.