ts3_remote_ham/ptt_daemon.c
2024-09-12 02:00:26 +02:00

39 lines
730 B
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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);
// The below flags can be replaced by TIOCM_DTR to use the DTR line instead, See $ man "TIOCMSET(2const)"
if (rtsEnable != 0) {
flags |= TIOCM_RTS; // brings the RTS line high
} else {
flags &= ~TIOCM_RTS;
}
ioctl(fd, TIOCMSET, &flags);
close(fd);
}