Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/json_from_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ def process(path):
elif 'Sub' in folder.name:
vehicle_type = 'ArduSub'
vehicle_json_type = 'Sub'
elif 'Tracker' in folder.name:
vehicle_type = 'AntennaTracker'
vehicle_json_type = 'Tracker'
elif 'Blimp' in folder.name:
vehicle_type = 'Blimp'
vehicle_json_type = 'Blimp'
elif 'AP_Periph' in folder.name:
vehicle_type = 'AP_Periph'
vehicle_json_type = 'AP_Periph'

xml = folder / 'apm.pdef.xml'
json_path = folder / 'apm.pdef.json'
Expand Down
23 changes: 20 additions & 3 deletions scripts/run_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ class Groundskeeper:
temp_folder = tempfile.mkdtemp()

valid_name_map = {
'AntennaTracker': 'Tracker',
'AP_Periph': 'AP_Periph',
'APMrover2': 'Rover',
'ArduCopter': 'Copter',
'ArduPlane': 'Plane',
'ArduSub': 'Sub',
'Blimp': 'Blimp',
'Copter': 'Copter',
'Plane': 'Plane',
'Rover': 'Rover',
'Sub': 'Sub',
'Tracker': 'Tracker'
}

def __init__(self):
Expand All @@ -45,7 +50,19 @@ def get_version_for_tag(self, tag) -> Tuple[int, int]:
# try to read <vehicle>/version.h
path1 = Path(f'{self.repository_path}/{tag["matches"]["name"]}/version.h')
path2 = Path(f'{self.repository_path}/{self.valid_name_map[tag["matches"]["name"]]}/version.h')
file = path1 if path1.exists() else path2
path3 = Path(f'{self.repository_path}/Tools/{tag["matches"]["name"]}/version.h')
path4 = Path(f'{self.repository_path}/Tools/{self.valid_name_map[tag["matches"]["name"]]}/version.h')
if path1.exists():
file = path1
elif path2.exists():
file = path2
elif path3.exists():
file = path3
elif path4.exists():
file = path4
else:
raise FileNotFoundError(f'No version.h found for tag {tag["matches"]["name"]}')
Comment on lines 51 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path1 = Path(f'{self.repository_path}/{tag["matches"]["name"]}/version.h')
path2 = Path(f'{self.repository_path}/{self.valid_name_map[tag["matches"]["name"]]}/version.h')
file = path1 if path1.exists() else path2
path3 = Path(f'{self.repository_path}/Tools/{tag["matches"]["name"]}/version.h')
path4 = Path(f'{self.repository_path}/Tools/{self.valid_name_map[tag["matches"]["name"]]}/version.h')
if path1.exists():
file = path1
elif path2.exists():
file = path2
elif path3.exists():
file = path3
elif path4.exists():
file = path4
else:
raise FileNotFoundError(f'No version.h found for tag {tag["matches"]["name"]}')
potential_paths = (
f'{self.repository_path}/{tag["matches"]["name"]}/version.h',
f'{self.repository_path}/{self.valid_name_map[tag["matches"]["name"]]}/version.h',
f'{self.repository_path}/Tools/{tag["matches"]["name"]}/version.h',
f'{self.repository_path}/Tools/{self.valid_name_map[tag["matches"]["name"]]}/version.h',
)
if (file := next((p for p in potential_paths if Path(p).exists()), None)) is None:
raise FileNotFoundError(f'No version.h found for tag {tag["matches"]["name"]}')

This isn't particularly necessary, but it does make it easier to add additional options in future...


with open(file=file, mode='r') as version_file:
content = version_file.read()
match = re.search(r'#define\s+FW_MAJOR\s+(\d+)', content)
Expand Down Expand Up @@ -126,7 +143,7 @@ def run(self):

print(f'Processing: {folder_name}..')
# Old versions are not mantained and generation of the files is not fully supported
if tag_major_version < 4:
if vehicle_type != "AP_Periph" and tag_major_version < 4:
print("Ignoring old version")
continue

Expand Down Expand Up @@ -157,7 +174,7 @@ def run(self):
os.remove(data)

# Run MAVLink messages parser
vehicle = f'{"Ardu" if vehicle_type != "Rover" else ""}{vehicle_type}'
vehicle = f'{"Ardu" if vehicle_type in ["Copter", "Plane", "Sub"] else ""}{vehicle_type}'
Copy link
Contributor

@ES-Alexander ES-Alexander Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
vehicle = f'{"Ardu" if vehicle_type in ["Copter", "Plane", "Sub"] else ""}{vehicle_type}'
prefix = 'Ardu' if vehicle_type in ('Copter', 'Plane', 'Sub') else 'Antenna' if vehicle_type == 'Tracker' else ''
vehicle = f'{prefix}{vehicle_type}'

try:
# The parser expects to be run from its normal place in the repository
script_folder = f'{self.repository_path}/Tools/scripts/'
Expand Down