Author Topic: Extract values from U32  (Read 11146 times)

Offline LBee11

  • PLUS+1 Developer
  • ***
  • Posts: 26
  • Karma: +1/-0
Extract values from U32
« on: March 07, 2017, 06:00:41 PM »
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!

Offline Jakob

  • PLUS+1 Expert
  • ****
  • Posts: 98
  • Karma: +2/-0
Re: Extract values from U32
« Reply #1 on: March 08, 2017, 08:06:16 AM »
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.
/Jakob

Offline acmall

  • PLUS+1 Guru
  • *****
  • Posts: 201
  • Karma: +37/-1
Re: Extract values from U32
« Reply #2 on: March 08, 2017, 09:07:23 AM »
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.

Alastair

Offline oiltronic

  • PLUS+1 Guru
  • *****
  • Posts: 170
  • Karma: +15/-0
Re: Extract values from U32
« Reply #3 on: March 08, 2017, 07:37:51 PM »
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: [Select]
Address = SPN_FMI_Addr_Buf & 0x000000ff
FMI = (SPN_FMI_Addr_Buf >> 8) & 0x0000001f
SPN = (SPN_FMI_Addr_Buf >> 13) & 0x0007ffff
« Last Edit: March 08, 2017, 07:41:52 PM by oiltronic »

Offline LBee11

  • PLUS+1 Developer
  • ***
  • Posts: 26
  • Karma: +1/-0
Re: Extract values from U32
« Reply #4 on: March 08, 2017, 09:02:28 PM »
Thank you all, I used the bitwise AND and shift right to get the results I was looking for  :)

Offline Lukey

  • PLUS+1 Expert
  • ****
  • Posts: 67
  • Karma: +6/-0
Re: Extract values from U32
« Reply #5 on: March 16, 2023, 08:13:40 AM »
@Lbee11 any chance you can share/screen shot the code you used?
I'm trying to get on the SPN number using from the buffer in the same way you have but I cannot work it out.
Thanks!

Offline Lukey

  • PLUS+1 Expert
  • ****
  • Posts: 67
  • Karma: +6/-0
Re: Extract values from U32
« Reply #6 on: March 17, 2023, 11:55:34 AM »
I fixed this, I overlooked that I needed to Get Array Element prior to using Right-Shift, followed by the Bitwise AND.

Attached for future reference if anyone needs it.