Browse Source

Some basic encoding functions has been fixed.
The test function for Datavalues can test now SevertimeStamp.
The test for DataValues to test Variants need to be updated when an enconding function has been created.

MaximilianBauer 11 years ago
parent
commit
48691c2a6f
2 changed files with 43 additions and 22 deletions
  1. 10 9
      OPCUAServer/src/opcua_binaryEncDec.c
  2. 33 13
      OPCUAServer/tests/check_stack.c

+ 10 - 9
OPCUAServer/src/opcua_binaryEncDec.c

@@ -573,7 +573,7 @@ Int32 decodeUInt16(char * const buf, Int32 *pos, UInt16 *dst)
 }
 void encodeUInt16(UInt16 value, Int32 *pos, char* dstBuf)
 {
-	memcpy(dstBuf, &value, sizeof(UInt16));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt16));
 	*pos = (*pos) + sizeof(UInt16);
 }
 
@@ -587,7 +587,7 @@ Int32 decodeInt16(char * const buf, Int32 *pos, Int16 *dst)
 }
 void encodeInt16(Int16 value, Int32 *pos, char *dstBuf)
 {
-	memcpy(dstBuf, &value, sizeof(Int16));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Int16));
 	*pos = (*pos) + sizeof(Int16);
 }
 
@@ -603,7 +603,7 @@ Int32 decodeInt32(char * const buf, Int32 *pos, Int32 *dst)
 }
 void encodeInt32(Int32 value, Int32 *pos, char *dstBuf)
 {
-	memcpy(dstBuf, &value, sizeof(Int32));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Int32));
 	*pos = (*pos) + sizeof(Int32);
 }
 
@@ -641,7 +641,7 @@ Int32 decodeInt64(char * const buf, Int32 *pos, Int64 *dst)
 }
 void encodeInt64(Int64 value, Int32 *pos, char *dstBuf)
 {
-	memcpy(dstBuf, &value, sizeof(Int64));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Int64));
 	*pos = (*pos) + sizeof(Int64);
 }
 
@@ -662,7 +662,7 @@ Int32 decodeUInt64(char * const buf, Int32 *pos, UInt64 *dst)
 }
 void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf)
 {
-	memcpy(dstBuf, &value, sizeof(UInt64));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt64));
 	*pos = (*pos) + sizeof(UInt64);
 }
 
@@ -1222,14 +1222,15 @@ Int32 encodeDataValue(UA_DataValue *dataValue, Int32 *pos, char *dstBuf)
 	}
 	if (dataValue->EncodingMask & 0x08)
 	{
-		encoder_encodeBuiltInDatatype((void*) &(dataValue->SourcePicoseconds),
-				UINT16, pos, dstBuf);
+		encoder_encodeBuiltInDatatype((void*) &(dataValue->ServerTimestamp),
+				DATE_TIME, pos, dstBuf);
 	}
 	if (dataValue->EncodingMask & 0x10)
 	{
-		encoder_encodeBuiltInDatatype((void*) &(dataValue->ServerTimestamp),
-				DATE_TIME, pos, dstBuf);
+		encoder_encodeBuiltInDatatype((void*) &(dataValue->SourcePicoseconds),
+				UINT16, pos, dstBuf);
 	}
+
 	if (dataValue->EncodingMask & 0x20)
 	{
 		encoder_encodeBuiltInDatatype((void*) &(dataValue->ServerPicoseconds),

+ 33 - 13
OPCUAServer/tests/check_stack.c

@@ -503,29 +503,49 @@ START_TEST(encodeDataValue_test)
 {
 	UA_DataValue dataValue;
 	Int32 pos = 0;
-	char *buf = (char*)opcua_malloc(500);
+	char *buf = (char*)opcua_malloc(15);
+	UA_DateTime dateTime;
+	dateTime = 80;
+	dataValue.ServerTimestamp = dateTime;
 
-	buf[0] = 99;
-	buf[1] = 99;
-	buf[2] = 99;
-
-	//without Variant
+	//--without Variant
 	dataValue.EncodingMask = 0x08; //Only the SourvePicoseconds
+	encodeDataValue(&dataValue, &pos, buf);
+
+	ck_assert_int_eq(pos, 9);// represents the length
+	ck_assert_int_eq(buf[0], 0x08);
+	ck_assert_int_eq(buf[1], 80);
+	ck_assert_int_eq(buf[2], 0);
+	ck_assert_int_eq(buf[3], 0);
+	ck_assert_int_eq(buf[4], 0);
+	ck_assert_int_eq(buf[5], 0);
+	ck_assert_int_eq(buf[6], 0);
+	ck_assert_int_eq(buf[7], 0);
+	ck_assert_int_eq(buf[8], 0);
+
+	//TestCase for a DataValue with a Variant!
+	//ToDo: Need to be checked after the function for encoding variants has been implemented
+	pos = 0;
+	dataValue.EncodingMask = 0x01 || 0x08; //Variant & SourvePicoseconds
 	UA_Variant variant;
 	variant.ArrayLength = 0;
-	variant.EncodingMask = VTEMT_UINT32;
+	variant.EncodingMask = VTEMT_INT32;
 	UA_VariantUnion variantUnion;
 	variantUnion.Int32 = 45;
 	variant.Value = &variantUnion;
 	dataValue.Value = variant;
-	dataValue.SourcePicoseconds = 12;
-	dataValue.ServerPicoseconds = 34;
-
 	encodeDataValue(&dataValue, &pos, buf);
-	ck_assert_int_eq(pos, 3);// represents the length
+
+	ck_assert_int_eq(pos, 14);// represents the length
 	ck_assert_int_eq(buf[0], 0x08);
-	ck_assert_int_eq(buf[1], 0);
-	ck_assert_int_eq(buf[2], 12);
+	ck_assert_int_eq(buf[1], 0x06);
+	ck_assert_int_eq(buf[2], 45);
+	ck_assert_int_eq(buf[3], 0);
+	ck_assert_int_eq(buf[4], 0);
+	ck_assert_int_eq(buf[5], 0);
+	ck_assert_int_eq(buf[6], 80);
+	ck_assert_int_eq(buf[7], 0);
+
 }
 END_TEST