Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mavdumplog: Handle TLog files saved with .log extension #900

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shancock884
Copy link
Contributor

@shancock884 shancock884 commented Jan 9, 2024

If a binary file is passed to the DFReader_is_text_log function, there is a good chance that it will throw an exception, as it attempts to interpret the binary data as a UTF8 string. It should simply return false to say "No, its not a DF Text log". This then allows the TLog reader to handle the file instead.

I was bitten by this when I did a file-naming mistake of my own, but then spotted that issue #710 mentioned the same thing, so thought I would put the proposed fix forward.

The main part of the fix is to simply catch the UnicodeDecodeError exception in DFReader_is_text_log, and return false, as proposed by @booo in the issue description.

A secondary part is that mavlogdump makes some assumptions about the file type based on the file extension, which may not hold true, if (for example) .log extension is used for a Mavlink/Tlog file.
One example of this is that 'dump --verbose' previously only did a verbose dump with a .tlog file extension - even if the file really IS a tlog with a different extension.
So, I am proposing to use the class type returned by mavutil.mavlink_connection instead to determine the type of the file being dumped.

I also thought that the summary text you get when typing 'mavlink.py -h' was not very clear or complete, so have updated it.

I tested this by downloading one of the tlogs from Audupilot autotest, renaming as .log, and running it through "mavlogdump" and "mavlogdump --verbose". Both work without crashing and generating the correct output.

fix #710

tools/mavlogdump.py Outdated Show resolved Hide resolved
mlog_type = str(type(mlog))
isbin = "DFReader_binary" in mlog_type
islog = "DFReader_text" in mlog_type # NOTE: "islog" does not mean a tlog
istlog = "mavmmaplog" in mlog_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only ever be a dataflash log - if you look at the class you can see it's a DFLOG parser.

So something very weird is going on here :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mavlogdump handles either DF binary, DF text or Mavlink/Tlog format files, and the class of the variable returned by mlog = mavutil.mavlink_connection(...) will reflect this.
I added a print on these flags during testing with all 3 file types (including the TLog named both as .log and .tlog), and the right flag gets set.

@shancock884 shancock884 force-pushed the iss710-is-text-log branch 2 times, most recently from 413415e to ecbe7c1 Compare January 11, 2024 08:25
DFReader: is_text_log should return false if binary

Mavlogdump: use class type not file ext to determine input format, to allow .log to be either text or tlog
Update description text in mavlogdump file header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mavlogdump fails on tlog with .log suffix
2 participants