From 6bf0a2618bf5e2680f61c4d2a1258eed62103f0e Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 21 Apr 2015 12:31:08 -0700 Subject: Add support for board attribute to parse output This allows for writing parameter meta data which is specific to a board type --- Tools/px4params/xmlout.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'Tools/px4params/xmlout.py') 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) -- cgit v1.2.3