From 8109b8b3d6a8e41061142ee7bb24380f59515865 Mon Sep 17 00:00:00 2001 From: Adam Megacz Date: Sun, 20 Sep 2009 12:36:18 -0700 Subject: [PATCH] add misc/bicat.c --- misc/bicat.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 misc/bicat.c diff --git a/misc/bicat.c b/misc/bicat.c new file mode 100644 index 0000000..b00da25 --- /dev/null +++ b/misc/bicat.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main (int argc, char **argv) { + char buf[20]; + int fd; + int retval; + int numread; + FILE* log; + fd = open(argv[1], O_RDWR); + log = fopen("bicat.log", "w"); + for(;;) { + fd_set rfds; + struct timeval tv; + + FD_ZERO(&rfds); + FD_SET(STDIN_FILENO, &rfds); + FD_SET(fd, &rfds); + + tv.tv_sec = 5; + tv.tv_usec = 0; + + retval = select(fd+1, &rfds, NULL, NULL, &tv); + + if (retval == -1) + perror("select()"); + else if (retval) { + if (FD_ISSET(fd, &rfds)) { + numread = read(fd, buf, 1); + if (numread==0) return; + if (numread<0) perror("read()"); + //fprintf(log, "fpga->host: %d\n", buf[0]); + write(STDOUT_FILENO, buf, numread); + if ((buf[0] & (3<<6)) == 0) { + buf[0] = (1<<6) | 1; + write(fd, buf, 1); + } + } else if (FD_ISSET(STDIN_FILENO, &rfds)) { + numread = read(STDIN_FILENO, buf, 1); + if (numread==0) return; + if (numread<0) perror("read()"); + //fprintf(log, "host->fpga: %d\n", buf[0]); + write(fd, buf, numread); + } else if (FD_ISSET(fd, &rfds)) { + perror("huh?\n"); + } + } else { + //fprintf(log, "sleep\n"); + } + //fflush(log); + } +} -- 1.7.10.4