generate_nodeid_header.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. from __future__ import print_function
  6. import sys
  7. import platform
  8. import getpass
  9. import time
  10. import argparse
  11. from io import open
  12. parser = argparse.ArgumentParser()
  13. parser.add_argument('statuscodes', help='path/to/Opc.Ua.NodeIds.csv')
  14. parser.add_argument('outfile', help='outfile w/o extension')
  15. parser.add_argument('namespace', help='NS0')
  16. args = parser.parse_args()
  17. rows = []
  18. with open(args.statuscodes, mode="rt") as f:
  19. lines = f.readlines()
  20. for l in lines:
  21. rows.append(tuple(l.strip().split(',')))
  22. fh = open(args.outfile + ".h", "wt", encoding='utf8')
  23. def printh(string):
  24. print(string, end=u'\n', file=fh)
  25. #########################
  26. # Print the header file #
  27. #########################
  28. printh(u'''/*---------------------------------------------------------
  29. * Autogenerated -- do not modify
  30. * Generated from {0} with script {1}
  31. *-------------------------------------------------------*/
  32. #ifndef UA_NODEIDS_{2}_H_
  33. #define UA_NODEIDS_{2}_H_
  34. /**
  35. * Namespace Zero NodeIds
  36. * ----------------------
  37. * Numeric identifiers of standard-defined nodes in namespace zero. The
  38. * following definitions are autogenerated from the ``{0}`` file */
  39. '''.format(args.statuscodes, sys.argv[0], args.namespace))
  40. for row in rows:
  41. printh(u"#define UA_{namespace}ID_{name} {id} /* {description} */".format(namespace=args.namespace, name=row[0].upper(), id=row[1], description=row[2]))
  42. printh(u'''#endif /* UA_NODEIDS_{0}_H_ */ '''.format(args.namespace))
  43. fh.close()