File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed
Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,26 @@ enum hawkbit_response hawkbit_probe(void);
9595 */
9696void hawkbit_reboot (void );
9797
98+ /**
99+ * @brief Callback to get the device identity.
100+ *
101+ * @param id Pointer to the buffer to store the device identity
102+ * @param id_max_len The maximum length of the buffer
103+ */
104+ typedef bool (* hawkbit_get_device_identity_cb_handler_t )(char * id , int id_max_len );
105+
106+ /**
107+ * @brief Set the device identity callback.
108+ *
109+ * @details This function is used to set a custom device identity callback.
110+ *
111+ * @param cb The callback function.
112+ *
113+ * @return 0 on success.
114+ * @return -EINVAL if the callback is NULL.
115+ */
116+ int hawkbit_set_device_identity_cb (hawkbit_get_device_identity_cb_handler_t cb );
117+
98118/**
99119 * @}
100120 */
Original file line number Diff line number Diff line change @@ -92,6 +92,20 @@ config HAWKBIT_STATUS_BUFFER_SIZE
9292 json strings, that are sent to the hawkBit server. It might
9393 be increased if the custom attributes are used extensively.
9494
95+ config HAWKBIT_CUSTOM_DEVICE_ID
96+ bool "Custom device id through callback function"
97+ help
98+ Be able to customize the device id during runtime to a custom value,
99+ by configuring the callback function. See `hawkbit_set_device_identity_cb`
100+
101+ config HAWKBIT_DEVICE_ID_MAX_LENGTH
102+ int "Maximum length of the device id"
103+ depends on HAWKBIT_CUSTOM_DEVICE_ID
104+ range 1 128
105+ default 32
106+ help
107+ Maximum length of the device id.
108+
95109module = HAWKBIT
96110module-str = Log Level for hawkbit
97111module-help = Enables logging for hawkBit code.
Original file line number Diff line number Diff line change 55 */
66#include "hawkbit_device.h"
77#include <string.h>
8+ #include <zephyr/mgmt/hawkbit.h>
9+
10+ static bool hawkbit_get_device_identity_default (char * id , int id_max_len );
11+
12+ static hawkbit_get_device_identity_cb_handler_t hawkbit_get_device_identity_cb_handler =
13+ hawkbit_get_device_identity_default ;
814
915bool hawkbit_get_device_identity (char * id , int id_max_len )
16+ {
17+ return hawkbit_get_device_identity_cb_handler (id , id_max_len );
18+ }
19+
20+ static bool hawkbit_get_device_identity_default (char * id , int id_max_len )
1021{
1122 uint8_t hwinfo_id [DEVICE_ID_BIN_MAX_SIZE ];
1223 ssize_t length ;
@@ -21,3 +32,16 @@ bool hawkbit_get_device_identity(char *id, int id_max_len)
2132
2233 return length > 0 ;
2334}
35+
36+ #ifdef CONFIG_HAWKBIT_CUSTOM_DEVICE_ID
37+ int hawkbit_set_device_identity_cb (hawkbit_get_device_identity_cb_handler_t cb )
38+ {
39+ if (cb == NULL ) {
40+ return - EINVAL ;
41+ }
42+
43+ hawkbit_get_device_identity_cb_handler = cb ;
44+
45+ return 0 ;
46+ }
47+ #endif /* CONFIG_HAWKBIT_CUSTOM_DEVICE_ID */
Original file line number Diff line number Diff line change 1010#include <zephyr/kernel.h>
1111#include <zephyr/drivers/hwinfo.h>
1212
13+ #ifdef CONFIG_HAWKBIT_CUSTOM_DEVICE_ID
14+ #define DEVICE_ID_BIN_MAX_SIZE (CONFIG_HAWKBIT_DEVICE_ID_MAX_LENGTH / 2)
15+ #define DEVICE_ID_HEX_MAX_SIZE (CONFIG_HAWKBIT_DEVICE_ID_MAX_LENGTH + 1)
16+ #else
1317#define DEVICE_ID_BIN_MAX_SIZE 16
1418#define DEVICE_ID_HEX_MAX_SIZE ((DEVICE_ID_BIN_MAX_SIZE * 2) + 1)
19+ #endif
1520
1621bool hawkbit_get_device_identity (char * id , int id_max_len );
1722
You can’t perform that action at this time.
0 commit comments