From 1a85b40444326aac996dd7188d7fbd6a6864d481 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Fri, 13 Jun 2025 10:26:57 +0200 Subject: [PATCH] Fixed setting in canbus --- software/lib/canbus.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/software/lib/canbus.c b/software/lib/canbus.c index 5d1047d..55442a3 100644 --- a/software/lib/canbus.c +++ b/software/lib/canbus.c @@ -13,9 +13,27 @@ LOG_MODULE_REGISTER(canbus, CONFIG_LOG_CAN_LEVEL); static int canbus_set(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg) { + const char *next; + int rc; + // Handle setting values for CAN bus configuration LOG_DBG("Setting CAN bus configuration: key=%s, len=%zu", key, len); - // Implement the logic to set the CAN bus configuration based on the key and value + if (settings_name_steq(key, "node_id", &next) && next != NULL) + { + if (len != sizeof(node_id)) + { + LOG_ERR("Invalid length for node_id setting: %zu", len); + return -EINVAL; // Invalid argument + } + + int rc = read_cb(cb_arg, &node_id, sizeof(node_id)); + if (rc < 0) + { + LOG_ERR("Failed to read node_id setting: %d", rc); + return rc; // Read error + } + LOG_DBG("Set CAN bus node ID to: %d", node_id); + } return 0; // Return 0 on success } @@ -30,7 +48,7 @@ int canbus_init(void) settings_subsys_init(); settings_register(&canbus_settings_handler); settings_load(); - + rc = settings_get_val_len("canbus/node_id"); if (rc < 0) { @@ -47,7 +65,9 @@ int canbus_init(void) LOG_ERR("Failed to save default CAN bus node id: %d", rc); return rc; } - } else { + } + else + { rc = settings_load_one("canbus/node_id", &node_id, sizeof(node_id)); if (rc < 0) {