From 723d64e6673c7871b7c26cdac005a862162cfa3e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 2 Aug 2005 09:17:15 +0000 Subject: [PATCH] * include/sys/termios.h: Define TIOCMBIS and TIOCMBIC. * fhandler.h (class fhandler_serial): Declare switch_modem_lines. * fhandler_serial.cc (fhandler_serial::switch_modem_lines): New static function to set or clear DTR and/or RTS. (fhandler_serial::ioctl): Use switch_modem_lines for TIOCMSET and new TIOCMBIS and TIOCMBIC. * include/cygwin/version.h: Bump API minor number. --- winsup/cygwin/ChangeLog | 10 +++ winsup/cygwin/fhandler.h | 1 + winsup/cygwin/fhandler_serial.cc | 97 ++++++++++++++++---------- winsup/cygwin/include/cygwin/version.h | 3 +- winsup/cygwin/include/sys/termios.h | 4 +- 5 files changed, 76 insertions(+), 39 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0b477b571..a8eec0fe8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2005-08-02 Yitzchak Scott-Thoennes + + * include/sys/termios.h: Define TIOCMBIS and TIOCMBIC. + * fhandler.h (class fhandler_serial): Declare switch_modem_lines. + * fhandler_serial.cc (fhandler_serial::switch_modem_lines): New + static function to set or clear DTR and/or RTS. + (fhandler_serial::ioctl): Use switch_modem_lines for TIOCMSET + and new TIOCMBIS and TIOCMBIC. + * include/cygwin/version.h: Bump API minor number. + 2005-07-29 Christopher Faylor * fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 9c0c45e20..6b698fa40 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -722,6 +722,7 @@ class fhandler_serial: public fhandler_base int tcdrain (); int tcflow (int); int ioctl (unsigned int cmd, void *); + int switch_modem_lines (int set, int clr); int tcsetattr (int a, const struct termios *t); int tcgetattr (struct termios *t); _off64_t lseek (_off64_t, int) { return 0; } diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index 3c6a3bcdc..3910ee97d 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -376,6 +376,56 @@ fhandler_serial::tcflow (int action) } +/* switch_modem_lines: set or clear RTS and/or DTR */ +int +fhandler_serial::switch_modem_lines (int set, int clr) +{ + int res = 0; + + if (set & TIOCM_RTS) + { + if (EscapeCommFunction (get_handle (), SETRTS)) + rts = TIOCM_RTS; + else + { + __seterrno (); + res = -1; + } + } + else if (clr & TIOCM_RTS) + { + if (EscapeCommFunction (get_handle (), CLRRTS)) + rts = 0; + else + { + __seterrno (); + res = -1; + } + } + if (set & TIOCM_DTR) + { + if (EscapeCommFunction (get_handle (), SETDTR)) + rts = TIOCM_DTR; + else + { + __seterrno (); + res = -1; + } + } + else if (clr & TIOCM_DTR) + { + if (EscapeCommFunction (get_handle (), CLRDTR)) + rts = 0; + else + { + __seterrno (); + res = -1; + } + } + + return res; +} + /* ioctl: */ int fhandler_serial::ioctl (unsigned int cmd, void *buffer) @@ -432,44 +482,17 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer) } break; case TIOCMSET: - if (ipbuffer & TIOCM_RTS) - { - if (EscapeCommFunction (get_handle (), SETRTS)) - rts = TIOCM_RTS; - else - { - __seterrno (); - res = -1; - } - } - else - { - if (EscapeCommFunction (get_handle (), CLRRTS)) - rts = 0; - else - { - __seterrno (); - res = -1; - } - } - if (ipbuffer & TIOCM_DTR) - { - if (EscapeCommFunction (get_handle (), SETDTR)) - dtr = TIOCM_DTR; - else - { - __seterrno (); - res = -1; - } - } - else if (EscapeCommFunction (get_handle (), CLRDTR)) - dtr = 0; - else - { - __seterrno (); - res = -1; - } + if (switch_modem_lines (ipbuffer, ~ipbuffer)) + res = -1; break; + case TIOCMBIS: + if (switch_modem_lines (ipbuffer, 0)) + res = -1; + break; + case TIOCMBIC: + if (switch_modem_lines (0, ipbuffer)) + res = -1; + break; case TIOCCBRK: if (ClearCommBreak (get_handle ()) == 0) { diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 477195fe5..7e823cd6d 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -262,12 +262,13 @@ details. */ 133: Export __getline, __getdelim. 134: Export getline, getdelim. 135: Export pread, pwrite + 136: Add TIOCMBIS/TIOCMBIC ioctl codes. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 135 +#define CYGWIN_VERSION_API_MINOR 136 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/sys/termios.h b/winsup/cygwin/include/sys/termios.h index 926e11ee7..589c91a57 100644 --- a/winsup/cygwin/include/sys/termios.h +++ b/winsup/cygwin/include/sys/termios.h @@ -1,6 +1,6 @@ /* sys/termios.h - Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc. + Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 Red Hat, Inc. This file is part of Cygwin. @@ -14,6 +14,8 @@ details. */ #define _SYS_TERMIOS_H #define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 #define TIOCINQ 0x541B -- 2.43.5