ソースを参照

introduced macro for prototypes

Leon Urbas 11 年 前
コミット
08e9d09a15
共有3 個のファイルを変更した228 個の追加504 個の削除を含む
  1. 0 235
      tool/generate_bulitin.py
  2. 97 89
      tool/opcua_basictypes.c
  3. 131 180
      tool/opcua_basictypes.h

+ 0 - 235
tool/generate_bulitin.py

@@ -1,235 +0,0 @@
-from __future__ import print_function
-import sys
-from collections import OrderedDict
-import re
-from lxml import etree
-
-if len(sys.argv) != 3:
-    print("Usage: python generate_builtin.py <path/to/Opc.Ua.Types.bsd> <outfile w/o extension>", file=sys.stdout)
-    exit(0)
-
-# types that are coded manually
-exclude_types = set(["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32",
-                    "Int64", "UInt64", "Float", "Double", "String", "DateTime", "Guid",
-                    "ByteString", "XmlElement", "NodeId", "ExpandedNodeId", "StatusCode", 
-                    "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
-                     "Variant", "DiagnosticInfo", "RequestHeader", "ResponseHeader", "NodeIdType"])
-
-elementary_size = dict()
-elementary_size["Boolean"] = 1;
-elementary_size["SByte"] = 1;
-elementary_size["Byte"] = 1;
-elementary_size["Int16"] = 2;
-elementary_size["UInt16"] = 2;
-elementary_size["Int32"] = 4;
-elementary_size["UInt32"] = 4;
-elementary_size["Int64"] = 8;
-elementary_size["UInt64"] = 8;
-elementary_size["Float"] = 4;
-elementary_size["Double"] = 8;
-elementary_size["DateTime"] = 8;
-elementary_size["StatusCode"] = 4;
-
-# indefinite_types = ["NodeId", "ExpandedNodeId", "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue", "Variant", "DiagnosticInfo"]
-indefinite_types = ["ExpandedNodeId", "QualifiedName", "ExtensionObject", "DataValue", "Variant", "DiagnosticInfo"]
-enum_types = []
-                   
-# indefinite types cannot be directly contained in a record as they don't have a definite size
-printed_types = exclude_types # types that were already printed and which we can use in the structures to come
-
-# types we do not want to autogenerate
-def skipType(name):
-    if name in exclude_types:
-        return True
-    if re.search("NodeId$", name) != None:
-        return True
-    return False
-
-def stripTypename(tn):
-    return tn[tn.find(":")+1:]
-
-def camlCase2AdaCase(item):
-    (newitem, n) = re.subn("(?<!^)(?<![A-Z])([A-Z])", "_\\1", item)
-    return newitem
-
-# are the prerequisites in place? if not, postpone.
-def printableStructuredType(element):
-    for child in element:
-        if child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
-            typename = stripTypename(child.get("TypeName"))
-            if typename not in printed_types:
-                return False
-    return True
-
-# There three types of types in the bsd file:
-# StructuredType, EnumeratedType OpaqueType
-
-def createEnumerated(element):
-    valuemap = OrderedDict()
-    name = "UA_" + element.get("Name")
-    enum_types.append(name)
-    print("// " + name, end='\n', file=fh)
-    for child in element:
-        if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
-            print("// " + child.text, end='\n', file=fh)
-        if child.tag == "{http://opcfoundation.org/BinarySchema/}EnumeratedValue":
-            valuemap[name + "_" + child.get("Name")] = child.get("Value")
-    valuemap = OrderedDict(sorted(valuemap.iteritems(), key=lambda (k,v): int(v)))
-    print("typedef UA_UInt32 " + name + ";", end='\n', file=fh);
-    print("enum " + name + "_enum { \n" + ",\n\t".join(map(lambda (key, value) : key + " = " + value, valuemap.iteritems())) + "\n};\n", end='\n', file=fh)
-    return
-    
-def createStructured(element):
-    valuemap = OrderedDict()
-    name = "UA_" + element.get("Name")
-    print("// " + name, end='\n', file=fh)
-
-    lengthfields = set()
-    for child in element:
-        if child.get("LengthField"):
-            lengthfields.add(child.get("LengthField"))
-    
-    for child in element:
-        if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
-            print("// " + child.text, end='\n', file=fh)
-        elif child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
-            if child.get("Name") in lengthfields:
-                continue
-            childname = camlCase2AdaCase(child.get("Name"))
-            if childname in printed_types:
-                childname = childname + "_Value" # attributes may not have the name of a type
-            typename = stripTypename(child.get("TypeName"))
-            if childname == "Response_Header" or childname == "Request_Header":
-                continue
-            if typename in indefinite_types:
-                valuemap[childname] = typename + "*"
-            elif child.get("LengthField"):
-                valuemap[childname] = typename + "**"
-            else:
-                valuemap[childname] = typename
-
-    # if "Response" in name[len(name)-9:]:
-    #    print("type " + name + " is new Response_Base with "),
-    # elif "Request" in name[len(name)-9:]:
-    #    print ("type " + name + " is new Request_Base with "),
-    # else:
-    #    print ("type " + name + " is new UA_Builtin with "),
-    print("typedef struct T_" + name + " {", end='\n', file=fh)
-    if len(valuemap) > 0:
-        for n,t in valuemap.iteritems():
-            if t.find("**") != -1:
-	        print("\t" + "UInt32 " + n + "_size;", end='\n', file=fh)
-            print("\t" + "UA_" + t + " " + n + ";", end='\n', file=fh)
-    else:
-        print("// null record", end='\n', file=fh)
-    print("} " + name + ";", end='\n', file=fh)
-
-    print("Int32 " + name + "_calcSize(" + name + " const * ptr);", end='\n', file=fh)
-    print("Int32 " + name + "_encode(" + name + " const * src, Int32* pos, char* dst);", end='\n', file=fh)
-    print("Int32 " + name + "_decode(char const * src, UInt32* pos, " + name + "* dst);", end='\n', file=fh)
-
-    if "Response" in name[len(name)-9:]:
-        print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_ResponseHeader_getSize()", end='', file=fc) 
-    elif "Request" in name[len(name)-9:]:
-        print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_RequestHeader_getSize()", end='', file=fc) 
-    else:
-	# code 
-        print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn 0", end='', file=fc)
-
-    # code _calcSize
-    for n,t in valuemap.iteritems():
-        if t in elementary_size:
-            print('\n\t + sizeof(UA_' + t + ") // " + n, end='', file=fc)
-        else:
-            if t in enum_types:
-                print('\n\t + 4 //' + n, end='', file=fc) # enums are all 32 bit
-            elif t.find("**") != -1:
-		print("\n\t + 4 //" + n + "_size", end='', file=fc),
-		print("\n\t + UA_Array_calcSize(ptr->" + n + "_size, UA_" + t[0:t.find("*")].upper() + ", (void**) ptr->" + n +")", end='', file=fc)
-            elif t.find("*") != -1:
-                print('\n\t + ' + "UA_" + t[0:t.find("*")] + "_calcSize(ptr->" + n + ')', end='', file=fc)
-            else:
-                print('\n\t + ' + "UA_" + t + "_calcSize(&(ptr->" + n + '))', end='', file=fc)
-
-    print("\n\t;\n};\n", end='\n', file=fc)
-
-    print("Int32 "+name+"_encode("+name+" const * src, Int32* pos, char* dst) {\n\tInt32 retval=0;", end='\n', file=fc)
-    # code _encode
-    for n,t in valuemap.iteritems():
-        if t in elementary_size:
-            print('\tretval |= UA_'+t+'_encode(&(src->'+n+'),pos,dst);', end='\n', file=fc)
-        else:
-            if t in enum_types:
-                print('\tretval |= UA_'+t+'_encode(&(src->'+n+'));', end='\n', file=fc)
-            elif t.find("**") != -1:
-                print('\tretval |= UA_Int32_encode(&(src->'+n+'_size)); // encode size', end='\n', file=fc)
-		print("\tretval |= UA_Array_encode((void**) (src->"+n+"),src->"+n+"_size, UA_" + t[0:t.find("*")].upper()+",pos,dst);", end='\n', file=fc)
-            elif t.find("*") != -1:
-                print('\tretval |= UA_' + t[0:t.find("*")] + "_encode(src->" + n + ',pos,dst);', end='\n', file=fc)
-            else:
-                print('\tretval |= UA_'+t+"_encode(&(src->"+n+"),pos,dst);", end='\n', file=fc)
-    print("\treturn retval;\n};\n", end='\n', file=fc)
-        
-def createOpaque(element):
-    name = "UA_" + element.get("Name")
-    print("// " + name , end='\n', file=fh)
-    for child in element:
-        if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
-            print("// " + child.text, end='\n', file=fh)
-
-    print("typedef void* " + name + ";\n", end='\n', file=fh)
-    return
-
-ns = {"opc": "http://opcfoundation.org/BinarySchema/"}
-tree = etree.parse(sys.argv[1])
-types = tree.xpath("/opc:TypeDictionary/*[not(self::opc:Import)]", namespaces=ns)
-
-fh = open(sys.argv[2] + ".h",'w');
-fc = open(sys.argv[2] + ".c",'w');
-print('#include "' + sys.argv[2] + '.h"', end='\n', file=fc);
-
-# types for which we create a vector type
-arraytypes = set()
-fields = tree.xpath("//opc:Field", namespaces=ns)
-for field in fields:
-    if field.get("LengthField"):
-        arraytypes.add(stripTypename(field.get("TypeName")))
-
-deferred_types = OrderedDict()
-
-print('#ifndef OPCUA_H_', end='\n', file=fh)
-print('#define OPCUA_H_', end='\n', file=fh)
-print('#include "opcua_basictypes.h"', end='\n', file=fh)
-print('#include "opcua_namespace_0.h"', end='\n', file=fh);
-
-for element in types:
-    name = element.get("Name")
-    if skipType(name):
-        continue
-        
-    if element.tag == "{http://opcfoundation.org/BinarySchema/}EnumeratedType":
-        createEnumerated(element)
-        printed_types.add(name)
-    elif element.tag == "{http://opcfoundation.org/BinarySchema/}StructuredType":
-        if printableStructuredType(element):
-            createStructured(element)
-            printed_types.add(name)
-        else: # the record contains types that were not yet detailed
-            deferred_types[name] = element
-            continue
-    elif element.tag == "{http://opcfoundation.org/BinarySchema/}OpaqueType":
-        createOpaque(element)
-        printed_types.add(name)
-
-    #if name in arraytypes:
-    #    print "package ListOf" + name + " is new Types.Arrays.UA_Builtin_Arrays(" + name + ");\n"
-
-for name, element in deferred_types.iteritems():
-    createStructured(element)
-    # if name in arraytypes:
-    #    print "package ListOf" + name + " is new Types.Arrays.UA_Builtin_Arrays(" + name + ");\n"
-
-print('#endif /* OPCUA_H_ */', end='\n', file=fh)
-fh.close()
-fc.close()
-

+ 97 - 89
tool/opcua_basictypes.c

@@ -60,7 +60,7 @@ Int32 UA_SByte_decode(char const * src, Int32* pos, UA_SByte * dst) {
 Int32 UA_SByte_delete(UA_SByte* p) { return UA_memfree(p); };
 Int32 UA_SByte_deleteMembers(UA_SByte* p) { return UA_SUCCESS; };
 
-Int32 UA_UInt16_calcSize(UA_UInt16* p) { return sizeof(UA_UInt16); }
+Int32 UA_UInt16_calcSize(UA_UInt16 const * p) { return sizeof(UA_UInt16); }
 Int32 UA_UInt16_encode(UA_UInt16 const *src, Int32* pos, char * dst) {
 	memcpy(&(dst[*pos]), src, sizeof(UA_UInt16));
 	*pos += sizeof(UA_UInt16);
@@ -75,8 +75,8 @@ Int32 UA_UInt16_decode(char const * src, Int32* pos, UA_UInt16* dst) {
 Int32 UA_UInt16_delete(UA_UInt16* p) { return UA_memfree(p); };
 Int32 UA_UInt16_deleteMembers(UA_UInt16* p) { return UA_SUCCESS; };
 
-Int32 UA_Int16_calcSize(UA_Int16* p) { return sizeof(UA_Int16); }
-Int32 UA_Int16_encode(UA_Int16 const* src, Int32* pos, char* dst) {
+Int32 UA_Int16_calcSize(UA_Int16 const * p) { return sizeof(UA_Int16); }
+Int32 UA_Int16_encode(UA_Int16 const * src, Int32* pos, char* dst) {
 	memcpy(&(dst[*pos]), src, sizeof(UA_Int16));
 	*pos += sizeof(UA_Int16);
 	return UA_SUCCESS;
@@ -90,72 +90,81 @@ Int32 UA_Int16_decode(char const * src, Int32* pos, UA_Int16 *dst) {
 Int32 UA_Int16_delete(UA_Int16* p) { return UA_memfree(p); };
 Int32 UA_Int16_deleteMembers(UA_Int16* p) { return UA_SUCCESS; };
 
-Int32 decodeInt32(char const * buf, Int32 *pos, Int32 *dst) {
-	Int32 t1 = (Int32) (((SByte) (buf[*pos]) & 0xFF));
-	Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
-	Int32 t3 = (Int32) (((SByte) (buf[*pos + 2]) & 0xFF) << 16);
-	Int32 t4 = (Int32) (((SByte) (buf[*pos + 3]) & 0xFF) << 24);
-	*pos += sizeof(Int32);
-	*dst = t1 + t2 + t3 + t4;
+Int32 UA_Int32_calcSize(UA_Int32 const * p) { return sizeof(UA_Int32); }
+Int32 UA_Int32_encode(UA_Int32 const * src, Int32* pos, char *dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_Int32));
+	*pos += sizeof(UA_Int32);
 	return UA_SUCCESS;
 }
-void encodeInt32(Int32 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Int32));
-	*pos = (*pos) + sizeof(Int32);
+Int32 UA_Int32_decode(char const * src, Int32* pos, UA_Int32* dst) {
+	Int32 t1 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF));
+	Int32 t2 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 8);
+	Int32 t3 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 16);
+	Int32 t4 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 24);
+	*dst = t1 + t2 + t3 + t4;
+	return UA_SUCCESS;
 }
+Int32 UA_Int32_delete(UA_Int32* p) { return UA_memfree(p); };
+Int32 UA_Int32_deleteMembers(UA_Int32* p) { return UA_SUCCESS; };
 
-Int32 decodeUInt32(char const * buf, Int32 *pos, UInt32 *dst) {
-	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;
-	*pos += sizeof(UInt32);
+Int32 UA_UInt32_calcSize(UA_UInt32 const * p) { return sizeof(UA_UInt32); }
+Int32 UA_UInt32_encode(UA_UInt32 const * src, Int32* pos, char *dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_UInt32));
+	*pos += sizeof(UA_UInt32);
+	return UA_SUCCESS;
+}
+Int32 UA_UInt32_decode(char const * src, Int32* pos, UA_UInt32 *dst) {
+	UInt32 t1 = (UInt32) src[(*pos)++];
+	UInt32 t2 = (UInt32) src[(*pos)++] << 8;
+	UInt32 t3 = (UInt32) src[(*pos)++] << 16;
+	UInt32 t4 = (UInt32) src[(*pos)++] << 24;
 	*dst = t1 + t2 + t3 + t4;
-	return UA_NO_ERROR;
+	return UA_SUCCESS;
 }
+Int32 UA_UInt32_delete(UA_UInt32* p) { return UA_memfree(p); };
+Int32 UA_UInt32_deleteMembers(UA_UInt32* p) { return UA_SUCCESS; };
 
-void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt32));
-	*pos += 4;
+Int32 UA_Int64_calcSize(UA_Int64 const * p) { return sizeof(UA_Int64); }
+Int32 UA_Int64_encode(UA_Int64 const * src, Int32* pos, char *dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_Int64));
+	*pos += sizeof(UA_Int64);
+	return UA_SUCCESS;
 }
-
-Int32 decodeInt64(char const * buf, Int32 *pos, Int64 *dst) {
-
-	SByte t1 = buf[*pos];
-	Int64 t2 = (Int64) buf[*pos + 1] << 8;
-	Int64 t3 = (Int64) buf[*pos + 2] << 16;
-	Int64 t4 = (Int64) buf[*pos + 3] << 24;
-	Int64 t5 = (Int64) buf[*pos + 4] << 32;
-	Int64 t6 = (Int64) buf[*pos + 5] << 40;
-	Int64 t7 = (Int64) buf[*pos + 6] << 48;
-	Int64 t8 = (Int64) buf[*pos + 7] << 56;
-	*pos += 8;
+Int32 UA_Int64_decode(char const * src, Int32* pos, UA_Int64* dst) {
+	Int64 t1 = (Int64) src[(*pos)++];
+	Int64 t2 = (Int64) src[(*pos)++] << 8;
+	Int64 t3 = (Int64) src[(*pos)++] << 16;
+	Int64 t4 = (Int64) src[(*pos)++] << 24;
+	Int64 t5 = (Int64) src[(*pos)++] << 32;
+	Int64 t6 = (Int64) src[(*pos)++] << 40;
+	Int64 t7 = (Int64) src[(*pos)++] << 48;
+	Int64 t8 = (Int64) src[(*pos)++] << 56;
 	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
-	return UA_NO_ERROR;
-}
-void encodeInt64(Int64 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Int64));
-	*pos = (*pos) + sizeof(Int64);
+	return UA_SUCCESS;
 }
+Int32 UA_Int64_delete(UA_Int64* p) { return UA_memfree(p); };
+Int32 UA_Int64_deleteMembers(UA_Int64* p) { return UA_SUCCESS; };
 
-Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst) {
-
-	Byte 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;
-	*pos += 8;
-	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
-	return UA_NO_ERROR;
+Int32 UA_UInt64_calcSize(UA_UInt64* p) { return sizeof(UA_UInt64); }
+Int32 UA_UInt64_encode(UA_UInt64 const * src , Int32* pos, char * dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_UInt64));
+	*pos += sizeof(UInt64);
+	return UA_SUCCESS;
 }
-void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt64));
-	*pos = (*pos) + sizeof(UInt64);
+Int32 UA_UInt64_decode(char const * src, Int32* pos, UA_UInt64* dst) {
+	UInt64 t1 = (UInt64) src[(*pos)++];
+	UInt64 t2 = (UInt64) src[(*pos)++] << 8;
+	UInt64 t3 = (UInt64) src[(*pos)++] << 16;
+	UInt64 t4 = (UInt64) src[(*pos)++] << 24;
+	UInt64 t5 = (UInt64) src[(*pos)++] << 32;
+	UInt64 t6 = (UInt64) src[(*pos)++] << 40;
+	UInt64 t7 = (UInt64) src[(*pos)++] << 48;
+	UInt64 t8 = (UInt64) src[(*pos)++] << 56;
+	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
+	return UA_SUCCESS;
 }
+Int32 UA_UInt64_delete(UA_UInt64* p) { return UA_memfree(p); };
+Int32 UA_UInt64_deleteMembers(UA_UInt64* p) { return UA_SUCCESS; };
 
 Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst) {
 	Float tmpFloat;
@@ -233,16 +242,15 @@ Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * localizedText) {
 Int32 UA_LocalizedText_delete(UA_LocalizedText* p) { return UA_memfree(p); };
 Int32 UA_LocalizedText_deleteMembers(UA_LocalizedText* p) {
 	return UA_SUCCESS
-// TODO: both locale and text are yet neither pointers nor allocated
-//		|| UA_ByteString_delete(p->locale)
-//		|| UA_ByteString_delete(p->text)
+			|| UA_ByteString_deleteMembers(&(p->locale))
+			|| UA_ByteString_deleteMembers(&(p->text))
 	;
 };
 
 
 Int32 UA_NodeId_calcSize(UA_NodeId const *nodeId) {
 	Int32 length = 0;
-	switch (nodeId->EncodingByte) {
+	switch (nodeId->encodingByte) {
 	case NIEVT_TWO_BYTE:
 		length += 2 * sizeof(UA_Byte);
 		break;
@@ -253,13 +261,13 @@ Int32 UA_NodeId_calcSize(UA_NodeId const *nodeId) {
 		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + sizeof(UInt32);
 		break;
 	case NIEVT_STRING:
-		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_String_calcSize(&(nodeId->Identifier.String));
+		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_String_calcSize(&(nodeId->identifier.string));
 		break;
 	case NIEVT_GUID:
-		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_Guid_calcSize(&(nodeId->Identifier.Guid));
+		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_Guid_calcSize(&(nodeId->identifier.guid));
 		break;
 	case NIEVT_BYTESTRING:
-		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_ByteString_calcSize(&(nodeId->Identifier.ByteString));
+		length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_ByteString_calcSize(&(nodeId->identifier.byteString));
 		break;
 	default:
 		break;
@@ -271,17 +279,17 @@ Int32 UA_NodeId_calcSize(UA_NodeId const *nodeId) {
 // TODO: UA_NodeID_delete
 // TODO: UA_NodeID_deleteMembers
 
-Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId) {
+Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId const * nodeId) {
 	Int32 length = sizeof(UA_Byte);
 
-	length += UA_NodeId_calcSize(&(nodeId->NodeId));
+	length += UA_NodeId_calcSize(&(nodeId->nodeId));
 
-	if (nodeId->NodeId.EncodingByte & NIEVT_NAMESPACE_URI_FLAG) {
-		length += sizeof(UInt16); //nodeId->NodeId.Namespace
-		length += UA_String_calcSize(&(nodeId->NamespaceUri)); //nodeId->NamespaceUri
+	if (nodeId->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
+		length += sizeof(UInt16); //nodeId->NodeId.namespace
+		length += UA_String_calcSize(&(nodeId->namespaceUri)); //nodeId->namespaceUri
 	}
-	if (nodeId->NodeId.EncodingByte & NIEVT_SERVERINDEX_FLAG) {
-		length += sizeof(UInt32); //nodeId->ServerIndex
+	if (nodeId->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
+		length += sizeof(UInt32); //nodeId->serverIndex
 	}
 	return length;
 }
@@ -290,20 +298,20 @@ Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId) {
 // TODO: UA_ExpandedNodeID_delete
 // TODO: UA_ExpandedNodeID_deleteMembers
 
-Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject *extensionObject) {
+Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject const * extensionObject) {
 	Int32 length = 0;
 
-	length += UA_NodeId_calcSize(&(extensionObject->TypeId));
+	length += UA_NodeId_calcSize(&(extensionObject->typeId));
 	length += sizeof(Byte); //extensionObject->Encoding
-	switch (extensionObject->Encoding) {
+	switch (extensionObject->encoding) {
 	case 0x00:
 		length += sizeof(Int32); //extensionObject->Body.Length
 		break;
 	case 0x01:
-		length += UA_ByteString_calcSize(&(extensionObject->Body));
+		length += UA_ByteString_calcSize(&(extensionObject->body));
 		break;
 	case 0x02:
-		length += UA_ByteString_calcSize(&(extensionObject->Body));
+		length += UA_ByteString_calcSize(&(extensionObject->body));
 		break;
 	}
 	return length;
@@ -313,28 +321,28 @@ Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject *extensionObject) {
 // TODO: UA_ExtensionObject_delete
 // TODO: UA_ExtensionObject_deleteMembers
 
-Int32 UA_DataValue_calcSize(UA_DataValue *dataValue) {
+Int32 UA_DataValue_calcSize(UA_DataValue const * dataValue) {
 	Int32 length = 0;
 
 	length += sizeof(UA_Byte); //dataValue->EncodingMask
 
-	if (dataValue->EncodingMask & 0x01) {
-		length += UA_Variant_calcSize(&(dataValue->Value));
+	if (dataValue->encodingMask & 0x01) {
+		length += UA_Variant_calcSize(&(dataValue->value));
 	}
-	if (dataValue->EncodingMask & 0x02) {
-		length += sizeof(UA_UInt32); //dataValue->Status
+	if (dataValue->encodingMask & 0x02) {
+		length += sizeof(UA_UInt32); //dataValue->status
 	}
-	if (dataValue->EncodingMask & 0x04) {
-		length += sizeof(UA_Int64); //dataValue->SourceTimestamp
+	if (dataValue->encodingMask & 0x04) {
+		length += sizeof(UA_Int64); //dataValue->sourceTimestamp
 	}
-	if (dataValue->EncodingMask & 0x08) {
-		length += sizeof(UA_Int64); //dataValue->ServerTimestamp
+	if (dataValue->encodingMask & 0x08) {
+		length += sizeof(UA_Int64); //dataValue->serverTimestamp
 	}
-	if (dataValue->EncodingMask & 0x10) {
-		length += sizeof(UA_Int64); //dataValue->SourcePicoseconds
+	if (dataValue->encodingMask & 0x10) {
+		length += sizeof(UA_Int64); //dataValue->sourcePicoseconds
 	}
-	if (dataValue->EncodingMask & 0x20) {
-		length += sizeof(UA_Int64); //dataValue->ServerPicoseconds
+	if (dataValue->encodingMask & 0x20) {
+		length += sizeof(UA_Int64); //dataValue->serverPicoseconds
 	}
 	return length;
 }
@@ -390,7 +398,7 @@ Int32 UA_DiagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo) {
 
 Int32 decodeUAString(char const * buf, Int32 *pos, UA_String * dstUAString) {
 
-	decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstUAString->Length));
+	decoder_decodeBuiltInDatatype(buf, UA_INT32, pos, &(dstUAString->Length));
 
 	if (dstUAString->Length > 0) {
 		dstUAString->Data = &(buf[*pos]);

+ 131 - 180
tool/opcua_basictypes.h

@@ -14,28 +14,55 @@ typedef uint8_t Byte;
 typedef int8_t SByte;
 typedef int16_t Int16;
 typedef int32_t Int32;
+typedef int64_t Int64;
 typedef uint16_t UInt16;
 typedef uint32_t UInt32;
+typedef uint64_t UInt64;
+
+
+#define UA_SUCCESS 0
+#define UA_TRUE (42==42)
+#define UA_FALSE (!UA_TRUE)
+
+#define UA_TYPE_METHOD_PROTOTYPES(TYPE) \
+Int32 TYPE##_calcSize(TYPE const * ptr);\
+Int32 TYPE##_encode(TYPE const * src, Int32* pos, char * dst);\
+Int32 TYPE##_decode(char const * src, Int32* pos, TYPE * dst);\
+Int32 TYPE##_delete(TYPE * p);\
+Int32 TYPE##_deleteMembers(TYPE * p); \
 
 typedef _Bool UA_Boolean;
-typedef int8_t UA_SByte;
-typedef uint8_t UA_Byte;
+UA_TYPE_METHOD_PROTOTYPES (UA_Boolean)
+
+typedef int8_t UA_Byte;
+UA_TYPE_METHOD_PROTOTYPES (UA_Byte)
+
+typedef uint8_t UA_SByte;
+UA_TYPE_METHOD_PROTOTYPES (UA_SByte)
+
 typedef int16_t UA_Int16;
+UA_TYPE_METHOD_PROTOTYPES (UA_Int16)
+
 typedef uint16_t UA_UInt16;
+UA_TYPE_METHOD_PROTOTYPES (UA_UInt16)
+
 typedef int32_t UA_Int32;
+UA_TYPE_METHOD_PROTOTYPES (UA_Int32)
+
 typedef uint32_t UA_UInt32;
+UA_TYPE_METHOD_PROTOTYPES (UA_UInt32)
+
 typedef int64_t UA_Int64;
+UA_TYPE_METHOD_PROTOTYPES (UA_Int64)
+
 typedef uint64_t UA_UInt64;
-typedef float UA_Float;
-typedef double UA_Double;
+UA_TYPE_METHOD_PROTOTYPES (UA_UInt64)
 
-#define UA_SUCCESS 0
-#define UA_TRUE (42==42)
-#define UA_FALSE (!UA_TRUE)
+typedef float UA_Float;
+UA_TYPE_METHOD_PROTOTYPES (UA_Float)
 
-Int32 UA_Boolean_calcSize(UA_Boolean const * ptr);
-Int32 UA_Boolean_encode(UA_Boolean const * src, Int32* pos, char * dst);
-Int32 UA_Boolean_decode(char const * src, Int32* pos, UA_Boolean * dst);
+typedef double UA_Double;
+UA_TYPE_METHOD_PROTOTYPES (UA_Double)
 
 /**
 * StatusCodeBinaryEncoding
@@ -50,140 +77,86 @@ enum UA_StatusCode_enum
 	//names that are unique
 	SC_Good 			= 			0x00
 };
-UInt32 UA_StatusCode_calcSize(UA_StatusCode const * ptr);
+UA_TYPE_METHOD_PROTOTYPES (UA_StatusCode)
 
-/**
-* VariantBinaryEncoding
-* Part: 6
-* Chapter: 5.2.2.16
-* Page: 22
-*/
-typedef struct _UA_Variant {
-	Byte EncodingMask; //Type of Enum UA_VariantTypeEncodingMaskType
+/* VariantBinaryEncoding - Part: 6, Chapter: 5.2.2.16, Page: 22 */
+typedef struct T_UA_Variant {
+	Byte encodingMask; // Type of Enum UA_VariantTypeEncodingMaskType
 	UA_Int32 size;
 	void** data;
 } UA_Variant;
-UInt32 UA_Variant_calcSize(UA_Variant const * ptr);
+UA_TYPE_METHOD_PROTOTYPES (UA_Variant)
 
-/**
-* String
-* Part: 6
-* Chapter: 5.2.2.4
-* Page: 16
-*/
-typedef struct UA_String
+/* String - Part: 6, Chapter: 5.2.2.4, Page: 16 */
+typedef struct T_UA_String
 {
 	UA_Int32 	length;
 	UA_Byte*	data;
 }
 UA_String;
-Int32 UA_String_calcSize(UA_String const * ptr);
+UA_TYPE_METHOD_PROTOTYPES (UA_String)
 
-/*
-* ByteString
-* Part: 6
-* Chapter: 5.2.2.7
-* Page: 17
-*/
-typedef struct UA_ByteString
+/* ByteString - Part: 6, Chapter: 5.2.2.7, Page: 17 */
+typedef struct T_UA_ByteString
 {
 	UA_Int32 	length;
 	UA_Byte*	data;
 }
 UA_ByteString;
-Int32 UA_ByteString_calcSize(UA_ByteString const * ptr);
+UA_TYPE_METHOD_PROTOTYPES (UA_ByteString)
 
-/**
-* LocalizedTextBinaryEncoding
-* Part: 6
-* Chapter: 5.2.2.14
-* Page: 21
-*/
-typedef struct UA_LocalizedText
+/** LocalizedTextBinaryEncoding - Part: 6, Chapter: 5.2.2.14, Page: 21 */
+typedef struct T_UA_LocalizedText
 {
-	UA_Byte EncodingMask;
-	UA_String Locale;
-	UA_String Text;
+	UA_Byte encodingMask;
+	UA_String locale;
+	UA_String text;
 }
 UA_LocalizedText;
-Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * ptr);
-
+UA_TYPE_METHOD_PROTOTYPES (UA_LocalizedText)
 
-/* GuidType
-* Part: 6
-* Chapter: 5.2.2.6
-* Page: 17
-*/
-typedef struct UA_Guid
+/* GuidType - Part: 6, Chapter: 5.2.2.6 Page: 17 */
+typedef struct T_UA_Guid
 {
-	UA_UInt32 Data1;
-	UA_UInt16 Data2;
-	UA_UInt16 Data3;
-	UA_ByteString Data4;
-
-}
-UA_Guid;
-Int32 UA_Guid_calcSize(UA_Guid const * ptr);
-
-/**
-* DateTime
-* Part: 6
-* Chapter: 5.2.2.5
-* Page: 16
-*/
+	UA_UInt32 data1;
+	UA_UInt16 data2;
+	UA_UInt16 data3;
+	UA_ByteString data4;
+} UA_Guid;
+UA_TYPE_METHOD_PROTOTYPES (UA_Guid)
+
+/* DateTime - Part: 6, Chapter: 5.2.2.5, Page: 16 */
 typedef UA_Int64 UA_DateTime; //100 nanosecond resolution
-Int32 UA_DataTime_calcSize(UA_DateTime const * ptr);
-
-
-
-/**
-* XmlElement
-* Part: 6
-* Chapter: 5.2.2.8
-* Page: 17
-*/
-//Überlegung ob man es direkt als ByteString speichert oder als String
-typedef struct UA_XmlElement
-{
-	UA_ByteString Data;
-}
-UA_XmlElement;
+UA_TYPE_METHOD_PROTOTYPES (UA_DateTime)
 
-
-typedef struct UA_XmlElementEncoded
-{
-	UA_UInt32 Length;
-	UA_Byte StartTag[3];
-	UA_Byte *Message;
-	UA_UInt32 EndTag[4];
-}
-UA_XmlElementEncoded;
-
-
-typedef struct _UA_NodeId
+typedef struct T_UA_NodeId
 {
-	UA_Byte   EncodingByte; //enum BID_NodeIdEncodingValuesType
-	UA_UInt16 Namespace;
+	UA_Byte   encodingByte; //enum BID_NodeIdEncodingValuesType
+	UA_UInt16 namespace;
 
     union
     {
-        UA_UInt32 Numeric;
-        UA_String String;
-        UA_Guid Guid;
-        UA_ByteString ByteString;
+        UA_UInt32 numeric;
+        UA_String string;
+        UA_Guid guid;
+        UA_ByteString byteString;
     }
-    Identifier;
+    identifier;
 } UA_NodeId;
-/**
- * NodeIds
-* Part: 6
-* Chapter: 5.2.2.9
-* Table 5
-*/
+UA_TYPE_METHOD_PROTOTYPES (UA_NodeId)
+
+/** XmlElement - Part: 6, Chapter: 5.2.2.8, Page: 17 */
+typedef struct T_UA_XmlElement
+{
+	//TODO Überlegung ob man es direkt als ByteString speichert oder als String
+	UA_ByteString Data;
+} UA_XmlElement;
+UA_TYPE_METHOD_PROTOTYPES (UA_XmlElement)
+
+/** NodeIds - Part: 6, Chapter: 5.2.2.9, Table 5 */
 enum UA_NodeIdEncodingValuesType_enum
 {
-	// Some Values are called the same as previous Enumerations so we need
-	// names that are unique
+	// Some Values are called the same as previous Enumerations so we need names that are unique
 	NIEVT_TWO_BYTE = 	0x00,
 	NIEVT_FOUR_BYTE = 	0x01,
 	NIEVT_NUMERIC = 	0x02,
@@ -194,97 +167,75 @@ enum UA_NodeIdEncodingValuesType_enum
 	NIEVT_SERVERINDEX_FLAG = 	0x40 	//Is only for ExpandedNodeId required
 };
 
-
-/**
-* ExpandedNodeId
-* Part: 6
-* Chapter: 5.2.2.10
-* Page: 19
-*/
-typedef struct UA_ExpandedNodeId
+/* ExpandedNodeId - Part: 6, Chapter: 5.2.2.10, Page: 19 */
+typedef struct T_UA_ExpandedNodeId
 {
-	UA_NodeId NodeId;
-	UA_Int32 EncodingByte; //enum BID_NodeIdEncodingValuesType
-	UA_String NamespaceUri;
-	UA_UInt32 ServerIndex;
+	UA_NodeId nodeId;
+	UA_Int32 encodingByte; //enum BID_NodeIdEncodingValuesType
+	UA_String namespaceUri;
+	UA_UInt32 serverIndex;
 }
 UA_ExpandedNodeId;
+UA_TYPE_METHOD_PROTOTYPES(UA_ExpandedNodeId)
 
 
-
-/**
- * NodeIds
-* Part: 6
-* Chapter: 5.2.2.9
-* Page: 17
-*/
-typedef enum UA_IdentifierType
-{
+/* NodeIds - Part: 6, Chapter: 5.2.2.9, Page: 17 */
+enum UA_IdentifierType_enum {
 	// Some Values are called the same as previouse Enumerations so we need
 	//names that are unique
 	IT_NUMERIC = 0,
 	IT_STRING = 1,
 	IT_GUID = 2,
 	IT_OPAQUE = 3
-}
-UA_IdentifierType;
-
-/**
-* ExtensionObjectBinaryEncoding
-* Part: 6
-* Chapter: 5.2.2.15
-* Page: 21
-*/
-typedef struct _UA_ExtensionObject {
-	UA_NodeId TypeId;
-	UA_Byte Encoding; //Type of the enum UA_ExtensionObjectEncodingMaskType
-	UA_ByteString Body;
+};
+typedef UA_Int32 UA_IdentifierType;
+UA_TYPE_METHOD_PROTOTYPES(UA_IdentifierType)
+
+/* ExtensionObjectBinaryEncoding - Part: 6, Chapter: 5.2.2.15, Page: 21 */
+typedef struct T_UA_ExtensionObject {
+	UA_NodeId typeId;
+	UA_Byte encoding; //Type of the enum UA_ExtensionObjectEncodingMaskType
+	UA_ByteString body;
 } UA_ExtensionObject;
+UA_TYPE_METHOD_PROTOTYPES(UA_ExtensionObject)
 
-/**
-* QualifiedNameBinaryEncoding
-* Part: 6
-* Chapter: 5.2.2.13
-* Page: 20
-*/
-typedef struct _UA_QualifiedName {
-	UInt16 NamespaceIndex;
-	UInt16 Reserved;
-	UA_String Name;
+/* QualifiedNameBinaryEncoding - Part: 6, Chapter: 5.2.2.13, Page: 20 */
+typedef struct T_UA_QualifiedName {
+	UInt16 namespaceIndex;
+	UInt16 reserved;
+	UA_String name;
 } UA_QualifiedName;
+UA_TYPE_METHOD_PROTOTYPES(UA_QualifiedName)
 
-/**
+/*
 * DataValueBinaryEncoding
 * Part: 6
 * Chapter: 5.2.2.17
 * Page: 23
 */
 typedef struct UA_DataValue {
-	UA_Byte EncodingMask;
-	UA_Variant Value;
-	UA_StatusCode Status;
-	UA_DateTime SourceTimestamp;
-	UA_Int16 SourcePicoseconds;
-	UA_DateTime ServerTimestamp;
-	UA_Int16 ServerPicoseconds;
+	UA_Byte encodingMask;
+	UA_Variant value;
+	UA_StatusCode status;
+	UA_DateTime sourceTimestamp;
+	UA_Int16 sourcePicoseconds;
+	UA_DateTime serverTimestamp;
+	UA_Int16 serverPicoseconds;
 } UA_DataValue;
-
-/**
-* DiagnoticInfoBinaryEncoding
-* Part: 6
-* Chapter: 5.2.2.12
-* Page: 20
-*/
-typedef struct _UA_DiagnosticInfo {
-	Byte EncodingMask; //Type of the Enum UA_DiagnosticInfoEncodingMaskType
-	UA_Int32 SymbolicId;
-	UA_Int32 NamespaceUri;
-	UA_Int32 LocalizedText;
-	UA_Int32 Locale;
-	UA_String AdditionalInfo;
-	UA_StatusCode InnerStatusCode;
-	struct _UA_DiagnosticInfo* InnerDiagnosticInfo;
+UA_TYPE_METHOD_PROTOTYPES(UA_DataValue)
+
+/* DiagnosticInfo - Part: 6, Chapter: 5.2.2.12, Page: 20 */
+typedef struct T_UA_DiagnosticInfo {
+	Byte encodingMask; //Type of the Enum UA_DiagnosticInfoEncodingMaskType
+	UA_Int32 symbolicId;
+	UA_Int32 namespaceUri;
+	UA_Int32 localizedText;
+	UA_Int32 locale;
+	UA_String additionalInfo;
+	UA_StatusCode innerStatusCode;
+	struct T_UA_DiagnosticInfo* InnerDiagnosticInfo;
 } UA_DiagnosticInfo;
+UA_TYPE_METHOD_PROTOTYPES(UA_DiagnosticInfo)
 
 enum UA_DiagnosticInfoEncodingMaskType_enum
 {