Skip to content

Commit fe8f8ef

Browse files
committed
AMC-975: Allow to select supported vehicle and to skip telemetry radio as another system on the same connection
1 parent f576736 commit fe8f8ef

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import os
12+
import time
1213
from argparse import ArgumentParser
1314
from logging import debug as logging_debug
1415
from logging import error as logging_error
@@ -452,36 +453,52 @@ def __create_connection_with_retry( # pylint: disable=too-many-arguments, too-m
452453
retries=retries,
453454
progress_callback=progress_callback,
454455
)
455-
logging_debug(_("Waiting for MAVLink heartbeat"))
456+
logging_debug(_("Waiting for MAVLink heartbeats..."))
456457
if not self.master:
457458
msg = f"Failed to create mavlink connect to {self.comport.device}"
458459
raise ConnectionError(msg)
459-
m = self.master.wait_heartbeat(timeout=timeout)
460-
if m is None:
460+
# --- NEW: collect all vehicles detected within timeout ---
461+
start_time = time.time()
462+
detected_vehicles = {} # sysid -> last HEARTBEAT
463+
464+
while time.time() - start_time < timeout:
465+
m = self.master.recv_match(type="HEARTBEAT", blocking=False)
466+
if m is None:
467+
time.sleep(0.1)
468+
continue
469+
sysid = m.get_srcSystem()
470+
compid = m.get_srcComponent()
471+
detected_vehicles[(sysid, compid)] = m
472+
logging_debug(_("Detected vehicle %u:%u (autopilot=%u, type=%u)"), sysid, compid, m.autopilot, m.type)
473+
474+
if not detected_vehicles:
461475
return _("No MAVLink heartbeat received, connection failed.")
462-
self.info.set_system_id_and_component_id(m.get_srcSystem(), m.get_srcComponent())
463-
logging_debug(
464-
_("Connection established with systemID %d, componentID %d."), self.info.system_id, self.info.component_id
465-
)
466476

467-
self.info.set_autopilot(m.autopilot)
468-
if self.info.is_supported:
469-
msg = _("Autopilot type {self.info.autopilot}")
470-
logging_info(msg.format(**locals()))
471-
else:
472-
msg = _("Unsupported autopilot type {self.info.autopilot}")
473-
return msg.format(**locals())
477+
for (sysid, compid), m in detected_vehicles.items():
478+
self.info.set_system_id_and_component_id(sysid, compid)
479+
logging_debug(
480+
_("Connection established with systemID %d, componentID %d."), self.info.system_id, self.info.component_id
481+
)
482+
self.info.set_autopilot(m.autopilot)
483+
if self.info.is_supported:
484+
msg = _("Autopilot type {self.info.autopilot}")
485+
logging_info(msg.format(**locals()))
486+
else:
487+
msg = _("Unsupported autopilot type {self.info.autopilot}")
488+
# return msg.format(**locals())
489+
continue
474490

475-
self.info.set_type(m.type)
476-
msg = _("Vehicle type: {self.info.mav_type} running {self.info.vehicle_type} firmware")
477-
logging_info(msg.format(**locals()))
491+
self.info.set_type(m.type)
492+
msg = _("Vehicle type: {self.info.mav_type} running {self.info.vehicle_type} firmware")
493+
logging_info(msg.format(**locals()))
478494

479495
self.__request_banner()
480496
banner_msgs = self.__receive_banner_text()
481497

482498
self.__request_message(mavutil.mavlink.MAVLINK_MSG_ID_AUTOPILOT_VERSION)
483499
m = self.master.recv_match(type="AUTOPILOT_VERSION", blocking=True, timeout=timeout)
484500
return self.__process_autopilot_version(m, banner_msgs)
501+
485502
except (ConnectionError, SerialException, PermissionError, ConnectionRefusedError) as e:
486503
if log_errors:
487504
logging_warning(_("Connection failed: %s"), e)

0 commit comments

Comments
 (0)