From f91f83c19138f03472423b4a20f77c40590e197a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 4 Jul 2011 21:40:46 +0000 Subject: [PATCH] added eet and new start-dart --- dart/eet.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dart/start-dart.sh | 12 +++++++- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 dart/eet.c diff --git a/dart/eet.c b/dart/eet.c new file mode 100644 index 0000000..af33b70 --- /dev/null +++ b/dart/eet.c @@ -0,0 +1,83 @@ +/* + * eet + * + * + * Copyright (C) 2011 Christian Pointner + * + * This file is part of eet. + * + * eet is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * eet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eet. If not, see . + */ + +#include +#include + +#include + +int write_buf(char* buf, int len) +{ + int i; + for(i=0; i < len;) { + int w = write(1, &(buf[i]), len - i); + if(w < 0) + return w; + + i+=w; + } + return 0; +} + +int main(int argc, char* argv[]) +{ + if(argc < 2) { + fprintf(stderr, "Please specify fd number\n"); + return 1; + } + int fd = atoi(argv[1]); + if(fd < 3) { + fprintf(stderr, "the specified fd is not valid (must be higher than 2\n"); + return 2; + } + + char buf[1024]; + fd_set rfds; + + for(;;) { + FD_ZERO(&rfds); + FD_SET(0, &rfds); + FD_SET(fd, &rfds); + int ret = select(fd+1, &rfds, NULL, NULL, NULL); + + if (ret == -1) { + perror("select()"); + return 3; + } + else { + int i; + for(i = 0; i < 2; i++) { + if(FD_ISSET((i ? fd : 0), &rfds)) { + int r = read((i ? fd : 0), buf, sizeof(buf)); + if(r <=0 ) { + return r; + } + + ret = write_buf(buf, r); + if(ret) return ret; + } + } + } + } + + return 0; +} diff --git a/dart/start-dart.sh b/dart/start-dart.sh index 49960b1..db62dec 100755 --- a/dart/start-dart.sh +++ b/dart/start-dart.sh @@ -8,5 +8,15 @@ fi mode=$1 shift +FIFO=/tmp/dart.fifo +rm -f $FIFO +mkfifo $FIFO +stty -echo + ssh dart stty -F /dev/ttyDart 57600 -ssh dart cat /dev/ttyDart | ./dart-$mode.pl $* | ./dart-soundonly.pl | ../dart-sounds/src/dart-sounds ../dart-sounds/media > /dev/null +ssh dart cat /dev/ttyDart >$FIFO & +exec 42<$FIFO +./eet 42 | ./dart-$mode.pl $* | ./dart-soundonly.pl | ../dart-sounds/src/dart-sounds ../dart-sounds/media > /dev/null +rm -f $FIFO + +exit 0 \ No newline at end of file -- 1.7.10.4