generate_nodeids.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if "_Encoding_Default" in row[0]:
  25. return False
  26. return True
  27. f = open(args.nodeids)
  28. input_str = f.read() + "\nHasModelParent,50,ReferenceType"
  29. f.close()
  30. input_str = input_str.replace('\r','')
  31. rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
  32. fh = open(args.outfile + ".h",'w')
  33. def printh(string):
  34. print(string, end='\n', file=fh)
  35. printh('''/**********************************************************
  36. * '''+args.outfile+'''.hgen -- do not modify
  37. **********************************************************
  38. * Generated from '''+args.nodeids+''' with script '''+sys.argv[0]+'''
  39. * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
  40. time.strftime("%Y-%m-%d %I:%M:%S")+'''
  41. **********************************************************/\n
  42. #ifndef ''' + args.outfile.upper().split("/")[-1] + '''_H_
  43. #define ''' + args.outfile.upper().split("/")[-1] + '''_H_
  44. ''')
  45. for row in rows:
  46. if useNodeId(row):
  47. printh("#define UA_NS0ID_%s %s // %s" % (row[0].upper(), row[1], row[2]))
  48. printh('\n#endif /* ' + args.outfile.upper().split("/")[-1] + '_H_ */')
  49. fh.close()