generate_datatypes.py 22 KB

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