diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-20 13:28:27 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-20 13:37:21 +0100 |
| commit | 07d29a0b6c1d4f550fa8c69f6bbe20443f0bdec3 (patch) | |
| tree | 27f4eaf81e6a8868185c8898afb2af1e17c7a337 /src/nodes_config.h | |
| parent | 2b632bd229edaa9999be5043f9a8ae2ac7d17e41 (diff) | |
| download | BobinkCOpcUa-07d29a0b6c1d4f550fa8c69f6bbe20443f0bdec3.tar.gz BobinkCOpcUa-07d29a0b6c1d4f550fa8c69f6bbe20443f0bdec3.zip | |
Replace static node values with random updates every second
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.
Diffstat (limited to 'src/nodes_config.h')
| -rw-r--r-- | src/nodes_config.h | 18 |
1 files changed, 16 insertions, 2 deletions
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=<name>). + * namespace 1 (ns=1;s=<name>). 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; @@ -114,6 +114,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. * * After this call the structure is zeroed and must not be used |
