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

_parse_container does not receive proper data to process #763

Closed
cucdat opened this issue Feb 6, 2020 · 15 comments · Fixed by #765
Closed

_parse_container does not receive proper data to process #763

cucdat opened this issue Feb 6, 2020 · 15 comments · Fixed by #765
Assignees
Labels
bug file-io about reading & writing to files

Comments

@cucdat
Copy link

cucdat commented Feb 6, 2020

Hi,

I am trying to use this tool to parse some blf files but there is one of them throwing me the Parsing Error.
I am tried to fix it by updating the source as well as relog it with different CANalyzer Version but it cannot work so I post it here to ask for your support.


Issue Description: The data given to _parse_container does not start with the proper signature (LOBJ), as a consequence, the _parse_data raised the BLFParseError.
Annotation

Environment:

  • Python 3.8 64bit
  • python-can: dev branch

If you have any idea to figure out the root cause of this, kindly let me know. I will appreciate it so much.
I can share with you the blf for debugging via email in case you need it.

@christiansandberg
Copy link
Collaborator

It would be interesting to know which obj_type came before the exception. There is a problem with blf files in that different object types are padded differently. One person had issues with FlexRay data in the log.

@christiansandberg
Copy link
Collaborator

It’s also normal that containers do not start with LOBJ. Objects can be split up in two containers since containers usually have a fixed size.

@cucdat
Copy link
Author

cucdat commented Feb 6, 2020

It is not the data of container actually, it is the data that will transfer to _parse_data. I will check what is the object type comes before this exception then get back to you later.

Usually, this tool works perfectly with other blf files, even up to hours, but only there are some files coming from specific PC/Vector Application have this issue.

@cucdat
Copy link
Author

cucdat commented Feb 7, 2020

Hi,

Thanks for your hint!
I tried to trace back to the root cause that made the unpacking exception.
First, the object is just a normal CAN 2 Message object, so I do not think it will make the exception here

image

The real root cause seems to be the buffer size required for Struct.unpack_from is bigger than the buffer size that we defined.
Actual Size: 131106
Required: 131120
image

By the way, the uncompressed when I unpacked the Container is 131072 = exact 128kb.
image

Shall we change this buffer size a little bit bigger to handle this case and how should we change it? (Where should we put the fixed code to not affect other functions)
It seems like we should check the buffer size and resize it to a proper one before unpacking
https://docs.python.org/3.0/library/struct.html#struct.unpack_from

@christiansandberg
Copy link
Collaborator

I think I know what the problem is. I did some optimizations recently in develop where I skipped checking if the object is split up in the next container and relies on struct raising an error if that’s the case. With CanMessage2 however we only read the first part of it so it could succeed even if the rest of the object is missing.

So I think the latest released version should work for you. I’ll fix it in the coming days.

@christiansandberg christiansandberg self-assigned this Feb 7, 2020
@christiansandberg christiansandberg added bug file-io about reading & writing to files labels Feb 7, 2020
@cucdat
Copy link
Author

cucdat commented Feb 7, 2020

That would be perfect.
Just left me a line when you fixed it, I will be happy to be the first one to test it.

By the way, can you explain why don't we need the tail of the CAN2? Doesn't it contain data?

Thank you so much.

@christiansandberg
Copy link
Collaborator

The rest of the data is not anything we use in our message class.

@duracell013
Copy link

Hello,

I've only been using this module (version 3.3.2) for a day, but I'm also facing some BLFParseError with some files due to header issues. I've modified the blf.py to print the header here.

In the console output, it seems like the file position is incorrect at the start of the iteration. In the exemple below, I think the position should be one byte earlier as we can clearly see the end of "LOBJ".

image

In another example, the position is "late" and I only see the end of "LOBJ".

For info, I'm using genuine BLF files generated by CANanlyzer.
Please, let me know if you need an example file.

Thank you for your help!
Stéphan

@cucdat
Copy link
Author

cucdat commented Feb 7, 2020

Hi Duracell,
Use the dev branch might fix this issue.
I used to encounter this with 3.3.2 but not anymore with the dev branch.

@christiansandberg
Copy link
Collaborator

This makes me slightly more confused. Any example log files would be great! You can email me at christiansandberg at me dot com if you don’t want to share them publicly.

@christiansandberg
Copy link
Collaborator

@duracell013, I just realized a bug fix for CAN-FD messages has not been released yet so you can try develop instead.

@duracell013
Copy link

@christiansandberg I've emailed you a sample file. I have tested the develop branch without success (though I'm not 100% sure the module installation from the ZIP file was correct).

Thank you for your help!

@christiansandberg
Copy link
Collaborator

I've made a fix that seems to work.

pip install https://github.com/hardbyte/python-can/archive/bugfix/763-fix-blf-reader.zip

@duracell013
Copy link

@christiansandberg Thank you so much for looking into it so quickly! That seems to work perfectly!

@cucdat
Copy link
Author

cucdat commented Feb 12, 2020

Sorry for my late feedback.

I have tested this on the blf files that I had problems with and it worked without any Parsing issues.
Also tested on other working files to check if it is compatible or not and found no issues.

The solution seems to work perfectly.

Thank you a lot for your support @christiansandberg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug file-io about reading & writing to files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants