generate_nodeids.py 1.6 KB

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