Skip to content

Commit 2f80cda

Browse files
committed
mavproxy_console.py: correct behaviour with old bindings
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
1 parent 71b64ba commit 2f80cda

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Diff for: MAVProxy/modules/mavproxy_console.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from MAVProxy.modules.lib import wxsettings
1717
from MAVProxy.modules.lib.mp_menu import *
1818

19+
green = (0, 128, 0)
20+
1921
class DisplayItem:
2022
def __init__(self, fmt, expression, row):
2123
self.expression = expression.strip('"\'')
@@ -350,7 +352,7 @@ def handle_gps_raw(self, msg):
350352
nsats = msg.satellites_visible
351353
fix_type = msg.fix_type
352354
if fix_type >= 3:
353-
self.console.set_status(field, '%s OK%s (%u)' % (prefix, fix_type, nsats), fg='green')
355+
self.console.set_status(field, '%s OK%s (%u)' % (prefix, fix_type, nsats), fg=green)
354356
else:
355357
self.console.set_status(field, '%s %u (%u)' % (prefix, fix_type, nsats), fg='red')
356358
if type == 'GPS_RAW_INT':
@@ -465,9 +467,9 @@ def handle_sys_status(self, msg):
465467
elif not healthy:
466468
fg = 'red'
467469
else:
468-
fg = 'green'
470+
fg = green
469471
# for terrain show yellow if still loading
470-
if s == 'TERR' and fg == 'green' and master.field('TERRAIN_REPORT', 'pending', 0) != 0:
472+
if s == 'TERR' and fg == green and master.field('TERRAIN_REPORT', 'pending', 0) != 0:
471473
fg = 'yellow'
472474
self.console.set_status(s, s, fg=fg)
473475
announce_unhealthy = {
@@ -516,19 +518,19 @@ def handle_ekf_status_report(self, msg):
516518
elif highest >= 0.5:
517519
fg = 'orange'
518520
else:
519-
fg = 'green'
521+
fg = green
520522
self.console.set_status('EKF', 'EKF', fg=fg)
521523

522524
def handle_power_status(self, msg):
523525
if msg.Vcc >= 4600 and msg.Vcc <= 5300:
524-
fg = 'green'
526+
fg = green
525527
else:
526528
fg = 'red'
527529
self.console.set_status('Vcc', 'Vcc %.2f' % (msg.Vcc * 0.001), fg=fg)
528530
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_CHANGED:
529531
fg = 'red'
530532
else:
531-
fg = 'green'
533+
fg = green
532534
status = 'PWR:'
533535
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_USB_CONNECTED:
534536
status += 'U'
@@ -541,7 +543,7 @@ def handle_power_status(self, msg):
541543
if msg.flags & mavutil.mavlink.MAV_POWER_STATUS_PERIPH_HIPOWER_OVERCURRENT:
542544
status += 'O2'
543545
self.console.set_status('PWR', status, fg=fg)
544-
self.console.set_status('Srv', 'Srv %.2f' % (msg.Vservo*0.001), fg='green')
546+
self.console.set_status('Srv', 'Srv %.2f' % (msg.Vservo*0.001), fg=green)
545547

546548
# this method is called on receipt of any HEARTBEAT so long as it
547549
# comes from the device we are interested in
@@ -557,7 +559,7 @@ def handle_heartbeat(self, msg):
557559
if len(self.vehicle_list) > 1:
558560
self.console.set_status('SysID', 'Sys:%u' % sysid, fg='blue')
559561
if self.master.motors_armed():
560-
arm_colour = 'green'
562+
arm_colour = green
561563
else:
562564
arm_colour = 'red'
563565
armstring = 'ARM'
@@ -692,26 +694,26 @@ def handle_high_latency2(self, msg):
692694
if failed:
693695
fg = 'red'
694696
else:
695-
fg = 'green'
697+
fg = green
696698
self.console.set_status(s, s, fg=fg)
697699

698700
# do the remaining non-standard system mappings
699701
fence_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GEOFENCE) == mavutil.mavlink.HL_FAILURE_FLAG_GEOFENCE)
700702
if fence_failed:
701703
fg = 'red'
702704
else:
703-
fg = 'green'
705+
fg = green
704706
self.console.set_status('Fence', 'FEN', fg=fg)
705707
gps_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GPS) == mavutil.mavlink.HL_FAILURE_FLAG_GPS)
706708
if gps_failed:
707709
self.console.set_status('GPS', 'GPS FAILED', fg='red')
708710
else:
709-
self.console.set_status('GPS', 'GPS OK', fg='green')
711+
self.console.set_status('GPS', 'GPS OK', fg=green)
710712
batt_failed = ((msg.failure_flags & mavutil.mavlink.HL_FAILURE_FLAG_GPS) == mavutil.mavlink.HL_FAILURE_FLAG_BATTERY)
711713
if batt_failed:
712714
self.console.set_status('PWR', 'PWR FAILED', fg='red')
713715
else:
714-
self.console.set_status('PWR', 'PWR OK', fg='green')
716+
self.console.set_status('PWR', 'PWR OK', fg=green)
715717

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

0 commit comments

Comments
 (0)