123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import logging
- import argparse
- from nodeset import *
- from backend_open62541 import generateOpen62541Code
- parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
- parser.add_argument('-e', '--existing',
- metavar="<existingNodeSetXML>",
- type=argparse.FileType('rb'),
- dest="existing",
- action='append',
- default=[],
- help='NodeSet XML files with nodes that are already present on the server.')
- parser.add_argument('-x', '--xml',
- metavar="<nodeSetXML>",
- type=argparse.FileType('rb'),
- action='append',
- dest="infiles",
- default=[],
- help='NodeSet XML files with nodes that shall be generated.')
- parser.add_argument('outputFile',
- metavar='<outputFile>',
- help='The path/basename for the <output file>.c and <output file>.h files to be generated. This will also be the function name used in the header and c-file.')
- parser.add_argument('--generate-ns0',
- action='store_true',
- dest="generate_ns0",
- help='Omit some consistency checks for bootstrapping namespace 0, create references to parents and type definitions manually')
- parser.add_argument('--internal-headers',
- action='store_true',
- dest="internal_headers",
- help='Include internal headers instead of amalgamated header')
- parser.add_argument('-b', '--blacklist',
- metavar="<blacklistFile>",
- type=argparse.FileType('r'),
- 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 nodeset prior to compilation. Any references to these nodes will also be removed')
- parser.add_argument('-i', '--ignore',
- metavar="<ignoreFile>",
- type=argparse.FileType('r'),
- action='append',
- dest="ignoreFiles",
- default=[],
- help='Loads a list of NodeIDs stored in ignoreFile (one NodeID per line). Any of the nodeIds encountered in this file will be kept in the nodestore but not printed in the generated code')
- parser.add_argument('-t', '--types-array',
- metavar="<typesArray>",
- action='append',
- type=str,
- dest="typesArray",
- default=[],
- help='Types array for the given namespace. Can be used mutliple times to define (in the same order as the .xml files, first for --existing, then --xml) the type arrays')
- parser.add_argument('--max-string-length',
- type=int,
- dest="max_string_length",
- default=0,
- help='Maximum allowed length of a string literal. If longer, it will be set to an empty string')
- parser.add_argument('--encode-binary-size',
- type=int,
- dest="encode_binary_size",
- default=32000,
- help='Size of the temporary array used to encode custom datatypes. If you don\'t know what it is, do not use this option')
- parser.add_argument('-v', '--verbose', action='count',
- default=1,
- help='Make the script more verbose. Can be applied up to 4 times')
- args = parser.parse_args()
- logger = logging.getLogger(__name__)
- logger.setLevel(logging.INFO)
- verbosity = 0
- if args.verbose:
- verbosity = int(args.verbose)
- if (verbosity == 1):
- logging.basicConfig(level=logging.ERROR)
- elif (verbosity == 2):
- logging.basicConfig(level=logging.WARNING)
- elif (verbosity == 3):
- logging.basicConfig(level=logging.INFO)
- elif (verbosity >= 4):
- logging.basicConfig(level=logging.DEBUG)
- else:
- logging.basicConfig(level=logging.CRITICAL)
- ns = NodeSet()
- nsCount = 0
- def getTypesArray(nsIdx):
- if nsIdx < len(args.typesArray):
- return args.typesArray[nsIdx]
- else:
- return "UA_TYPES"
- for xmlfile in args.existing:
- logger.info("Preprocessing (existing) " + str(xmlfile.name))
- ns.addNodeSet(xmlfile, True, typesArray=getTypesArray(nsCount))
- nsCount +=1
- for xmlfile in args.infiles:
- logger.info("Preprocessing " + str(xmlfile.name))
- ns.addNodeSet(xmlfile, typesArray=getTypesArray(nsCount))
- nsCount +=1
- for blacklist in args.blacklistFiles:
- for line in blacklist.readlines():
- line = line.replace(" ", "")
- id = line.replace("\n", "")
- if ns.getNodeByIDString(id) == None:
- logger.info("Can't blacklist node, namespace does currently not contain a node with id " + str(id))
- else:
- ns.removeNodeById(line)
- blacklist.close()
- for ignoreFile in args.ignoreFiles:
- for line in ignoreFile.readlines():
- line = line.replace(" ", "")
- id = line.replace("\n", "")
- ns.hide_node(NodeId(id))
-
-
- ignoreFile.close()
- ns.sanitize()
- ns.buildEncodingRules()
- ns.allocateVariables()
- logger.info("Generating Code")
- generateOpen62541Code(ns, args.outputFile, args.generate_ns0, args.internal_headers, args.typesArray, args.max_string_length, args.encode_binary_size)
- logger.info("NodeSet generation code successfully printed")
|