Explorar o código

cheking diagnostic info

FlorianPalm %!s(int64=11) %!d(string=hai) anos
pai
achega
8eb8bd50a1

+ 3 - 0
OPCUAServer/configure.ac

@@ -6,6 +6,9 @@ AC_INIT(OPCUAServer, 1.0)
 
 AC_CANONICAL_SYSTEM
 AM_INIT_AUTOMAKE()
+if test -z $CFLAGS; then
+    CFLAGS='-O2'
+fi
 AC_PROG_CC
 AM_PROG_CC_C_O
 AC_CHECK_LIB([m],[exp],,AC_MSG_ERROR([Libm missing]))

+ 18 - 2
OPCUAServer/examples/src/opcuaServer.c

@@ -63,10 +63,26 @@ void server_run()
 	struct sockaddr_in client_addr;
 	int addrlen=sizeof(client_addr);
 
+
+	Int32 valreal = 0;
+	Int32 valcalc = 0;
+	UA_DiagnosticInfo diagnosticInfo;
+	diagnosticInfo.EncodingMask |= 0x01 | 0x02 | 0x04 | 0x04 | 0x08 | 0x10 | 0x10;
+	diagnosticInfo.SymbolicId = 30;
+	diagnosticInfo.NamespaceUri = 25;
+	diagnosticInfo.LocalizedText = 22;
+	diagnosticInfo.AdditionalInfo.Data = "OPCUA";
+	diagnosticInfo.AdditionalInfo.Length = 5;
+
+	if (diagnosticInfo_calcSize(&diagnosticInfo) > 10)
+	{
+
+
 	//---Create streaming socket---
-    if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
+	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
 	{
-    	puts("socket error");
+		puts("socket error");
+	}
 	}
 	bzero(&self, sizeof(self));
 	self.sin_family = AF_INET;

+ 1 - 1
OPCUAServer/src/opcua_advancedDatatypes.h

@@ -729,7 +729,7 @@ struct BED_ResponseHeader
 	UA_DateTime timestamp;
 	BED_IntegerId requestHandle;
 	UA_StatusCode serviceResult;
-	UA_DiagnosticInfo serviceDiagnostics;
+	UA_DiagnosticInfo *serviceDiagnostics;
 	UA_String stringTable[];
 //ToDo	struct BED_ExtensibleParameterAdditionalHeader additionalHeader;		//ToDo
 };

+ 47 - 9
OPCUAServer/src/opcua_binaryEncDec.c

@@ -7,7 +7,8 @@
 
 #include "opcua_binaryEncDec.h"
 #include "opcua_types.h"
-
+#include <stdio.h>
+#include <stdlib.h>
 Byte decodeByte(const char *buf, Int32 *pos)
 {
 	*pos = (*pos) + 1;
@@ -118,7 +119,7 @@ void decodeUAByteString(const char *buf, Int32* pos,
 		UA_ByteString *dstBytestring)
 {
 
-	decodeUAString(buf, pos, dstBytestring->Data);
+	decodeUAString(buf, pos, (UA_String*)dstBytestring);
 }
 
 UA_DateTime decodeUADateTime(const char *buf, Int32 *pos)
@@ -250,14 +251,48 @@ Int32 decodeToDiagnosticInfo(char* buf, Int32 *pos,
 	*pos += 1;
 	return 0;
 }
-Int32 DiagnosticInfo_calcSize(T_DiagnosticInfo *diagnosticInfo)
+Int32 diagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo)
 {
-	Int32 minimumLength = 20;
-	Int32 length;
-	length += minimumLength;
-	length += diagnosticInfo->additionalInfo.Length;
-	length += sizeof(UInt32);
-	length += DiagnosticInfo_calcSize(diagnosticInfo->innerDiagnosticInfo);
+	Int32 minimumLength = 1;
+	Int32 length = minimumLength;
+	Byte mask;
+	Int32 j = 0;
+	mask = 0;
+	puts("diagnosticInfo called");
+	for(mask = 1; mask <= 0x40; mask *= 2)
+	{
+		j++;
+		puts("loop");
+		printf("mask %u",mask);
+		printf("mask calc %u",mask & (diagnosticInfo->EncodingMask));
+		switch(mask & (diagnosticInfo->EncodingMask))
+		{
+
+		DIEMT_SYMBOLIC_ID:
+			puts("diagnosticInfo symbolic id");
+			length += sizeof(Int32);
+			break;
+		DIEMT_NAMESPACE:
+			length += sizeof(Int32);
+			break;
+		DIEMT_LOCALIZED_TEXT:
+			length += sizeof(Int32);
+			break;
+		DIEMT_LOCALE:
+			length += sizeof(Int32);
+			break;
+		DIEMT_ADDITIONAL_INFO:
+			length += diagnosticInfo->AdditionalInfo.Length;
+			length += sizeof(Int32);
+			break;
+		DIEMT_INNER_STATUS_CODE:
+			length += sizeof(UA_StatusCode);
+			break;
+		DIEMT_INNER_DIAGNOSTIC_INFO:
+			length += diagnosticInfo_calcSize(diagnosticInfo->InnerDiagnosticInfo);
+			break;
+		}
+	}
 	return length;
 }
 /**
@@ -310,6 +345,9 @@ Int32 ResponseHeader_calcSize(T_ResponseHeader *responseHeader)
 		length += responseHeader->stringTable[i].Length;
 		length += sizeof(UInt32); // length of the encoded length field
 	}
+
+	length += diagnosticInfo_calcSize(responseHeader->serviceDiagnostics);
+
 //TODO
 	return 0;
 }

+ 6 - 1
OPCUAServer/src/opcua_binaryEncDec.h

@@ -165,7 +165,12 @@ Int32 decodeResponseHeader(const AD_RawMessage *srcRaw, Int32 *pos, T_ResponseHe
 Int32 encodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos, AD_RawMessage *dstBuf);
 
 
-
+/**
+ *
+ * @param diagnosticInfo
+ * @return length of the binary encoded data
+ */
+Int32 diagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo);
 
 
 

+ 10 - 10
OPCUAServer/src/opcua_secureChannelLayer.c

@@ -25,7 +25,7 @@ Int32 SL_secureChannel_ResponseHeader_form(UA_connection *connection, T_Response
 	responseHeader->requestHandle = 0;
 	responseHeader->serviceResult = 0; // TODO insert service result code
 
-	responseHeader->serviceDiagnostics.EncodingMask = 0;
+	responseHeader->serviceDiagnostics->EncodingMask = 0;
 	responseHeader->noOfStringTable = 0;
 
 	responseHeader->additionalHeader.Body = 0;
@@ -101,8 +101,8 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
 			&readPosition,&SequenceHeader);
 
 	//get Secure Channel Message
-	SL_secureChannel_Message_get(connection, secureChannelMessage,
-			&readPosition,serviceMessage);
+	//SL_secureChannel_Message_get(connection, secureChannelMessage,
+//			&readPosition,serviceMessage);
 
 	if (secureChannelMessage->length > 0)
 	{
@@ -121,15 +121,15 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
 			break;
 		case packetType_OPN:
 			//Server Handling
-			if (openSecureChannelHeader_check(connection, secureChannelMessage))
-			{
+	//		if (openSecureChannelHeader_check(connection, secureChannelMessage))
+	//		{
 				//check if the request is valid
 				SL_openSecureChannelRequest_check(connection, secureChannelMessage);
-			}
-			else
-			{
-				//TODO send back Error Message
-			}
+	//		}
+	//		else
+	//		{
+	//			//TODO send back Error Message
+	//		}
 		//Client Handling
 
 		//TODO free memory for secureChannelMessage

+ 1 - 1
OPCUAServer/src/opcua_types.h

@@ -805,7 +805,7 @@ typedef struct _T_ResponseHeader
 	UA_DateTime timestamp;
 	T_IntegerId requestHandle;
 	UA_StatusCode serviceResult;
-	UA_DiagnosticInfo serviceDiagnostics;
+	UA_DiagnosticInfo *serviceDiagnostics;
 	UInt16 noOfStringTable;
 	UA_String* stringTable;
 	UA_ExtensionObject additionalHeader;

+ 2 - 4
OPCUAServer/tests/Makefile.am

@@ -1,8 +1,6 @@
 TESTS = check_stack
 check_PROGRAMS = check_stack
-check_stack_SOURCES = check_stack.c $(top_builddir)/src/opcua_transportLayer.h\
-						$(top_builddir)/src/opcua_advancedDatatypes.h\
-						$(top_builddir)/src/opcua_connectionHelper.h
+check_stack_SOURCES = check_stack.c
 
 check_stack_CFLAGS = @CHECK_CFLAGS@
-check_stack_LDADD = $(top_builddir)/bin/libOpen62541.la @CHECK_LIBS@
+check_stack_LDADD = $(top_builddir)/src/.libs/libopen62541.la @CHECK_LIBS@

+ 36 - 1
OPCUAServer/tests/check_stack.c

@@ -121,6 +121,28 @@ START_TEST(encodeUInt16_test)
 END_TEST
 
 
+START_TEST(diagnosticInfo_calcSize_test)
+{
+
+
+	Int32 valreal = 0;
+	Int32 valcalc = 0;
+	UA_DiagnosticInfo diagnosticInfo;
+	diagnosticInfo.EncodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
+	diagnosticInfo.SymbolicId = 30;
+	diagnosticInfo.NamespaceUri = 25;
+	diagnosticInfo.LocalizedText = 22;
+	diagnosticInfo.AdditionalInfo.Data = "OPCUA";
+	diagnosticInfo.AdditionalInfo.Length = 5;
+
+
+	valcalc = diagnosticInfo_calcSize(&diagnosticInfo);
+	valreal = 23;
+	ck_assert_int_eq(valcalc,valreal);
+
+
+}
+END_TEST
 Suite* TL_testSuite_getPacketType(void)
 {
 	Suite *s = suite_create("getPacketType");
@@ -165,7 +187,14 @@ Suite* TL_<TESTSUITENAME>(void)
 	return s;
 }
 */
-
+Suite* TL_testSuite_diagnosticInfo_calcSize()
+{
+	Suite *s = suite_create("diagnosticInfo_calcSize");
+	TCase *tc_core = tcase_create("Core");
+	tcase_add_test(tc_core, diagnosticInfo_calcSize_test);
+	suite_add_tcase(s,tc_core);
+	return s;
+}
 int main (void)
 {
 	int number_failed = 0;
@@ -194,6 +223,12 @@ int main (void)
 	number_failed += srunner_ntests_failed(sr);
 	srunner_free(sr);
 
+	s = TL_testSuite_diagnosticInfo_calcSize();
+	sr = srunner_create(s);
+	srunner_run_all(sr,CK_NORMAL);
+	number_failed += srunner_ntests_failed(sr);
+	srunner_free(sr);
+
 	/* <TESTSUITE_TEMPLATE>
 	s =  <TESTSUITENAME>;
 	sr = srunner_create(s);