Merge remote-tracking branch 'upstream/master' into hotfix/localeid

# Conflicts:
#	examples/client.c
#	examples/discovery/server_multicast.c
#	examples/discovery/server_register.c
#	examples/server.c
#	examples/server_inheritance.c
#	examples/tutorial_server_datasource.c
#	examples/tutorial_server_variabletype.c
This commit is contained in:
Stefan Profanter 2017-09-07 10:28:44 +02:00
commit 61f5018854
No known key found for this signature in database
GPG Key ID: 400F1D46162772CA
24 changed files with 71 additions and 66 deletions

View File

@ -318,8 +318,7 @@ Let's look at an example that will create a pump instance given the newly define
UA_NodeId createdNodeId;
UA_Int32 myHandle = 42;
UA_ObjectAttributes object_attr;
UA_ObjectAttributes_init(&object_attr);
UA_ObjectAttributes object_attr = UA_ObjectAttributes_default;
object_attr.description = UA_LOCALIZEDTEXT("en-US","A pump!");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US","Pump1");

View File

@ -178,8 +178,7 @@ int main(int argc, char *argv[]) {
/* Add new nodes*/
/* New ReferenceType */
UA_NodeId ref_id;
UA_ReferenceTypeAttributes ref_attr;
UA_ReferenceTypeAttributes_init(&ref_attr);
UA_ReferenceTypeAttributes ref_attr = UA_ReferenceTypeAttributes_default;
ref_attr.displayName = UA_LOCALIZEDTEXT("en-US", "NewReference");
ref_attr.description = UA_LOCALIZEDTEXT("en-US", "References something that might or might not exist");
ref_attr.inverseName = UA_LOCALIZEDTEXT("en-US", "IsNewlyReferencedBy");
@ -194,8 +193,7 @@ int main(int argc, char *argv[]) {
/* New ObjectType */
UA_NodeId objt_id;
UA_ObjectTypeAttributes objt_attr;
UA_ObjectTypeAttributes_init(&objt_attr);
UA_ObjectTypeAttributes objt_attr = UA_ObjectTypeAttributes_default;
objt_attr.displayName = UA_LOCALIZEDTEXT("en-US", "TheNewObjectType");
objt_attr.description = UA_LOCALIZEDTEXT("en-US", "Put innovative description here");
retval = UA_Client_addObjectTypeNode(client,
@ -209,8 +207,7 @@ int main(int argc, char *argv[]) {
/* New Object */
UA_NodeId obj_id;
UA_ObjectAttributes obj_attr;
UA_ObjectAttributes_init(&obj_attr);
UA_ObjectAttributes obj_attr = UA_ObjectAttributes_default;
obj_attr.displayName = UA_LOCALIZEDTEXT("en-US", "TheNewGreatNode");
obj_attr.description = UA_LOCALIZEDTEXT("de-DE", "Hier koennte Ihre Webung stehen!");
retval = UA_Client_addObjectNode(client,
@ -225,8 +222,7 @@ int main(int argc, char *argv[]) {
/* New Integer Variable */
UA_NodeId var_id;
UA_VariableAttributes var_attr;
UA_VariableAttributes_init(&var_attr);
UA_VariableAttributes var_attr = UA_VariableAttributes_default;
var_attr.displayName = UA_LOCALIZEDTEXT("en-US", "TheNewVariableNode");
var_attr.description =
UA_LOCALIZEDTEXT("en-US", "This integer is just amazing - it has digits and everything.");

View File

@ -119,8 +119,7 @@ int main(int argc, char **argv) {
UA_DataSource dateDataSource;
dateDataSource.read = readInteger;
dateDataSource.write = writeInteger;
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.description = UA_LOCALIZEDTEXT("en-US", "the answer");
attr.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");

View File

@ -81,8 +81,7 @@ int main(int argc, char **argv) {
UA_DataSource dateDataSource;
dateDataSource.read = readInteger;
dateDataSource.write = writeInteger;
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.description = UA_LOCALIZEDTEXT("en-US", "the answer");
attr.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");

View File

@ -123,8 +123,7 @@ int main(int argc, char** argv) {
UA_Server *server = UA_Server_new(config);
/* add a static variable node to the server */
UA_VariableAttributes myVar;
UA_VariableAttributes_init(&myVar);
UA_VariableAttributes myVar = UA_VariableAttributes_default;
myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer");
myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");
myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
@ -142,8 +141,7 @@ int main(int argc, char** argv) {
UA_DataSource dateDataSource;
dateDataSource.read = readTimeData;
dateDataSource.write = NULL;
UA_VariableAttributes v_attr;
UA_VariableAttributes_init(&v_attr);
UA_VariableAttributes v_attr = UA_VariableAttributes_default;
v_attr.description = UA_LOCALIZEDTEXT("en-US","current time");
v_attr.displayName = UA_LOCALIZEDTEXT("en-US","current time");
v_attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
@ -172,8 +170,7 @@ int main(int argc, char** argv) {
outputArguments.name = UA_STRING("greeting");
outputArguments.valueRank = -1;
UA_MethodAttributes addmethodattributes;
UA_MethodAttributes_init(&addmethodattributes);
UA_MethodAttributes addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "Hello World");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
@ -192,8 +189,7 @@ int main(int argc, char** argv) {
#define MATRIXID 50003
#define DEPTHID 50004
UA_ObjectAttributes object_attr;
UA_ObjectAttributes_init(&object_attr);
UA_ObjectAttributes object_attr = UA_ObjectAttributes_default;
object_attr.description = UA_LOCALIZEDTEXT("en-US", "Demo");
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Demo");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEMOID),
@ -227,8 +223,7 @@ int main(int argc, char** argv) {
if(type == UA_TYPES_VARIANT || type == UA_TYPES_DIAGNOSTICINFO)
continue;
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.valueRank = -2;
attr.dataType = UA_TYPES[type].typeId;
#ifndef UA_ENABLE_TYPENAMES
@ -326,7 +321,7 @@ int main(int argc, char** argv) {
#ifdef UA_ENABLE_METHODCALLS
/* adding some more method nodes to pass CTT */
/* Method without arguments */
UA_MethodAttributes_init(&addmethodattributes);
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "noarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
@ -338,7 +333,7 @@ int main(int argc, char** argv) {
0, NULL, 0, NULL, NULL, NULL);
/* Method with in arguments */
UA_MethodAttributes_init(&addmethodattributes);
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
@ -357,7 +352,7 @@ int main(int argc, char** argv) {
1, &inputArguments, 0, NULL, NULL, NULL);
/* Method with out arguments */
UA_MethodAttributes_init(&addmethodattributes);
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "outarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;
@ -376,7 +371,7 @@ int main(int argc, char** argv) {
0, NULL, 1, &outputArguments, NULL, NULL);
/* Method with inout arguments */
UA_MethodAttributes_init(&addmethodattributes);
addmethodattributes = UA_MethodAttributes_default;
addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inoutarg");
addmethodattributes.executable = true;
addmethodattributes.userExecutable = true;

View File

@ -28,8 +28,7 @@ int main() {
UA_Server *server = UA_Server_new(config);
// add a variable node to the adresspace
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
UA_Int32 myInteger = 42;
UA_Variant_setScalarCopy(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
attr.description = UA_LOCALIZEDTEXT_ALLOC("en-US","the answer");

View File

@ -32,10 +32,9 @@ int main(void) {
* v- MakeSound = "Wuff"
* v- FetchNewPaper
*/
UA_StatusCode retval;
UA_ObjectTypeAttributes otAttr;
UA_ObjectTypeAttributes_init(&otAttr);
UA_StatusCode retval;
UA_ObjectTypeAttributes otAttr = UA_ObjectTypeAttributes_default;
otAttr.description = UA_LOCALIZEDTEXT("en-US", "A mamal");
otAttr.displayName = UA_LOCALIZEDTEXT("en-US", "MamalType");
UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 10000),
@ -43,8 +42,7 @@ int main(void) {
UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
UA_QUALIFIEDNAME(1, "MamalType"), otAttr, NULL, NULL);
UA_VariableAttributes vAttr;
UA_VariableAttributes_init(&vAttr);
UA_VariableAttributes vAttr = UA_VariableAttributes_default;
vAttr.description = UA_LOCALIZEDTEXT("en-US", "This mamals class");
vAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Class");
UA_String classVar = UA_STRING("mamalia");
@ -55,7 +53,7 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Class"), UA_NODEID_NULL,
vAttr, NULL, NULL);
UA_VariableAttributes_init(&vAttr);
vAttr = UA_VariableAttributes_default;
vAttr.description = UA_LOCALIZEDTEXT("en-US", "This mamals species");
vAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Species");
UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10002),
@ -64,9 +62,7 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL,
vAttr, NULL, NULL);
UA_ObjectTypeAttributes_init(&otAttr);
otAttr = UA_ObjectTypeAttributes_default;
otAttr.description = UA_LOCALIZEDTEXT("en-US", "A dog, subtype of mamal");
otAttr.displayName = UA_LOCALIZEDTEXT("en-US", "DogType");
UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 20000),
@ -74,7 +70,7 @@ int main(void) {
UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
UA_QUALIFIEDNAME(1, "DogType"), otAttr, NULL, NULL);
UA_VariableAttributes_init(&vAttr);
vAttr = UA_VariableAttributes_default;
vAttr.description = UA_LOCALIZEDTEXT("en-US", "This dogs species");
vAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Species");
UA_String defaultSpecies = UA_STRING("Canis");
@ -85,7 +81,7 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL,
vAttr, NULL, NULL);
UA_VariableAttributes_init(&vAttr);
vAttr = UA_VariableAttributes_default;
vAttr.description = UA_LOCALIZEDTEXT("en-US", "This dogs name");
vAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Name");
UA_String defaultName = UA_STRING("unnamed dog");
@ -96,7 +92,6 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Name"), UA_NODEID_NULL,
vAttr, NULL, NULL);
/* Instatiate a dog named bello:
* (O) Objects
* + O Bello <DogType>
@ -104,8 +99,7 @@ int main(void) {
* + Name
*/
UA_ObjectAttributes oAttr;
UA_ObjectAttributes_init(&oAttr);
UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
oAttr.description = UA_LOCALIZEDTEXT("en-US", "A dog named Bello");
oAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Bello");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0),
@ -114,7 +108,7 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Bello"), UA_NODEID_NUMERIC(1, 20000),
oAttr, NULL, NULL);
UA_ObjectAttributes_init(&oAttr);
oAttr = UA_ObjectAttributes_default;
oAttr.description = UA_LOCALIZEDTEXT("en-US", "Another dog");
oAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Dog2");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0),
@ -123,7 +117,7 @@ int main(void) {
UA_QUALIFIEDNAME(1, "Dog2"), UA_NODEID_NUMERIC(1, 20000),
oAttr, NULL, NULL);
UA_ObjectAttributes_init(&oAttr);
oAttr = UA_ObjectAttributes_default;
oAttr.description = UA_LOCALIZEDTEXT("en-US", "A mamal");
oAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Mamal1");
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0),

View File

@ -26,8 +26,7 @@ int main(int argc, char** argv) {
UA_Server *server = UA_Server_new(config);
// add a variable node to the adresspace
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
UA_Int32 myInteger = 42;
UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
attr.description = UA_LOCALIZEDTEXT("en-US","the answer");

View File

@ -40,9 +40,9 @@ updateCurrentTime(UA_Server *server) {
static void
addCurrentTimeVariable(UA_Server *server) {
UA_DateTime now = 0;
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.displayName = UA_LOCALIZEDTEXT("en-US", "Current time");
attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
UA_Variant_setScalar(&attr.value, &now, &UA_TYPES[UA_TYPES_DATETIME]);
UA_NodeId currentNodeId = UA_NODEID_STRING(1, "current-time");
@ -132,9 +132,9 @@ writeCurrentTime(UA_Server *server,
static void
addCurrentTimeDataSourceVariable(UA_Server *server) {
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
attr.displayName = UA_LOCALIZEDTEXT("en-US", "Current time - data source");
attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
UA_NodeId currentNodeId = UA_NODEID_STRING(1, "current-time-datasource");
UA_QualifiedName currentName = UA_QUALIFIEDNAME(1, "current-time-datasource");

View File

@ -9,6 +9,9 @@
* to a server. First, we add a new variable to the server. Take a look at the
* definition of the ``UA_VariableAttrbitues`` structure to see the list of all
* attributes defined for VariableNodes.
*
* Note that the default settings have the AccessLevel of the variable value as
* read only. See below for making the variable writable.
*/
#include <signal.h>
@ -24,6 +27,7 @@ addVariable(UA_Server *server) {
attr.description = UA_LOCALIZEDTEXT("en-US","the answer");
attr.displayName = UA_LOCALIZEDTEXT("en-US","the answer");
attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
/* Add the variable node to the information model */
UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");

View File

@ -62,6 +62,7 @@ addVariable(UA_Server *server) {
vAttr.arrayDimensions = arrayDims;
vAttr.arrayDimensionsSize = 1;
vAttr.displayName = UA_LOCALIZEDTEXT("en-US", "2DPoint Variable");
vAttr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
/* vAttr.value is left empty, the server instantiates with the default value */
/* Add the node */

View File

@ -195,6 +195,9 @@ UA_Server_workerCallback(UA_Server *server, UA_ServerCallback callback, void *da
/* Utility Functions */
/*********************/
/* A few global NodeId definitions */
extern const UA_NodeId subtypeId;
UA_StatusCode
UA_NumericRange_parseFromString(UA_NumericRange *range, const UA_String *str);

View File

@ -69,11 +69,12 @@ typeEquivalence(const UA_DataType *t) {
return TYPE_EQUIVALENCE_NONE;
}
const UA_NodeId subtypeId = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_HASSUBTYPE}};
static const UA_NodeId enumNodeId = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_ENUMERATION}};
UA_Boolean
compatibleDataType(UA_Server *server, const UA_NodeId *dataType,
const UA_NodeId *constraintDataType) {
const UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
/* Do not allow empty datatypes */
if(UA_NodeId_isNull(dataType))
return false;
@ -87,11 +88,25 @@ compatibleDataType(UA_Server *server, const UA_NodeId *dataType,
return true;
/* Enum allows Int32 (only) */
UA_NodeId enumNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ENUMERATION);
if(isNodeInTree(server->nodestore, constraintDataType, &enumNodeId, &subtypeId, 1))
return UA_NodeId_equal(dataType, &UA_TYPES[UA_TYPES_INT32].typeId);
return isNodeInTree(server->nodestore, dataType, constraintDataType, &subtypeId, 1);
/* Is the value-type a subtype of the required type? */
if(isNodeInTree(server->nodestore, dataType, constraintDataType, &subtypeId, 1))
return true;
/* If value is a built-in type: The target data type may be a sub type of
* the built-in type. (e.g. UtcTime is sub-type of DateTime and has a
* DateTime value). A type is builtin if its NodeId is in Namespace 0 and
* has a numeric identifier <= 25 (DiagnosticInfo) */
if(dataType->namespaceIndex == 0 &&
dataType->identifierType == UA_NODEIDTYPE_NUMERIC &&
dataType->identifier.numeric <= 25 &&
isNodeInTree(server->nodestore, constraintDataType,
dataType, &subtypeId, 1))
return true;
return false;
}
/* Test whether a valurank and the given arraydimensions are compatible. zero

View File

@ -95,7 +95,6 @@ checkParentReference(UA_Server *server, UA_Session *session, UA_NodeClass nodeCl
}
/* Check hassubtype relation for type nodes */
const UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
if(nodeClass == UA_NODECLASS_DATATYPE ||
nodeClass == UA_NODECLASS_VARIABLETYPE ||
nodeClass == UA_NODECLASS_OBJECTTYPE ||

View File

@ -17,8 +17,7 @@ int main(int argc, char** argv) {
UA_Server *server = UA_Server_new(config);
/* add a variable node to the address space */
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
UA_VariableAttributes attr = UA_VariableAttributes_default;
UA_Int32 myInteger = 42;
UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
attr.description = UA_LOCALIZEDTEXT("en-US","the answer");

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
# WARNING: This is till work in progress
#
# Load into gdb with 'source ../tools/gdb-prettyprint.py'

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public

View File

@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public