我试图通过套接字发送 29 位 EFF CAN 消息,但由于某种原因,它使用 11 位标识符发送它们,从 ID 中删除 5 个字节。使用环回模式,通过 candump 我可以看到消息以 11 位形式接收。
我没有收到任何错误,什么也没有,这就是我感到困惑的原因
我正在使用树莓派 3b+,如果这有什么区别的话。和 Can-utils 库。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include </home/pi/can-utils/lib.h>
int main(int argc, char **argv)
{
int s,loop = 1;
int nbytes;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr;
//can interface
if((s=socket(PF_CAN, SOCK_RAW, CAN_RAW))<0){
perror("socket");
return 1;
}
strcpy(ifr.ifr_name, "can0");
if(ioctl(s, SIOCGIFINDEX, &ifr) …Run Code Online (Sandbox Code Playgroud)