39 lines
730 B
C
39 lines
730 B
C
#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);
|
||
|
||
}
|