显示我的CAN ID时出现问题。我通过CAN总线发送一条消息,ID为0x18FF11F3。我的程序收到此消息以及所有数据字段,只有ID不完全匹配
void set_can_listener(uint16 *s16_Socket, struct can_frame *Frame) {
/* Create the socket */
*s16_Socket = socket(PF_CAN, SOCK_RAW, CAN_RAW);
/* Locate the interface you wish to use */
struct ifreq t_Ifr;
strcpy(t_Ifr.ifr_name, "can0");
ioctl(*s16_Socket, SIOCGIFINDEX, &t_Ifr); /* Ifr.ifr_ifindex gets filled with that device's index*/
/* Select that CAN interface, and bind the socket to it.*/
struct sockaddr_can t_Addr;
t_Addr.can_family = AF_CAN;
t_Addr.can_ifindex = t_Ifr.ifr_ifindex;
bind(*s16_Socket, (struct sockaddr*) &t_Addr, sizeof(t_Addr));
}
void can_listener(uint16 *s16_Socket, struct can_frame *Frame) {
/* Read message from CAN */
unsigned int i;
uint16 s16_BytesRead = read(*s16_Socket, Frame, sizeof(*Frame));
if (s16_BytesRead >= 0) {
printf("\nMessage received!\nID: 0x%X\nDLC: %X\n", Frame->can_id,
Frame->can_dlc);
}
}
我的输出如下:
Message received!
ID: 0x98FF11F3
DLC: 8