How to extract bytes from CAN_FRAME..?

Hi all.

Having a little trouble extracting bytes from a CAN_FRAME class.

Trying this…

CAN_FRAME ChalFrame;
CAN_FRAME RespFrame;

Can0.watchFor(0x00040020);

  if (Can0.available() > 0)
    {
      Can0.read(ChalFrame);

  // Split the Challenge into raw bytes

  ChalByte[0] = (ChalFrame & 0xFF000000)>>24;
  ChalByte[1] = (ChalFrame & 0x00FF0000)>>16;
  ChalByte[2] = (ChalFrame & 0x0000FF00)>>8;
  ChalByte[3] = (ChalFrame & 0x000000FF);

Gives error message “no match for ‘operator&’ (operand types are ‘CAN_FRAME’ and ‘unsigned int’)” in Arduino IDE.

I need to extract these bytes, modify them individually, then reassemble and send.

If you have any pointers please let me know!

Thanks

Joe

Fixed thanks to Colin.

No need to use bit shifting.

 ChalByte[0] = ChalFrame.data.byte[0];

Is appropriate :slight_smile: