generate_datatypes.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. from __future__ import print_function
  5. import sys
  6. import time
  7. import platform
  8. import getpass
  9. from collections import OrderedDict
  10. import re
  11. import xml.etree.ElementTree as etree
  12. import itertools
  13. import argparse
  14. types = OrderedDict() # contains types that were already parsed
  15. typedescriptions = {} # contains type nodeids
  16. excluded_types = ["NodeIdType", "InstanceNode", "TypeNode", "Node", "ObjectNode",
  17. "ObjectTypeNode", "VariableNode", "VariableTypeNode", "ReferenceTypeNode",
  18. "MethodNode", "ViewNode", "DataTypeNode",
  19. "UA_ServerDiagnosticsSummaryDataType", "UA_SamplingIntervalDiagnosticsDataType",
  20. "UA_SessionSecurityDiagnosticsDataType", "UA_SubscriptionDiagnosticsDataType",
  21. "UA_SessionDiagnosticsDataType"]
  22. builtin_types = ["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32",
  23. "Int64", "UInt64", "Float", "Double", "String", "DateTime", "Guid",
  24. "ByteString", "XmlElement", "NodeId", "ExpandedNodeId", "StatusCode",
  25. "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
  26. "Variant", "DiagnosticInfo"]
  27. # If the type does not contain pointers, it can be copied with memcpy
  28. # (internally, not into the protocol message). This dict contains the sizes of
  29. # pointer-free types. Parsed types are added if they apply.
  30. builtin_pointerfree = ["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32",
  31. "Int64", "UInt64", "Float", "Double", "DateTime", "Guid", "StatusCode"]
  32. # Some types can be memcpy'd off the binary stream. That's especially important
  33. # for arrays. But we need to check if they contain padding and whether the
  34. # endianness is correct. This dict gives the C-statement that must be true for the
  35. # type to be overlayable. Parsed types are added if they apply.
  36. builtin_overlayable = {"Boolean": "true", "SByte": "true", "Byte": "true",
  37. "Int16": "UA_BINARY_OVERLAYABLE_INTEGER", "UInt16": "UA_BINARY_OVERLAYABLE_INTEGER",
  38. "Int32": "UA_BINARY_OVERLAYABLE_INTEGER", "UInt32": "UA_BINARY_OVERLAYABLE_INTEGER",
  39. "Int64": "UA_BINARY_OVERLAYABLE_INTEGER", "UInt64": "UA_BINARY_OVERLAYABLE_INTEGER",
  40. "Float": "UA_BINARY_OVERLAYABLE_FLOAT", "Double": "UA_BINARY_OVERLAYABLE_FLOAT",
  41. "DateTime": "UA_BINARY_OVERLAYABLE_INTEGER", "StatusCode": "UA_BINARY_OVERLAYABLE_INTEGER",
  42. "Guid": "(UA_BINARY_OVERLAYABLE_INTEGER && offsetof(UA_Guid, data2) == sizeof(UA_UInt32) && " + \
  43. "offsetof(UA_Guid, data3) == (sizeof(UA_UInt16) + sizeof(UA_UInt32)) && " + \
  44. "offsetof(UA_Guid, data4) == (2*sizeof(UA_UInt32)))"}
  45. ################
  46. # Type Classes #
  47. ################
  48. class StructMember(object):
  49. def __init__(self, name, memberType, isArray):
  50. self.name = name
  51. self.memberType = memberType
  52. self.isArray = isArray
  53. class Type(object):
  54. def __init__(self, outname, xml):
  55. self.name = xml.get("Name")
  56. self.ns0 = ("true" if outname == "ua_types" else "false")
  57. self.typeIndex = outname.upper() + "_" + self.name.upper()
  58. self.outname = outname
  59. self.description = ""
  60. self.pointerfree = "false"
  61. self.overlayable = "false"
  62. if self.name in builtin_types:
  63. self.builtin = "true"
  64. else:
  65. self.builtin = "false"
  66. self.members = [StructMember("", self, False)] # Returns one member: itself. Overwritten by some types.
  67. for child in xml:
  68. if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
  69. self.description = child.text
  70. break
  71. def datatype_c(self):
  72. xmlEncodingId = "0"
  73. binaryEncodingId = "0"
  74. if self.name in typedescriptions:
  75. description = typedescriptions[self.name]
  76. typeid = "{%s, UA_NODEIDTYPE_NUMERIC, {%s}}" % (description.namespaceid, description.nodeid)
  77. xmlEncodingId = description.xmlEncodingId
  78. binaryEncodingId = description.binaryEncodingId
  79. else:
  80. typeid = "{0, UA_NODEIDTYPE_NUMERIC, {0}}"
  81. return "{\n UA_TYPENAME(\"%s\") /* .typeName */\n" % self.name + \
  82. " " + typeid + ", /* .typeId */\n" + \
  83. " sizeof(UA_" + self.name + "), /* .memSize */\n" + \
  84. " " + self.typeIndex + ", /* .typeIndex */\n" + \
  85. " " + str(len(self.members)) + ", /* .membersSize */\n" + \
  86. " " + self.builtin + ", /* .builtin */\n" + \
  87. " " + self.pointerfree + ", /* .pointerFree */\n" + \
  88. " " + self.overlayable + ", /* .overlayable */ \n" + \
  89. " " + binaryEncodingId + ", /* .binaryEncodingId */\n" + \
  90. " %s_members" % self.name + " /* .members */\n}"
  91. def members_c(self):
  92. if len(self.members)==0:
  93. return "#define %s_members NULL" % (self.name)
  94. members = "static UA_DataTypeMember %s_members[%s] = {" % (self.name, len(self.members))
  95. before = None
  96. for index, member in enumerate(self.members):
  97. m = "\n{\n UA_TYPENAME(\"%s\") /* .memberName */\n" % member.name
  98. m += " %s_%s, /* .memberTypeIndex */\n" % (member.memberType.outname.upper(), member.memberType.name.upper())
  99. m += " "
  100. if not before:
  101. m += "0,"
  102. else:
  103. if member.isArray:
  104. m += "offsetof(UA_%s, %sSize)" % (self.name, member.name)
  105. else:
  106. m += "offsetof(UA_%s, %s)" % (self.name, member.name)
  107. m += " - offsetof(UA_%s, %s)" % (self.name, before.name)
  108. if before.isArray:
  109. m += " - sizeof(void*),"
  110. else:
  111. m += " - sizeof(UA_%s)," % before.memberType.name
  112. m += " /* .padding */\n"
  113. m += " %s, /* .namespaceZero */\n" % member.memberType.ns0
  114. m += (" true" if member.isArray else " false") + " /* .isArray */\n},"
  115. members += m
  116. before = member
  117. return members + "};"
  118. def datatype_ptr(self):
  119. return "&" + self.outname.upper() + "[" + self.outname.upper() + "_" + self.name.upper() + "]"
  120. def functions_c(self):
  121. funcs = "static UA_INLINE void\nUA_%s_init(UA_%s *p) {\n memset(p, 0, sizeof(UA_%s));\n}\n\n" % (self.name, self.name, self.name)
  122. funcs += "static UA_INLINE UA_%s *\nUA_%s_new(void) {\n return (UA_%s*)UA_new(%s);\n}\n\n" % (self.name, self.name, self.name, self.datatype_ptr())
  123. if self.pointerfree == "true":
  124. funcs += "static UA_INLINE UA_StatusCode\nUA_%s_copy(const UA_%s *src, UA_%s *dst) {\n *dst = *src;\n return UA_STATUSCODE_GOOD;\n}\n\n" % (self.name, self.name, self.name)
  125. funcs += "static UA_INLINE void\nUA_%s_deleteMembers(UA_%s *p) { }\n\n" % (self.name, self.name)
  126. else:
  127. funcs += "static UA_INLINE UA_StatusCode\nUA_%s_copy(const UA_%s *src, UA_%s *dst) {\n return UA_copy(src, dst, %s);\n}\n\n" % (self.name, self.name, self.name, self.datatype_ptr())
  128. funcs += "static UA_INLINE void\nUA_%s_deleteMembers(UA_%s *p) {\n UA_deleteMembers(p, %s);\n}\n\n" % (self.name, self.name, self.datatype_ptr())
  129. funcs += "static UA_INLINE void\nUA_%s_delete(UA_%s *p) {\n UA_delete(p, %s);\n}" % (self.name, self.name, self.datatype_ptr())
  130. return funcs
  131. def encoding_h(self):
  132. enc = "static UA_INLINE UA_StatusCode\nUA_%s_encodeBinary(const UA_%s *src, UA_Byte **bufPos, const UA_Byte **bufEnd) {\n return UA_encodeBinary(src, %s, bufPos, bufEnd, NULL, NULL);\n}\n"
  133. enc += "static UA_INLINE UA_StatusCode\nUA_%s_decodeBinary(const UA_ByteString *src, size_t *offset, UA_%s *dst) {\n return UA_decodeBinary(src, offset, dst, %s, 0, NULL);\n}"
  134. return enc % tuple(list(itertools.chain(*itertools.repeat([self.name, self.name, self.datatype_ptr()], 2))))
  135. class BuiltinType(Type):
  136. def __init__(self, name):
  137. self.name = name
  138. self.ns0 = "true"
  139. self.typeIndex = "UA_TYPES_" + self.name.upper()
  140. self.outname = "ua_types"
  141. self.description = ""
  142. self.pointerfree = "false"
  143. if self.name in builtin_pointerfree:
  144. self.pointerfree = "true"
  145. self.overlayable = "false"
  146. if name in builtin_overlayable:
  147. self.overlayable = builtin_overlayable[name]
  148. self.builtin = "true"
  149. if self.name == "QualifiedName":
  150. self.members = [StructMember("namespaceIndex", types["Int16"], False), StructMember("name", types["String"], False)]
  151. elif self.name in ["String", "ByteString", "XmlElement"]:
  152. self.members = [StructMember("", types["Byte"], True)]
  153. else:
  154. self.members = [StructMember("", self, False)]
  155. class EnumerationType(Type):
  156. def __init__(self, outname, xml):
  157. Type.__init__(self, outname, xml)
  158. self.pointerfree = "true"
  159. self.overlayable = "UA_BINARY_OVERLAYABLE_INTEGER"
  160. self.members = [StructMember("", types["Int32"], False)] # encoded as uint32
  161. self.builtin = "true"
  162. self.typeIndex = "UA_TYPES_INT32"
  163. self.elements = OrderedDict()
  164. for child in xml:
  165. if child.tag == "{http://opcfoundation.org/BinarySchema/}EnumeratedValue":
  166. self.elements[child.get("Name")] = child.get("Value")
  167. def typedef_h(self):
  168. if sys.version_info[0] < 3:
  169. values = self.elements.iteritems()
  170. else:
  171. values = self.elements.items()
  172. return "typedef enum {\n " + ",\n ".join(map(lambda kv : "UA_" + self.name.upper() + "_" + kv[0].upper() + \
  173. " = " + kv[1], values)) + "\n} UA_%s;" % self.name
  174. class OpaqueType(Type):
  175. def __init__(self, outname, xml):
  176. Type.__init__(self, outname, xml)
  177. self.members = [StructMember("", types["ByteString"], False)] # encoded as string
  178. def typedef_h(self):
  179. return "typedef UA_ByteString UA_%s;" % self.name
  180. class StructType(Type):
  181. def __init__(self, outname, xml):
  182. Type.__init__(self, outname, xml)
  183. self.members = []
  184. lengthfields = [] # lengthfields of arrays are not included as members
  185. for child in xml:
  186. if child.get("LengthField"):
  187. lengthfields.append(child.get("LengthField"))
  188. for child in xml:
  189. if not child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
  190. continue
  191. if child.get("Name") in lengthfields:
  192. continue
  193. memberName = child.get("Name")
  194. memberName = memberName[:1].lower() + memberName[1:]
  195. memberTypeName = child.get("TypeName")
  196. memberType = types[memberTypeName[memberTypeName.find(":")+1:]]
  197. isArray = True if child.get("LengthField") else False
  198. self.members.append(StructMember(memberName, memberType, isArray))
  199. self.pointerfree = "true"
  200. self.overlayable = "true"
  201. before = None
  202. for m in self.members:
  203. if m.isArray or m.memberType.pointerfree != "true":
  204. self.pointerfree = "false"
  205. self.overlayable = "false"
  206. else:
  207. self.overlayable += " && " + m.memberType.overlayable
  208. if before:
  209. self.overlayable += " && offsetof(UA_%s, %s) == (offsetof(UA_%s, %s) + sizeof(UA_%s))" % \
  210. (self.name, m.name, self.name, before.name, before.memberType.name)
  211. if "false" in self.overlayable:
  212. self.overlayable = "false"
  213. before = m
  214. def typedef_h(self):
  215. if len(self.members) == 0:
  216. return "typedef void * UA_%s;" % self.name
  217. returnstr = "typedef struct {\n"
  218. for member in self.members:
  219. if member.isArray:
  220. returnstr += " size_t %sSize;\n" % member.name
  221. returnstr += " UA_%s *%s;\n" % (member.memberType.name, member.name)
  222. else:
  223. returnstr += " UA_%s %s;\n" % (member.memberType.name, member.name)
  224. return returnstr + "} UA_%s;" % self.name
  225. #########################
  226. # Parse Typedefinitions #
  227. #########################
  228. def parseTypeDefinitions(outname, xmlDescription):
  229. def typeReady(element):
  230. "Are all member types defined?"
  231. for child in element:
  232. if child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
  233. childname = child.get("TypeName")
  234. if childname[childname.find(":")+1:] not in types:
  235. return False
  236. return True
  237. def skipType(name):
  238. if name in excluded_types:
  239. return True
  240. if "Test" in name: # skip all test types
  241. return True
  242. if re.search("NodeId$", name) != None:
  243. return True
  244. return False
  245. snippets = {}
  246. for typeXml in etree.parse(xmlDescription).getroot():
  247. if not typeXml.get("Name"):
  248. continue
  249. name = typeXml.get("Name")
  250. snippets[name] = typeXml
  251. while(len(snippets) > 0):
  252. for name, typeXml in list(snippets.items()):
  253. if name in types or skipType(name):
  254. del snippets[name]
  255. continue
  256. if not typeReady(typeXml):
  257. continue
  258. if name in builtin_types:
  259. types[name] = BuiltinType(name)
  260. elif typeXml.tag == "{http://opcfoundation.org/BinarySchema/}EnumeratedType":
  261. types[name] = EnumerationType(outname, typeXml)
  262. elif typeXml.tag == "{http://opcfoundation.org/BinarySchema/}OpaqueType":
  263. types[name] = OpaqueType(outname, typeXml)
  264. elif typeXml.tag == "{http://opcfoundation.org/BinarySchema/}StructuredType":
  265. types[name] = StructType(outname, typeXml)
  266. else:
  267. raise Exception("Type not known")
  268. del snippets[name]
  269. ##########################
  270. # Parse TypeDescriptions #
  271. ##########################
  272. class TypeDescription(object):
  273. def __init__(self, name, nodeid, namespaceid):
  274. self.name = name
  275. self.nodeid = nodeid
  276. self.namespaceid = namespaceid
  277. self.xmlEncodingId = "0"
  278. self.binaryEncodingId = "0"
  279. def parseTypeDescriptions(filename, namespaceid):
  280. definitions = {}
  281. with open(filename) as f:
  282. input_str = f.read()
  283. input_str = input_str.replace('\r','')
  284. rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
  285. for index, row in enumerate(rows):
  286. if len(row) < 3:
  287. continue
  288. if row[2] == "Object":
  289. # Check if node name ends with _Encoding_(DefaultXml|DefaultBinary) and store the node id in the corresponding DataType
  290. m = re.match('(.*?)_Encoding_Default(Xml|Binary)$',row[0])
  291. if (m):
  292. baseType = m.group(1)
  293. if baseType not in types:
  294. continue
  295. if m.group(2) == "Xml":
  296. definitions[baseType].xmlEncodingId = row[1]
  297. else:
  298. definitions[baseType].binaryEncodingId = row[1]
  299. continue
  300. if row[2] != "DataType":
  301. continue
  302. if row[0] == "BaseDataType":
  303. definitions["Variant"] = TypeDescription(row[0], row[1], namespaceid)
  304. elif row[0] == "Structure":
  305. definitions["ExtensionObject"] = TypeDescription(row[0], row[1], namespaceid)
  306. elif row[0] not in types:
  307. continue
  308. elif type(types[row[0]]) == EnumerationType:
  309. definitions[row[0]] = TypeDescription(row[0], "6", namespaceid) # enumerations look like int32 on the wire
  310. else:
  311. definitions[row[0]] = TypeDescription(row[0], row[1], namespaceid)
  312. return definitions
  313. ###############################
  314. # Parse the Command Line Input#
  315. ###############################
  316. parser = argparse.ArgumentParser()
  317. parser.add_argument('--typedescriptions', help='csv file with type descriptions')
  318. parser.add_argument('--namespace', type=int, default=0, help='namespace id of the generated type nodeids (defaults to 0)')
  319. parser.add_argument('--selected_types', help='file with list of types (among those parsed) to be generated')
  320. parser.add_argument('typexml_ns0', help='path/to/Opc.Ua.Types.bsd ...')
  321. parser.add_argument('typexml_additional', nargs='*', help='path/to/Opc.Ua.Types.bsd ...')
  322. parser.add_argument('outfile', help='output file w/o extension')
  323. args = parser.parse_args()
  324. outname = args.outfile.split("/")[-1]
  325. inname = ', '.join([args.typexml_ns0.split("/")[-1]] + list(map(lambda x:x.split("/")[-1], args.typexml_additional)))
  326. ################
  327. # Create Types #
  328. ################
  329. for builtin in builtin_types:
  330. types[builtin] = BuiltinType(builtin)
  331. with open(args.typexml_ns0) as f:
  332. parseTypeDefinitions("ua_types", f)
  333. for typexml in args.typexml_additional:
  334. with open(typexml) as f:
  335. parseTypeDefinitions(outname, f)
  336. typedescriptions = {}
  337. if args.typedescriptions:
  338. typedescriptions = parseTypeDescriptions(args.typedescriptions, args.namespace)
  339. selected_types = types.keys()
  340. if args.selected_types:
  341. with open(args.selected_types) as f:
  342. selected_types = list(filter(len, [line.strip() for line in f]))
  343. #############################
  344. # Write out the Definitions #
  345. #############################
  346. fh = open(args.outfile + "_generated.h",'w')
  347. ff = open(args.outfile + "_generated_handling.h",'w')
  348. fe = open(args.outfile + "_generated_encoding_binary.h",'w')
  349. fc = open(args.outfile + "_generated.c",'w')
  350. def printh(string):
  351. print(string, end='\n', file=fh)
  352. def printf(string):
  353. print(string, end='\n', file=ff)
  354. def printe(string):
  355. print(string, end='\n', file=fe)
  356. def printc(string):
  357. print(string, end='\n', file=fc)
  358. def iter_types(v):
  359. l = None
  360. if sys.version_info[0] < 3:
  361. l = list(v.itervalues())
  362. else:
  363. l = list(v.values())
  364. return filter(lambda t: t.name in selected_types, l)
  365. ################
  366. # Print Header #
  367. ################
  368. printh('''/* Generated from ''' + inname + ''' with script ''' + sys.argv[0] + '''
  369. * on host ''' + platform.uname()[1] + ''' by user ''' + getpass.getuser() + \
  370. ''' at ''' + time.strftime("%Y-%m-%d %I:%M:%S") + ''' */
  371. #ifndef ''' + outname.upper() + '''_GENERATED_H_
  372. #define ''' + outname.upper() + '''_GENERATED_H_
  373. #ifdef __cplusplus
  374. extern "C" {
  375. #endif
  376. #include "ua_types.h"
  377. ''' + ('#include "ua_types_generated.h"\n' if outname != "ua_types" else ''))
  378. printh('''/**
  379. * Every type is assigned an index in an array containing the type descriptions.
  380. * These descriptions are used during type handling (copying, deletion,
  381. * binary encoding, ...). */''')
  382. printh("#define " + outname.upper() + "_COUNT %s" % (str(len(selected_types))))
  383. printh("extern UA_EXPORT const UA_DataType " + outname.upper() + "[" + outname.upper() + "_COUNT];")
  384. i = 0
  385. for t in iter_types(types):
  386. printh("\n/**\n * " + t.name)
  387. printh(" * " + "^" * len(t.name))
  388. if t.description == "":
  389. printh(" */")
  390. else:
  391. printh(" * " + t.description + " */")
  392. if type(t) != BuiltinType:
  393. printh(t.typedef_h() + "\n")
  394. printh("#define " + outname.upper() + "_" + t.name.upper() + " " + str(i))
  395. i += 1
  396. printh('''
  397. #ifdef __cplusplus
  398. } // extern "C"
  399. #endif\n
  400. #endif /* %s_GENERATED_H_ */''' % outname.upper())
  401. ##################
  402. # Print Handling #
  403. ##################
  404. printf('''/* Generated from ''' + inname + ''' with script ''' + sys.argv[0] + '''
  405. * on host ''' + platform.uname()[1] + ''' by user ''' + getpass.getuser() + \
  406. ''' at ''' + time.strftime("%Y-%m-%d %I:%M:%S") + ''' */
  407. #ifndef ''' + outname.upper() + '''_GENERATED_HANDLING_H_
  408. #define ''' + outname.upper() + '''_GENERATED_HANDLING_H_
  409. #ifdef __cplusplus
  410. extern "C" {
  411. #endif
  412. #include "''' + outname + '''_generated.h"
  413. #if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
  414. # pragma GCC diagnostic push
  415. # pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  416. # pragma GCC diagnostic ignored "-Wmissing-braces"
  417. #endif
  418. ''')
  419. for t in iter_types(types):
  420. printf("\n/* " + t.name + " */")
  421. printf(t.functions_c())
  422. printf('''
  423. #if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
  424. # pragma GCC diagnostic pop
  425. #endif
  426. #ifdef __cplusplus
  427. } // extern "C"
  428. #endif\n
  429. #endif /* %s_GENERATED_HANDLING_H_ */''' % outname.upper())
  430. ###########################
  431. # Print Description Array #
  432. ###########################
  433. printc('''/* Generated from ''' + inname + ''' with script ''' + sys.argv[0] + '''
  434. * on host ''' + platform.uname()[1] + ''' by user ''' + getpass.getuser() + \
  435. ''' at ''' + time.strftime("%Y-%m-%d %I:%M:%S") + ''' */
  436. #include "''' + outname + '''_generated.h"
  437. #include "ua_util.h"''')
  438. for t in iter_types(types):
  439. printc("")
  440. printc("/* " + t.name + " */")
  441. printc(t.members_c())
  442. printc("const UA_DataType %s[%s_COUNT] = {" % (outname.upper(), outname.upper()))
  443. for t in iter_types(types):
  444. printc("")
  445. printc("/* " + t.name + " */")
  446. printc(t.datatype_c() + ",")
  447. printc("};\n")
  448. ##################
  449. # Print Encoding #
  450. ##################
  451. printe('''/* Generated from ''' + inname + ''' with script ''' + sys.argv[0] + '''
  452. * on host ''' + platform.uname()[1] + ''' by user ''' + getpass.getuser() + \
  453. ''' at ''' + time.strftime("%Y-%m-%d %I:%M:%S") + ''' */
  454. #include "ua_types_encoding_binary.h"
  455. #include "''' + outname + '''_generated.h"''')
  456. for t in iter_types(types):
  457. printe("\n/* " + t.name + " */")
  458. printe(t.encoding_h())
  459. fh.close()
  460. ff.close()
  461. fc.close()
  462. fe.close()