0

I want to receive messages periodically using socketCAN. But the program didnt receive any telegrams. I think one problem may be the telegram ID inside the BCM.

Can somebody help me with a hint?

Thank you

Edit: The goal is to send and to receive can frames on the embedded hw device. I am able to send can frames from the hw to the connected pc. Thats still working fine. But actual I am not able to receive any can frames, which where send from the pc. The bitrate is actual 125000. I think one problem is, that I have to subscribe the can-id of the received telegrams to the broad cast manager. But I cant find an example in the documentation. If I run the code with strace on the hw, I can see the code stucks at the recvfrom() method.

/* Create the socket */
int skt = socket(PF_CAN, SOCK_DGRAM, CAN_BCM);

/* Locate the interface can0 */
struct ifreq ifr;
strcpy(ifr.ifr_name, "can0");

/* Set that interface in the address structure */
struct sockaddr_can addr;
socklen_t addrlen = sizeof(addr);
addr.can_family = PF_CAN;
addr.can_ifindex = 0;
 
/* Connect the socket to that interface */
ret = connect(skt, (struct sockaddr *) &addr, sizeof(addr));

/* Create a struct to set up a sequence of one CAN frame */
struct {
        struct bcm_msg_head msg_head;
        struct can_frame frame[1];
} msg;

msg.msg_head.opcode = RX_SETUP;
msg.msg_head.flags = RX_FILTER_ID | SETTIMER;
msg.frame[0].can_id = 0x123;
 
nbytes = recvfrom(skt, &msg.frame, sizeof(struct can_frame), 0, (struct sockaddr*) &addr, &addrlen);
Or25
  • 1
  • 1
  • 1
    You should [edit] your question and add more details. Describe what you want to achieve. Are you trying to filter the CAN messages? What messages are sent to the bus? How do you set up the bitrate? Please create a [mre]. Can you use the can interface with the command line tools from the `can-utils` package, e.g. `candump`? What Linux distribution do you use? – Bodo Dec 08 '20 at 12:28
  • Also see this checklist: [What are the most common causes of CAN bus communication errors?](https://electrical.codidact.com/q/276251) – Lundin Dec 08 '20 at 15:04

0 Answers0