Re: correct length of bcm message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Patrick,

On 04.02.21 18:47, Patrick Menschel wrote:
Am 04.02.21 um 16:38 schrieb Patrick Menschel:
Hi,

is anyone writing to BCMSocket on the Raspberry Pi from Python3 ?

I'm digging through an endianess / alignment issue on armhf platform.

My testcode [1] that I wrote years ago on works on X86_64 platform but
fails on armhf platform with OSERROR 22 "invalid argument".

Some more details.

The length on X86_64 results in 72 bytes which are consumed by bcm.

On armhf it results in 52 bytes which cause OSError: [Errno 22] Invalid
argument.


Then I started concatenating bytes by hand instead of using ctypes.

What I came around is that frames[0] is somehow expected to be 8 bytes
length although it should be 16 bytes.

struct can_frames[0] is used in this struct definition to point out, that this struct is followed by a number (0..257) struct can_frame's.

This creates a padding at the end of struct bcm_head, so that the struct can_frame (which is always 64 bit aligned) can be directly concatenated.

Regards,
Oliver


struct bcm_msg_head {
...
         struct can_frame frames[0];
};

I ended up inserting padding 8 bytes instead of frames[0] value and that
actually works.

I have to amend that, it's 4 padding bytes.

struct.pack("=IIIllllII4xIB3x8s",opcode,flags,count,ival1_sec,ival1_usec,ival2_sec,ival2_usec,can_id,nframes,can_id,can_dlc,data)
                        ^^ padding bytes

Sending the resulting 56bytes to bcmsocket gets me a cyclic message on
armhf.


That makes my overall BCMHead 40 bytes and the complete bcm message
including the can frame 56bytes.

[1] https://github.com/menschel/pysocketcan


Thanks,
Patrick




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux