mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
parameters: move XML injection to the group level (#15403)
So that they are also in the markdown and json output.
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# Injects params from XML file into a param_group
|
||||||
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
from px4params import srcscanner, srcparser, xmlout, markdownout
|
||||||
|
from .srcparser import ParameterGroup, Parameter
|
||||||
|
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class XMLInject():
|
||||||
|
def __init__(self, injected_xml_filename):
|
||||||
|
self.groups=[]
|
||||||
|
|
||||||
|
valid_parameter_attributes = set(["category", "default", "name", "type", "volatile"])
|
||||||
|
valid_field_tags = set(["board","short_desc", "long_desc", "min", "max", "unit", "decimal", "increment", "reboot_required"])
|
||||||
|
valid_other_top_level_tags = set(["group","values"])
|
||||||
|
|
||||||
|
importtree = ET.parse(injected_xml_filename)
|
||||||
|
injectgroups = importtree.getroot().findall("group")
|
||||||
|
not_handled_parameter_tags=set()
|
||||||
|
not_handled_parameter_attributes=set()
|
||||||
|
for igroup in injectgroups:
|
||||||
|
group_name=igroup.get('name')
|
||||||
|
imported_group = ParameterGroup(group_name)
|
||||||
|
no_code_generation=igroup.get('no_code_generation')
|
||||||
|
if no_code_generation:
|
||||||
|
imported_group.no_code_generation=no_code_generation
|
||||||
|
for iparam in igroup:
|
||||||
|
param_name=iparam.get('name')
|
||||||
|
param_type=iparam.get('type')
|
||||||
|
new_param= Parameter(param_name, param_type)
|
||||||
|
#get other param info stored as attributes
|
||||||
|
for param_attrib in iparam.attrib:
|
||||||
|
if param_attrib not in valid_parameter_attributes:
|
||||||
|
not_handled_parameter_attributes.add(param_attrib)
|
||||||
|
elif param_attrib == 'category':
|
||||||
|
new_param.SetCategory(iparam.get('category'))
|
||||||
|
elif param_attrib == 'default':
|
||||||
|
new_param.default = iparam.get('default')
|
||||||
|
elif param_attrib == 'volatile':
|
||||||
|
new_param.SetVolatile()
|
||||||
|
|
||||||
|
|
||||||
|
#get param info stored as child tags
|
||||||
|
for child in iparam:
|
||||||
|
if child.tag in valid_field_tags:
|
||||||
|
new_param.SetField(child.tag, child.text)
|
||||||
|
elif child.tag == 'values':
|
||||||
|
for value in child:
|
||||||
|
new_param.SetEnumValue(value.get('code'), value.text)
|
||||||
|
elif child.tag == 'bitmask':
|
||||||
|
for bit in child:
|
||||||
|
new_param.SetBitmaskBit(bit.get('index'), bit.text)
|
||||||
|
else:
|
||||||
|
not_handled_parameter_tags.add(child.tag)
|
||||||
|
|
||||||
|
imported_group.AddParameter(new_param)
|
||||||
|
self.groups.append(imported_group)
|
||||||
|
|
||||||
|
|
||||||
|
if not_handled_parameter_tags or not_handled_parameter_attributes:
|
||||||
|
print("WARNING: Injected file parameter has unhandled child tags: %s" % not_handled_parameter_tags)
|
||||||
|
print("WARNING: Injected file parameter has unhandled attributes: %s" % not_handled_parameter_attributes)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def injected(self):
|
||||||
|
return self.groups
|
||||||
@@ -11,6 +11,7 @@ class ParameterGroup(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.no_code_generation = False #for injected parameters
|
||||||
self.params = []
|
self.params = []
|
||||||
|
|
||||||
def AddParameter(self, param):
|
def AddParameter(self, param):
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ def indent(elem, level=0):
|
|||||||
|
|
||||||
class XMLOutput():
|
class XMLOutput():
|
||||||
|
|
||||||
def __init__(self, groups, board, inject_xml_file_name):
|
def __init__(self, groups, board):
|
||||||
xml_parameters = ET.Element("parameters")
|
xml_parameters = ET.Element("parameters")
|
||||||
xml_version = ET.SubElement(xml_parameters, "version")
|
xml_version = ET.SubElement(xml_parameters, "version")
|
||||||
xml_version.text = "3"
|
xml_version.text = "3"
|
||||||
@@ -26,15 +26,13 @@ class XMLOutput():
|
|||||||
xml_version.text = "1"
|
xml_version.text = "1"
|
||||||
xml_version = ET.SubElement(xml_parameters, "parameter_version_minor")
|
xml_version = ET.SubElement(xml_parameters, "parameter_version_minor")
|
||||||
xml_version.text = "15"
|
xml_version.text = "15"
|
||||||
importtree = ET.parse(inject_xml_file_name)
|
|
||||||
injectgroups = importtree.getroot().findall("group")
|
|
||||||
for igroup in injectgroups:
|
|
||||||
xml_parameters.append(igroup)
|
|
||||||
last_param_name = ""
|
last_param_name = ""
|
||||||
board_specific_param_set = False
|
board_specific_param_set = False
|
||||||
for group in groups:
|
for group in groups:
|
||||||
xml_group = ET.SubElement(xml_parameters, "group")
|
xml_group = ET.SubElement(xml_parameters, "group")
|
||||||
xml_group.attrib["name"] = group.GetName()
|
xml_group.attrib["name"] = group.GetName()
|
||||||
|
if group.no_code_generation:
|
||||||
|
xml_group.attrib["no_code_generation"] = group.no_code_generation
|
||||||
for param in group.GetParams():
|
for param in group.GetParams():
|
||||||
if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
|
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 = ET.SubElement(xml_group, "parameter")
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ from __future__ import print_function
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
from px4params import srcscanner, srcparser, xmlout, markdownout
|
from px4params import srcscanner, srcparser, injectxmlparams, xmlout, markdownout
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
@@ -118,6 +118,12 @@ def main():
|
|||||||
if len(param_groups) == 0:
|
if len(param_groups) == 0:
|
||||||
print("Warning: no parameters found")
|
print("Warning: no parameters found")
|
||||||
|
|
||||||
|
|
||||||
|
#inject parameters at front of set
|
||||||
|
cur_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
groups_to_inject = injectxmlparams.XMLInject(os.path.join(cur_dir, args.inject_xml)).injected()
|
||||||
|
param_groups=groups_to_inject+param_groups
|
||||||
|
|
||||||
override_dict = json.loads(args.overrides)
|
override_dict = json.loads(args.overrides)
|
||||||
if len(override_dict.keys()) > 0:
|
if len(override_dict.keys()) > 0:
|
||||||
for group in param_groups:
|
for group in param_groups:
|
||||||
@@ -132,9 +138,7 @@ def main():
|
|||||||
if args.xml:
|
if args.xml:
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("Creating XML file " + args.xml)
|
print("Creating XML file " + args.xml)
|
||||||
cur_dir = os.path.dirname(os.path.realpath(__file__))
|
out = xmlout.XMLOutput(param_groups, args.board)
|
||||||
out = xmlout.XMLOutput(param_groups, args.board,
|
|
||||||
os.path.join(cur_dir, args.inject_xml))
|
|
||||||
out.Save(args.xml)
|
out.Save(args.xml)
|
||||||
|
|
||||||
# Output to Markdown/HTML tables
|
# Output to Markdown/HTML tables
|
||||||
|
|||||||
Reference in New Issue
Block a user