Repository navigation
When parsing DBC, make sure there are no unused VAL_ and SIG_VALTYPE_ entries - #661
Conversation
Pull Request Test Coverage Report for Build 8840594508Details
💛 - Coveralls |
|
@andlaus do you want me to rebase this on top of master to pick up the linter fix that you just merged? |
|
I'm not sure about this. I do not see the benefit of raising an exception on unused values. If CANdb++ can open these files, then they are valid and we should accept them. |
that would probably a good idea... |
CANDB++ fails to open these files (and prints a very unhelpful error message). Current cantools (39.4.5) accepts these bogus/questionable files. This PR brings cantools into closer alignment with the CANDB++ parser. |
|
(Oops, didn't mean to close this PR!) |
|
And this latest force-push should fix the ruff linter error i introduced. 🙄 Sorry for all the churn... |
|
hm, I wonder about the use case of this. Is it if the DBC was written by an external tool (not using cantools) and the result is only read by a script based on cantools? if yes, I think there's no harm in cantools accepting slightly incorrect files. (The developers of the external tool should occasionally check if its results can be loaded by candb++...) |
The use case is validating a DBC. I am writing software to communicate over CAN with a device made by a different team (or rather, i was 2.5 years ago when i opened this PR). The team that made the device publishes a DBC to describe their packet structure. I don't know how they wrote their DBC, or what tools/editors they used, all i have is their DBC. Their DBC contained a number of errors, and i wanted a tool to help me find these errors so i could report them back to the producer of the DBC for them to fix. Since i was already using cantools in my project, and since cantools had already found a number of other errors in the DBC, this change seemed in scope to me. If this is not a use case you want cantools to support then please feel free to close this PR and discard. |
|
okay. If you are confident that with this feature cantools can still load any DBC which is accepted by candb++, I'll merge the PR after it has been rebased on the latest master and a unit test for the new code paths has been added. |
|
I make no general claims about the relationship between this branch and the candb++ parser, beyond the spot-check shown above. In that case, with the two DBC files i tested, this PR makes cantools behave more like the candb++ parser. |
|
I think we can risk it. If we get bug reports about DBCs not loading anymore, it should be reverted rather quickly... (rebasing it on master and a unit test is required for merging, though.) |
|
@SebKuzminsky: Any appetite for rebasing this on the current master? (if not, please close the PR.) |
8cd4c5c to
0509b95
Compare
|
Rebased on top of master, added tests. Happy to make any changes requested. |
hm, github still says that there are merge conflicts. did you pull your master to the latest version before rebasing? |
|
(there was a pretty big cleanup of the DBC code recently, though it did not change fundamentally.) |
|
Oops, you're right, i used an older |
I came across a DBC in the wild which contained a VAL_ line that specified the wrong frame ID for its signal. cantools accepted the DBC file, but failed to interpret the signal correctly. This commit tries to detect this DBC error by removing VAL_ choices as they are used by Messages, and raising an exception if any choices remain after parsing the entire DBC.
I came across a DBC in the wild which contained a SIG_VALTYPE_ line that specified the wrong frame ID for its signal. cantools accepted the DBC file, but failed to interpret the signal correctly. This commit tries to detect this DBC error by removing SIG_VALTYPE_ choices from the signal_types dict as they are used by Messages, and raising an exception if any entries remain after parsing the entire DBC.
0509b95 to
01d8240
Compare
|
This version should be good, let me know if you want any further changes. |
|
I'm happy now. Let's jump the gun and take it back if we get complaints. Thanks for your patience. |



This makes DBC parsing a little more strict, rejecting DBCs with some common(?) errors.