Mavdumplog: Handle TLog files saved with .log extension #900
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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