Browse Source

convertGuid, convertInt16 has been created.
function encodeRequestHeader is under construction.

MaximilianBauer 11 years ago
parent
commit
3f3e0fac68

+ 162 - 0
OPCUAServer/src/opcua_binaryEncDec.c

@@ -8,6 +8,168 @@
 #include "opcua_binaryEncDec.h"
 
 
+/*
+ * convert byte array to Byte
+ */
+Byte convertToByte(char* buf, int pos)
+{
+	return (Byte)buf[pos];
+}
+/*
+ * convert byte array to UInt16
+ */
+UInt16 convertToUInt16(char* buf, int pos)
+{
+
+	Byte t1 = buf[pos];
+	Int32 t2 = (UInt16)(buf[pos+1] << 8);
+
+	return t1 + t2;
+}
+/*
+ * convert byte array to Int32
+ */
+Int32 convertToInt32(char* buf, int pos)
+{
+
+	SByte t1 = buf[pos];
+	Int32 t2 = (UInt32)(buf[pos+1] << 8);
+	Int32 t3 = (UInt32)(buf[pos+2] << 16);
+	Int32 t4 = (UInt32)(buf[pos+3] << 24);
+
+	return t1 + t2 + t3 + t4;
+}
+/*
+ * convert byte array to UInt32
+ */
+UInt32 convertToUInt32(char* buf, int pos)
+{
+	Byte t1 = buf[pos];
+	UInt32 t2 = (UInt32)(buf[pos+1] << 8);
+	UInt32 t3 = (UInt32)(buf[pos+2] << 16);
+	UInt32 t4 = (UInt32)(buf[pos+3] << 24);
+
+	return t1 + t2 + t3 + t4;
+}
+
+void convertUInt32ToByteArray(UInt32 value,char *buf,int pos)
+{
+	buf[pos] = (char)(value && 0xFF);
+	buf[pos + 1] = (char)((value >> 8) && 0xFF);
+	buf[pos + 2] = (char)((value >> 16) && 0xFF);
+	buf[pos + 3] = (char)((value >> 24) && 0xFF);
+}
+/*
+ * convert byte array to Int64
+ */
+Int64 convertToInt64(char* buf, int pos)
+{
+
+	SByte t1 = buf[pos];
+	UInt64 t2 = (UInt64)(buf[pos+1] << 8);
+	UInt64 t3 = (UInt64)(buf[pos+2] << 16);
+	UInt64 t4 = (UInt64)(buf[pos+3] << 24);
+	UInt64 t5 = (UInt64)(buf[pos+4] << 32);
+	UInt64 t6 = (UInt64)(buf[pos+5] << 40);
+	UInt64 t7 = (UInt64)(buf[pos+6] << 48);
+	UInt64 t8 = (UInt64)(buf[pos+7] << 56);
+
+	return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
+}
+
+UA_String convertToUAString(char* buf, int pos)
+{
+	UA_String tmpUAString;
+	tmpUAString.Length = convertToInt32(buf,pos);
+	tmpUAString.Data = &(buf[sizeof(UInt32)]);
+	return tmpUAString;
+}
+
+UA_Guid convertToUAGuid(char* buf, int pos)
+{
+	UA_Guid tmpUAGuid;
+	int counter = 0;
+	UInt32 i = 0;
+	for(i = 1; i <= 4; i++)
+	{
+		tmpUAGuid.Data1[i] = convertToUInt32(*buf, pos+counter);
+		counter += sizeof(UInt32);
+	}
+	for(i = 1; i <= 2; i++)
+	{
+		tmpUAGuid.Data2[i] = convertToUInt16(*buf, pos+counter);
+		counter += sizeof(UInt16);
+	}
+	for(i = 1; i <= 2; i++)
+	{
+		tmpUAGuid.Data3[i] = convertToUInt16(*buf, pos+counter);
+		counter += sizeof(UInt16);
+	}
+	for(i = 1; i <= 8; i++)
+	{
+		tmpUAGuid.Data4[i] = convertToByte(*buf, pos+counter);
+		counter += sizeof(Byte);
+	}
+	return tmpUAGuid;
+}
+
+UA_NodeId convertToUANodeId(char* buf, int pos){
+	UA_NodeId tmpUANodeId;
+	tmpUANodeId.EncodingByte = convertToInt32(*buf, 0);
+	int counter = sizeof(UInt32);
+
+	UA_NodeIdEncodingValuesType encodingType = tmpUANodeId.EncodingByte;
+
+	switch(encodingType)
+	{
+		case NIEVT_TWO_BYTE:
+		{
+			tmpUANodeId.Identifier.Numeric = convertToInt32(*buf, counter);
+			counter += sizeof(UInt16);
+			break;
+		}
+		case NIEVT_FOUR_BYTE:
+		{
+			tmpUANodeId.Identifier.Numeric = convertToInt32(*buf, counter);
+			counter += sizeof(Int64);
+			break;
+		}
+		case NIEVT_NUMERIC:
+		{
+			tmpUANodeId.Identifier.Numeric = convertToInt32(*buf, counter);
+			counter += sizeof(UInt32);
+			break;
+		}
+		case NIEVT_STRING:
+		{
+			tmpUANodeId.Identifier.String = convertToUAString(*buf, counter);
+			counter += sizeof(sizeof(UInt32) + tmpUANodeId.Identifier.String.Length*sizeof(char));
+			break;
+		}
+		case NIEVT_GUID:
+		{
+			UA_Guid tempGuid = convertToUAGuid(*buf, counter);
+			tmpUANodeId.Identifier.Guid = &tempGuid;
+			counter += sizeof(UA_Guid);
+			break;
+		}
+		case NIEVT_BYTESTRING:
+		{
+			//ToDo
+			break;
+		}
+		case NIEVT_NAMESPACE_URI_FLAG:
+		{
+			break;
+		}
+		case NIEVT_SERVERINDEX_FLAG:
+		{
+			break;
+		}
+	}
+
+	return tmpUANodeId;
+}
 
 
 

+ 7 - 0
OPCUAServer/src/opcua_binaryEncDec.h

@@ -8,6 +8,13 @@
 #ifndef OPCUA_BINARYENCDEC_NEU_H_
 #define OPCUA_BINARYENCDEC_NEU_H_
 
+#include "opcua_builtInDatatypes.h"
 
 
+
+//functions
+Byte convertToByte(char* buf, int pos);
+Int32 convertToInt32(char* buf,int pos);
+UInt32 convertToUInt32(char* buf, int pos);
+
 #endif /* OPCUA_BINARYENCDEC_NEU_H_ */

+ 2 - 2
OPCUAServer/src/opcua_types.h

@@ -767,13 +767,13 @@ T_RelativePath;
 */
 typedef struct _T_RequestHeader
 {
-//ToDo	struct BED_SessionAuthenticationToken authenticationToken;		//ToDo
+	UA_NodeId authenticationToken;
 	UA_DateTime timestamp;
 	T_IntegerId requestHandle;
 	UInt32 returnDiagnostics;
 	UA_String auditEntryId;
 	UInt32 timeoutHint;
-//ToDo	struct BED_ExtensibleParameterAdditionalHeader additionalHeader;		//ToDo
+	UA_ExpandedNodeId additionalHeader;
 }
 T_RequestHeader;