Skip to content

Commit

Permalink
FEATURE: annotate_params.py allow selecting firmware version
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jun 15, 2024
1 parent 24a68c9 commit 545bd84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
51 changes: 38 additions & 13 deletions MethodicConfigurator/annotate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,35 +650,60 @@ def print_read_only_params(doc):
logging.info(param_name)


def annotate_parameters(xml_dir: str, xml_file: str, target: str, vehicle_type: str, # pylint: disable=too-many-arguments
_firmware_version: str, max_line_length: int, sort: str,
delete_documentation_annotations: bool) -> Dict[str, Any]:
def get_xml_dir(target: str) -> str:
return target if os_path.isdir(target) else os_path.dirname(os_path.realpath(target))


def get_xml_url(vehicle_type: str, firmware_version: str) -> str:
vehicle_parm_subdir = {
"ArduCopter": "versioned/Copter/stable-",
"ArduPlane": "versioned/Plane/stable-",
"Rover": "versioned/Rover/stable-",
"ArduSub": "versioned/Sub/stable-",
"AntennaTracker": "versioned/Tracker/stable-",
# Not yet versioned in the https://autotest.ardupilot.org/Parameters server
'AP_Periph': 'versioned/Periph/stable-',
'Blimp': 'versioned/Blimp/stable-',
'Heli': 'versioned/Heli/stable-',
'SITL': 'versioned/SITL/stable-'
}
if firmware_version:
xml_url = BASE_URL + vehicle_parm_subdir[vehicle_type] + firmware_version + "/"
else:
xml_url = BASE_URL + vehicle_type + "/"
return xml_url

def annotate_parameters(xml_url: str, xml_dir: str, xml_file: str,
vehicle_type: str, max_line_length: int) -> Dict[str, Any]:
"""
Annotates parameters with documentation fetched from an XML file.
"""
xml_root, param_default_dict = get_xml_data(BASE_URL + vehicle_type + "/", xml_dir, xml_file)
xml_root, param_default_dict = get_xml_data(xml_url, xml_dir, xml_file)
doc_dict = create_doc_dict(xml_root, vehicle_type, max_line_length)
update_parameter_documentation(doc_dict, target, sort, param_default_dict, delete_documentation_annotations)
return doc_dict
return doc_dict, param_default_dict


def main():
args = arg_parser()
try:
xml_dir = args.target if os_path.isdir(args.target) else os_path.dirname(os_path.realpath(args.target))
xml_url = get_xml_url(args.vehicle_type, args.firmware_version)
xml_dir = get_xml_dir(args.target)

doc_dict = annotate_parameters(xml_dir, PARAM_DEFINITION_XML_FILE, args.target, args.vehicle_type,
args.firmware_version, args.max_line_length,
args.sort, args.delete_documentation_annotations)
[doc_dict, param_default_dict] = annotate_parameters(xml_url, xml_dir, PARAM_DEFINITION_XML_FILE,
args.vehicle_type, args.max_line_length)
update_parameter_documentation(doc_dict, args.target, args.sort, param_default_dict,
args.delete_documentation_annotations)
if args.verbose:
print_read_only_params(doc_dict)

# Annotate lua MAGfit XML documentation into the respective parameter file
xml_file = LUA_PARAM_DEFINITION_XML_FILE
target = os_path.join(os_path.dirname(args.target), "24_inflight_magnetometer_fit_setup.param")
if os_path.isfile(os_path.join(os_path.dirname(args.target), xml_file)):
doc_dict = annotate_parameters(xml_dir, xml_file, target, args.vehicle_type, args.firmware_version,
args.max_line_length, args.sort, args.delete_documentation_annotations)
[doc_dict, param_default_dict] = annotate_parameters(xml_url, xml_dir, xml_file,
args.vehicle_type, args.max_line_length)
target = os_path.join(os_path.dirname(args.target), "24_inflight_magnetometer_fit_setup.param")
update_parameter_documentation(doc_dict, target, args.sort, param_default_dict,
args.delete_documentation_annotations)
else:
logging.warning("No LUA MAGfit XML documentation found, skipping annotation of %s", target)

Expand Down
30 changes: 8 additions & 22 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@

from zipfile import ZipFile

from MethodicConfigurator.annotate_params import BASE_URL, PARAM_DEFINITION_XML_FILE, Par
from MethodicConfigurator.annotate_params import get_xml_data
from MethodicConfigurator.annotate_params import create_doc_dict
from MethodicConfigurator.annotate_params import PARAM_DEFINITION_XML_FILE, Par
from MethodicConfigurator.annotate_params import get_xml_url
from MethodicConfigurator.annotate_params import get_xml_dir
from MethodicConfigurator.annotate_params import annotate_parameters
from MethodicConfigurator.annotate_params import format_columns
from MethodicConfigurator.annotate_params import split_into_lines
from MethodicConfigurator.annotate_params import update_parameter_documentation
Expand Down Expand Up @@ -110,25 +111,10 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
self.fw_version = self.get_fc_fw_version_from_vehicle_components_json()

# Read ArduPilot parameter documentation
xml_dir = vehicle_dir if os_path.isdir(vehicle_dir) else os_path.dirname(os_path.realpath(vehicle_dir))
vehicle_parm_subdir = {
"ArduCopter": "versioned/Copter/stable-",
"ArduPlane": "versioned/Plane/stable-",
"Rover": "versioned/Rover/stable-",
"ArduSub": "versioned/Sub/stable-",
"AntennaTracker": "versioned/Tracker/stable-",
# Not yet versioned in the https://autotest.ardupilot.org/Parameters server
'AP_Periph': 'versioned/Periph/stable-',
'Blimp': 'versioned/Blimp/stable-',
'Heli': 'versioned/Heli/stable-',
'SITL': 'versioned/SITL/stable-'
}
if self.fw_version:
xml_url = BASE_URL + vehicle_parm_subdir[vehicle_type] + self.fw_version + "/"
else:
xml_url = BASE_URL + vehicle_type + "/"
xml_root, self.param_default_dict = get_xml_data(xml_url, xml_dir, PARAM_DEFINITION_XML_FILE)
self.doc_dict = create_doc_dict(xml_root, vehicle_type, TOOLTIP_MAX_LENGTH)
xml_url = get_xml_url(vehicle_type, self.fw_version)
xml_dir = get_xml_dir(vehicle_dir)
[self.doc_dict, self.param_default_dict] = annotate_parameters(xml_url, xml_dir, PARAM_DEFINITION_XML_FILE,
vehicle_type, TOOLTIP_MAX_LENGTH)

self.__extend_and_reformat_parameter_documentation_metadata()

Expand Down

0 comments on commit 545bd84

Please sign in to comment.