diff --git a/tools/reader/obreader.c b/tools/reader/obreader.c index 9c46630..542d1a4 100644 --- a/tools/reader/obreader.c +++ b/tools/reader/obreader.c @@ -18,6 +18,7 @@ #include #include #include +#include #define INTERVAL 1 @@ -72,6 +73,74 @@ void setnonblocking(int fd) { return; } +void setupserial(int fd){ + struct termios config; + + if(!isatty(fd)) { + fprintf(stderr,"fd %d is not a tty?",fd); + exit(EXIT_FAILURE); + }; + if(tcgetattr(fd, &config) < 0) { + perror("tcgetattr"); + exit(EXIT_FAILURE); + }; + // + // Input flags - Turn off input processing + // convert break to null byte, no CR to NL translation, + // no NL to CR translation, don't mark parity errors or breaks + // no input parity check, don't strip high bit off, + // no XON/XOFF software flow control + // + config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | + INLCR | PARMRK | INPCK | ISTRIP | IXON); + // + // Output flags - Turn off output processing + // no CR to NL translation, no NL to CR-NL translation, + // no NL to CR translation, no column 0 CR suppression, + // no Ctrl-D suppression, no fill characters, no case mapping, + // no local output processing + // + // config.c_oflag &= ~(OCRNL | ONLCR | ONLRET | + // ONOCR | ONOEOT| OFILL | OLCUC | OPOST); + config.c_oflag = 0; + // + // No line processing: + // echo off, echo newline off, canonical mode off, + // extended input processing off, signal chars off + // + config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); + // + // Turn off character processing + // clear current char size mask, no parity checking, + // no output processing, force 8 bit input + // + config.c_cflag &= ~(CSIZE | PARENB); + config.c_cflag |= CS8; + // + // One input byte is enough to return from read() + // Inter-character timer off + // + config.c_cc[VMIN] = 1; + config.c_cc[VTIME] = 0; + // + // Communication speed (simple version, using the predefined + // constants) + // + /* + if(cfsetispeed(&config, B9600) < 0 || cfsetospeed(&config, B9600) < 0) { + perror("cfset[io]speed"); + exit(EXIT_FAILURE); + } + */ + // + // Finally, apply the configuration + // + if(tcsetattr(fd, TCSAFLUSH, &config) < 0) { + perror("tcsetattr"); + exit(EXIT_FAILURE); + }; +}; + /* Reference is https://r0ket.badge.events.ccc.de/tracking:reader */ void pkt_cleanup(int idx){ static u_int32_t ctr; @@ -285,7 +354,8 @@ and sends them off via TCP/UDP to a central host\n\n\ perror("open(device)"); exit(EXIT_FAILURE); }; - setnonblocking(devfd); + setupserial(devfd); + setnonblocking(devfd); setup_r0ket(devfd); /* Open & prep outout device */