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

canmatrix.py --> decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>] #773

Closed
daestx opened this issue Feb 23, 2024 · 7 comments
Assignees

Comments

@daestx
Copy link

daestx commented Feb 23, 2024

I have an issue with doing a diff on two DBC files. I get following debug info:

File "canmatrix\formats_init_.py", line 79, in loadp_flat
File "canmatrix\formats_init_.py", line 71, in loadp
File "canmatrix\formats_init_.py", line 90, in load
File "canmatrix\formats\dbc.py", line 960, in load
File "canmatrix\canmatrix.py", line 450, in phys2raw
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]

coming from this line
raw_value = (self.float_factory(value) - self.float_factory(self.offset)) / self.float_factory(self.factor)

obviously, division by 0 is not handled correctly.

I changed the code as workaround

if self.factor == 0:
    self.factor = 1

raw_value = (self.float_factory(value) - self.float_factory(self.offset)) / self.float_factory(self.factor)

please check if there is a better solution

@daestx
Copy link
Author

daestx commented Feb 23, 2024

issue #766 looks similar

@daestx daestx changed the title canmatrix.py canmatrix.py --> decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>] Feb 23, 2024
@ebroecker ebroecker self-assigned this Feb 25, 2024
@ebroecker
Copy link
Owner

Some Idea:

canmatrix for now only uses COMPU-INTERNAL-TO-PHYS compu-methods,

Maybe your ARXML uses COMPU-PHYS-TO-INTERNAL.

@daestx
Copy link
Author

daestx commented Feb 28, 2024

I used dbc file as input not an ARXML

@ebroecker
Copy link
Owner

Oh sorry you are right...

Do you have a chance to check the dbc itself?
A factor of 0 does not make sense at all. I just want to know if it's a problem with canmatrix or with the dbc file...

@daestx
Copy link
Author

daestx commented Mar 4, 2024

So, I checked the DBC file now and identified, that the DBC is buggy. According the documentation in https://www.influxtechnology.com/post/understanding-can-dbc

image

So, I presume this definition of a DBC file I received is wrong, right?

image

So the question to me is if such an issue shall be handled in the library. I don't know as well if the scaling factor shall not be 0. So far, I didn't find any CANdbc file spec. But what I see from Vectors CANdb++ tool, the factor for the given signal was interpreted as 1.

@ebroecker
Copy link
Owner

ebroecker commented Mar 4, 2024

Hi @daestx

thanks for your analysis.
Yes the dbc defines the scale (=factor) to zero which is nonsense.
Seems so, that candb++ has some plausibility-check here to get around with a scale of 0.
So maybe canmatrix should do the same...

Maybe I'll add some warning if scale is 0 and set it to 1

@ebroecker
Copy link
Owner

should be merged

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

No branches or pull requests

2 participants