DBC file to XML conversion

Hello,

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?

Regards

isn’t this bitwise (logical) addition?
disjunction!

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!

conversion = “(V * 0.25)*(-1)”

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 sequence that you specified cannot be equal to such a small number!
Because your number translated into DEC = 2448000955409506478

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 …

:question:

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.

Why do you consider 1D as something separate? To topicstarter!

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))))

Its OK to discuss, maybe somebody will find a way to do this. But I can’t think of any way to make those bytes match on a negative value.

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?

Hello Jani,

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.

1110111100110 → 0001000011001 → 537 + 1 → 538 * (-1) → -538

Afterwards it’s only the factor of 0.25 which we should use in order to receive -134.5

Do you think we can make this calculation with current tools in RealDash’s XML or if not can you add support for it?

Regards,
Nikolay

I think I could do something like:

  • if value is marked as ‘signed=“true”’ and bitcount does not match common 8-16-32 the two’s complement would be used to calculate final value.

I will try to fix something into XML parsing.

Fix for this is implemented to RealDash version 1.8.3. Value must be marked in XML as signed=“true”, and bitcount must be other than 8,16,32 or 64.

Thank you very much for the fast reaction! I will test it and post the results as soon as I got this version.

Hello, what are you using to convert dbc to xml format? Thanks

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.

Tested it and it’s working fine. Thanks again.

yes please!