18
18
from shutil import copytree as shutil_copytree
19
19
20
20
from re import compile as re_compile
21
+ from re import match as re_match
21
22
22
23
# from sys import exit as sys_exit
23
24
from logging import debug as logging_debug
@@ -107,6 +108,20 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
107
108
if not self .file_parameters :
108
109
return # No files intermediate parameters files found, no need to continue, the rest needs them
109
110
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
+
110
125
# Read ArduPilot parameter documentation
111
126
xml_dir = vehicle_dir if os_path .isdir (vehicle_dir ) else os_path .dirname (os_path .realpath (vehicle_dir ))
112
127
vehicle_parm_subdir = {
@@ -129,7 +144,6 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
129
144
self .doc_dict = create_doc_dict (xml_root , vehicle_type , TOOLTIP_MAX_LENGTH )
130
145
131
146
self .__extend_and_reformat_parameter_documentation_metadata ()
132
- self .load_vehicle_components_json_data (vehicle_dir )
133
147
134
148
def rename_parameter_files (self ):
135
149
# Rename parameter files if some new files got added to the vehicle directory
0 commit comments