I’m trying to parse following data from a CAN DB (.dbc) file but can’t figure out how to parse them in the XML: RearTorque: 24|13@1- (0.25,0) [-1024|1023.75] “NM”
So I need a signed value of 13 bits starting from the 24th (or 4th Byte) in the input value itself.
I tried with this value and it’s working for Positive values but NOT working for negative ones.
Maybe it’s not working because it gets the full length of 2 bytes (instead of 13 bits) and negative values got other bits which are part of other data.
I tried also with length=1 but then the values are not correct either.
Am I missing something and how exactly should I extract the 13 bits value?
Perhaps in your condition you just need to compare the 24th bit and the 13th bit?
Then you should output both of these bits to different data separately and act through triggers!
In any case, “13-bit number sounds like not very good”)))
And even if you follow your own logic, then you need not:
startbit = 24, bitcount = 13 … this is not …
You will get the decimal value of 13 bits combined …
8191 DEC -max
may be!
The OEM decided to use 13 bit number so I guess he had some ideas in mind for optimization of the can message. Anyway I’m asking how to parse the value with the XML in RealDash.
Here are two examples:
Message is - 21 F9 0B 8D 03 00 20 AE
RearTorque: 227.25 NM
For positive values it’s working - Data in HEX is 38D → DEC 909 → 909 * 0.25 → 227.25
Message is - 21 F9 0B E6 1D 00 20 AE
RearTorque: -134.5 NM
For negative values it’s not working - Data in HEX is 1DE6 → not a negative value but big int value because it’s getting the last 3 bits from 1D which are zeroes (0001 1101)
So I need a way in the XML to tell RealDash to parse only 13bits signed integer, not 16bits.
Any idea how to do that? (extract -134.5 from E6 1D)
the more so that the condition contains the “|”
What is a bitwise operator
it does not work with integers, let alone decimal numbers.
Let’s ask JANI if he understands more in this abracadabr …
This is a tough one. I assume that the MSB ‘sign’ marking value as negative is in 13th bit? This would require some fancy math to move the MSB into 16th bit to be able to handle it as negative value. But to get a value of -134.5 from 0x1DE6 (little endian) is beyond my understanding.
I think that your data is tritely widened with a key like “xor” or something similar! So there is no point in continuing the topic! Only those who know the meaning of the key will decrypt them! So that’s it!
I was so with the values for the diagnostic device “Launch” fought uselessly))))
I found the conversion itself and it’s standard - Two’s complement conversion
Check it yourself here: https://www.exploringbinary.com/twos-complement-converter/
With Hex - 1DE6 (1110111100110) and option 13bit in the calculator
I got -538 as decimal and if we apply the factor on this value of 0.25 → we are getting exactly -134.5
So can we calculate values from two’s complement with the xml?
The more I read about it the more I see it commonly used in vehicle, Gyro or other communication interfaces.
Here is how it works:
Let’s say we have data 1DE6 and we know it’s 13bit two’s complement representation of a negative value.
In binary data is 1110111100110 which means that 13bit is 1 → so our value is negative and we have to invert the binary numbers, add 1 in order to get the value and multiply by -1.
I’m converting it by hand for now because I need only few signals but it will be nice if there is some kind of converter although it should be something very specific in order to support RealDashCAN XMLs.