forked from Archive/PX4-Autopilot
Add support for board attribute to parse output
This allows for writing parameter meta data which is specific to a board type
This commit is contained in:
parent
39f6e13c18
commit
6bf0a2618b
|
@ -12,11 +12,11 @@ class DokuWikiTablesOutput():
|
|||
result += "^ Name ^ Description ^ Min ^ Max ^ Default ^\n"
|
||||
result += "^ ::: ^ Comment ^^^^\n"
|
||||
for param in group.GetParams():
|
||||
code = param.GetFieldValue("code")
|
||||
code = param.GetName()
|
||||
def_val = param.GetDefault()
|
||||
name = param.GetFieldValue("short_desc")
|
||||
min_val = param.GetFieldValue("min")
|
||||
max_val = param.GetFieldValue("max")
|
||||
def_val = param.GetFieldValue("default")
|
||||
long_desc = param.GetFieldValue("long_desc")
|
||||
|
||||
if name == code:
|
||||
|
|
|
@ -37,20 +37,30 @@ class Parameter(object):
|
|||
|
||||
# Define sorting order of the fields
|
||||
priority = {
|
||||
"code": 10,
|
||||
"type": 9,
|
||||
"board": 9,
|
||||
"short_desc": 8,
|
||||
"long_desc": 7,
|
||||
"default": 6,
|
||||
"min": 5,
|
||||
"max": 4,
|
||||
"unit": 3,
|
||||
# all others == 0 (sorted alphabetically)
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, name, type, default = ""):
|
||||
self.fields = {}
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.default = default
|
||||
|
||||
def GetName(self):
|
||||
return self.name
|
||||
|
||||
def GetType(self):
|
||||
return self.type
|
||||
|
||||
def GetDefault(self):
|
||||
return self.default
|
||||
|
||||
def SetField(self, code, value):
|
||||
"""
|
||||
Set named field value
|
||||
|
@ -88,7 +98,7 @@ class SourceParser(object):
|
|||
re_is_a_number = re.compile(r'^-?[0-9\.]')
|
||||
re_remove_dots = re.compile(r'\.+$')
|
||||
|
||||
valid_tags = set(["group", "min", "max", "unit"])
|
||||
valid_tags = set(["group", "board", "min", "max", "unit"])
|
||||
|
||||
# Order of parameter groups
|
||||
priority = {
|
||||
|
@ -177,15 +187,12 @@ class SourceParser(object):
|
|||
# Non-empty line outside the comment
|
||||
m = self.re_parameter_definition.match(line)
|
||||
if m:
|
||||
tp, code, defval = m.group(1, 2, 3)
|
||||
tp, name, defval = m.group(1, 2, 3)
|
||||
# Remove trailing type specifier from numbers: 0.1f => 0.1
|
||||
if self.re_is_a_number.match(defval):
|
||||
defval = self.re_cut_type_specifier.sub('', defval)
|
||||
param = Parameter()
|
||||
param.SetField("code", code)
|
||||
param.SetField("short_desc", code)
|
||||
param.SetField("type", tp)
|
||||
param.SetField("default", defval)
|
||||
param = Parameter(name, tp, defval)
|
||||
param.SetField("short_desc", name)
|
||||
# If comment was found before the parameter declaration,
|
||||
# inject its data into the newly created parameter.
|
||||
group = "Miscellaneous"
|
||||
|
@ -211,11 +218,9 @@ class SourceParser(object):
|
|||
# Nasty code dup, but this will all go away soon, so quick and dirty (DonLakeFlyer)
|
||||
m = self.re_px4_parameter_definition.match(line)
|
||||
if m:
|
||||
tp, code = m.group(1, 2)
|
||||
param = Parameter()
|
||||
param.SetField("code", code)
|
||||
param.SetField("short_desc", code)
|
||||
param.SetField("type", tp)
|
||||
tp, name = m.group(1, 2)
|
||||
param = Parameter(name, tp)
|
||||
param.SetField("short_desc", name)
|
||||
# If comment was found before the parameter declaration,
|
||||
# inject its data into the newly created parameter.
|
||||
group = "Miscellaneous"
|
||||
|
|
|
@ -18,26 +18,36 @@ def indent(elem, level=0):
|
|||
|
||||
class XMLOutput():
|
||||
|
||||
def __init__(self, groups):
|
||||
def __init__(self, groups, board):
|
||||
xml_parameters = ET.Element("parameters")
|
||||
xml_version = ET.SubElement(xml_parameters, "version")
|
||||
xml_version.text = "2"
|
||||
xml_version.text = "3"
|
||||
last_param_name = ""
|
||||
board_specific_param_set = False
|
||||
for group in groups:
|
||||
xml_group = ET.SubElement(xml_parameters, "group")
|
||||
xml_group.attrib["name"] = group.GetName()
|
||||
for param in group.GetParams():
|
||||
xml_param = ET.SubElement(xml_group, "parameter")
|
||||
for code in param.GetFieldCodes():
|
||||
value = param.GetFieldValue(code)
|
||||
if code == "code":
|
||||
xml_param.attrib["name"] = value
|
||||
elif code == "default":
|
||||
xml_param.attrib["default"] = value
|
||||
elif code == "type":
|
||||
xml_param.attrib["type"] = value
|
||||
else:
|
||||
xml_field = ET.SubElement(xml_param, code)
|
||||
xml_field.text = value
|
||||
if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
|
||||
xml_param = ET.SubElement(xml_group, "parameter")
|
||||
xml_param.attrib["name"] = param.GetName()
|
||||
xml_param.attrib["default"] = param.GetDefault()
|
||||
xml_param.attrib["type"] = param.GetType()
|
||||
last_param_name = param.GetName()
|
||||
for code in param.GetFieldCodes():
|
||||
value = param.GetFieldValue(code)
|
||||
if code == "board":
|
||||
if value == board:
|
||||
board_specific_param_set = True
|
||||
xml_field = ET.SubElement(xml_param, code)
|
||||
xml_field.text = value
|
||||
else:
|
||||
xml_group.remove(xml_param)
|
||||
else:
|
||||
xml_field = ET.SubElement(xml_param, code)
|
||||
xml_field.text = value
|
||||
if last_param_name != param.GetName():
|
||||
board_specific_param_set = False
|
||||
indent(xml_parameters)
|
||||
self.xml_document = ET.ElementTree(xml_parameters)
|
||||
|
||||
|
|
|
@ -65,6 +65,11 @@ def main():
|
|||
metavar="FILENAME",
|
||||
help="Create XML file"
|
||||
" (default FILENAME: parameters.xml)")
|
||||
parser.add_argument("-b", "--board",
|
||||
nargs='?',
|
||||
const="",
|
||||
metavar="BOARD",
|
||||
help="Board to create xml parameter xml for")
|
||||
parser.add_argument("-w", "--wiki",
|
||||
nargs='?',
|
||||
const="parameters.wiki",
|
||||
|
@ -116,7 +121,7 @@ def main():
|
|||
# Output to XML file
|
||||
if args.xml:
|
||||
print("Creating XML file " + args.xml)
|
||||
out = xmlout.XMLOutput(param_groups)
|
||||
out = xmlout.XMLOutput(param_groups, args.board)
|
||||
out.Save(args.xml)
|
||||
|
||||
# Output to DokuWiki tables
|
||||
|
|
Loading…
Reference in New Issue