generate_nodeids.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. for index, row in enumerate(rows):
  33. if row[0] == "BaseDataType":
  34. rows[index]= ("Variant", row[1], row[2])
  35. elif row[0] == "Structure":
  36. rows[index] = ("ExtensionObject", row[1], row[2])
  37. fh = open(args.outfile + ".h",'w')
  38. def printh(string):
  39. print(string, end='\n', file=fh)
  40. printh('''/**********************************************************
  41. * '''+args.outfile+'''.hgen -- do not modify
  42. **********************************************************
  43. * Generated from '''+args.nodeids+''' with script '''+sys.argv[0]+'''
  44. * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
  45. time.strftime("%Y-%m-%d %I:%M:%S")+'''
  46. **********************************************************/\n
  47. #ifndef ''' + args.outfile.upper().split("/")[-1] + '''_H_
  48. #define ''' + args.outfile.upper().split("/")[-1] + '''_H_
  49. ''')
  50. for row in rows:
  51. if useNodeId(row):
  52. printh("#define UA_NS0ID_%s %s // %s" % (row[0].upper(), row[1], row[2]))
  53. printh('\n#endif /* ' + args.outfile.upper().split("/")[-1] + '_H_ */')
  54. fh.close()