* fhandler_serial.cc: Fix formatting problems introduced by below changes.

This commit is contained in:
Christopher Faylor 2002-07-22 14:30:30 +00:00
parent 780c42b43a
commit 08e2551c20
2 changed files with 65 additions and 68 deletions

View File

@ -1,17 +1,22 @@
2002-07-22 Christopher Faylor <cgf@redhat.com>
* fhandler_serial.cc: Fix formatting problems introduced by below
changes.
2002-07-22 Jacek Trzcinski <jacek@certum.pl> 2002-07-22 Jacek Trzcinski <jacek@certum.pl>
* fhandler.h (class fhandler_serial): Add new members of * fhandler.h (class fhandler_serial): Add new members of the class -
the class - rts,dtr and method ioctl(). Variables rts and dtr rts,dtr and method ioctl(). Variables rts and dtr important for Win 9x
important for Win 9x only. only.
* fhandler_serial.cc (fhandler_serial::open): Add initial setting * fhandler_serial.cc (fhandler_serial::open): Add initial setting of
of dtr and rts. Important for Win 9x only. dtr and rts. Important for Win 9x only.
(fhandler_serial::ioctl): New function. Implements commands TIOCMGET, (fhandler_serial::ioctl): New function. Implements commands TIOCMGET,
TIOCMSET and TIOCINQ. TIOCMSET and TIOCINQ.
(fhandler_serial::tcflush): Fixed found error. (fhandler_serial::tcflush): Fixed found error.
(fhandler_serial::tcsetattr): Add settings of rts and dtr. Important (fhandler_serial::tcsetattr): Add settings of rts and dtr. Important
for Win 9x only. for Win 9x only.
* termios.h: Add new defines as a support for ioctl() function * termios.h: Add new defines as a support for ioctl() function on
on serial device. serial device.
2002-07-20 Christopher Faylor <cgf@redhat.com> 2002-07-20 Christopher Faylor <cgf@redhat.com>

View File

@ -118,7 +118,7 @@ fhandler_serial::raw_read (void *ptr, size_t ulen)
if (inq > ulen) if (inq > ulen)
inq = ulen; inq = ulen;
debug_printf ("inq %d", inq); debug_printf ("inq %d", inq);
if (ReadFile (get_handle(), ptr, min (inq, ulen), &n, &io_status)) if (ReadFile (get_handle (), ptr, min (inq, ulen), &n, &io_status))
/* Got something */; /* Got something */;
else if (GetLastError () != ERROR_IO_PENDING) else if (GetLastError () != ERROR_IO_PENDING)
goto err; goto err;
@ -162,7 +162,7 @@ fhandler_serial::raw_write (const void *ptr, size_t len)
for (;;) for (;;)
{ {
if (WriteFile (get_handle(), ptr, len, &bytes_written, &write_status)) if (WriteFile (get_handle (), ptr, len, &bytes_written, &write_status))
break; break;
switch (GetLastError ()) switch (GetLastError ())
@ -181,13 +181,13 @@ fhandler_serial::raw_write (const void *ptr, size_t len)
break; break;
} }
ForceCloseHandle(write_status.hEvent); ForceCloseHandle (write_status.hEvent);
return bytes_written; return bytes_written;
err: err:
__seterrno (); __seterrno ();
ForceCloseHandle(write_status.hEvent); ForceCloseHandle (write_status.hEvent);
return -1; return -1;
} }
@ -269,22 +269,22 @@ fhandler_serial::open (path_conv *, int flags, mode_t mode)
} }
/* setting rts and dtr to known state so that ioctl() function with /* setting rts and dtr to known state so that ioctl() function with
request TIOCMGET could return correct value of RTS and DTR lines. request TIOCMGET could return correct value of RTS and DTR lines.
Important only for Win 9x systems */ Important only for Win 9x systems */
if (wincap.is_winnt() == false) if (!wincap.is_winnt ())
{ {
if (EscapeCommFunction (get_handle (), SETDTR) == 0) if (EscapeCommFunction (get_handle (), SETDTR) == 0)
system_printf ("couldn't set initial state of DTR for %s, %E", get_name ()); system_printf ("couldn't set initial state of DTR for %s, %E", get_name ());
if (EscapeCommFunction (get_handle (), SETRTS) == 0) if (EscapeCommFunction (get_handle (), SETRTS) == 0)
system_printf ("couldn't set initial state of RTS for %s, %E", get_name ()); system_printf ("couldn't set initial state of RTS for %s, %E", get_name ());
/* even though one of above functions fail I have to set rts and dtr /* even though one of above functions fail I have to set rts and dtr
variables to initial value. */ variables to initial value. */
rts = TIOCM_RTS; rts = TIOCM_RTS;
dtr = TIOCM_DTR; dtr = TIOCM_DTR;
} }
SetCommMask (get_handle (), EV_RXCHAR); SetCommMask (get_handle (), EV_RXCHAR);
set_open_status (); set_open_status ();
syscall_printf ("%p = fhandler_serial::open (%s, %p, %p)", syscall_printf ("%p = fhandler_serial::open (%s, %p, %p)",
@ -341,7 +341,7 @@ fhandler_serial::tcflow (int action)
DWORD win32action = 0; DWORD win32action = 0;
DCB dcb; DCB dcb;
char xchar; char xchar;
termios_printf ("action %d", action); termios_printf ("action %d", action);
switch (action) switch (action)
@ -390,7 +390,7 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
bool result; bool result;
int modemStatus; int modemStatus;
int request; int request;
request = *(int *) buffer; request = *(int *) buffer;
action = 0; action = 0;
modemStatus = 0; modemStatus = 0;
@ -400,81 +400,73 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
{ {
case TIOCMGET: case TIOCMGET:
if (GetCommModemStatus (get_handle (), &modemLines) == 0) if (GetCommModemStatus (get_handle (), &modemLines) == 0)
return -1; return -1;
if (modemLines & MS_CTS_ON) if (modemLines & MS_CTS_ON)
modemStatus |= TIOCM_CTS; modemStatus |= TIOCM_CTS;
if (modemLines & MS_DSR_ON) if (modemLines & MS_DSR_ON)
modemStatus |= TIOCM_DSR; modemStatus |= TIOCM_DSR;
if (modemLines & MS_RING_ON) if (modemLines & MS_RING_ON)
modemStatus |= TIOCM_RI; modemStatus |= TIOCM_RI;
if (modemLines & MS_RLSD_ON) if (modemLines & MS_RLSD_ON)
modemStatus |= TIOCM_CD; modemStatus |= TIOCM_CD;
if (wincap.is_winnt() == true) if (!wincap.is_winnt ())
{ modemStatus |= rts | dtr;
/* here is Windows NT or Windows 2000 part */
result = DeviceIoControl (get_handle (),
0x001B0078,
NULL, 0, &mcr, 4, &cbReturned, 0);
if (!result)
return -1;
if (cbReturned != 4)
return -1;
if (mcr & 2)
modemStatus |= TIOCM_RTS;
if (mcr & 1)
modemStatus |= TIOCM_DTR;
}
else else
{ {
result = DeviceIoControl (get_handle (),
/* here is Windows 9x part */ 0x001B0078,
modemStatus |= rts | dtr; NULL, 0, &mcr, 4, &cbReturned, 0);
if (!result)
return -1;
if (cbReturned != 4)
return -1;
if (mcr & 2)
modemStatus |= TIOCM_RTS;
if (mcr & 1)
modemStatus |= TIOCM_DTR;
} }
*(int *) buffer = modemStatus; *(int *) buffer = modemStatus;
return 0; return 0;
case TIOCMSET: case TIOCMSET:
if (request & TIOCM_RTS) if (request & TIOCM_RTS)
{ {
if (EscapeCommFunction (get_handle (), SETRTS) == 0) if (EscapeCommFunction (get_handle (), SETRTS) == 0)
return -1; return -1;
else else
rts = TIOCM_RTS; rts = TIOCM_RTS;
} }
else else
{ {
if (EscapeCommFunction (get_handle (), CLRRTS) == 0) if (EscapeCommFunction (get_handle (), CLRRTS) == 0)
return -1; return -1;
else else
rts = 0; rts = 0;
} }
if (request & TIOCM_DTR) if (request & TIOCM_DTR)
{ {
if (EscapeCommFunction (get_handle (), SETDTR) == 0) if (EscapeCommFunction (get_handle (), SETDTR) == 0)
return -1; return -1;
else else
dtr = TIOCM_DTR; dtr = TIOCM_DTR;
} }
else else
{ {
if (EscapeCommFunction (get_handle (), CLRDTR) == 0) if (EscapeCommFunction (get_handle (), CLRDTR) == 0)
return -1; return -1;
else else
dtr = 0; dtr = 0;
} }
return 0; return 0;
case TIOCINQ: case TIOCINQ:
if (ev & CE_FRAME | ev & CE_IOE | ev & CE_OVERRUN | if (ev & CE_FRAME | ev & CE_IOE | ev & CE_OVERRUN |
ev & CE_RXOVER | ev & CE_RXPARITY) ev & CE_RXOVER | ev & CE_RXPARITY)
return -1; return -1;
*(int *) buffer = st.cbInQue; *(int *) buffer = st.cbInQue;
return 0; return 0;
default: default:
return -1; return -1;
} }
} }
/* tcflush: POSIX 7.2.2.1 */ /* tcflush: POSIX 7.2.2.1 */
int int
@ -727,7 +719,7 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
EscapeCommFunction (get_handle (), SETDTR); EscapeCommFunction (get_handle (), SETDTR);
tmpDtr = TIOCM_DTR; tmpDtr = TIOCM_DTR;
} }
rts = tmpRts; rts = tmpRts;
dtr = tmpDtr; dtr = tmpDtr;