Ejemplo n.º 1
0
	}END_TEST

START_TEST(ReadSingleAttributeNodeIdWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_NODEID;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);
		UA_NodeId* respval;
		respval = (UA_NodeId*) resp.value.data;
		const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
		ck_assert_int_eq(1, respval->namespaceIndex);
		for (int var = 0; var < respval->identifier.string.length; ++var) {
			ck_assert_int_eq(myIntegerNodeId.identifier.string.data[var],
					respval->identifier.string.data[var]);
		}
		UA_free(respval);
	}END_TEST
Ejemplo n.º 2
0
static void
addVariable(size_t size) {
    /* Define the attribute of the myInteger variable node */
    UA_VariableAttributes attr = UA_VariableAttributes_default;
    UA_Int32* array = (UA_Int32*)UA_malloc(size * sizeof(UA_Int32));
    memset(array, 0, size * sizeof(UA_Int32));
    UA_Variant_setArray(&attr.value, array, size, &UA_TYPES[UA_TYPES_INT32]);

    char name[] = "my.variable";
    attr.description = UA_LOCALIZEDTEXT("en-US", name);
    attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
    attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;

    /* Add the variable node to the information model */
    UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, name);
    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, name);
    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, parentNodeId,
                              parentReferenceNodeId, myIntegerName,
                              UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
                              attr, NULL, NULL);

    UA_free(array);
}
Ejemplo n.º 3
0
	}END_TEST

START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId =
				UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);

		UA_Double* respval;
		respval = (UA_Double*) resp.value.data;
		UA_VariableNode *compNode = makeCompareSequence();
		UA_Double comp;
		comp = (UA_Double) compNode->minimumSamplingInterval;

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_DOUBLE], resp.value.type);
		ck_assert(*respval == comp);
	}END_TEST
Ejemplo n.º 4
0
	}END_TEST

START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DATATYPE;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);

		UA_NodeId* respval;
		respval = (UA_NodeId*) resp.value.data;

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODEID], resp.value.type);
		ck_assert_int_eq(respval->namespaceIndex,0);
		ck_assert_int_eq(respval->identifier.numeric,UA_NS0ID_INT32);
	}END_TEST
Ejemplo n.º 5
0
	}END_TEST

START_TEST(ReadSingleAttributeUserWriteMaskWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_USERWRITEMASK;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);

		UA_UInt32* respval;
		respval = (UA_UInt32*) resp.value.data;

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type);
		ck_assert_int_eq(0,*respval);
	}END_TEST
} END_TEST

START_TEST(AddNodeTwiceGivesError) {
    /* add a variable node to the address space */
    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");
    attr.displayName = UA_LOCALIZEDTEXT("en-US","the answer");
    UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
    UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
    UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
    UA_StatusCode res =
        UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
                                  parentReferenceNodeId, myIntegerName,
                                  UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
                                  attr, NULL, NULL);
    ck_assert_int_eq(UA_STATUSCODE_GOOD, res);
    res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
                                    parentReferenceNodeId, myIntegerName,
                                    UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
                                    attr, NULL, NULL);
    ck_assert_int_eq(res, UA_STATUSCODE_BADNODEIDEXISTS);
} END_TEST
Ejemplo n.º 7
0
	}END_TEST

START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_DESCRIPTION;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);
		UA_LocalizedText* respval;
		respval = (UA_LocalizedText*) resp.value.data;
		UA_VariableNode* compNode = makeCompareSequence();

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type);
		ck_assert_int_eq(compNode->description.locale.length, respval->locale.length);
				for (int var = 0; var < respval->locale.length - 1; ++var) {
					ck_assert_int_eq(compNode->description.locale.data[var], respval->locale.data[var]);
				}
		ck_assert_int_eq(compNode->description.text.length, respval->text.length);
		for (int var = 0; var < respval->text.length - 1; ++var) {
			ck_assert_int_eq(compNode->description.text.data[var], respval->text.data[var]);
		}
		UA_free(respval);
	}END_TEST
Ejemplo n.º 8
0
	}END_TEST

START_TEST(ReadSingleAttributeBrowseNameWithoutTimestamp)
	{
		UA_Server *server = makeTestSequence();

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_BROWSENAME;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
				&resp);

		UA_QualifiedName* respval;
		respval = (UA_QualifiedName*) resp.value.data;
		const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1,
				"the answer");

		ck_assert_int_eq(-1, resp.value.arrayLength);
		ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_QUALIFIEDNAME], resp.value.type);
		ck_assert_int_eq(1, respval->namespaceIndex);
		ck_assert_int_eq(myIntegerName.name.length, respval->name.length);
		for (int var = 0; var < respval->name.length - 1; ++var) {
			ck_assert_int_eq(myIntegerName.name.data[var],
					respval->name.data[var]);
		}
		UA_free(respval);
	}END_TEST
Ejemplo n.º 9
0
int main(int argc, char** argv) {
    signal(SIGINT,  stopHandler);
    signal(SIGTERM, stopHandler);

    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl;
    nl = UA_ServerNetworkLayerUDP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    // add a variable node to the adresspace
    UA_VariableAttributes attr;
    UA_VariableAttributes_init(&attr);
    UA_Int32 myInteger = 42;
    UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
    attr.description = UA_LOCALIZEDTEXT("en_US","the answer");
    attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer");
    UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(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, parentNodeId,
                              parentReferenceNodeId, myIntegerName,
                              UA_NODEID_NULL, attr, NULL, NULL);

    UA_StatusCode retval = UA_Server_run(server, &running);
    UA_Server_delete(server);

    return (int) retval;
}
Ejemplo n.º 10
0
int main(int argc, char** argv) {
    signal(SIGINT, stopHandler); /* catches ctrl-c */

    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    /* add a variable node to the address space */
    UA_Int32 myInteger = 42;
    UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
    UA_DataSource dateDataSource = (UA_DataSource) {
        .handle = &myInteger, .read = readInteger, .write = writeInteger};
    UA_VariableAttributes attr;
    UA_VariableAttributes_init(&attr);
    attr.description = UA_LOCALIZEDTEXT("en_US","the answer");
    attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer");

    UA_Server_addDataSourceVariableNode(server, myIntegerNodeId,
                                        UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                                        UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
                                        myIntegerName, UA_NODEID_NULL, attr, dateDataSource, NULL);

    UA_StatusCode retval = UA_Server_run(server, &running);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);

    return (int)retval;
}
Ejemplo n.º 11
0
	}END_TEST

START_TEST(WriteSingleAttributeWriteMask)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Int32 testValue = 0;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_UINT32]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_WRITEMASK;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	}END_TEST
Ejemplo n.º 12
0
	}END_TEST

START_TEST(WriteSingleAttributeDescription)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer");
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
		wValue.value.hasValue = UA_TRUE;
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	}END_TEST
Ejemplo n.º 13
0
//#######################################MAIN#######################################
int main(int argc, char** argv) {
    signal(SIGINT, stopHandler); /* catches ctrl-c */


    if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed\n");
      return 1;

}

    gpioSetMode(17, PI_OUTPUT);
    gpioSetMode(22, PI_INPUT);
    gpioSetMode(24, PI_OUTPUT);


    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

 /* add a variable node to the address space */
    UA_Int32 myIntegerB = 32;
    UA_NodeId myIntegerBNodeId = UA_NODEID_STRING(1, "button");
    UA_QualifiedName myIntegerBName = UA_QUALIFIEDNAME(1, "button");
    UA_DataSource dateDataSource = (UA_DataSource) {
        .handle = &myIntegerB, .read = readIntegerB, .write = writeIntegerB};
    UA_VariableAttributes attr;
    UA_VariableAttributes_init(&attr);
    attr.description = UA_LOCALIZEDTEXT("en_US","button_on_off");
    attr.displayName = UA_LOCALIZEDTEXT("en_US","button");

    UA_Server_addDataSourceVariableNode(server, myIntegerBNodeId,
                                        UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                                        UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
                                        myIntegerBName, UA_NODEID_NULL, attr, dateDataSource, NULL);



 /* add a repeated job to the server */
    UA_Job job = {.type = UA_JOBTYPE_METHODCALL,
                  .job.methodCall = {.method = testCallback, .data = NULL} };
    UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec




    UA_StatusCode retval = UA_Server_run(server, &running);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);


    return (int)retval;
}
Ejemplo n.º 14
0
	}END_TEST


START_TEST(WriteSingleAttributeValue)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Variant *myIntegerVariant = UA_Variant_new();
		UA_Int32 myInteger = 20;
		UA_Variant_setScalarCopy(myIntegerVariant, &myInteger,
						&UA_TYPES[UA_TYPES_INT32]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_VALUE;
		wValue.value.hasValue = UA_TRUE;
		wValue.value.value = *myIntegerVariant;
		UA_StatusCode retval = writeValue(server, &wValue);

		UA_DataValue resp;
		UA_DataValue_init(&resp);
		UA_ReadRequest rReq;
		UA_ReadRequest_init(&rReq);
		rReq.nodesToRead = UA_ReadValueId_new();
		rReq.nodesToReadSize = 1;
		rReq.nodesToRead[0].nodeId = UA_NODEID_STRING(1, "the.answer");
		rReq.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;

		readValue(server, UA_TIMESTAMPSTORETURN_NEITHER, &rReq.nodesToRead[0],
					&resp);

		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
		ck_assert(wValue.value.hasValue);
		const UA_Node *node = UA_NodeStore_get(server->nodestore, &wValue.nodeId);
		ck_assert_int_eq(node->nodeClass, UA_NODECLASS_VARIABLE);
		const UA_VariableNode *vn = (const UA_VariableNode*)node;
		const UA_Variant *oldV = &vn->value.variant.value;
		ck_assert_ptr_eq(&oldV->type->typeId, &wValue.value.value.type->typeId);

		ck_assert_int_eq(20, *(UA_Int32* )resp.value.data);
	}END_TEST
Ejemplo n.º 15
0
	}END_TEST

START_TEST(WriteSingleAttributeNoValue)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
		wValue.value.hasValue = UA_FALSE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_BADTYPEMISMATCH);
	}END_TEST
Ejemplo n.º 16
0
	}END_TEST

START_TEST(WriteSingleAttributeDataType)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_DATATYPE;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
	}END_TEST
Ejemplo n.º 17
0
static UA_Server* makeTestSequence(void) {
    UA_Server *server = UA_Server_new(UA_ServerConfig_standard);

    /* VariableNode */
    UA_Variant *myIntegerVariant = UA_Variant_new();
    UA_Int32 myInteger = 42;
    UA_Variant_setScalarCopy(myIntegerVariant, &myInteger,
                    &UA_TYPES[UA_TYPES_INT32]);
    const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
    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"), 0, 0,
                              parentNodeId, parentReferenceNodeId, myIntegerVariant, NULL);

    /* ObjectNode */
    UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 50), 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);

    /* ReferenceTypeNode */
    UA_ReferenceTypeNode *organizes = UA_ReferenceTypeNode_new();
    copyNames((UA_Node*)organizes, "Organizes");
    organizes->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrganizedBy");
    organizes->nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
    organizes->isAbstract = UA_FALSE;
    organizes->symmetric  = UA_FALSE;
    UA_Server_addNode(server, (UA_Node*)organizes, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));

    /* ViewNode */
    UA_ViewNode *viewtest = UA_ViewNode_new();
    copyNames((UA_Node*)viewtest, "Viewtest");
    viewtest->nodeId.identifier.numeric = UA_NS0ID_VIEWNODE;

    UA_Server_addNode(server, (UA_Node*)viewtest,
                      UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
                      UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));

	/* MethodNode */
    UA_MethodNode *methodtest = UA_MethodNode_new();
    copyNames((UA_Node*)methodtest, "Methodtest");
    methodtest->nodeId.identifier.numeric = UA_NS0ID_METHODNODE;

    UA_Server_addNode(server, (UA_Node*)methodtest,
                      UA_EXPANDEDNODEID_NUMERIC(0, 3),
                      UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));


	return server;
}
Ejemplo n.º 18
0
	}END_TEST

START_TEST(WriteSingleAttributeHistorizing)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Boolean testValue = UA_TRUE;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_HISTORIZING;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	}END_TEST
Ejemplo n.º 19
0
	}END_TEST

START_TEST(WriteSingleAttributeMinimumSamplingInterval)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Double testValue = 0.0;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_DOUBLE]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	}END_TEST
Ejemplo n.º 20
0
	}END_TEST

START_TEST(WriteSingleAttributeBrowseName)
	{
		UA_Server *server = makeTestSequence();
		
		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_QualifiedName testValue = UA_QUALIFIEDNAME(1, "the.answer");
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_BROWSENAME;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	}END_TEST
Ejemplo n.º 21
0
	}END_TEST

START_TEST(WriteSingleAttributeInverseName)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_US", "not.the.answer");
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_INVERSENAME;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
	}END_TEST
Ejemplo n.º 22
0
	}END_TEST

START_TEST(WriteSingleAttributeUserExecutable)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Boolean testValue = UA_TRUE;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BOOLEAN]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_USEREXECUTABLE;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
	}END_TEST
Ejemplo n.º 23
0
	}END_TEST

START_TEST(WriteSingleAttributeEventNotifier)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Byte testValue = 0;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_BYTE]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_EVENTNOTIFIER;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
	}END_TEST
Ejemplo n.º 24
0
END_TEST

START_TEST(Client_read) {
    UA_Client *client = UA_Client_new(UA_ClientConfig_default);
    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

    UA_Variant val;
    UA_NodeId nodeId = UA_NODEID_STRING(1, "my.variable");
    retval = UA_Client_readValueAttribute(client, nodeId, &val);
    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

    UA_Variant_deleteMembers(&val);

    UA_Client_disconnect(client);
    UA_Client_delete(client);
}
Ejemplo n.º 25
0
	}END_TEST

START_TEST(WriteSingleAttributeValueRank)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Int32 testValue = -1;
		UA_Variant_setScalarCopy(&wValue.value.value, &testValue, &UA_TYPES[UA_TYPES_INT32]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_VALUERANK;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		// Returns attributeInvalid, since variant/value may be writable
		ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
	}END_TEST
Ejemplo n.º 26
0
	}END_TEST

START_TEST(WriteSingleAttributeArrayDimensions)
	{
		UA_Server *server = makeTestSequence();

		UA_WriteValue wValue;
		UA_WriteValue_init(&wValue);
		UA_Int32 testValue[] = {-1,-1,-1};
		UA_Variant_setArrayCopy(&wValue.value.value, &testValue, 3, &UA_TYPES[UA_TYPES_INT32]);
		wValue.nodeId = UA_NODEID_STRING(1, "the.answer");
		wValue.attributeId = UA_ATTRIBUTEID_ARRAYDIMENSIONS;
		wValue.value.hasValue = UA_TRUE;
		UA_StatusCode retval = writeValue(server, &wValue);
		// Returns attributeInvalid, since variant/value may be writable
		ck_assert_int_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
	}END_TEST
Ejemplo n.º 27
0
static void
variables_nodeids(void) {
    UA_NodeId id1 = UA_NODEID_NUMERIC(1, 1234);
    id1.namespaceIndex = 3;

    UA_NodeId id2 = UA_NODEID_STRING(1, "testid"); /* the string is static */
    UA_Boolean eq = UA_NodeId_equal(&id1, &id2);
    if(eq)
        return;

    UA_NodeId id3;
    UA_NodeId_copy(&id2, &id3);
    UA_NodeId_deleteMembers(&id3);

    UA_NodeId id4 = UA_NODEID_STRING_ALLOC(1, "testid"); /* the string is copied
                                                            to the heap */
    UA_NodeId_deleteMembers(&id4);
}
Ejemplo n.º 28
0
int main(int argc, char** argv)
{
    signal(SIGINT, signalHandler); /* catch ctrl-c */

    /* Create a server with one network layer listening on port 4840 */
    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    /* Add a variable node */
    UA_VariableAttributes attr;
    UA_VariableAttributes_init(&attr);
    attr.displayName = UA_LOCALIZEDTEXT("en_US", "Test Var");
    UA_Int32 myInteger = 2572;
    UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);

    UA_NodeId newNodeId = UA_NODEID_STRING(1, "Test.Var");
    UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
    UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
    UA_NodeId variableType = UA_NODEID_NULL; /* take the default variable type */
    UA_QualifiedName browseName = UA_QUALIFIEDNAME(1, "Test Node");


    UA_DataSource dateDataSource = (UA_DataSource) {.handle = &myInteger, .read = onRead, .write = NULL};

    UA_Server_addDataSourceVariableNode(server, newNodeId,
                                        parentNodeId, parentReferenceNodeId,
                                        browseName, UA_NODEID_NULL, attr, dateDataSource, NULL);

    UA_Job job = {.type = UA_JOBTYPE_METHODCALL,
                  .job.methodCall = {.method = testCallback, .data = NULL} };
    UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec


    /* Run the server loop */
    UA_StatusCode status = UA_Server_run(server, &running);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);
    return status;
}
} END_TEST

START_TEST(AddComplexTypeWithInheritance) {
    /* add a variable node to the address space */
    UA_ObjectAttributes attr = UA_ObjectAttributes_default;
    attr.description = UA_LOCALIZEDTEXT("en-US","fakeServerStruct");
    attr.displayName = UA_LOCALIZEDTEXT("en-US","fakeServerStruct");
  
    UA_NodeId myObjectNodeId = UA_NODEID_STRING(1, "the.fake.Server.Struct");
    UA_QualifiedName myObjectName = UA_QUALIFIEDNAME(1, "the.fake.Server.Struct");
    UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
    UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
    UA_StatusCode res =
        UA_Server_addObjectNode(server, myObjectNodeId, parentNodeId,
                                parentReferenceNodeId, myObjectName,
                                UA_NODEID_NUMERIC(0, 2004), attr,
                                &handleCalled, NULL);
    ck_assert_int_eq(UA_STATUSCODE_GOOD, res);
    ck_assert_int_gt(handleCalled, 0); // Should be 58, but may depend on NS0 XML detail
} END_TEST
Ejemplo n.º 30
0
static UA_VariableNode* makeCompareSequence(void) {
	UA_VariableNode *node = UA_VariableNode_new();
	UA_Variant *myIntegerVariant = UA_Variant_new();
	UA_Int32 myInteger = 42;
	UA_Variant_setScalarCopy(myIntegerVariant, &myInteger,
			&UA_TYPES[UA_TYPES_INT32]);
	const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
	const UA_LocalizedText myIntegerDisplName = UA_LOCALIZEDTEXT("en_US", "the answer");
        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);
	node->value.variant.value = *myIntegerVariant;
	UA_NodeId_copy(&myIntegerNodeId,&node->nodeId);
	UA_QualifiedName_copy(&myIntegerName,&node->browseName);
        UA_LocalizedText_copy(&myIntegerDisplName, &node->displayName);
        UA_LocalizedText_copy(&myIntegerDisplName, &node->description);
        UA_ExpandedNodeId parentId;
	UA_ExpandedNodeId_init(&parentId);
	UA_NodeId_copy(&parentNodeId,&parentId.nodeId);

	return node;
}