Extract values from U32

(1/2) > >>

Hi Again All,

I'm facing a new issue and I wonder if anyone has a solution.

I have a U32 signal that contains 3 pieces of information. The first is a number that uses 19bits of the U32, the second uses 5 bits and the last uses the remaining 8.

Is there a method I can use to extract the information in to it's 3 separate values? I've tried using Bit-Shift etc, but nothing seems to give me what I am looking for. The fact that the first value given uses 19bits isn't helping!

Just for reference, the data I am trying to get is from the J1939 DM1_RX function from Danfoss' website, the values reside in the "SPN_FMI_ADD_BUF" signal.

Any help would be appreciated!

hi LBee11,
have you tried the decode component, it is what I would use.

Divide the value into 8 bit using split component.
Decode each 8bit into 8 bool values with the decode component.

After that you can extract and encode whatever bits you need.

I would like to read if somebody has a better way, but I know this will work.

You could try masking and bit shifting to extract the valves.

Use the Bitwise AND component with the appropriate mask to extract the target bits then use the Shift Right component to align them to zero.


The information in SPN_FMI_Addr_Buf can also be obtained by setting the "Next" input of PGN 65226 (DM1_Rx1) to TRUE, which will allegedly move to the next position in the error buffer.

But if you want to extract the data from the unsigned 32-bit elements of SPN_FMI_Addr_Buf, the Right-Shift component is the one to use, followed by a safe Bitwise AND.  There must have been a mistake in how you tried using shift, because that's the standard one to use for this.  In pseudo-code ('>>' is shift right, and '&' is bitwise AND):

--- Code: ---Address = SPN_FMI_Addr_Buf & 0x000000ff
FMI = (SPN_FMI_Addr_Buf >> 8) & 0x0000001f
SPN = (SPN_FMI_Addr_Buf >> 13) & 0x0007ffff
--- End code ---

Thank you all, I used the bitwise AND and shift right to get the results I was looking for  :)


[0] Message Index

[#] Next page

Go to full version