Skip to content

Commit d079459

Browse files
committed
IMPROVEMENT: use FC FW version string from vehicle_components.json if it is available
1 parent ea80bc2 commit d079459

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

MethodicConfigurator/backend_filesystem.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from shutil import copytree as shutil_copytree
1919

2020
from re import compile as re_compile
21+
from re import match as re_match
2122

2223
# from sys import exit as sys_exit
2324
from logging import debug as logging_debug
@@ -107,6 +108,20 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
107108
if not self.file_parameters:
108109
return # No files intermediate parameters files found, no need to continue, the rest needs them
109110

111+
self.load_vehicle_components_json_data(vehicle_dir)
112+
113+
if self.vehicle_components and 'Components' in self.vehicle_components:
114+
components = self.vehicle_components['Components']
115+
else:
116+
components = None
117+
if self.fw_version is None and components:
118+
version_str = components.get('Flight Controller', {}).get('Firmware', {}).get('Version', '')
119+
version_str = version_str.lstrip().split(' ')[0] if version_str else ''
120+
if re_match(r'^\d+\.\d+\.\d+$', version_str):
121+
self.fw_version = version_str
122+
else:
123+
logging_error(f"FW version string {version_str} on {self.vehicle_components_json_filename} is invalid")
124+
110125
# Read ArduPilot parameter documentation
111126
xml_dir = vehicle_dir if os_path.isdir(vehicle_dir) else os_path.dirname(os_path.realpath(vehicle_dir))
112127
vehicle_parm_subdir = {
@@ -129,7 +144,6 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
129144
self.doc_dict = create_doc_dict(xml_root, vehicle_type, TOOLTIP_MAX_LENGTH)
130145

131146
self.__extend_and_reformat_parameter_documentation_metadata()
132-
self.load_vehicle_components_json_data(vehicle_dir)
133147

134148
def rename_parameter_files(self):
135149
# Rename parameter files if some new files got added to the vehicle directory

0 commit comments

Comments
 (0)