From a6346f7b5bf6d4ccda029d881d9f62dc54e9e9bb Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Mon, 15 Jan 2007 21:36:41 +0000 Subject: Add a pair of simpleminded utilities for capturing and replaying data on a pty. This is probably useful for developing new protocols or when gpsfake may be suspect. --- contrib/binlog.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 contrib/binlog.c (limited to 'contrib/binlog.c') diff --git a/contrib/binlog.c b/contrib/binlog.c new file mode 100644 index 00000000..72c43259 --- /dev/null +++ b/contrib/binlog.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void spinner(int ); + +int main(int argc, char **argv) { + int speed, n, l, ifd, ofd; + struct termios term; + char buf[BUFSIZ]; + + if (argc != 4){ + fprintf(stderr, "usage: binlog \n"); + return 1; + } + + speed = atoi(argv[1]); + switch (speed) { + case 230400: + case 115200: + case 57600: + case 38400: + case 28800: + case 14400: + case 9600: + case 4800: + break; + default: + fprintf(stderr, "invalid speed\n"); + return 1; + } + + if ((ifd = open(argv[2], O_RDWR | O_NONBLOCK | O_NOCTTY, 0644)) == -1) + err(1, "open"); + + if ((ofd = open(argv[3], O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + err(1, "open"); + + tcgetattr(ifd, &term); + cfmakeraw(&term); + cfsetospeed(&term, speed); + cfsetispeed(&term, speed); + if (tcsetattr(ifd, TCSANOW | TCSAFLUSH, &term) == -1) + err(1, "tcsetattr"); + + tcflush(ifd, TCIOFLUSH); + n = 0; + while (1){ + l = read(ifd, buf, BUFSIZ); + if (l > 0) + write(ofd, buf, l); + usleep(1000); + bzero(buf, BUFSIZ); + spinner( n++ ); + } + return 0; +} + +void spinner(int n){ + char *s = "|/-\\"; + + if (n % 4) + return; + + n /= 4; + + fprintf(stderr, "\010\010\010\010\010\010\010\010\010\010\010\010\010"); + fprintf(stderr, "%c %d", s[n%4], n); + fflush(stderr); +} -- cgit v1.2.1