From 07d29a0b6c1d4f550fa8c69f6bbe20443f0bdec3 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Fri, 20 Feb 2026 13:28:27 +0100 Subject: Replace static node values with random updates every second MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the value field from nodes config — nodes are now created with zero-initialized values, then randomized at startup and every 1000ms via UA_Server_addRepeatedCallback. This is intended for testing OPC UA monitoring and subscriptions. --- src/nodes_config.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/nodes_config.h') diff --git a/src/nodes_config.h b/src/nodes_config.h index 0207a55..cb42942 100644 --- a/src/nodes_config.h +++ b/src/nodes_config.h @@ -8,7 +8,8 @@ * Reads a config file containing node.N.field entries, parses them into * an array of node descriptors, and creates corresponding OPC UA variable * nodes in the server address space. Each node gets a string NodeId in - * namespace 1 (ns=1;s=). + * namespace 1 (ns=1;s=). Nodes are created with zero-initialized + * values; call nodes_config_randomize() to assign random values. * * Supported types (scalar and 1D array via "type[]" suffix): * bool, int16, uint16, int32, uint32, int64, uint64, float, double, string @@ -62,7 +63,6 @@ typedef struct char *description; /**< Optional description text (NULL when absent). */ node_type type; /**< OPC UA data type. */ UA_Boolean is_array; /**< true when the type name ended with "[]". */ - char *value_str; /**< Raw value string (comma-separated for arrays). */ node_access_level access; /**< Read or read-write. */ } node_config; @@ -113,6 +113,20 @@ int nodes_config_load (const char *path, nodes_config *out); */ int nodes_config_add (UA_Server *server, const nodes_config *nc); +/** + * @brief Writes random values to all configured variable nodes. + * + * Generates a random value appropriate for each node's type and writes + * it to the server using UA_Server_writeValue. For array nodes, each + * element is randomized independently. Call srand() before the first + * invocation to seed the random number generator. + * + * @param server The UA_Server containing the nodes. + * @param nc The parsed nodes configuration. + * @return 0 when all nodes were updated, -1 if any write failed. + */ +int nodes_config_randomize (UA_Server *server, const nodes_config *nc); + /** * @brief Frees all memory owned by a nodes_config structure. * -- cgit v1.2.3