Skip to content

Commit c3c97f4

Browse files
committed
mavflightview.py: allow individual instances of GPS/VEH messages to be plotted
"map GPS" will give you all GPSs "map GPS[0]" will give you just the first instance "map GPS[1] GPS[2]" will give you just the 2nd and third instances this should also extend the ability to map instance positions to other messages which have instance fields
1 parent e6f5c50 commit c3c97f4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

MAVProxy/tools/mavflightview.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,21 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
287287
types.extend(['AHR2', 'AHRS2', 'GPS'])
288288

289289
# handle forms like GPS[0], mapping to GPS for recv_match_types
290-
for i in range(len(types)):
291-
bracket = types[i].find('[')
292-
if bracket != -1:
293-
types[i] = types[i][:bracket]
294290

291+
# it may be possible to pass conditions in to recv_match_types,
292+
# but for now we filter to desired instances later.
293+
want_instances = {}
295294
recv_match_types = types[:]
295+
for i in range(len(recv_match_types)):
296+
match = re.match('(?P<name>.*)\[(?P<instancenum>[^\]+])\]', recv_match_types[i])
297+
if match is not None:
298+
name = match.group("name")
299+
number = match.group("instancenum")
300+
if name not in want_instances:
301+
want_instances[name] = set()
302+
want_instances[name].add(number)
303+
recv_match_types[i] = name
304+
296305
colour_source = getattr(options, "colour_source")
297306
re_caps = re.compile('[A-Z_][A-Z0-9_]+')
298307

@@ -365,17 +374,28 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
365374
except Exception:
366375
pass
367376
continue
377+
368378
if not mlog.check_condition(options.condition):
369379
continue
370380
if options.mode is not None and mlog.flightmode.lower() != options.mode.lower():
371381
continue
372382

373-
if not type in types:
383+
if not type in types and type not in want_instances:
374384
# may only be present for colour-source expressions to work
375385
continue
376386

377-
if type in ['GPS','VEH'] and hasattr(m,'I'):
378-
type = '%s[%u]' % (type, m.I)
387+
try:
388+
# remember that "m" here might be a mavlink message.
389+
instance_field = m.fmt.instance_field
390+
m_instance_field_value = eval(f"m.{instance_field}")
391+
if (type in want_instances and
392+
str(m_instance_field_value) not in want_instances[type]
393+
):
394+
continue
395+
396+
type = '%s[%u]' % (type, m_instance_field_value)
397+
except Exception:
398+
pass
379399

380400
if not all_false and len(flightmode_selections) > 0 and idx < len(options._flightmodes) and m._timestamp >= options._flightmodes[idx][2]:
381401
idx += 1

0 commit comments

Comments
 (0)