sysdep1.c
上传用户:tianjinjs
上传日期:2007-01-05
资源大小:309k
文件大小:10k
- /*
- * sysdep1.c system dependant routines.
- *
- * $Id: sysdep1.c,v 1.2 1999/09/03 12:25:24 walker Exp $
- *
- * m_dtrtoggle - dropt dtr and raise it again
- * m_break - send BREAK signal
- * m_getdcd - get modem dcd status
- * m_setdcd - set modem dcd status
- * m_savestate - save modem state
- * m_restorestate - restore saved modem state
- * m_nohang - tell driver not to hang up at DTR drop
- * m_hupcl - set hangup on close on/off
- * m_setparms - set baudrate, parity and number of bits.
- * m_readchk - see if there is input waiting.
- * m_wait - wait for child to finish. Sysdep. too.
- *
- * If it's possible, Posix termios are preferred.
- *
- * This file is part of the minicom communications package,
- * Copyright 1991-1995 Miquel van Smoorenburg.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * jl 23.06.97 adjustable DTR downtime
- */
- #include "sysdep.h"
- /* Set hardware flow control. */
- void m_sethwf(fd, on)
- int fd, on;
- {
- #ifdef _DGUX_SOURCE
- struct termiox x;
- #endif
- #ifdef _POSIX
- struct termios tty;
- tcgetattr(fd, &tty);
- if (on)
- tty.c_cflag |= CRTSCTS;
- else
- tty.c_cflag &= ~CRTSCTS;
- tcsetattr(fd, TCSANOW, &tty);
- #endif
- #ifdef _DGUX_SOURCE
- if (ioctl(fd, TCGETX, &x) < 0) {
- fprintf(stderr, "can't get termiox attr.n");
- return;
- }
- x.x_hflag = on ? RTSXOFF|CTSXON : 0;
- if (ioctl(fd, TCSETX, &x) < 0) {
- fprintf(stderr, "can't set termiox attr.n");
- return;
- }
- #endif
- }
- /* Set RTS line. Sometimes dropped. Linux specific? */
- void m_setrts(fd)
- int fd;
- {
- #if defined(TIOCM_RTS) && defined(TIOCMODG)
- int mcs;
- ioctl(fd, TIOCMODG, &mcs);
- mcs |= TIOCM_RTS;
- ioctl(fd, TIOCMODS, &mcs);
- #endif
- #ifdef _COHERENT
- ioctl(fd, TIOCSRTS, 0);
- #endif
- }
- /*
- * Drop DTR line and raise it again.
- */
- void m_dtrtoggle(fd,sec)
- int fd;
- int sec;
- {
- #ifdef TIOCSDTR
- /* Use the ioctls meant for this type of thing. */
- ioctl(fd, TIOCCDTR, 0);
- if (sec>0) {
- sleep(sec);
- ioctl(fd, TIOCSDTR, 0);
- }
- #else /* TIOCSDTR */
- # if defined (_POSIX) && !defined(_HPUX_SOURCE)
- /* Posix - set baudrate to 0 and back */
- struct termios tty, old;
- tcgetattr(fd, &tty);
- tcgetattr(fd, &old);
- cfsetospeed(&tty, B0);
- cfsetispeed(&tty, B0);
- tcsetattr(fd, TCSANOW, &tty);
- if (sec>0) {
- sleep(sec);
- tcsetattr(fd, TCSANOW, &old);
- }
- # else /* POSIX */
- # ifdef _V7
- /* Just drop speed to 0 and back to normal again */
- struct sgttyb sg, ng;
-
- ioctl(fd, TIOCGETP, &sg);
- ioctl(fd, TIOCGETP, &ng);
-
- ng.sg_ispeed = ng.sg_ospeed = 0;
- ioctl(fd, TIOCSETP, &ng);
- if (sec>0) {
- sleep(sec);
- ioctl(fd, TIOCSETP, &sg);
- }
- # endif /* _V7 */
- # ifdef _HPUX_SOURCE
- unsigned long mflag = 0L;
- ioctl(fd, MCSETAF, &mflag);
- ioctl(fd, MCGETA, &mflag);
- mflag = MRTS | MDTR;
- if (sec>0) {
- sleep(sec);
- ioctl(fd, MCSETAF, &mflag);
- }
- # endif /* _HPUX_SOURCE */
- # endif /* POSIX */
- #endif /* TIOCSDTR */
- }
- /*
- * Send a break
- */
- void m_break(fd)
- int fd;
- {
- #ifdef _POSIX
- tcsendbreak(fd, 0);
- #else
- # ifdef _V7
- # ifndef TIOCSBRK
- struct sgttyb sg, ng;
- ioctl(fd, TIOCGETP, &sg);
- ioctl(fd, TIOCGETP, &ng);
- ng.sg_ispeed = ng.sg_ospeed = B110;
- ng.sg_flags = BITS8 | RAW;
- ioctl(fd, TIOCSETP, &ng);
- write(fd, "