From 5185afffb92f69e2f0de3d3693c1654a9622e1d4 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Fri, 20 Feb 2026 15:36:20 +0100 Subject: Add sbyte, byte, datetime, guid, and bytestring data types to nodes config --- src/nodes_config.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------ src/nodes_config.h | 10 ++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nodes_config.c b/src/nodes_config.c index 3468436..f1a18a2 100644 --- a/src/nodes_config.c +++ b/src/nodes_config.c @@ -37,6 +37,11 @@ static const type_map_entry _s_type_map[] = { { "float", NODE_TYPE_FLOAT, UA_TYPES_FLOAT }, { "double", NODE_TYPE_DOUBLE, UA_TYPES_DOUBLE }, { "string", NODE_TYPE_STRING, UA_TYPES_STRING }, + { "sbyte", NODE_TYPE_SBYTE, UA_TYPES_SBYTE }, + { "byte", NODE_TYPE_BYTE, UA_TYPES_BYTE }, + { "datetime", NODE_TYPE_DATETIME, UA_TYPES_DATETIME }, + { "guid", NODE_TYPE_GUID, UA_TYPES_GUID }, + { "bytestring", NODE_TYPE_BYTESTRING, UA_TYPES_BYTESTRING }, }; #define TYPE_MAP_SIZE (sizeof (_s_type_map) / sizeof (_s_type_map[0])) @@ -375,6 +380,8 @@ nodes_config_add (UA_Server *server, const nodes_config *nc) union { UA_Boolean b; + UA_SByte sb; + UA_Byte byte; UA_Int16 i16; UA_UInt16 u16; UA_Int32 i32; @@ -383,11 +390,13 @@ nodes_config_add (UA_Server *server, const nodes_config *nc) UA_UInt64 u64; UA_Float f; UA_Double d; + UA_DateTime dt; + UA_Guid g; } zero = { 0 }; - if (n->type == NODE_TYPE_STRING) + if (n->type == NODE_TYPE_STRING || n->type == NODE_TYPE_BYTESTRING) { - UA_String empty_str = UA_STRING (""); - UA_Variant_setScalarCopy (&attr.value, &empty_str, dt); + UA_String empty = UA_STRING (""); + UA_Variant_setScalarCopy (&attr.value, &empty, dt); } else { @@ -443,7 +452,8 @@ nodes_config_add (UA_Server *server, const nodes_config *nc) } /* UA_Server_addVariableNode deep-copies everything. */ - if (n->type == NODE_TYPE_STRING && !n->is_array) + if ((n->type == NODE_TYPE_STRING || n->type == NODE_TYPE_BYTESTRING) + && !n->is_array) UA_Variant_clear (&attr.value); if (array_buf) UA_Array_delete (array_buf, NODES_DEFAULT_ARRAY_SIZE, dt); @@ -502,6 +512,34 @@ _s_random_scalar (node_type type, void *out, UA_String *out_str) *out_str = UA_String_fromChars (buf); break; } + case NODE_TYPE_SBYTE: + *(UA_SByte *)out = (UA_SByte)(rand () % 201 - 100); + break; + case NODE_TYPE_BYTE: + *(UA_Byte *)out = (UA_Byte)(rand () % 256); + break; + case NODE_TYPE_DATETIME: + *(UA_DateTime *)out = UA_DateTime_now (); + break; + case NODE_TYPE_GUID: + { + UA_Guid *g = (UA_Guid *)out; + g->data1 = (UA_UInt32)rand (); + g->data2 = (UA_UInt16)(rand () % 65536); + g->data3 = (UA_UInt16)(rand () % 65536); + for (int k = 0; k < 8; k++) + g->data4[k] = (UA_Byte)(rand () % 256); + break; + } + case NODE_TYPE_BYTESTRING: + { + UA_ByteString bs; + UA_ByteString_allocBuffer (&bs, 8); + for (size_t k = 0; k < 8; k++) + bs.data[k] = (UA_Byte)(rand () % 256); + *out_str = bs; + break; + } } } @@ -530,6 +568,8 @@ nodes_config_randomize (UA_Server *server, const nodes_config *nc) union { UA_Boolean b; + UA_SByte sb; + UA_Byte byte; UA_Int16 i16; UA_UInt16 u16; UA_Int32 i32; @@ -538,12 +578,14 @@ nodes_config_randomize (UA_Server *server, const nodes_config *nc) UA_UInt64 u64; UA_Float f; UA_Double d; + UA_DateTime dt; + UA_Guid g; } buf; UA_String str_buf = UA_STRING_NULL; _s_random_scalar (n->type, &buf, &str_buf); - if (n->type == NODE_TYPE_STRING) + if (n->type == NODE_TYPE_STRING || n->type == NODE_TYPE_BYTESTRING) { UA_Variant_setScalarCopy (&value, &str_buf, dt); UA_String_clear (&str_buf); @@ -567,7 +609,8 @@ nodes_config_randomize (UA_Server *server, const nodes_config *nc) void *elem = (char *)array + j * dt->memSize; UA_String str_buf = UA_STRING_NULL; _s_random_scalar (n->type, elem, &str_buf); - if (n->type == NODE_TYPE_STRING) + if (n->type == NODE_TYPE_STRING + || n->type == NODE_TYPE_BYTESTRING) *(UA_String *)elem = str_buf; } diff --git a/src/nodes_config.h b/src/nodes_config.h index cb42942..1fb220c 100644 --- a/src/nodes_config.h +++ b/src/nodes_config.h @@ -12,7 +12,8 @@ * 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 + * bool, sbyte, byte, int16, uint16, int32, uint32, int64, uint64, + * float, double, string, datetime, guid, bytestring * * Access levels: read, readwrite. */ @@ -39,7 +40,12 @@ typedef enum NODE_TYPE_UINT64, NODE_TYPE_FLOAT, NODE_TYPE_DOUBLE, - NODE_TYPE_STRING + NODE_TYPE_STRING, + NODE_TYPE_SBYTE, + NODE_TYPE_BYTE, + NODE_TYPE_DATETIME, + NODE_TYPE_GUID, + NODE_TYPE_BYTESTRING } node_type; /** -- cgit v1.2.3