]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/utils/readburst.c
The first enhanced version of Linux CAN-bus driver for OCERA project
[lincan.git] / lincan / utils / readburst.c
index 139e55891af09602ef7d9136c8f5ea5d0566f2d7..8c61069fa7cc3c87df27e4d12eaf32d83b8b2fd0 100644 (file)
@@ -1,14 +1,32 @@
 #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)
        {
@@ -43,11 +61,19 @@ int main(void)
                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);