diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 06:19:23 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-19 06:19:23 +0100 |
| commit | 2b632bd229edaa9999be5043f9a8ae2ac7d17e41 (patch) | |
| tree | 5071ef9fa36a898fbe009f477441fd2f34a4cb2d /src/server_register.c | |
| parent | 37c0fee672afd3701ea3ed87958da4d548bf1be3 (diff) | |
| download | BobinkCOpcUa-2b632bd229edaa9999be5043f9a8ae2ac7d17e41.tar.gz BobinkCOpcUa-2b632bd229edaa9999be5043f9a8ae2ac7d17e41.zip | |
Add configurable variable node initialization for server_register
New optional CLI argument [nodes-config] lets the server populate its
address space from a dot-indexed config file (node.N.name/type/value/
accessLevel/description). Supports 10 scalar types plus 1D arrays.
Diffstat (limited to 'src/server_register.c')
| -rw-r--r-- | src/server_register.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/server_register.c b/src/server_register.c index b1d87fd..b938ca4 100644 --- a/src/server_register.c +++ b/src/server_register.c @@ -10,6 +10,7 @@ #include "common.h" #include "config.h" +#include "nodes_config.h" #include <open62541/client.h> #include <open62541/client_config_default.h> @@ -110,18 +111,36 @@ main (int argc, char **argv) signal (SIGINT, _s_stop_handler); signal (SIGTERM, _s_stop_handler); - if (argc < 4 || argc > 5) + if (argc < 4 || argc > 6) { UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Usage: %s <server-config> <client-config> " - "<discovery-url> [log-level]", + "<discovery-url> [nodes-config] [log-level]", argv[0]); return EXIT_FAILURE; } const char *discovery_endpoint = argv[3]; - const char *log_level_str = (argc == 5) ? argv[4] : "info"; + /* Parse the optional [nodes-config] and [log-level] arguments. + When only one optional arg is given, disambiguate by checking + whether it is a valid log-level name. */ + const char *nodes_config_path = NULL; + const char *log_level_str = "info"; + + if (argc == 6) + { + nodes_config_path = argv[4]; + log_level_str = argv[5]; + } + else if (argc == 5) + { + if (parse_log_level (argv[4]) >= 0) + log_level_str = argv[4]; + else + nodes_config_path = argv[4]; + } + int log_level = parse_log_level (log_level_str); if (log_level < 0) { @@ -139,6 +158,7 @@ main (int argc, char **argv) config client_cfg = { 0 }; security_config server_sec = { 0 }; security_config client_sec = { 0 }; + nodes_config nodes_cfg = { 0 }; UA_Server *server = NULL; if (config_load (argv[1], &server_cfg) != 0) @@ -198,6 +218,18 @@ main (int argc, char **argv) server_config->applicationDescription.applicationType = UA_APPLICATIONTYPE_SERVER; + /* ── Load and create variable nodes (optional) ───────────── */ + + if (nodes_config_path) + { + if (nodes_config_load (nodes_config_path, &nodes_cfg) != 0) + goto cleanup; + + if (nodes_cfg.count > 0 && nodes_config_add (server, &nodes_cfg) != 0) + UA_LOG_WARNING (UA_Log_Stdout, UA_LOGCATEGORY_SERVER, + "Some nodes failed to initialize"); + } + lds_client_params lds_params = { .app_uri = client_app_uri, .sec = client_sec, @@ -250,6 +282,7 @@ main (int argc, char **argv) cleanup: if (server) UA_Server_delete (server); + nodes_config_free (&nodes_cfg); free_trust_store (client_sec.trust_paths, client_sec.trust_size); free_trust_store (server_sec.trust_paths, server_sec.trust_size); config_free (&client_cfg); |
