diff options
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/px4params/srcparser.py | 37 | ||||
-rw-r--r-- | Tools/px4params/xmlout.py | 38 | ||||
-rw-r--r-- | Tools/px_process_params.py | 7 |
3 files changed, 51 insertions, 31 deletions
diff --git a/Tools/px4params/srcparser.py b/Tools/px4params/srcparser.py index 891db7ecd..0d2413a75 100644 --- a/Tools/px4params/srcparser.py +++ b/Tools/px4params/srcparser.py @@ -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" diff --git a/Tools/px4params/xmlout.py b/Tools/px4params/xmlout.py index 89f495dc0..07cced478 100644 --- a/Tools/px4params/xmlout.py +++ b/Tools/px4params/xmlout.py @@ -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) diff --git a/Tools/px_process_params.py b/Tools/px_process_params.py index 12128a997..cb2202d52 100644 --- a/Tools/px_process_params.py +++ b/Tools/px_process_params.py @@ -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 |