#include #include #include #include #include #include #include #include #include #include void usage(char *name) { fprintf(stderr, "usage: %s [enable|disable]\n", name); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { int fd, ret; struct serial_struct ss; if (argc < 2) usage(argv[0]); fd = open(argv[1], O_RDWR); if (fd < 0) { perror("open"); exit(EXIT_FAILURE); } ret = ioctl(fd, TIOCGSERIAL, &ss); if (ret < 0 ) { perror("ioctl(TIOCGSERIAL)"); exit(EXIT_FAILURE); } if (argc < 3) { /* just read PPS status */ printf("PPS is %sabled\n", ss.flags & ASYNC_HARDPPS_CD ? "en" : "dis"); exit(EXIT_SUCCESS); } if (argv[2][0] == 'e' || argv[2][0] == '1') ss.flags |= ASYNC_HARDPPS_CD; else if (argv[2][0] == 'd' || argv[2][0] == '0') ss.flags &= ~ASYNC_HARDPPS_CD; else { fprintf(stderr, "invalid state argument \"%s\"\n", argv[2]); exit(EXIT_FAILURE); } ret = ioctl(fd, TIOCSSERIAL, &ss); if (ret < 0) { perror("ioctl(TIOCSSERIAL)"); exit(EXIT_FAILURE); } return 0; }