Skip to content

Commit a5ede6f

Browse files
MichelleRospeterbarker
authored andcommitted
MAVExplorer: allow dump to work with instance ids, also update dump's usage text
1 parent 10b58b0 commit a5ede6f

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

MAVProxy/tools/MAVExplorer.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ def cmd_stats(args):
528528

529529
def cmd_dump(args):
530530
'''dump messages from log'''
531+
import re
531532
global xlimits
532533

533534
# understand --verbose to give as much information about message as possible
@@ -539,30 +540,59 @@ def cmd_dump(args):
539540
if len(args) > 0:
540541
wildcard = args[0]
541542
else:
542-
print("Usage: dump PATTERN")
543+
print("Usage: dump MSG1,MSG2[0]...")
543544
return
544545
mlog = mestate.mlog
545546
mlog.rewind()
546-
types = []
547-
for p in wildcard.split(','):
548-
for t in mlog.name_to_id.keys():
549-
if fnmatch.fnmatch(t, p):
550-
types.extend([t])
547+
types_inst = []
548+
types_filt_inst_id = []
549+
types_inst_no_id = []
550+
for t in wildcard.split(','):
551+
#remove instance id if it exists
552+
t2 = re.sub(r'\[.*\]', '', t)
553+
types_filt_inst_id.extend([t2])
554+
if t.find('[') != -1:
555+
# add message with instance id to instances list
556+
types_inst.extend([t])
557+
types_inst_no_id.extend([t2])
558+
559+
#begin first dump msg on new line
560+
print("")
561+
ext = False
551562
while True:
552-
msg = mlog.recv_match(type=types, condition=mestate.settings.condition)
563+
msg = mlog.recv_match(type=types_filt_inst_id, condition=mestate.settings.condition)
553564
if msg is None:
554565
break
555566
in_range = xlimits.timestamp_in_range(msg._timestamp)
556567
if in_range < 0:
557568
continue
558569
if in_range > 0:
559570
continue
571+
572+
instid = None
573+
if msg.get_type() in types_inst_no_id:
574+
if msg.fmt.instance_field is not None:
575+
idx = types_inst_no_id.index(msg.get_type())
576+
type_inst = types_inst[idx]
577+
instid = re.sub(r'.*\[', '', type_inst)
578+
instid = re.sub(r'\]', '', instid)
579+
else:
580+
print(f"{msg.get_type()} is not instance.")
581+
ext = True
582+
if ext:
583+
break
584+
560585
if verbose and "pymavlink.dialects" in str(type(msg)):
561586
mavutil.dump_message_verbose(sys.stdout, msg)
562587
elif verbose and hasattr(msg,"dump_verbose"):
563588
msg.dump_verbose(sys.stdout)
564589
else:
565-
print("%s %s" % (timestring(msg), msg))
590+
if instid is not None:
591+
inst = getattr(msg, msg.fmt.instance_field, None)
592+
if str(inst) == instid:
593+
print("%s %s" % (timestring(msg), msg))
594+
else:
595+
print("%s %s" % (timestring(msg), msg))
566596
mlog.rewind()
567597

568598
mfit_tool = None

0 commit comments

Comments
 (0)