From 8a3e4eb784c9ce683ed498fd0b9ac5a5ed6c6c9b Mon Sep 17 00:00:00 2001 From: Diane Bruce Date: Sat, 7 Jan 2006 16:48:20 +0000 Subject: [PATCH] - initial cut at a portable ptt module for all unix and unix like systems It will be refined later on for OSX/Solaris etc. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/trunk@56 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- ptt_unix.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ptt_unix.c diff --git a/ptt_unix.c b/ptt_unix.c new file mode 100644 index 000000000..7894d84de --- /dev/null +++ b/ptt_unix.c @@ -0,0 +1,69 @@ +/* + * WSJT is Copyright (c) 2001-2006 by Joseph H. Taylor, Jr., K1JT, + * and is licensed under the GNU General Public License (GPL). + */ + +#include +#include +#include +#include + +#if (defined(__unix__) || defined(unix)) && !defined(USG) +#include +#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) +#define TTYNAME "/dev/ttyd%d" +#else +#include +#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 + +int ptt_(int *nport, int *ntx, int *iptt) +{ + 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)) { + snprintf(s, TTYNAME_SIZE, TTYNAME, *nport); + s[TTYNAME_SIZE] = '\0'; + + //open the device + if ((fd = open(s, O_RDWR | O_NDELAY)) < 0) { + fprintf(stderr, "device not found"); + return(1); + } + nopen=1; + return(0); + } + + if(*ntx && nopen) { + // printf("Set DTR/RTS %d %d\n",TIOCMBIS,control); + ioctl(fd, TIOCMBIS, &control); // Set DTR and RTS + *iptt=1; + } + + else { + // printf("Clear DTR/RTS %d %d\n",TIOCMBIC,control); + ioctl(fd, TIOCMBIC, &control); + close(fd); + *iptt=0; + nopen=0; + } + return(0); +}