Browse Source

adding datasource example
cleaned up server addnode api (not done yet) #375

Stasik0 9 years ago
parent
commit
f4ef1e7662

+ 3 - 0
examples/CMakeLists.txt

@@ -17,6 +17,9 @@ endif(ENABLE_MULTITHREADING)
 add_executable(server_variable server_variable.c)
 target_link_libraries(server_variable ${LIBS})
 
+add_executable(server_datasource server_datasource.c)
+target_link_libraries(server_datasource ${LIBS})
+
 add_executable(server_repeated_job server_repeated_job.c)
 target_link_libraries(server_repeated_job ${LIBS})
 

+ 43 - 23
examples/server.c

@@ -223,8 +223,15 @@ int main(int argc, char** argv) {
   // add node with the datetime data source
   UA_DataSource dateDataSource = (UA_DataSource) {.handle = NULL, .read = readTimeData, .write = NULL};
   const UA_QualifiedName dateName = UA_QUALIFIEDNAME(1, "current time");
-  UA_Server_addDataSourceVariableNode(server, dateDataSource, dateName, UA_NODEID_NULL,
-                                  UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), NULL);
+  const UA_LocalizedText dateNameBrowseName = UA_LOCALIZEDTEXT("en_US","current time");
+  UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, dateName, dateNameBrowseName, dateNameBrowseName, 0, 0,
+
+                                  UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                  UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+
+                                  dateDataSource,
+
+                                  NULL);
 
 #ifndef _WIN32
   //cpu temperature monitoring for linux machines
@@ -232,8 +239,15 @@ int main(int argc, char** argv) {
           // add node with the data source
           UA_DataSource temperatureDataSource = (UA_DataSource) {.handle = NULL, .read = readTemperature, .write = NULL};
           const UA_QualifiedName tempName = UA_QUALIFIEDNAME(1, "cpu temperature");
-          UA_Server_addDataSourceVariableNode(server, temperatureDataSource, tempName, UA_NODEID_NULL,
-                                              UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), NULL);
+          const UA_LocalizedText tempNameBrowseName = UA_LOCALIZEDTEXT("en_US","temperature");
+          UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, tempName, tempNameBrowseName, tempNameBrowseName, 0, 0,
+
+                                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                            UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+
+                                            temperatureDataSource,
+
+                                            NULL);
   }
 
   //LED control for rpi
@@ -250,9 +264,15 @@ int main(int argc, char** argv) {
       // add node with the LED status data source
       UA_DataSource ledStatusDataSource = (UA_DataSource) {.handle = NULL, .read = readLedStatus, .write = writeLedStatus};
       const UA_QualifiedName statusName = UA_QUALIFIEDNAME(0, "status LED");
-      UA_Server_addDataSourceVariableNode(server, ledStatusDataSource, statusName, UA_NODEID_NULL,
-                                          UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
-                                          UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), NULL);
+      const UA_LocalizedText statusNameBrowseName = UA_LOCALIZEDTEXT("en_US","status LED");
+      UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, statusName, statusNameBrowseName, statusNameBrowseName, 0, 0,
+
+                                        UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                        UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+
+                                        ledStatusDataSource,
+
+                                        NULL);
     } else {
       UA_LOG_WARNING(logger, UA_LOGCATEGORY_USERLAND, "[Raspberry Pi] LED file exist, but I have no access (try to run server with sudo)");
     }
@@ -267,32 +287,32 @@ int main(int argc, char** argv) {
   const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
   UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
   UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
-  UA_Server_addVariableNode(server, myIntegerNodeId, myIntegerName, UA_LOCALIZEDTEXT("en_US", "the answer"), UA_LOCALIZEDTEXT("en_US", "the answer"),
-                            parentNodeId, parentReferenceNodeId, 0, 0, myIntegerVariant, NULL);
+  UA_Server_addVariableNode(server, myIntegerNodeId, myIntegerName, UA_LOCALIZEDTEXT("en_US", "the answer"), UA_LOCALIZEDTEXT("en_US", "the answer"),  0, 0,
+                            parentNodeId, parentReferenceNodeId, myIntegerVariant, NULL);
 
   /**************/
   /* Demo Nodes */
   /**************/
 
 #define DEMOID 50000
-  UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEMOID), UA_QUALIFIEDNAME(1, "Demo"), UA_LOCALIZEDTEXT("en_US","Demo"), 
-                          UA_LOCALIZEDTEXT("en_US","Demo"), UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 
-                          0, 0, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
+  UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEMOID), UA_QUALIFIEDNAME(1, "Demo"), UA_LOCALIZEDTEXT("en_US","Demo"),
+                          UA_LOCALIZEDTEXT("en_US","Demo"), 0, 0, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+                          UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
 
 #define SCALARID 50001
   UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SCALARID), UA_QUALIFIEDNAME(1, "Scalar"), UA_LOCALIZEDTEXT("en_US","Demo"), 
-                          UA_LOCALIZEDTEXT("en_US","Demo"), UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 
-                          0, 0, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
+                          UA_LOCALIZEDTEXT("en_US","Demo"), 0, 0, UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+                          UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
 
 #define ARRAYID 50002
   UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, ARRAYID), UA_QUALIFIEDNAME(1, "Array"), UA_LOCALIZEDTEXT("en_US","Demo"), 
-                          UA_LOCALIZEDTEXT("en_US","Demo"), UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 
-                          0, 0, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
+                          UA_LOCALIZEDTEXT("en_US","Demo"), 0, 0, UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+                          UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
 
 #define MATRIXID 50003
   UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, MATRIXID), UA_QUALIFIEDNAME(1, "Matrix"), UA_LOCALIZEDTEXT("en_US","Demo"), 
-                          UA_LOCALIZEDTEXT("en_US","Demo"), UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 
-                          0, 0,  UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
+                          UA_LOCALIZEDTEXT("en_US","Demo"), 0, 0, UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+                          UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL);
 
   UA_UInt32 id = 51000; //running id in namespace 0
   for(UA_UInt32 type = 0; UA_IS_BUILTIN(type); type++) {
@@ -305,14 +325,14 @@ int main(int argc, char** argv) {
     char name[15];
     sprintf(name, "%02d", type);
     UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
-    UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), qualifiedName, UA_LOCALIZEDTEXT("en_US",""), UA_LOCALIZEDTEXT("en_US",""),
-                              UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 0, 0, variant, NULL);
+    UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), qualifiedName, UA_LOCALIZEDTEXT("en_US",""), UA_LOCALIZEDTEXT("en_US",""), 0, 0,
+                              UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), variant, NULL);
 
     //add an array node for every built-in type
     UA_Variant *arrayvar = UA_Variant_new();
     UA_Variant_setArray(arrayvar, UA_Array_new(&UA_TYPES[type], 10), 10, &UA_TYPES[type]);
-    UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), qualifiedName, UA_LOCALIZEDTEXT("en_US",""), UA_LOCALIZEDTEXT("en_US",""),
-                              UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 0, 0, arrayvar, NULL);
+    UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), qualifiedName, UA_LOCALIZEDTEXT("en_US",""), UA_LOCALIZEDTEXT("en_US",""), 0, 0,
+                              UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), arrayvar, NULL);
 
     //add an matrix node for every built-in type
     arrayvar = UA_Variant_new();
@@ -325,7 +345,7 @@ int main(int argc, char** argv) {
     arrayvar->data = myMultiArray;
     arrayvar->type = &UA_TYPES[type];
     UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), qualifiedName, UA_LOCALIZEDTEXT("en_US",""), UA_LOCALIZEDTEXT("en_US",""),
-                              UA_NODEID_NUMERIC(1, MATRIXID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), 0, 0, arrayvar, NULL);
+                              0, 0, UA_NODEID_NUMERIC(1, MATRIXID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), arrayvar, NULL);
   }
 
 #ifdef ENABLE_METHODCALLS

+ 72 - 0
examples/server_datasource.c

@@ -0,0 +1,72 @@
+/*
+ * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ */
+
+#include <signal.h>
+#include <stdio.h>
+
+#ifdef UA_NO_AMALGAMATION
+# include "ua_types.h"
+# include "ua_server.h"
+# include "logger_stdout.h"
+# include "networklayer_tcp.h"
+#else
+# include "open62541.h"
+#endif
+
+UA_Boolean running = 1;
+UA_Logger logger;
+
+static void stopHandler(int sign) {
+    UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
+    running = 0;
+}
+
+static UA_StatusCode readInteger(void *handle, UA_Boolean sourceTimeStamp, const UA_NumericRange *range, UA_DataValue *dataValue) {
+    dataValue->hasValue = UA_TRUE;
+    UA_Variant_setScalarCopy(&dataValue->value, (UA_UInt32*)handle, &UA_TYPES[UA_TYPES_INT32]);
+    UA_LOG_INFO(logger, UA_LOGCATEGORY_USERLAND, "read value %i", *(UA_UInt32*)handle);
+    return UA_STATUSCODE_GOOD;
+}
+
+static UA_StatusCode writeInteger(void *handle, const UA_Variant *data, const UA_NumericRange *range){
+    if(UA_Variant_isScalar(data) && data->type == &UA_TYPES[UA_TYPES_INT32] && data->data){
+        *(UA_UInt32*)handle = *(UA_Int32*)data->data;
+    }
+    UA_LOG_INFO(logger, UA_LOGCATEGORY_USERLAND, "written value %i", *(UA_UInt32*)handle);
+    return UA_STATUSCODE_GOOD;
+}
+
+
+int main(int argc, char** argv) {
+    signal(SIGINT, stopHandler); /* catches ctrl-c */
+
+    UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
+    logger = Logger_Stdout_new();
+    UA_Server_setLogger(server, logger);
+    UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
+
+    UA_Int32 myInteger = 42;
+
+    /* add a variable node to the address space */
+    UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer"); /* UA_NODEID_NULL would assign a random free nodeid */
+    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
+    UA_LocalizedText myIntegerBrowseName = UA_LOCALIZEDTEXT("en_US","the answer");
+
+    UA_DataSource dateDataSource = (UA_DataSource) {.handle = &myInteger, .read = readInteger, .write = writeInteger};
+
+    UA_Server_addDataSourceVariableNode(server, myIntegerNodeId, myIntegerName, myIntegerBrowseName, myIntegerBrowseName, 0, 0,
+
+                                    UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                    UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
+
+                                    dateDataSource,
+
+                                    NULL);
+
+    UA_StatusCode retval = UA_Server_run(server, 1, &running);
+    UA_Server_delete(server);
+
+    return retval;
+}

+ 3 - 3
examples/server_variable.c

@@ -30,7 +30,7 @@ int main(int argc, char** argv) {
     UA_Server_setLogger(server, logger);
     UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
 
-    /* add a variable node to the adresspace */
+    /* add a variable node to the address space */
     UA_Variant *myIntegerVariant = UA_Variant_new();
     UA_Int32 myInteger = 42;
     UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
@@ -41,8 +41,8 @@ int main(int argc, char** argv) {
     UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
     UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
 
-    UA_Server_addVariableNode(server, myIntegerNodeId, myIntegerName, myIntegerBrowseName, myIntegerBrowseName,
-                              parentNodeId, parentReferenceNodeId, 0, 0, myIntegerVariant, NULL);
+    UA_Server_addVariableNode(server, myIntegerNodeId, myIntegerName, myIntegerBrowseName, myIntegerBrowseName, 0, 0,
+                              parentNodeId, parentReferenceNodeId, myIntegerVariant, NULL);
 
     UA_StatusCode retval = UA_Server_run(server, 1, &running);
     UA_Server_delete(server);

+ 75 - 34
include/ua_server.h

@@ -184,67 +184,108 @@ UA_Server_getNodeCopy(UA_Server *server, UA_NodeId nodeId, void **copyInto);
  * @param browseName    The qualified name of this node
  * @param displayName   The localized text shown when displaying the node
  * @param description   The localized human readable description
- * @param parentNodeId  The node under which this node exists ("parent")
- * @param referenceTypeId Reference type used by the parent to reference this node
  * @param userWriteMask Bitmask defining the user write permissions
  * @param writeMask     Bitmask defining the write permissions
+ * @param parentNodeId  The node under which this node exists ("parent")
+ * @param referenceTypeId Reference type used by the parent to reference this node
  * @param value         A variant containing the value to be assigned to this node.
  * @param createdNodeId Pointer to a NULL pointer that will hold the copy of the nodeId on a successfull return.
  * 
  * @return Return UA_STATUSCODE_GOOD if the node was created or an appropriate error code if not.
  */
 UA_StatusCode UA_EXPORT
-UA_Server_addVariableNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                          UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                          const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                          UA_Variant *value, UA_NodeId *createdNodeId);
+UA_Server_addVariableNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                          const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                          const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                          UA_Variant *value,
+
+                          UA_NodeId *createdNodeId);
 
 // Missing: eventNotifier
 UA_StatusCode UA_EXPORT
-UA_Server_addObjectNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                        UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                        const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                        const UA_ExpandedNodeId typeDefinition, UA_NodeId *createdNodeId);
+UA_Server_addObjectNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                        const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                        const UA_ExpandedNodeId typeDefinition,
+
+                        UA_NodeId *createdNodeId);
 
 // Missing: isAbstract, symmetric
 UA_StatusCode UA_EXPORT 
-UA_Server_addReferenceTypeNode(UA_Server *server, UA_NodeId nodeId, UA_QualifiedName browseName, 
-                               UA_LocalizedText displayName, UA_LocalizedText description, UA_NodeId parentNodeId, 
-                               const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                               const UA_ExpandedNodeId typeDefinition, UA_LocalizedText inverseName, UA_NodeId *createdNodeId );
+UA_Server_addReferenceTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                               const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                               const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                               const UA_ExpandedNodeId typeDefinition,
+                               const UA_LocalizedText inverseName,
+
+                               UA_NodeId *createdNodeId );
 
 UA_StatusCode UA_EXPORT
-UA_Server_addObjectTypeNode(UA_Server *server, UA_NodeId nodeId, UA_QualifiedName browseName, 
-                            UA_LocalizedText displayName, UA_LocalizedText description, UA_NodeId parentNodeId, 
-                            UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                            UA_ExpandedNodeId typeDefinition, UA_Boolean isAbstract,  
+UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                            const UA_LocalizedText displayName, const UA_LocalizedText description,  const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                            const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                            const UA_ExpandedNodeId typeDefinition,
+                            const UA_Boolean isAbstract,
+
                             UA_NodeId *createdNodeId );
 
 UA_StatusCode UA_EXPORT 
-UA_Server_addVariableTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                              UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                              const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                              UA_Variant *value,  UA_Int32 valueRank, UA_Boolean isAbstract, UA_NodeId *createdNodeId);
+UA_Server_addVariableTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                              const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                              const UA_NodeId parentNodeId,
+                              const UA_NodeId referenceTypeId,
+
+                              UA_Variant *value,
+                              const UA_Int32 valueRank,
+                              const UA_Boolean isAbstract,
+
+                              UA_NodeId *createdNodeId);
 
 UA_StatusCode UA_EXPORT
-UA_Server_addDataTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                          UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                          const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                          UA_ExpandedNodeId typeDefinition, UA_Boolean isAbstract, UA_NodeId *createdNodeId);
+UA_Server_addDataTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                          const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                          const UA_NodeId parentNodeId,
+                          const UA_NodeId referenceTypeId,
+
+                          const UA_ExpandedNodeId typeDefinition,
+                          const UA_Boolean isAbstract,
+
+                          UA_NodeId *createdNodeId);
 
 
 UA_StatusCode UA_EXPORT
-UA_Server_addViewNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                      UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                      const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                      UA_ExpandedNodeId typeDefinition, UA_NodeId *createdNodeId);
+UA_Server_addViewNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                      const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                      const UA_NodeId parentNodeId,
+                      const UA_NodeId referenceTypeId,
+
+                      const UA_ExpandedNodeId typeDefinition,
+
+                      UA_NodeId *createdNodeId);
 
 UA_StatusCode UA_EXPORT
-UA_Server_addDataSourceVariableNode(UA_Server *server, UA_DataSource dataSource,
-                                    const UA_QualifiedName browseName, UA_NodeId nodeId,
-                                    const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+UA_Server_addDataSourceVariableNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                                    const UA_LocalizedText displayName, const UA_LocalizedText description,  const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                                    const UA_NodeId parentNodeId,
+                                    const UA_NodeId referenceTypeId,
+
+                                    const UA_DataSource dataSource,
+
                                     UA_NodeId *createdNodeId);
 
+/* --------------------- */
 UA_StatusCode UA_EXPORT
 UA_Server_addMonodirectionalReference(UA_Server *server, UA_NodeId sourceNodeId,
                                       UA_ExpandedNodeId targetNodeId, UA_NodeId referenceTypeId,
@@ -279,7 +320,7 @@ typedef UA_StatusCode (*UA_MethodCallback)(const UA_NodeId objectId, const UA_Va
  * 
  */
 UA_StatusCode UA_EXPORT
-UA_Server_addMethodNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName,
+UA_Server_addMethodNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
                         UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
                         const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
                         UA_MethodCallback method, void *handle, UA_Int32 inputArgumentsSize, const UA_Argument *inputArguments, 

+ 81 - 39
src/server/ua_server_addressspace.c

@@ -145,10 +145,14 @@ UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId, UA_Nod
 }
 
 UA_StatusCode
-UA_Server_addVariableNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                          UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                          const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                          UA_Variant *value, UA_NodeId *createdNodeId) {
+UA_Server_addVariableNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                          const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                          const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                          UA_Variant *value,
+
+                          UA_NodeId *createdNodeId) {
     UA_VariableNode *node = UA_VariableNode_new();
     UA_StatusCode retval;
     node->value.variant = *value; // copy content
@@ -180,10 +184,14 @@ UA_Server_addVariableNode(UA_Server *server, UA_NodeId nodeId, const UA_Qualifie
 }
 
 UA_StatusCode
-UA_Server_addObjectNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                        UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                        const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, 
-                        UA_UInt32 writeMask, const UA_ExpandedNodeId typeDefinition, UA_NodeId *createdNodeId) {
+UA_Server_addObjectNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                        const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+                        const UA_ExpandedNodeId typeDefinition,
+
+                        UA_NodeId *createdNodeId){
     UA_ObjectNode *node = UA_ObjectNode_new();
     UA_StatusCode retval;
     
@@ -212,9 +220,14 @@ UA_Server_addObjectNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedN
 }
 
 UA_StatusCode
-UA_Server_addDataSourceVariableNode(UA_Server *server, UA_DataSource dataSource,
-                                    const UA_QualifiedName browseName, UA_NodeId nodeId,
-                                    const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+UA_Server_addDataSourceVariableNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+                                    const UA_LocalizedText displayName, const UA_LocalizedText description,  const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+                                    const UA_NodeId parentNodeId,
+                                    const UA_NodeId referenceTypeId,
+
+                                    const UA_DataSource dataSource,
+
                                     UA_NodeId *createdNodeId) {
     UA_VariableNode *node = UA_VariableNode_new();
     UA_StatusCode retval;
@@ -223,7 +236,10 @@ UA_Server_addDataSourceVariableNode(UA_Server *server, UA_DataSource dataSource,
     node->value.dataSource = dataSource;
     UA_NodeId_copy(&nodeId, &node->nodeId);
     UA_QualifiedName_copy(&browseName, &node->browseName);
-    UA_String_copy(&browseName.name, &node->displayName.text);
+    UA_LocalizedText_copy(&displayName, &node->displayName);
+    UA_LocalizedText_copy(&description, &node->description);
+    node->writeMask = writeMask;
+    node->userWriteMask = userWriteMask;
     UA_ExpandedNodeId parentId; // dummy exapndednodeid
     UA_ExpandedNodeId_init(&parentId);
     UA_NodeId_copy(&parentNodeId, &parentId.nodeId);
@@ -242,10 +258,17 @@ UA_Server_addDataSourceVariableNode(UA_Server *server, UA_DataSource dataSource,
 
                                     
 UA_StatusCode
-UA_Server_addVariableTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                              UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                              const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                              UA_Variant *value,  UA_Int32 valueRank, UA_Boolean isAbstract, UA_NodeId *createdNodeId) {
+UA_Server_addVariableTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+        const UA_NodeId parentNodeId,
+        const UA_NodeId referenceTypeId,
+
+        UA_Variant *value,
+        const UA_Int32 valueRank,
+        const UA_Boolean isAbstract,
+
+        UA_NodeId *createdNodeId) {
     UA_VariableTypeNode *node = UA_VariableTypeNode_new();
     UA_StatusCode retval;
     node->value.variant = *value; // copy content
@@ -278,10 +301,16 @@ UA_Server_addVariableTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_Qual
 }
 
 UA_StatusCode
-UA_Server_addDataTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                          UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                          const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                          UA_ExpandedNodeId typeDefinition, UA_Boolean isAbstract, UA_NodeId *createdNodeId) {
+UA_Server_addDataTypeNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+        const UA_NodeId parentNodeId,
+        const UA_NodeId referenceTypeId,
+
+        const UA_ExpandedNodeId typeDefinition,
+        const UA_Boolean isAbstract,
+
+        UA_NodeId *createdNodeId) {
   UA_DataTypeNode *node = UA_DataTypeNode_new();
   UA_StatusCode retval;
   
@@ -312,10 +341,15 @@ UA_Server_addDataTypeNode(UA_Server *server, UA_NodeId nodeId, const UA_Qualifie
 }
 
 UA_StatusCode
-UA_Server_addViewNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
-                          UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
-                          const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                          UA_ExpandedNodeId typeDefinition, UA_NodeId *createdNodeId) {
+UA_Server_addViewNode(UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+        const UA_NodeId parentNodeId,
+        const UA_NodeId referenceTypeId,
+
+        const UA_ExpandedNodeId typeDefinition,
+
+        UA_NodeId *createdNodeId) {
   UA_ViewNode *node = UA_ViewNode_new();
   UA_StatusCode retval;
   
@@ -346,11 +380,15 @@ UA_Server_addViewNode(UA_Server *server, UA_NodeId nodeId, const UA_QualifiedNam
   return retval;
 }
 
-UA_StatusCode UA_Server_addReferenceTypeNode (UA_Server *server, UA_NodeId nodeId, UA_QualifiedName browseName, 
-                                              UA_LocalizedText displayName, UA_LocalizedText description, UA_NodeId parentNodeId, 
-                                              UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                                              UA_ExpandedNodeId typeDefinition, UA_LocalizedText inverseName, 
-                                              UA_NodeId *createdNodeId ){
+UA_StatusCode UA_Server_addReferenceTypeNode (UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+        const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+        const UA_ExpandedNodeId typeDefinition,
+        const UA_LocalizedText inverseName,
+
+        UA_NodeId *createdNodeId ){
   UA_ReferenceTypeNode *node = UA_ReferenceTypeNode_new();
   UA_StatusCode retval;
   
@@ -379,11 +417,15 @@ UA_StatusCode UA_Server_addReferenceTypeNode (UA_Server *server, UA_NodeId nodeI
   return retval;
 }
 
-UA_StatusCode UA_Server_addObjectTypeNode ( UA_Server *server, UA_NodeId nodeId, UA_QualifiedName browseName, 
-                                          UA_LocalizedText displayName, UA_LocalizedText description, UA_NodeId parentNodeId, 
-                                          UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
-                                          UA_ExpandedNodeId typeDefinition, UA_Boolean isAbstract, 
-                                          UA_NodeId *createdNodeId ){
+UA_StatusCode UA_Server_addObjectTypeNode (UA_Server *server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
+        const UA_LocalizedText displayName, const UA_LocalizedText description, const UA_UInt32 userWriteMask, const UA_UInt32 writeMask,
+
+        const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
+
+        const UA_ExpandedNodeId typeDefinition,
+        const UA_Boolean isAbstract,
+
+        UA_NodeId *createdNodeId ){
   UA_ObjectTypeNode *node = UA_ObjectTypeNode_new();
   UA_StatusCode retval;
   
@@ -763,7 +805,7 @@ UA_Server_addNodeWithSession(UA_Server *server, UA_Session *session, UA_Node *no
 
 #ifdef ENABLE_METHODCALLS
 UA_StatusCode
-UA_Server_addMethodNode(UA_Server* server, UA_NodeId nodeId, const UA_QualifiedName browseName, 
+UA_Server_addMethodNode(UA_Server* server, const UA_NodeId nodeId, const UA_QualifiedName browseName,
                         UA_LocalizedText displayName, UA_LocalizedText description, const UA_NodeId parentNodeId, 
                         const UA_NodeId referenceTypeId, UA_UInt32 userWriteMask, UA_UInt32 writeMask, 
                         UA_MethodCallback method, void *handle, UA_Int32 inputArgumentsSize, const UA_Argument* inputArguments, 
@@ -1292,8 +1334,8 @@ static void UA_Server_addInstanceOf_instatiateChildObject(UA_Server *server,
   // Create the object root as specified by the user
   UA_NodeId objectRoot;
   retval |= UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(parentId.namespaceIndex, 0), objectCopy->browseName, objectCopy->displayName, 
-                                    objectCopy->description, parentId, referenceTypeId, objectCopy->userWriteMask, objectCopy->writeMask,
-                                    typeDefinition, &objectRoot);
+                                    objectCopy->description, objectCopy->userWriteMask, objectCopy->writeMask,
+                                      parentId, referenceTypeId, typeDefinition, &objectRoot);
   if (retval)
     return;
   
@@ -1477,8 +1519,8 @@ UA_StatusCode UA_Server_addInstanceOf(UA_Server *server, UA_NodeId nodeId, const
   
   // Create the object root as specified by the user
   UA_NodeId objectRoot;
-  retval |= UA_Server_addObjectNode(server, nodeId, browseName, displayName, description, 
-                          parentNodeId, referenceTypeId, userWriteMask, writeMask,
+  retval |= UA_Server_addObjectNode(server, nodeId, browseName, displayName, description, userWriteMask, writeMask,
+                          parentNodeId, referenceTypeId,
                           typeDefinition, &objectRoot
   );
   if (retval)

+ 1 - 1
tools/pyUANamespace/open62541_MacroHelper.py

@@ -119,9 +119,9 @@ class open62541_MacroHelper():
       code.append("       UA_QUALIFIEDNAME(0, \"" + str(node.browseName()) + "\"),")  # browseName
     code.append("       UA_LOCALIZEDTEXT(\"\", \"" + str(node.displayName()) + "\"),")  # displayName
     code.append("       UA_LOCALIZEDTEXT(\"\", \"" + str(node.description()) + "\"),")  # description
+    code.append("       " + str(node.writeMask()) + ", " + str(node.userWriteMask()) + ",") # write/userWriteMask
     code.append("       " + str(self.getCreateNodeIDMacro(parentNode)) + ",") # ParentNode
     code.append("       " + str(self.getCreateNodeIDMacro(parentReference.referenceType())) + ",") # ReferenceTypeId
-    code.append("       " + str(node.writeMask()) + ", " + str(node.userWriteMask()) + ",") # write/userWriteMask
       
     return code