From 8b211ae74a29459ee6ad322d29aca768480cd95e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 31 Oct 2018 22:46:15 +0100 Subject: [PATCH] Make the bodet client read from a serial port. --- client/bodet.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/client/bodet.cpp b/client/bodet.cpp index b9eecc9..0c94116 100644 --- a/client/bodet.cpp +++ b/client/bodet.cpp @@ -1,7 +1,9 @@ // Bodet BT-6000 decoder. +#include #include #include +#include #include #include @@ -68,13 +70,29 @@ int main(int argc, char **argv) } saddr6.sin6_port = htons(port); - // TODO: open serial port + const char *serialpath = "/dev/ttyUSB0"; + if (argc >= 4) { + serialpath = argv[3]; + } + int serialfd = open(serialpath, O_RDWR); + if (serialfd == -1) { + perror(serialpath); + exit(1); + } + + struct termios options; + memset(&options, 0, sizeof(options)); + options.c_cflag = B9600 | CS8 | CLOCAL | CREAD; + options.c_iflag = IGNBRK | IGNPAR; + options.c_lflag = 0; + options.c_cc[VMIN] = 1; // Blocking read, minimum one byte. + tcsetattr(serialfd, TCSANOW, &options); string buf; for ( ;; ) { char ch; - int ret = read(0, &ch, 1); + int ret = read(serialfd, &ch, 1); if (ret == -1) { perror("read"); exit(1); @@ -84,6 +102,7 @@ int main(int argc, char **argv) exit(1); } + putchar(ch); if (ch == 1) { // SOH buf = ch; continue; -- 2.39.2