Kaynağa Gözat

add nodeid to addVariableNode call

Julius Pfrommer 9 yıl önce
ebeveyn
işleme
5b8477ff35

+ 2 - 2
examples/opcuaServer.c

@@ -79,7 +79,7 @@ int main(int argc, char** argv) {
     UA_Variant_setValue(myIntegerVariant, myInteger, UA_TYPES_INT32);
     UA_QualifiedName myIntegerName;
     UA_QUALIFIEDNAME_ASSIGN(myIntegerName, "the answer");
-    UA_Server_addVariableNode(server, myIntegerVariant, &myIntegerName,
+    UA_Server_addVariableNode(server, myIntegerVariant, &UA_NODEID_NULL, &myIntegerName,
                               &UA_NODEID_STATIC(UA_NS0ID_OBJECTSFOLDER,0),
                               &UA_NODEID_STATIC(UA_NS0ID_ORGANIZES,0));
     
@@ -94,7 +94,7 @@ int main(int argc, char** argv) {
         UA_QualifiedName *nodeName = UA_QualifiedName_new();
         sprintf(str,"%d",i);
         UA_QualifiedName_copycstring(str, nodeName);
-        UA_Server_addVariableNode(server, variant, nodeName,
+        UA_Server_addVariableNode(server, variant, &UA_NODEID_NULL, nodeName,
                                   &UA_NODEID_STATIC(UA_NS0ID_OBJECTSFOLDER,0),
                                   &UA_NODEID_STATIC(UA_NS0ID_ORGANIZES,0));
     }

+ 3 - 2
include/ua_server.h

@@ -59,8 +59,9 @@ UA_StatusCode UA_EXPORT UA_Server_run(UA_Server *server, UA_UInt16 nThreads, UA_
 /** Add a reference to the server's address space */
 UA_StatusCode UA_EXPORT UA_Server_addReference(UA_Server *server, const UA_AddReferencesItem *item);
 
-UA_StatusCode UA_EXPORT UA_Server_addVariableNode(UA_Server *server, UA_Variant *value, UA_QualifiedName *browseName,
-                                                  const UA_NodeId *parentNodeId, const UA_NodeId *referenceTypeId );
+UA_StatusCode UA_EXPORT UA_Server_addVariableNode(UA_Server *server, UA_Variant *value, UA_NodeId *nodeId,
+                                                  UA_QualifiedName *browseName, const UA_NodeId *parentNodeId,
+                                                  const UA_NodeId *referenceTypeId);
 
 /** Work that is run in the main loop (singlethreaded) or dispatched to a worker
     thread. */

+ 1 - 0
include/ua_types.h

@@ -369,6 +369,7 @@ UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
 #define UA_NODEID_STATIC(NUMERICID, NAMESPACE)                          \
     (UA_NodeId){.namespaceIndex = NAMESPACE, .identifierType = UA_NODEIDTYPE_NUMERIC, \
             .identifier.numeric = NUMERICID}
+#define UA_NODEID_NULL UA_NODEID_STATIC(0,0)
 
 /* ExpandedNodeId */
 UA_Boolean UA_EXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);

+ 4 - 2
src/server/ua_server_addressspace.c

@@ -12,10 +12,12 @@
     /* } */
     /* tmpNode->value.type = &UA_TYPES[i]; */
 
-UA_StatusCode UA_Server_addVariableNode(UA_Server *server, UA_Variant *value, UA_QualifiedName *browseName,
-                                        const UA_NodeId *parentNodeId, const UA_NodeId *referenceTypeId ) {
+UA_StatusCode UA_Server_addVariableNode(UA_Server *server, UA_Variant *value, UA_NodeId *nodeId,
+                                        UA_QualifiedName *browseName, const UA_NodeId *parentNodeId,
+                                        const UA_NodeId *referenceTypeId) {
     UA_VariableNode *node = UA_VariableNode_new();
     node->value = *value; // copy content
+    UA_NodeId_copy(nodeId, &node->nodeId);
     UA_QualifiedName_copy(browseName, &node->browseName);
     UA_String_copy(&browseName->name, &node->displayName.text);
     UA_ExpandedNodeId parentId; // we need an expandednodeid