10 #include "../include/can.h"
14 int can_fd_wait(int fd, int wait_sec)
17 struct timeval timeout;
22 timeout.tv_sec = wait_sec;
24 while ((ret=select(FD_SETSIZE,&set, NULL, NULL,&timeout))==-1
30 /*--- handler on SIGINT signal : the program quit with CTL-C ---*/
34 printf("Terminated by user\n");
42 struct canmsg_t readmsg={0,0,5,0,0,{0,}};
45 /*------- register handler on SIGINT signal -------*/
46 act.sa_handler=sortie;
47 sigemptyset(&act.sa_mask);
49 sigaction(SIGINT,&act,0);
50 /*---------------------------------------*/
52 if ((fd=open("/dev/can0",O_RDWR)) < 0)
55 printf("Error opening /dev/can0\n");
65 ret=can_fd_wait(fd, 5);
66 printf("can_fd_wait returnet %d\n",ret);
68 ret=read(fd,&readmsg,sizeof(struct canmsg_t));
71 printf("Error reading message\n");
75 printf("No message arrived\n");
79 printf("Received message #%lu: id=%lX dlc=%u",i,readmsg.id,readmsg.length);
80 for(n=0 ; n<readmsg.length ; n++)
81 printf(" %.2X",(unsigned char)readmsg.data[n]);