X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=client%2Fbodet.cpp;h=4a2e14d83162642d5465b1cb8d7465fad18d9184;hb=HEAD;hp=54ec609e1f9ea108b156c8881ed3e85d887a4e31;hpb=e5ca9f8c9d6277669bbb8ae244172cfe547e56a4;p=ultimatescore diff --git a/client/bodet.cpp b/client/bodet.cpp index 54ec609..4a2e14d 100644 --- a/client/bodet.cpp +++ b/client/bodet.cpp @@ -1,7 +1,9 @@ // Bodet BT-6000 decoder. +#include #include #include +#include #include #include @@ -61,15 +63,36 @@ int main(int argc, char **argv) } else { inet_pton(AF_INET6, "::1", &saddr6.sin6_addr); } - saddr6.sin6_port = htons(6000); - // TODO: open serial port + int port = 6000; + if (argc >= 3) { + port = atoi(argv[2]); + } + saddr6.sin6_port = htons(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); @@ -79,6 +102,8 @@ int main(int argc, char **argv) exit(1); } + putchar(ch); + fflush(stdout); if (ch == 1) { // SOH buf = ch; continue;