|
@@ -8,9 +8,6 @@
|
|
|
#include "opcua_binaryEncDec.h"
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/*
|
|
|
* convert byte array to Byte
|
|
|
*/
|
|
@@ -18,6 +15,17 @@ 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
|
|
|
*/
|
|
@@ -51,6 +59,23 @@ void convertUInt32ToByteArray(UInt32 value,char *buf,int pos)
|
|
|
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)
|
|
|
{
|
|
@@ -59,3 +84,92 @@ UA_String convertToUAString(char* buf, int 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;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|