From ac50244de3b552540f07e14c97258d83dd2a96db Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Wed, 25 Mar 2020 14:32:27 +0900 Subject: [PATCH] Simplify termios setting for serial port Testing MMDVMCal on OpenBSD/armv7 + BananaPi BPI-P2 requires CLOCAL flag. Flags for termios should be same between OSX and other OSes so unified them (except VMIN and VTIME setting). --- SerialController.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/SerialController.cpp b/SerialController.cpp index 43e9e2a..cfb448d 100644 --- a/SerialController.cpp +++ b/SerialController.cpp @@ -256,28 +256,18 @@ bool CSerialController::open() return false; } + termios.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK); + termios.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL); + termios.c_iflag &= ~(IXON | IXOFF | IXANY); + termios.c_oflag &= ~(OPOST); + termios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CRTSCTS); + termios.c_cflag |= (CS8 | CLOCAL | CREAD); + termios.c_lflag &= ~(ISIG | ICANON | IEXTEN); + termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); #if defined(__APPLE__) - termios.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */ - termios.c_cflag &= ~CSIZE; - termios.c_cflag |= CS8; /* 8-bit characters */ - termios.c_cflag &= ~PARENB; /* no parity bit */ - termios.c_cflag &= ~CSTOPB; /* only need 1 stop bit */ - termios.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */ - - /* setup for non-canonical mode */ - termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - termios.c_oflag &= ~OPOST; - - /* fetch bytes as they become available */ termios.c_cc[VMIN] = 1; termios.c_cc[VTIME] = 1; #else - termios.c_lflag &= ~(ECHO | ECHOE | ICANON | IEXTEN | ISIG); - termios.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON | IXOFF | IXANY); - termios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CRTSCTS); - termios.c_cflag |= CS8; - termios.c_oflag &= ~(OPOST); termios.c_cc[VMIN] = 0; termios.c_cc[VTIME] = 10; #endif