Skip to content

Commit

Permalink
mavproxy_console.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 Oct 6, 2024
1 parent 0274c57 commit 3c240f4
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions MAVProxy/modules/mavproxy_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from MAVProxy.modules.lib import wxsettings
from MAVProxy.modules.lib.mp_menu import *

green = (0, 128, 0)

class DisplayItem:
def __init__(self, fmt, expression, row):
self.expression = expression.strip('"\'')
Expand Down Expand Up @@ -350,7 +352,7 @@ def handle_gps_raw(self, msg):
nsats = msg.satellites_visible
fix_type = msg.fix_type
if fix_type >= 3:
self.console.set_status(field, '%s OK%s (%u)' % (prefix, fix_type, nsats), fg='green')
self.console.set_status(field, '%s OK%s (%u)' % (prefix, fix_type, nsats), fg=green)
else:
self.console.set_status(field, '%s %u (%u)' % (prefix, fix_type, nsats), fg='red')
if type == 'GPS_RAW_INT':
Expand Down Expand Up @@ -465,9 +467,9 @@ def handle_sys_status(self, msg):
elif not healthy:
fg = 'red'
else:
fg = 'green'
fg = green
# for terrain show yellow if still loading
if s == 'TERR' and fg == 'green' and master.field('TERRAIN_REPORT', 'pending', 0) != 0:
if s == 'TERR' and fg == green and master.field('TERRAIN_REPORT', 'pending', 0) != 0:
fg = 'yellow'
self.console.set_status(s, s, fg=fg)
announce_unhealthy = {
Expand Down Expand Up @@ -516,19 +518,19 @@ def handle_ekf_status_report(self, msg):
elif highest >= 0.5:
fg = 'orange'
else:
fg = 'green'
fg = green
self.console.set_status('EKF', 'EKF', fg=fg)

def handle_power_status(self, msg):
if msg.Vcc >= 4600 and msg.Vcc <= 5300:
fg = 'green'
fg = green
else:
fg = 'red'
self.console.set_status('Vcc', 'Vcc %.2f' % (msg.Vcc * 0.001), fg=fg)
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_CHANGED:
fg = 'red'
else:
fg = 'green'
fg = green
status = 'PWR:'
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_USB_CONNECTED:
status += 'U'
Expand All @@ -541,7 +543,7 @@ def handle_power_status(self, msg):
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_PERIPH_HIPOWER_OVERCURRENT:
status += 'O2'
self.console.set_status('PWR', status, fg=fg)
self.console.set_status('Srv', 'Srv %.2f' % (msg.Vservo*0.001), fg='green')
self.console.set_status('Srv', 'Srv %.2f' % (msg.Vservo*0.001), fg=green)

# this method is called on receipt of any HEARTBEAT so long as it
# comes from the device we are interested in
Expand All @@ -557,7 +559,7 @@ def handle_heartbeat(self, msg):
if len(self.vehicle_list) > 1:
self.console.set_status('SysID', 'Sys:%u' % sysid, fg='blue')
if self.master.motors_armed():
arm_colour = 'green'
arm_colour = green
else:
arm_colour = 'red'
armstring = 'ARM'
Expand Down Expand Up @@ -692,26 +694,26 @@ def handle_high_latency2(self, msg):
if failed:
fg = 'red'
else:
fg = 'green'
fg = green
self.console.set_status(s, s, fg=fg)

# do the remaining non-standard system mappings
fence_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GEOFENCE) == mavutil.mavlink.HL_FAILURE_FLAG_GEOFENCE)
if fence_failed:
fg = 'red'
else:
fg = 'green'
fg = green
self.console.set_status('Fence', 'FEN', fg=fg)
gps_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GPS) == mavutil.mavlink.HL_FAILURE_FLAG_GPS)
if gps_failed:
self.console.set_status('GPS', 'GPS FAILED', fg='red')
else:
self.console.set_status('GPS', 'GPS OK', fg='green')
self.console.set_status('GPS', 'GPS OK', fg=green)
batt_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GPS) == mavutil.mavlink.HL_FAILURE_FLAG_BATTERY)
if batt_failed:
self.console.set_status('PWR', 'PWR FAILED', fg='red')
else:
self.console.set_status('PWR', 'PWR OK', fg='green')
self.console.set_status('PWR', 'PWR OK', fg=green)

# update user-added console entries; called after a mavlink packet
# is received:
Expand Down

0 comments on commit 3c240f4

Please sign in to comment.