OpcUaCanOpen
CANopen OPC-UA server
generate_nodeids.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import sys
3 import platform
4 import getpass
5 import time
6 import argparse
7 
8 parser = argparse.ArgumentParser()
9 parser.add_argument('nodeids', help='path/to/NodeIds.csv')
10 parser.add_argument('outfile', help='outfile w/o extension')
11 args = parser.parse_args()
12 
13 f = open(args.nodeids)
14 input_str = f.read()
15 f.close()
16 input_str = input_str.replace('\r','')
17 rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
18 
19 fh = open(args.outfile + ".h",'w')
20 def printh(string):
21  print(string)
22  print(string, end='\n', file=fh)
23 
24 printh('''/**********************************************************
25  * '''+args.outfile+'''.hgen -- do not modify
26  **********************************************************
27  * Generated from '''+args.nodeids+''' with script '''+sys.argv[0]+'''
28  * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
29  time.strftime("%Y-%m-%d %I:%M:%S")+'''
30  **********************************************************/\n
31 #ifndef ''' + args.outfile.upper().split("/")[-1] + '''_H_
32 #define ''' + args.outfile.upper().split("/")[-1] + '''_H_
33 ''')
34 
35 for row in rows:
36 
37  printh("#define BA_%s %s // %s" % (row[0].upper(), row[1], row[2]))
38 
39 printh('\n#endif /* ' + args.outfile.upper().split("/")[-1] + '_H_ */')
40 
41 fh.close()