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);
95
95
*/
96
96
void hawkbit_reboot (void );
97
97
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
+
98
118
/**
99
119
* @}
100
120
*/
Original file line number Diff line number Diff line change @@ -92,6 +92,20 @@ config HAWKBIT_STATUS_BUFFER_SIZE
92
92
json strings, that are sent to the hawkBit server. It might
93
93
be increased if the custom attributes are used extensively.
94
94
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
+
95
109
module = HAWKBIT
96
110
module-str = Log Level for hawkbit
97
111
module-help = Enables logging for hawkBit code.
Original file line number Diff line number Diff line change 5
5
*/
6
6
#include "hawkbit_device.h"
7
7
#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 ;
8
14
9
15
bool 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 )
10
21
{
11
22
uint8_t hwinfo_id [DEVICE_ID_BIN_MAX_SIZE ];
12
23
ssize_t length ;
@@ -21,3 +32,16 @@ bool hawkbit_get_device_identity(char *id, int id_max_len)
21
32
22
33
return length > 0 ;
23
34
}
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 10
10
#include <zephyr/kernel.h>
11
11
#include <zephyr/drivers/hwinfo.h>
12
12
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
13
17
#define DEVICE_ID_BIN_MAX_SIZE 16
14
18
#define DEVICE_ID_HEX_MAX_SIZE ((DEVICE_ID_BIN_MAX_SIZE * 2) + 1)
19
+ #endif
15
20
16
21
bool hawkbit_get_device_identity (char * id , int id_max_len );
17
22
You can’t perform that action at this time.
0 commit comments