generate_nodeid_descriptions.py 1.5 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. args = parser.parse_args()
  16. rows = []
  17. with open(args.statuscodes, mode="rt") as f:
  18. lines = f.readlines()
  19. for l in lines:
  20. rows.append(tuple(l.strip().split(',')))
  21. fh = open(args.outfile + ".h", "wt", encoding='utf8')
  22. def printh(string):
  23. print(string, end=u'\n', file=fh)
  24. #########################
  25. # Print the header file #
  26. #########################
  27. printh(u'''/*---------------------------------------------------------
  28. * Autogenerated -- do not modify
  29. * Generated from %s with script %s
  30. *-------------------------------------------------------*/
  31. #ifndef UA_NODEIDS_H_
  32. #define UA_NODEIDS_H_
  33. /**
  34. * Namespace Zero NodeIds
  35. * ----------------------
  36. * Numeric identifiers of standard-defined nodes in namespace zero. The
  37. * following definitions are autogenerated from the ``NodeIds.csv`` file
  38. * provided with the OPC UA standard. */
  39. ''' % (args.statuscodes, sys.argv[0]))
  40. for row in rows:
  41. printh(u"#define UA_NS0ID_%s %s /* %s */" % (row[0].upper(), row[1], row[2]))
  42. printh(u'''#endif /* UA_NODEIDS_H_ */ ''')
  43. fh.close()