ts3_remote_ham/ptt_daemon.c

39 lines
730 B
C
Raw Normal View History

2022-03-02 10:54:02 +01:00
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Usage: ./ptt_daemon <device> <1 or 0 (RTS high or low)>\n");
exit(1);
}
int fd = open(argv[1], O_RDWR | O_NDELAY);
if (fd < 0) {
exit(1);
}
int rtsEnable;
sscanf(argv[2], "%d", &rtsEnable);
int flags;
ioctl(fd, TIOCMGET, &flags);
2024-09-12 02:00:26 +02:00
// The below flags can be replaced by TIOCM_DTR to use the DTR line instead, See $ man "TIOCMSET(2const)"
2022-03-02 10:54:02 +01:00
if (rtsEnable != 0) {
2024-09-12 02:00:26 +02:00
flags |= TIOCM_RTS; // brings the RTS line high
2022-03-02 10:54:02 +01:00
} else {
flags &= ~TIOCM_RTS;
}
ioctl(fd, TIOCMSET, &flags);
close(fd);
}