2006-01-07 11:48:20 -05:00
|
|
|
/*
|
|
|
|
* WSJT is Copyright (c) 2001-2006 by Joseph H. Taylor, Jr., K1JT,
|
|
|
|
* and is licensed under the GNU General Public License (GPL).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
2006-01-07 15:14:23 -05:00
|
|
|
#include "conf.h" /* XXX Could use CFLAGS later instead --db */
|
2006-01-07 11:48:20 -05:00
|
|
|
|
2006-01-07 15:14:23 -05:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2006-01-07 11:48:20 -05:00
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* First cut, note that this only distinguishes Linux from BSDs,
|
|
|
|
* it will be done better later on using configure. N.B. that OSX
|
|
|
|
* will come up as BSD but I think this is also the right serial port
|
|
|
|
* for OSX. -db
|
|
|
|
*/
|
|
|
|
#if defined(BSD)
|
2006-01-15 18:32:39 -05:00
|
|
|
#define TTYNAME "/dev/cuad%d" /* Use non blocking form */
|
2006-01-07 11:48:20 -05:00
|
|
|
#else
|
|
|
|
#include <sys/io.h>
|
|
|
|
#define TTYNAME "/dev/ttyS%d"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Not quite right for size but '%d + 1' should be plenty enough -db */
|
|
|
|
#define TTYNAME_SIZE sizeof(TTYNAME)+1
|
|
|
|
|
2006-01-15 18:32:39 -05:00
|
|
|
int
|
|
|
|
ptt_(int *nport, int *ntx, int *iptt)
|
2006-01-07 11:48:20 -05:00
|
|
|
{
|
|
|
|
static int nopen=0;
|
|
|
|
int control = TIOCM_RTS | TIOCM_DTR;
|
|
|
|
int fd;
|
|
|
|
char s[TTYNAME_SIZE];
|
|
|
|
|
|
|
|
if(*nport < 0) {
|
|
|
|
*iptt=*ntx;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ntx && (!nopen)) {
|
2006-01-15 18:32:39 -05:00
|
|
|
snprintf(s, TTYNAME_SIZE, TTYNAME, (*nport) - 1); /* Comport 1 == dev 0 */
|
2006-01-07 11:48:20 -05:00
|
|
|
s[TTYNAME_SIZE] = '\0';
|
|
|
|
|
2006-01-15 18:32:39 -05:00
|
|
|
/* open the device */
|
2006-01-07 11:48:20 -05:00
|
|
|
if ((fd = open(s, O_RDWR | O_NDELAY)) < 0) {
|
2006-01-15 18:32:39 -05:00
|
|
|
fprintf(stderr, "Can't open %s.", s);
|
2006-01-07 11:48:20 -05:00
|
|
|
return(1);
|
|
|
|
}
|
2006-01-15 18:32:39 -05:00
|
|
|
|
2006-01-07 11:48:20 -05:00
|
|
|
nopen=1;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ntx && nopen) {
|
|
|
|
ioctl(fd, TIOCMBIS, &control); // Set DTR and RTS
|
|
|
|
*iptt=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
ioctl(fd, TIOCMBIC, &control);
|
|
|
|
close(fd);
|
|
|
|
*iptt=0;
|
|
|
|
nopen=0;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|