generate_datatypes.py 22 KB

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