mgmt: hawkbit: samples: add event callbacks

add event callbacks to sample.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-05-08 09:43:34 +02:00 committed by Benjamin Cabé
parent 49f5bc9698
commit 97cdd97840
2 changed files with 32 additions and 0 deletions

View file

@ -70,3 +70,6 @@ CONFIG_BUILD_OUTPUT_HEX=y
#Use custom attributes for hawkBit
CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES=y
# Use event callbacks for hawkBit
CONFIG_HAWKBIT_EVENT_CALLBACKS=y

View file

@ -8,6 +8,7 @@
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/mgmt/hawkbit/autohandler.h>
#include <zephyr/mgmt/hawkbit/event.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/reboot.h>
@ -55,6 +56,29 @@ int hawkbit_new_config_data_cb(const char *device_id, uint8_t *buffer, const siz
}
#endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */
#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS
void hawkbit_event_cb(struct hawkbit_event_callback *cb, enum hawkbit_event_type event)
{
LOG_INF("hawkBit event: %d", event);
switch (event) {
case HAWKBIT_EVENT_START_RUN:
LOG_INF("Run of hawkBit started");
break;
case HAWKBIT_EVENT_END_RUN:
LOG_INF("Run of hawkBit ended");
break;
default:
break;
}
}
static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_start, hawkbit_event_cb, HAWKBIT_EVENT_START_RUN);
static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_end, hawkbit_event_cb, HAWKBIT_EVENT_END_RUN);
#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */
int main(void)
{
int ret = -1;
@ -73,6 +97,11 @@ int main(void)
}
#endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */
#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS
hawkbit_event_add_callback(&hb_event_cb_start);
hawkbit_event_add_callback(&hb_event_cb_end);
#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */
ret = hawkbit_init();
if (ret < 0) {
LOG_ERR("Failed to init hawkBit");