generate_nodeids.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 inspect
  6. import sys
  7. import platform
  8. import getpass
  9. import time
  10. import re
  11. import argparse
  12. parser = argparse.ArgumentParser()
  13. parser.add_argument('nodeids', help='path/to/NodeIds.csv')
  14. parser.add_argument('outfile', help='outfile w/o extension')
  15. args = parser.parse_args()
  16. def useNodeId(row):
  17. if row[0] == "":
  18. return False
  19. if "Test" in row[0]:
  20. return False
  21. if row[0].startswith("OpcUa_"):
  22. return False
  23. if row[0].startswith("SessionsDiagnosticsSummaryType_"):
  24. return False
  25. if "Type_" in row[0]:
  26. return False
  27. return True
  28. f = open(args.nodeids)
  29. input_str = f.read() + "\nHasModelParent,50,ReferenceType"
  30. f.close()
  31. input_str = input_str.replace('\r','')
  32. rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
  33. fh = open(args.outfile + ".h",'w')
  34. def printh(string):
  35. print(string, end='\n', file=fh)
  36. printh('''/**********************************************************
  37. * '''+args.outfile+'''.hgen -- do not modify
  38. **********************************************************
  39. * Generated from '''+args.nodeids+''' with script '''+sys.argv[0]+'''
  40. * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
  41. time.strftime("%Y-%m-%d %I:%M:%S")+'''
  42. **********************************************************/\n
  43. #ifndef ''' + args.outfile.upper().split("/")[-1] + '''_H_
  44. #define ''' + args.outfile.upper().split("/")[-1] + '''_H_
  45. ''')
  46. for row in rows:
  47. if useNodeId(row):
  48. printh("#define UA_NS0ID_%s %s // %s" % (row[0].upper(), row[1], row[2]))
  49. printh('\n#endif /* ' + args.outfile.upper().split("/")[-1] + '_H_ */')
  50. fh.close()