13 #include <sys/ioctl.h> 15 #if HAVE_LINUX_SERIAL_H 16 # include <linux/serial.h> 20 static inline void cfmakeraw(
struct termios *termios_p)
22 termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
23 termios_p->c_oflag &= ~OPOST;
24 termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
25 termios_p->c_cflag &= ~(CSIZE|PARENB);
26 termios_p->c_cflag |= CS8;
55 WvModemBase::WvModemBase(
int _fd) :
WvFile(_fd)
61 WvModemBase::~WvModemBase()
67 int WvModemBase::get_real_speed()
71 if (!isok())
return 0;
73 tcgetattr( getrfd(), &t );
74 s = cfgetospeed( &t );
75 for (
unsigned int i = 0; i <
sizeof(speeds) /
sizeof(*speeds); i++)
77 if (speeds[i].speedt == s)
79 baud = speeds[i].baud;
108 int i, oldbaud = baud;
110 if (die_fast || !isok())
return;
119 for (i = 0; !select(200,
false,
true) && i < 10; i++)
126 cfsetospeed( &t, B0 );
127 tcsetattr( getrfd(), TCSANOW, &t );
128 for (i = 0; carrier() && i < 10; i++)
129 usleep( 100 * 1000 );
139 usleep( 1500 * 1000 );
142 for (i = 0; carrier() && i < 5; i++)
143 usleep( 100 * 1000 );
149 WvModem::WvModem(
WvStringParm filename,
int _baud,
bool rtscts,
bool _no_reset)
150 :
WvModemBase(), lock(filename), log(
"WvModem", WvLog::Debug1)
155 no_reset = _no_reset;
169 open(filename, O_RDWR|O_NONBLOCK|O_NOCTTY);
182 void WvModem::setup_modem(
bool rtscts)
186 if (tcgetattr(getrfd(), &t) || tcgetattr(getrfd(), &old_t))
196 #if HAVE_LINUX_SERIAL_H 197 struct serial_struct old_sinfo, sinfo;
198 sinfo.reserved_char[0] = 0;
199 if (ioctl(getrfd(), TIOCGSERIAL, &old_sinfo) < 0)
200 log(
"Cannot get information for serial port.");
207 sinfo.closing_wait = ASYNC_CLOSING_WAIT_NONE;
208 sinfo.closing_wait2 = ASYNC_CLOSING_WAIT_NONE;
210 if (ioctl(getrfd(), TIOCSSERIAL, &sinfo) < 0)
211 log(
"Cannot set information for serial port.");
217 t.c_iflag &= ~(BRKINT | ISTRIP | IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
218 t.c_iflag |= (IGNBRK | IGNPAR);
219 t.c_oflag &= ~(OLCUC);
220 t.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD);
221 t.c_cflag |= (CS8 | CREAD | HUPCL | CLOCAL);
223 t.c_cflag |= CRTSCTS;
224 t.c_lflag &= ~(ISIG | XCASE | ECHO);
225 tcsetattr(getrfd(), TCSANOW, &t);
229 old_t.c_cflag |= CLOCAL;
232 if (cfgetospeed(&t) != B0 && !no_reset)
234 for(
int i=0; i<5; i++)
245 tcsetattr(getrfd(), TCSANOW, &t);
277 tcflush(getrfd(), TCIOFLUSH);
279 tcsetattr(getrfd(), TCSANOW, &old_t);
280 tcflush(getrfd(), TCIOFLUSH);
292 for (
unsigned int i = 0; i <
sizeof(speeds) /
sizeof(*speeds); i++)
294 if (speeds[i].baud <= _baud)
296 s = speeds[i].speedt;
303 tcsetattr(getrfd(), TCSANOW, &t);
305 return get_real_speed();
309 int WvModem::getstatus()
311 if (!isok())
return 0;
313 ioctl(getrfd(), TIOCMGET, &status);
320 return (getstatus() & TIOCM_CD) ? 1 : 0;
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
virtual void close()
do-nothing method that is not needed in WvModemBase
WvFile implements a stream connected to a file or Unix device.
virtual void close()
Closes the file descriptors.
virtual bool carrier()
Is there a carrier present?
virtual void close()
Close the connection to the modem.
virtual void hangup()
may need to hangup for redial reasons
virtual int speed(int _baud)
_baud is the desired speed, that you wish the modem to communicate with, and this method returns the ...
virtual bool carrier()
do-nothing method that is not needed in WvModemBase
virtual int speed(int _baud)
do-nothing method that is not needed in WvModemBase
WvModemBase provides the methods used to control a modem, but without real implementation for most of...