2000-10-01 14:24:47 +00:00
|
|
|
/*
|
2001-07-13 19:08:15 +00:00
|
|
|
* Hamlib Interface - serial communication low-level support
|
2005-04-03 12:27:17 +00:00
|
|
|
* Copyright (c) 2000-2005 by Stephane Fillod and Frank Singleton
|
2001-07-13 19:08:15 +00:00
|
|
|
* Parts of the PTT handling are derived from soundmodem, an excellent
|
|
|
|
* ham packet softmodem written by Thomas Sailer, HB9JNX.
|
2000-10-01 14:24:47 +00:00
|
|
|
*
|
2006-10-15 00:27:52 +00:00
|
|
|
* $Id: serial.c,v 1.45 2006-10-15 00:27:52 aa6e Exp $
|
2000-10-01 14:24:47 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
2001-02-11 23:16:07 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details.
|
2001-02-11 23:16:07 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2000-10-01 14:24:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup rig_internal
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Serial port IO
|
|
|
|
* \file serial.c
|
|
|
|
*/
|
|
|
|
|
2001-02-09 23:08:20 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-10-01 14:24:47 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h> /* Standard input/output definitions */
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
#include <fcntl.h> /* File control definitions */
|
|
|
|
#include <errno.h> /* Error number definitions */
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2003-04-16 22:33:18 +00:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
2000-10-01 14:24:47 +00:00
|
|
|
#include <sys/ioctl.h>
|
2003-04-16 22:33:18 +00:00
|
|
|
#endif
|
2000-10-01 14:24:47 +00:00
|
|
|
|
2002-09-08 22:45:16 +00:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
2001-02-14 01:09:57 +00:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
#include <termios.h> /* POSIX terminal control definitions */
|
2002-09-05 18:20:30 +00:00
|
|
|
#else
|
2001-02-14 01:09:57 +00:00
|
|
|
#ifdef HAVE_TERMIO_H
|
|
|
|
#include <termio.h>
|
|
|
|
#else /* sgtty */
|
2003-04-16 22:33:18 +00:00
|
|
|
#ifdef HAVE_SGTTY_H
|
2001-02-14 01:09:57 +00:00
|
|
|
#include <sgtty.h>
|
|
|
|
#endif
|
2002-09-05 18:20:30 +00:00
|
|
|
#endif
|
2003-04-16 22:33:18 +00:00
|
|
|
#endif
|
2001-02-14 01:09:57 +00:00
|
|
|
|
2003-08-20 07:22:40 +00:00
|
|
|
#if defined(WIN32) && !defined(HAVE_TERMIOS_H)
|
2003-08-15 01:25:26 +00:00
|
|
|
#include "win32termios.h"
|
2004-10-02 20:37:24 +00:00
|
|
|
#define HAVE_TERMIOS_H 1 /* we have replacement */
|
2003-08-15 01:25:26 +00:00
|
|
|
#else
|
|
|
|
#define OPEN open
|
|
|
|
#define CLOSE close
|
2004-08-01 23:13:17 +00:00
|
|
|
#define IOCTL ioctl
|
2003-08-15 01:25:26 +00:00
|
|
|
#endif
|
|
|
|
|
2000-10-08 21:46:09 +00:00
|
|
|
#include <hamlib/rig.h>
|
2000-10-01 14:24:47 +00:00
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2001-02-09 23:08:20 +00:00
|
|
|
#ifdef HAVE_SYS_IOCCOM_H
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#endif
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Open serial port using rig.state data
|
|
|
|
* \param rp port data structure (must spec port id eg /dev/ttyS1)
|
|
|
|
* \return RIG_OK or < 0 if error
|
2000-10-01 14:24:47 +00:00
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API serial_open(hamlib_port_t *rp) {
|
2000-10-01 14:24:47 +00:00
|
|
|
|
|
|
|
int fd; /* File descriptor for the port */
|
2002-03-07 22:49:00 +00:00
|
|
|
int err;
|
2001-02-14 01:09:57 +00:00
|
|
|
|
2001-06-05 18:08:30 +00:00
|
|
|
if (!rp)
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open in Non-blocking mode. Watch for EAGAIN errors!
|
|
|
|
*/
|
2003-08-15 01:25:26 +00:00
|
|
|
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
|
2000-10-01 14:24:47 +00:00
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
|
|
|
|
/* Could not open the port. */
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "serial_open: Unable to open %s - %s\n",
|
2001-07-25 21:59:55 +00:00
|
|
|
rp->pathname, strerror(errno));
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
|
2002-03-07 22:49:00 +00:00
|
|
|
rp->fd = fd;
|
|
|
|
|
|
|
|
err = serial_setup(rp);
|
|
|
|
if (err != RIG_OK) {
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2002-03-07 22:49:00 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Set up Serial port according to requests in port
|
|
|
|
* \param rp
|
|
|
|
* \return RIG_OK or < 0
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
2002-03-07 22:49:00 +00:00
|
|
|
{
|
|
|
|
int fd;
|
2003-08-15 01:25:26 +00:00
|
|
|
/* There's a lib replacement for termios under Mingw */
|
2004-10-02 20:37:24 +00:00
|
|
|
#if defined(HAVE_TERMIOS_H)
|
2003-04-19 11:49:43 +00:00
|
|
|
speed_t speed; /* serial comm speed */
|
2002-03-07 22:49:00 +00:00
|
|
|
struct termios options;
|
|
|
|
#elif defined(HAVE_TERMIO_H)
|
|
|
|
struct termio options;
|
|
|
|
#elif defined(HAVE_SGTTY_H)
|
|
|
|
struct sgttyb sg;
|
|
|
|
#else
|
|
|
|
#error "No term control supported!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!rp)
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
|
|
|
|
fd = rp->fd;
|
|
|
|
|
2000-10-01 14:24:47 +00:00
|
|
|
/*
|
|
|
|
* Get the current options for the port...
|
|
|
|
*/
|
|
|
|
|
2004-10-02 20:37:24 +00:00
|
|
|
#if defined(HAVE_TERMIOS_H)
|
2000-10-01 14:24:47 +00:00
|
|
|
tcgetattr(fd, &options);
|
2001-02-14 01:09:57 +00:00
|
|
|
#elif defined(HAVE_TERMIO_H)
|
2004-08-01 23:13:17 +00:00
|
|
|
IOCTL (fd, TCGETA, &options);
|
2001-02-14 01:09:57 +00:00
|
|
|
#else /* sgtty */
|
2004-08-01 23:13:17 +00:00
|
|
|
IOCTL (fd, TIOCGETP, &sg);
|
2001-02-14 01:09:57 +00:00
|
|
|
#endif
|
2002-01-22 21:17:55 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CFMAKERAW
|
2002-01-07 17:14:22 +00:00
|
|
|
cfmakeraw(&options); /* Set serial port to RAW mode by default. */
|
2002-01-22 21:17:55 +00:00
|
|
|
#endif
|
2002-01-07 17:14:22 +00:00
|
|
|
|
2000-10-01 14:24:47 +00:00
|
|
|
/*
|
|
|
|
* Set the baud rates to requested values
|
|
|
|
*/
|
|
|
|
|
2001-06-04 17:01:21 +00:00
|
|
|
switch(rp->parm.serial.rate) {
|
2000-10-01 14:24:47 +00:00
|
|
|
case 300:
|
|
|
|
speed = B300; /* yikes... */
|
|
|
|
break;
|
|
|
|
case 1200:
|
|
|
|
speed = B1200;
|
|
|
|
break;
|
|
|
|
case 2400:
|
|
|
|
speed = B2400;
|
|
|
|
break;
|
|
|
|
case 4800:
|
|
|
|
speed = B4800;
|
|
|
|
break;
|
|
|
|
case 9600:
|
|
|
|
speed = B9600;
|
|
|
|
break;
|
|
|
|
case 19200:
|
|
|
|
speed = B19200;
|
|
|
|
break;
|
|
|
|
case 38400:
|
|
|
|
speed = B38400;
|
|
|
|
break;
|
|
|
|
case 57600:
|
|
|
|
speed = B57600; /* cool.. */
|
|
|
|
break;
|
2001-06-02 17:56:37 +00:00
|
|
|
case 115200:
|
|
|
|
speed = B115200; /* awsome! */
|
|
|
|
break;
|
2000-10-01 14:24:47 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported rate specified: %d\n",
|
2001-06-04 17:01:21 +00:00
|
|
|
rp->parm.serial.rate);
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF;
|
|
|
|
}
|
2001-02-14 01:09:57 +00:00
|
|
|
/* TODO */
|
2000-10-01 14:24:47 +00:00
|
|
|
cfsetispeed(&options, speed);
|
|
|
|
cfsetospeed(&options, speed);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the receiver and set local mode...
|
|
|
|
*/
|
|
|
|
|
|
|
|
options.c_cflag |= (CLOCAL | CREAD);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set data to requested values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-06-04 17:01:21 +00:00
|
|
|
switch(rp->parm.serial.data_bits) {
|
2000-10-01 14:24:47 +00:00
|
|
|
case 7:
|
|
|
|
options.c_cflag &= ~CSIZE;
|
|
|
|
options.c_cflag |= CS7;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
options.c_cflag &= ~CSIZE;
|
|
|
|
options.c_cflag |= CS8;
|
|
|
|
break;
|
|
|
|
default:
|
2001-06-04 17:01:21 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"open_serial: unsupported serial_data_bits "
|
|
|
|
"specified: %d\n", rp->parm.serial.data_bits);
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set stop bits to requested values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-06-04 17:01:21 +00:00
|
|
|
switch(rp->parm.serial.stop_bits) {
|
2000-10-01 14:24:47 +00:00
|
|
|
case 1:
|
|
|
|
options.c_cflag &= ~CSTOPB;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
options.c_cflag |= CSTOPB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-06-04 17:01:21 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_stop_bits "
|
|
|
|
"specified: %d\n",
|
|
|
|
rp->parm.serial.stop_bits);
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set parity to requested values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-06-04 17:01:21 +00:00
|
|
|
switch(rp->parm.serial.parity) {
|
2000-10-01 14:24:47 +00:00
|
|
|
case RIG_PARITY_NONE:
|
|
|
|
options.c_cflag &= ~PARENB;
|
|
|
|
break;
|
|
|
|
case RIG_PARITY_EVEN:
|
|
|
|
options.c_cflag |= PARENB;
|
|
|
|
options.c_cflag &= ~PARODD;
|
|
|
|
break;
|
|
|
|
case RIG_PARITY_ODD:
|
|
|
|
options.c_cflag |= PARENB;
|
|
|
|
options.c_cflag |= PARODD;
|
|
|
|
break;
|
|
|
|
default:
|
2001-06-04 17:01:21 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported serial_parity "
|
|
|
|
"specified: %d\n",
|
|
|
|
rp->parm.serial.parity);
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set flow control to requested mode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-06-04 17:01:21 +00:00
|
|
|
switch(rp->parm.serial.handshake) {
|
2000-10-01 14:24:47 +00:00
|
|
|
case RIG_HANDSHAKE_NONE:
|
|
|
|
options.c_cflag &= ~CRTSCTS;
|
|
|
|
options.c_iflag &= ~IXON;
|
|
|
|
break;
|
|
|
|
case RIG_HANDSHAKE_XONXOFF:
|
|
|
|
options.c_cflag &= ~CRTSCTS;
|
|
|
|
options.c_iflag |= IXON; /* Enable Xon/Xoff software handshaking */
|
|
|
|
break;
|
|
|
|
case RIG_HANDSHAKE_HARDWARE:
|
|
|
|
options.c_cflag |= CRTSCTS; /* Enable Hardware handshaking */
|
|
|
|
options.c_iflag &= ~IXON;
|
|
|
|
break;
|
|
|
|
default:
|
2001-06-04 17:01:21 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: unsupported flow_control "
|
|
|
|
"specified: %d\n",
|
|
|
|
rp->parm.serial.handshake);
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose raw input, no preprocessing please ..
|
|
|
|
*/
|
|
|
|
|
2004-10-02 20:37:24 +00:00
|
|
|
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
|
2000-10-01 14:24:47 +00:00
|
|
|
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose raw output, no preprocessing please ..
|
|
|
|
*/
|
|
|
|
|
|
|
|
options.c_oflag &= ~OPOST;
|
|
|
|
|
2001-02-14 01:09:57 +00:00
|
|
|
#else /* sgtty */
|
|
|
|
sg.sg_flags = RAW;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-10-01 14:24:47 +00:00
|
|
|
/*
|
|
|
|
* Flush serial port
|
|
|
|
*/
|
|
|
|
|
|
|
|
tcflush(fd, TCIFLUSH);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, set the new options for the port...
|
|
|
|
*/
|
|
|
|
|
2004-10-02 20:37:24 +00:00
|
|
|
#if defined(HAVE_TERMIOS_H)
|
2000-10-01 14:24:47 +00:00
|
|
|
if (tcsetattr(fd, TCSANOW, &options) == -1) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: tcsetattr failed: %s\n",
|
|
|
|
strerror(errno));
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2000-10-01 14:24:47 +00:00
|
|
|
return -RIG_ECONF; /* arg, so close! */
|
|
|
|
}
|
2001-02-14 01:09:57 +00:00
|
|
|
#elif defined(HAVE_TERMIO_H)
|
2004-08-01 23:13:17 +00:00
|
|
|
if (IOCTL(fd, TCSETA, &options) == -1) {
|
2001-02-14 01:09:57 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TCSETA) failed: %s\n",
|
|
|
|
strerror(errno));
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2001-02-14 01:09:57 +00:00
|
|
|
return -RIG_ECONF; /* arg, so close! */
|
|
|
|
}
|
|
|
|
#else /* sgtty */
|
2004-08-01 23:13:17 +00:00
|
|
|
if (IOCTL(fd, TIOCSETP, &sg) == -1) {
|
2001-02-14 01:09:57 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "open_serial: ioctl(TIOCSETP) failed: %s\n",
|
|
|
|
strerror(errno));
|
2003-08-15 01:25:26 +00:00
|
|
|
CLOSE(fd);
|
2001-02-14 01:09:57 +00:00
|
|
|
return -RIG_ECONF; /* arg, so close! */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-10-01 14:24:47 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Flush all characters waiting in RX buffer.
|
|
|
|
* \param p
|
|
|
|
* \return RIG_OK
|
2001-12-15 03:13:39 +00:00
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API serial_flush(hamlib_port_t *p )
|
2001-12-15 03:13:39 +00:00
|
|
|
{
|
|
|
|
tcflush(p->fd, TCIFLUSH);
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Open serial port
|
|
|
|
* \param p
|
|
|
|
* \return fd
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int ser_open(hamlib_port_t *p)
|
2001-06-02 17:56:37 +00:00
|
|
|
{
|
2004-08-01 23:13:17 +00:00
|
|
|
return (p->fd = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY));
|
2001-06-02 17:56:37 +00:00
|
|
|
}
|
2001-02-09 23:08:20 +00:00
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Close serial port
|
|
|
|
* \param p fd
|
|
|
|
* \return RIG_OK or < 0
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int ser_close(hamlib_port_t *p)
|
2001-02-09 23:08:20 +00:00
|
|
|
{
|
2004-08-01 23:13:17 +00:00
|
|
|
return CLOSE(p->fd);
|
2001-02-09 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Set Request to Send (RTS) bit
|
|
|
|
* \param p
|
|
|
|
* \param state true/false
|
|
|
|
* \return RIG_OK or < 0
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
|
2001-01-28 22:18:09 +00:00
|
|
|
{
|
2003-08-25 22:35:55 +00:00
|
|
|
unsigned int y = TIOCM_RTS;
|
2004-08-01 23:13:17 +00:00
|
|
|
|
2003-08-25 22:35:55 +00:00
|
|
|
#if defined(TIOCMBIS) && defined(TIOCMBIC)
|
2004-10-02 20:18:16 +00:00
|
|
|
return IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y) < 0 ?
|
|
|
|
-RIG_EIO : RIG_OK;
|
2003-08-25 22:35:55 +00:00
|
|
|
#else
|
2004-08-01 23:13:17 +00:00
|
|
|
if (IOCTL(p->fd, TIOCMGET, &y) < 0) {
|
2003-08-25 22:35:55 +00:00
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
if (state)
|
|
|
|
y |= TIOCM_RTS;
|
|
|
|
else
|
|
|
|
y &= ~TIOCM_RTS;
|
2004-10-02 20:18:16 +00:00
|
|
|
return IOCTL(p->fd, TIOCMSET, &y) < 0 ? -RIG_EIO : RIG_OK;
|
2003-02-23 22:36:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-01-28 22:18:09 +00:00
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Get RTS bit
|
|
|
|
* \param p supposed to be &rig->state.rigport
|
|
|
|
* \param state non-NULL
|
2003-08-17 22:39:07 +00:00
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_get_rts(hamlib_port_t *p, int *state)
|
2003-08-17 22:39:07 +00:00
|
|
|
{
|
2004-10-02 20:18:16 +00:00
|
|
|
int retcode;
|
2003-08-17 22:39:07 +00:00
|
|
|
unsigned int y;
|
2004-10-02 20:18:16 +00:00
|
|
|
|
|
|
|
retcode = IOCTL(p->fd, TIOCMGET, &y);
|
|
|
|
*state = (y & TIOCM_RTS) == TIOCM_RTS;
|
|
|
|
|
|
|
|
return retcode < 0 ? -RIG_EIO : RIG_OK;
|
2003-08-17 22:39:07 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Set Data Terminal Ready (DTR) bit
|
|
|
|
* \param p
|
|
|
|
* \param state true/false
|
|
|
|
* \return RIG_OK or < 0
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
|
2003-02-23 22:36:30 +00:00
|
|
|
{
|
2003-08-25 22:35:55 +00:00
|
|
|
unsigned int y = TIOCM_DTR;
|
2004-08-01 23:13:17 +00:00
|
|
|
|
2003-08-25 22:35:55 +00:00
|
|
|
#if defined(TIOCMBIS) && defined(TIOCMBIC)
|
2004-10-02 20:18:16 +00:00
|
|
|
return IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y) < 0 ?
|
|
|
|
-RIG_EIO : RIG_OK;
|
2003-08-25 22:35:55 +00:00
|
|
|
#else
|
2004-08-01 23:13:17 +00:00
|
|
|
if (IOCTL(p->fd, TIOCMGET, &y) < 0) {
|
2003-08-25 22:35:55 +00:00
|
|
|
return -RIG_EIO;
|
|
|
|
}
|
|
|
|
if (state)
|
|
|
|
y |= TIOCM_DTR;
|
|
|
|
else
|
|
|
|
y &= ~TIOCM_DTR;
|
2004-10-02 20:18:16 +00:00
|
|
|
return IOCTL(p->fd, TIOCMSET, &y) < 0 ? -RIG_EIO : RIG_OK;
|
2001-06-02 17:56:37 +00:00
|
|
|
#endif
|
2003-02-23 22:36:30 +00:00
|
|
|
}
|
2001-02-09 23:08:20 +00:00
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Get DTR bit
|
|
|
|
* \param p supposed to be &rig->state.rigport
|
|
|
|
* \param state non-NULL
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_get_dtr(hamlib_port_t *p, int *state)
|
2003-08-17 22:39:07 +00:00
|
|
|
{
|
2004-10-02 20:18:16 +00:00
|
|
|
int retcode;
|
2003-08-25 22:35:55 +00:00
|
|
|
unsigned int y;
|
2004-10-02 20:18:16 +00:00
|
|
|
|
|
|
|
retcode = IOCTL(p->fd, TIOCMGET, &y);
|
|
|
|
*state = (y & TIOCM_DTR) == TIOCM_DTR;
|
|
|
|
|
|
|
|
return retcode < 0 ? -RIG_EIO : RIG_OK;
|
2003-08-17 22:39:07 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Set Break
|
|
|
|
* \param p
|
|
|
|
* \param state (ignored?)
|
|
|
|
* \return RIG_OK or < 0
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_set_brk(hamlib_port_t *p, int state)
|
2004-04-16 20:04:11 +00:00
|
|
|
{
|
|
|
|
#if defined(TIOCSBRK) && defined(TIOCCBRK)
|
2004-10-02 20:18:16 +00:00
|
|
|
return IOCTL(p->fd, state ? TIOCSBRK : TIOCCBRK, 0 ) < 0 ?
|
|
|
|
-RIG_EIO : RIG_OK;
|
2004-04-16 20:04:11 +00:00
|
|
|
#else
|
|
|
|
return -RIG_ENIMPL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Get Carrier (CI?) bit
|
|
|
|
* \param p supposed to be &rig->state.rigport
|
|
|
|
* \param state non-NULL
|
2003-08-17 22:39:07 +00:00
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_get_car(hamlib_port_t *p, int *state)
|
2003-08-17 22:39:07 +00:00
|
|
|
{
|
2004-10-02 20:18:16 +00:00
|
|
|
int retcode;
|
2003-08-17 22:39:07 +00:00
|
|
|
unsigned int y;
|
|
|
|
|
2004-10-02 20:18:16 +00:00
|
|
|
retcode = IOCTL(p->fd, TIOCMGET, &y);
|
|
|
|
*state = (y & TIOCM_CAR) == TIOCM_CAR;
|
|
|
|
|
|
|
|
return retcode < 0 ? -RIG_EIO : RIG_OK;
|
2001-02-09 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Get Clear to Send (CTS) bit
|
|
|
|
* \param p supposed to be &rig->state.rigport
|
|
|
|
* \param state non-NULL
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_get_cts(hamlib_port_t *p, int *state)
|
2001-02-09 23:08:20 +00:00
|
|
|
{
|
2004-10-02 20:18:16 +00:00
|
|
|
int retcode;
|
|
|
|
unsigned int y;
|
|
|
|
|
|
|
|
retcode = IOCTL(p->fd, TIOCMGET, &y);
|
|
|
|
*state = (y & TIOCM_CTS) == TIOCM_CTS;
|
2001-02-09 23:08:20 +00:00
|
|
|
|
2004-10-02 20:18:16 +00:00
|
|
|
return retcode < 0 ? -RIG_EIO : RIG_OK;
|
2001-02-09 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
|
|
|
* \brief Get Data Set Ready (DSR) bit
|
|
|
|
* \param p supposed to be &rig->state.rigport
|
|
|
|
* \param state non-NULL
|
|
|
|
*/
|
2005-04-03 12:27:17 +00:00
|
|
|
int HAMLIB_API ser_get_dsr(hamlib_port_t *p, int *state)
|
2001-02-09 23:08:20 +00:00
|
|
|
{
|
2004-10-02 20:18:16 +00:00
|
|
|
int retcode;
|
|
|
|
unsigned int y;
|
|
|
|
|
|
|
|
retcode = IOCTL(p->fd, TIOCMGET, &y);
|
|
|
|
*state = (y & TIOCM_DSR) == TIOCM_DSR;
|
2001-02-09 23:08:20 +00:00
|
|
|
|
2004-10-02 20:18:16 +00:00
|
|
|
return retcode < 0 ? -RIG_EIO : RIG_OK;
|
2001-02-09 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/** @} */
|