Patchwork [2/3] serprog: ignore failures when setting serial port options.

login
register
about
Submitter Stefan Tauner
Date 2015-06-28 01:56:51
Message ID <1435456612-12131-3-git-send-email-stefan.tauner@alumni.tuwien.ac.at>
Download mbox | patch
Permalink /patch/4308/
State Superseded
Headers show

Comments

Stefan Tauner - 2015-06-28 01:56:51
There is no good reason to abort earlier just because some options did
not stick. This should improve compatibility without negative effects. If
communication is affected by the missing flag(s) then we abort later
anyway.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
---
 serial.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
Stefan Tauner - 2016-02-21 17:53:35
On Sun, 28 Jun 2015 03:56:51 +0200
Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> wrote:

> There is no good reason to abort earlier just because some options did
> not stick. This should improve compatibility without negative effects. If
> communication is affected by the missing flag(s) then we abort later
> anyway.
> 
> Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>

Acked-by: Urja Rannikko <urjaman@gmail.com>
and committed already in r1906 some time ago.

Patch

diff --git a/serial.c b/serial.c
index 63774a5..b216143 100644
--- a/serial.c
+++ b/serial.c
@@ -209,12 +209,25 @@  int serialport_config(fdtype fd, unsigned int baud)
 	if (observed.c_cflag != wanted.c_cflag ||
 	    observed.c_lflag != wanted.c_lflag ||
 	    observed.c_iflag != wanted.c_iflag ||
-	    observed.c_oflag != wanted.c_oflag ||
-	    cfgetispeed(&observed) != cfgetispeed(&wanted)) {
-		msg_perr("%s: Some requested options did not stick.\n", __func__);
-		return 1;
+	    observed.c_oflag != wanted.c_oflag) {
+		msg_pwarn("Some requested serial options did not stick, continuing anyway.\n");
+		msg_pdbg("          observed    wanted\n"
+			 "c_cflag:  0x%08X  0x%08X\n"
+			 "c_lflag:  0x%08X  0x%08X\n"
+			 "c_iflag:  0x%08X  0x%08X\n"
+			 "c_oflag:  0x%08X  0x%08X\n",
+			 observed.c_cflag, wanted.c_cflag,
+			 observed.c_lflag, wanted.c_lflag,
+			 observed.c_iflag, wanted.c_iflag,
+			 observed.c_oflag, wanted.c_oflag
+			);
+	}
+	if (cfgetispeed(&observed) != cfgetispeed(&wanted) ||
+	    cfgetospeed(&observed) != cfgetospeed(&wanted)) {
+		msg_pwarn("Could not set baud rates exactly\n");
+		msg_pdbg("Actual baud flags are: ispeed: 0x%08lX, ospeed: 0x%08lX\n",
+			  (long)cfgetispeed(&observed), (long)cfgetispeed(&wanted));
 	}
-	msg_pdbg("Baud rate is %d now.\n", entry->baud);
 #endif
 	return 0;
 }