- changed status to open
signed value raw to physical error
If a signal is less than 64 bit width and it's physical value is negative,then calculate physical value just by
double Signal::rawToPhysicalValue(double rawValue)
{
/* physicalValue = rawValue * factor + offset */
return rawValue * factor + offset;
}
will result in a hugn value, which is not the real physical value.
The singed bits '1' filled in function
uint64_t Signal::decode(std::vector<uint8_t> & data)
are all recognized as valid value bits.
Hope reply,thank you!
Comments (12)
-
repo owner -
repo owner -
assigned issue to
-
assigned issue to
-
repo owner I'll check it on the weekend.
Currently I don't see the issue in the library, although the data types are different.
So filling in signed 1 bits for a negative value is correct for a uint64_t in decode, right? And doing calculations of positive/negative values with a double also seems correct in rawToPhysicalValue.
I guess, the issue is the cast in between from uint64_t to double. So how do you do this? Is the rawValue as double correct, after the cast?
-
I wrote my own rawToPhysicalValue function, in which i did the mandatory type conversion to rawValue according to the signal size and signed type before
return rawValue * factor + offset;
That's may not a nice solution, but i got the correct physical Value by doing it.
-
repo owner Ok, so you basically followed my suggestion. You wrote an own function that does signal size and signed type casts before passing it to rawToPhysicalValue?
-
repo owner So, is this still still a major bug, or can I downgrade this?
-
Yes, you can downgrade it. I only want to report my trouble in using this library. So, is that indeed a problem, or i am wrong using it ?
Thanks!
-
repo owner Yes, maybe it's wise to add some examples on how to do the type conversions properly.
Also the unit test (test_Signal.cpp) only shows the functions separately: decode/encode and rawToPhysicalValue/physicalToRawValue.
-
repo owner -
repo owner I extended the test_Signal.cpp to show how decode and rawToPhysicalValue works in combination. I used a union instead of an explicit cast to access the raw data with the right signedness. I hope that gives an appropriate example.
-
repo owner - changed status to resolved
Resolved with this commit: https://bitbucket.org/tobylorenz/vector_dbc/commits/969a7712251467a636b2be8e9b09a5f1793afeb2
-
Using a union is a better way, thank you!
- Log in to comment