#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <signal.h>
#include "../include/can.h"
int fd;
+int can_fd_wait(int fd, int wait_sec)
+{
+ int ret;
+ struct timeval timeout;
+ fd_set set;
+
+ FD_ZERO (&set);
+ FD_SET (fd, &set);
+ timeout.tv_sec = wait_sec;
+ timeout.tv_usec = 0;
+ while ((ret=select(FD_SETSIZE,&set, NULL, NULL,&timeout))==-1
+ &&errno==-EINTR);
+ return ret;
+}
+
+
/*--- handler on SIGINT signal : the program quit with CTL-C ---*/
void sortie(int sig)
{
readmsg.flags=0;
readmsg.cob=0;
readmsg.timestamp=0;
+ #if 1
+ ret=can_fd_wait(fd, 5);
+ printf("can_fd_wait returnet %d\n",ret);
+ #endif
ret=read(fd,&readmsg,sizeof(struct canmsg_t));
if(ret <0)
{
printf("Error reading message\n");
}
+ else if(ret == 0)
+ {
+ printf("No message arrived\n");
+ }
else
{
printf("Received message #%lu: id=%lX dlc=%u",i,readmsg.id,readmsg.length);