generate_nodeid_header.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 argparse
  8. from io import open
  9. parser = argparse.ArgumentParser()
  10. parser.add_argument('statuscodes', help='path/to/Opc.Ua.NodeIds.csv')
  11. parser.add_argument('outfile', help='outfile w/o extension')
  12. parser.add_argument('namespace', help='NS0')
  13. args = parser.parse_args()
  14. rows = []
  15. with open(args.statuscodes, mode="rt") as f:
  16. lines = f.readlines()
  17. for l in lines:
  18. rows.append(tuple(l.strip().split(',')))
  19. fh = open(args.outfile + ".h", "wt", encoding='utf8')
  20. def printh(string):
  21. print(string, end=u'\n', file=fh)
  22. #########################
  23. # Print the header file #
  24. #########################
  25. printh(u'''/*---------------------------------------------------------
  26. * Autogenerated -- do not modify
  27. * Generated from {0} with script {1}
  28. *-------------------------------------------------------*/
  29. #ifndef UA_NODEIDS_{2}_H_
  30. #define UA_NODEIDS_{2}_H_
  31. /**
  32. * Namespace Zero NodeIds
  33. * ----------------------
  34. * Numeric identifiers of standard-defined nodes in namespace zero. The
  35. * following definitions are autogenerated from the ``{0}`` file */
  36. '''.format(args.statuscodes, sys.argv[0], args.namespace))
  37. for row in rows:
  38. printh(u"#define UA_{namespace}ID_{name} {id} /* {description} */".format(namespace=args.namespace, name=row[0].upper(), id=row[1], description=row[2]))
  39. printh(u'''#endif /* UA_NODEIDS_{0}_H_ */ '''.format(args.namespace))
  40. fh.close()