Skip to content

Commit

Permalink
mavproxy_link.py: correct behaviour with old bindings
Browse files Browse the repository at this point in the history
some of these MAV_TYPEs are not known in older bindings, e.g. MAV_TYPE_BATTERY.  Avoid fatal errors here when we're working with older bindings
  • Loading branch information
peterbarker committed Sep 10, 2024
1 parent 6eaee8f commit f703d6c
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions MAVProxy/modules/mavproxy_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,35 @@ def emit_accumulated_statustext(self, key, id, pending):
self.status.last_apm_msg_time = time.time()
del self.status.statustexts_by_sysidcompid[key][id]

mav_types_which_are_not_vehicles = frozenset([
"MAV_TYPE_GCS",
"MAV_TYPE_ONBOARD_CONTROLLER",
"MAV_TYPE_GIMBAL",
"MAV_TYPE_ADSB",
"MAV_TYPE_CAMERA",
"MAV_TYPE_CHARGING_STATION",
"MAV_TYPE_SERVO",
"MAV_TYPE_ODID",
"MAV_TYPE_BATTERY",
"MAV_TYPE_LOG",
"MAV_TYPE_OSD",
"MAV_TYPE_IMU",
"MAV_TYPE_GPS",
"MAV_TYPE_WINCH",
])

mav_autopilots_which_are_not_vehicles = frozenset([
mavutil.mavlink.MAV_AUTOPILOT_INVALID,
mavutil.mavlink.MAV_AUTOPILOT_RESERVED,
])

component_ids_which_are_not_vehicles = frozenset([
mavutil.mavlink.MAV_COMP_ID_ADSB,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_1,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_2,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_3
])

def heartbeat_is_from_autopilot(self, m):
'''returns true if m is a HEARTBEAT (or HIGH_LATENCY2) message and
looks like it is from an actual autopilot rather than from e.g. a
Expand All @@ -622,42 +651,23 @@ def heartbeat_is_from_autopilot(self, m):
if mtype not in ['HEARTBEAT', 'HIGH_LATENCY2']:
return False

mav_autopilots_which_are_not_vehicles = frozenset([
mavutil.mavlink.MAV_AUTOPILOT_INVALID,
mavutil.mavlink.MAV_AUTOPILOT_RESERVED,
])
if m.autopilot in mav_autopilots_which_are_not_vehicles:
if m.autopilot in LinkModule.mav_autopilots_which_are_not_vehicles:
return False

# this is a rather bogus assumption - and might break people's
# setups. It should probably be removed in favour of trusting
# the MAV_TYPE field.
component_ids_which_are_not_vehicles = frozenset([
mavutil.mavlink.MAV_COMP_ID_ADSB,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_1,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_2,
mavutil.mavlink.MAV_COMP_ID_ODID_TXRX_3
])
if m.get_srcComponent() in component_ids_which_are_not_vehicles:
if m.get_srcComponent() in LinkModule.component_ids_which_are_not_vehicles:
return False

mav_types_which_are_not_vehicles = frozenset([
mavutil.mavlink.MAV_TYPE_GCS,
mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER,
mavutil.mavlink.MAV_TYPE_GIMBAL,
mavutil.mavlink.MAV_TYPE_ADSB,
mavutil.mavlink.MAV_TYPE_CAMERA,
mavutil.mavlink.MAV_TYPE_CHARGING_STATION,
mavutil.mavlink.MAV_TYPE_SERVO,
mavutil.mavlink.MAV_TYPE_ODID,
mavutil.mavlink.MAV_TYPE_BATTERY,
mavutil.mavlink.MAV_TYPE_LOG,
mavutil.mavlink.MAV_TYPE_OSD,
mavutil.mavlink.MAV_TYPE_IMU,
mavutil.mavlink.MAV_TYPE_GPS,
mavutil.mavlink.MAV_TYPE_WINCH,
])
if m.type in mav_types_which_are_not_vehicles:
found_mav_type = False
# not all of these are present in all versions of mavlink:
for t in LinkModule.mav_types_which_are_not_vehicles:
if getattr(mavutil.mavlink, t, None) is not None:
found_mav_type = True
break

if not found_mav_type:
return False

return True
Expand Down

0 comments on commit f703d6c

Please sign in to comment.