summaryrefslogtreecommitdiff
path: root/contrib/binlog.c
diff options
context:
space:
mode:
authorChris Kuethe <chris.kuethe@gmail.com>2007-01-15 21:36:41 +0000
committerChris Kuethe <chris.kuethe@gmail.com>2007-01-15 21:36:41 +0000
commita6346f7b5bf6d4ccda029d881d9f62dc54e9e9bb (patch)
tree91eadea788f51f4f8a8b8bb12016cf9b3e6fbfbe /contrib/binlog.c
parent0d8793d744b4c64529efbb24e65a1eb3e77b5b2a (diff)
downloadgpsd-a6346f7b5bf6d4ccda029d881d9f62dc54e9e9bb.tar.gz
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.
Diffstat (limited to 'contrib/binlog.c')
-rw-r--r--contrib/binlog.c77
1 files changed, 77 insertions, 0 deletions
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 <sys/types.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+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 <speed> <port> <logfile>\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);
+}