X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/4ddb8468e0688f83f24fc041cfb62512ee45194a..4cf24de229090b1ab6279570a564d224e13dd706:/lincan/utils/readburst.c diff --git a/lincan/utils/readburst.c b/lincan/utils/readburst.c new file mode 100644 index 0000000..139e558 --- /dev/null +++ b/lincan/utils/readburst.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include + +#include "../include/can.h" + +int fd; + +/*--- handler on SIGINT signal : the program quit with CTL-C ---*/ +void sortie(int sig) + { + close(fd); + printf("Terminated by user\n"); + exit(0); + } + +int main(void) + { + int n,ret; + unsigned long i=0; + struct canmsg_t readmsg={0,0,5,0,0,{0,}}; + struct sigaction act; + + /*------- register handler on SIGINT signal -------*/ + act.sa_handler=sortie; + sigemptyset(&act.sa_mask); + act.sa_flags=0; + sigaction(SIGINT,&act,0); + /*---------------------------------------*/ + + if ((fd=open("/dev/can0",O_RDWR)) < 0) + { + perror("open"); + printf("Error opening /dev/can0\n"); + exit(1); + } + + while (1) + { + readmsg.flags=0; + readmsg.cob=0; + readmsg.timestamp=0; + ret=read(fd,&readmsg,sizeof(struct canmsg_t)); + if(ret <0) + { + printf("Error reading message\n"); + } + else + { + printf("Received message #%lu: id=%lX dlc=%u",i,readmsg.id,readmsg.length); + for(n=0 ; n