|
@@ -21,23 +21,25 @@
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
-from ua_namespace import *
|
|
|
import logging
|
|
|
import argparse
|
|
|
+from os.path import basename
|
|
|
+from ua_namespace import *
|
|
|
from open62541_XMLPreprocessor import open62541_XMLPreprocessor
|
|
|
|
|
|
-logger = logging.getLogger(__name__)
|
|
|
-
|
|
|
parser = argparse.ArgumentParser(
|
|
|
- description="""Parse OPC UA NamespaceXML file(s) and create C code for generating nodes in open62541
|
|
|
+ description="""Parse OPC UA NodeSetXML file(s) and create C code for generating nodes in open62541
|
|
|
|
|
|
-generate_open62541CCode.py will first read all XML files passed on the command line, then link and check the namespace. All nodes that fulfill the basic requirements will then be printed as C-Code intended to be included in the open62541 OPC UA Server that will initialize the corresponding namespace.""",
|
|
|
+generate_open62541CCode.py will first read all XML files passed on the command
|
|
|
+line, then link and check the nodeset. All nodes that fulfill the basic
|
|
|
+requirements will then be printed as C-Code intended to be included in the
|
|
|
+open62541 OPC UA Server that will initialize the corresponding nodeset.""",
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
parser.add_argument('infiles',
|
|
|
- metavar="<namespaceXML>",
|
|
|
+ metavar="<nodeSetXML>",
|
|
|
nargs='+',
|
|
|
type=argparse.FileType('r'),
|
|
|
- help='Namespace XML file(s). Note that the last definition of a node encountered will be used and all prior definitions are discarded.')
|
|
|
+ help='NodeSet XML file(s). Note that the last definition of a node encountered will be used and all prior definitions are discarded.')
|
|
|
parser.add_argument('outputFile',
|
|
|
metavar='<outputFile>',
|
|
|
|
|
@@ -55,7 +57,7 @@ parser.add_argument('-b','--blacklist',
|
|
|
action='append',
|
|
|
dest="blacklistFiles",
|
|
|
default=[],
|
|
|
- help='Loads a list of NodeIDs stored in blacklistFile (one NodeID per line). Any of the nodeIds encountered in this file will be removed from the namespace prior to compilation. Any references to these nodes will also be removed')
|
|
|
+ help='Loads a list of NodeIDs stored in blacklistFile (one NodeID per line). Any of the nodeIds encountered in this file will be removed from the nodeset prior to compilation. Any references to these nodes will also be removed')
|
|
|
parser.add_argument('-s','--suppress',
|
|
|
metavar="<attribute>",
|
|
|
action='append',
|
|
@@ -71,34 +73,28 @@ parser.add_argument('-v','--verbose', action='count', help='Make the script more
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
-level = logging.CRITICAL
|
|
|
+
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
+logger.setLevel(logging.INFO)
|
|
|
verbosity = 0
|
|
|
if args.verbose:
|
|
|
verbosity = int(args.verbose)
|
|
|
if (verbosity==1):
|
|
|
- level = logging.ERROR
|
|
|
+ logging.basicConfig(level=logging.ERROR)
|
|
|
elif (verbosity==2):
|
|
|
- level = logging.WARNING
|
|
|
+ logging.basicConfig(level=logging.WARNING)
|
|
|
elif (verbosity==3):
|
|
|
- level = logging.INFO
|
|
|
+ logging.basicConfig(level=logging.INFO)
|
|
|
elif (verbosity>=4):
|
|
|
- level = logging.DEBUG
|
|
|
-
|
|
|
-logging.basicConfig(level=level)
|
|
|
-logger.setLevel(logging.INFO)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ logging.basicConfig(level=logging.DEBUG)
|
|
|
+else:
|
|
|
+ logging.basicConfig(level=logging.CRITICAL)
|
|
|
|
|
|
|
|
|
outfileh = open(args.outputFile+".h", r"w+")
|
|
|
outfilec = open(args.outputFile+".c", r"w+")
|
|
|
|
|
|
-
|
|
|
+
|
|
|
ns = opcua_namespace("open62541")
|
|
|
|
|
|
|
|
@@ -118,10 +114,7 @@ namespaceArrayNames = preProc.getUsedNamespaceArrayNames()
|
|
|
for key in namespaceArrayNames:
|
|
|
ns.addNamespace(key, namespaceArrayNames[key])
|
|
|
|
|
|
-
|
|
|
-preProc.removePreprocessedFiles()
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
for blacklist in args.blacklistFiles:
|
|
@@ -134,7 +127,7 @@ for blacklist in args.blacklistFiles:
|
|
|
ns.removeNodeById(line)
|
|
|
blacklist.close()
|
|
|
|
|
|
-
|
|
|
+
|
|
|
logger.info("Linking namespace nodes and references")
|
|
|
ns.linkOpenPointers()
|
|
|
|
|
@@ -165,7 +158,7 @@ for ignore in args.ignoreFiles:
|
|
|
line = line.replace(" ","")
|
|
|
id = line.replace("\n","")
|
|
|
if ns.getNodeByIDString(id) == None:
|
|
|
- logger.warn("Can't ignore node, Namespace does currently not contain a node with id " + str(id))
|
|
|
+ logger.warn("Can't ignore node, NodeSet does currently not contain a node with id " + str(id))
|
|
|
else:
|
|
|
ignoreNodes.append(ns.getNodeByIDString(id))
|
|
|
ignore.close()
|
|
@@ -173,14 +166,14 @@ for ignore in args.ignoreFiles:
|
|
|
|
|
|
logger.info("Generating Header")
|
|
|
|
|
|
-from os.path import basename
|
|
|
-generatedCode = ns.printOpen62541Header(ignoreNodes, args.suppressedAttributes, outfilename=basename(args.outputFile), high_level_api=args.high_level_api)
|
|
|
+
|
|
|
+generatedCode = ns.printOpen62541Header(ignoreNodes, args.suppressedAttributes, outfilename=basename(args.outputFile))
|
|
|
for line in generatedCode[0]:
|
|
|
- outfileh.write(line+"\n")
|
|
|
+ print(line, end='\n', file=outfileh)
|
|
|
for line in generatedCode[1]:
|
|
|
- outfilec.write(line+"\n")
|
|
|
+ print(line, end='\n', file=outfilec)
|
|
|
|
|
|
outfilec.close()
|
|
|
outfileh.close()
|
|
|
|
|
|
-logger.info("Namespace generation code successfully printed")
|
|
|
+logger.info("NodeSet generation code successfully printed")
|