123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- from sys import argv, exit
- from os import path
- from ua_namespace import *
- from logger import *
- def usage():
- print "Skript usage:"
- print "generate_open62541CCode <namespace XML> [namespace.xml[ namespace.xml[...]]] <output file>"
- print ""
- print "generate_open62541CCode will first read all XML files passed on the command line, then "
- print "link and check the namespace. All nodes that fullfill the basic requirements will then be"
- print "printed as C-Code intended to be included in the open62541 OPC-UA Server that will"
- print "initialize the corresponding name space."
- if __name__ == '__main__':
-
- infiles = []
- ouffile = ""
-
- GLOBAL_LOG_LEVEL = LOG_LEVEL_INFO
-
- if len(argv) < 2:
- usage()
- exit(1)
- for filename in argv[1:-1]:
- if path.exists(filename):
- infiles.append(filename)
- else:
- log(None, "File " + str(filename) + " does not exist.", LOG_LEVEL_ERROR)
- usage()
- exit(1)
-
-
- if path.exists(argv[-1]):
- log(None, "File " + str(filename) + " does already exists.", LOG_LEVEL_INFO)
- log(None, "Header generation will be skipped. Delete the header and rerun this script if necessary.", LOG_LEVEL_INFO)
- exit(0)
-
- outfile = open(argv[-1], r"w+")
-
-
-
-
-
- ns = opcua_namespace("open62541")
-
- for xmlfile in infiles:
- log(None, "Parsing " + str(xmlfile), LOG_LEVEL_INFO)
- ns.parseXML(xmlfile)
-
- log(None, "Linking namespace nodes and references", LOG_LEVEL_INFO)
- ns.linkOpenPointers()
-
-
- ns.sanitize()
-
-
-
-
-
- log(None, "Building datatype encoding rules", LOG_LEVEL_INFO)
- ns.buildEncodingRules()
-
-
- log(None, "Allocating variables", LOG_LEVEL_INFO)
- ns.allocateVariables()
-
- log(None, "Generating Header", LOG_LEVEL_INFO)
- for line in ns.printOpen62541Header():
- outfile.write(line+"\n")
- outfile.close()
|