|
@@ -8,56 +8,54 @@ import platform
|
|
|
import getpass
|
|
|
import time
|
|
|
import argparse
|
|
|
+from io import open
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
parser.add_argument('statuscodes', help='path/to/Opc.Ua.StatusCodes.csv')
|
|
|
parser.add_argument('outfile', help='outfile w/o extension')
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
-f = open(args.statuscodes)
|
|
|
-input_str = f.read()
|
|
|
-f.close()
|
|
|
-input_str = input_str.replace('\r','')
|
|
|
-rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
|
|
|
+rows = []
|
|
|
+with open(args.statuscodes, mode="rt") as f:
|
|
|
+ lines = f.readlines()
|
|
|
+ for l in lines:
|
|
|
+ rows.append(tuple(l.strip().split(',')))
|
|
|
|
|
|
-fc = open(args.outfile + ".c",'w')
|
|
|
+fc = open(args.outfile + ".c", "wt", encoding='utf8')
|
|
|
def printc(string):
|
|
|
- print(string, end='\n', file=fc)
|
|
|
+ print(string, end=u'\n', file=fc)
|
|
|
|
|
|
-printc('''/**********************************************************
|
|
|
- * '''+args.outfile+'''.hgen -- do not modify
|
|
|
- **********************************************************
|
|
|
- * Generated from '''+args.statuscodes+''' with script '''+sys.argv[0]+'''
|
|
|
- * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
|
|
|
- time.strftime("%Y-%m-%d %I:%M:%S")+'''
|
|
|
- **********************************************************/\n
|
|
|
+printc(u'''/**********************************************************
|
|
|
+ * Autogenerated -- do not modify
|
|
|
+ * Generated from %s with script %s
|
|
|
+ *********************************************************/
|
|
|
|
|
|
-#include "ua_types.h"''')
|
|
|
+#include "ua_types.h"''' % (args.statuscodes, sys.argv[0]))
|
|
|
|
|
|
count = 2
|
|
|
for row in rows:
|
|
|
count += 1
|
|
|
|
|
|
-printc('''
|
|
|
+printc(u'''
|
|
|
#ifndef UA_ENABLE_STATUSCODE_DESCRIPTIONS
|
|
|
static const size_t statusCodeDescriptionsSize = 1;
|
|
|
static const UA_StatusCodeDescription statusCodeDescriptions[1] = {
|
|
|
-{0xffffffff, \"StatusCode descriptions not available\", \"open62541 was compiled without support for statuscode descriptions\"}
|
|
|
+ {0xffffffff, \"StatusCode descriptions not available\", \"open62541 was compiled without support for statuscode descriptions\"}
|
|
|
};
|
|
|
#else
|
|
|
static const size_t statusCodeDescriptionsSize = %s;
|
|
|
static const UA_StatusCodeDescription statusCodeDescriptions[%i] =
|
|
|
{''' % (count, count))
|
|
|
|
|
|
-printc(" {UA_STATUSCODE_GOOD, \"Good\", \"Success / No error\"},")
|
|
|
+printc(u" {UA_STATUSCODE_GOOD, \"Good\", \"Success / No error\"},")
|
|
|
for row in rows:
|
|
|
- printc(" {UA_STATUSCODE_%s, \"%s\", \"%s\"}," % (row[0].upper(), row[0], row[2]))
|
|
|
-printc(" {0xffffffff, \"Unknown\", \"Unknown StatusCode\"},")
|
|
|
-printc('''\n};
|
|
|
-#endif''')
|
|
|
+ printc(u" {UA_STATUSCODE_%s, \"%s\", \"%s\"}," % (row[0].upper(), row[0], row[2]))
|
|
|
+printc(u''' {0xffffffff, \"Unknown\", \"Unknown StatusCode\"},
|
|
|
+};
|
|
|
+#endif
|
|
|
|
|
|
-printc('''
|
|
|
-const UA_StatusCodeDescription * UA_StatusCode_description(UA_StatusCode code) {
|
|
|
+const UA_StatusCodeDescription *
|
|
|
+UA_StatusCode_description(UA_StatusCode code) {
|
|
|
for(size_t i = 0; i < statusCodeDescriptionsSize; ++i) {
|
|
|
if(statusCodeDescriptions[i].code == code)
|
|
|
return &statusCodeDescriptions[i];
|