diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-10-27 18:42:15 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-10-27 18:42:15 -0400 |
commit | 8e081d14aeb9419b57b34126570644037081f24a (patch) | |
tree | 3143a5b1688ae44a87244831ce75554d96a5d31b /contrib | |
parent | 6e83e35d584d22c73a885989d867ef84ff89377e (diff) | |
download | gpsd-8e081d14aeb9419b57b34126570644037081f24a.tar.gz |
Add contrib/ppscheck utility to test for 1PPS without a lot of code complexity.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/README | 7 | ||||
-rw-r--r-- | contrib/ppscheck.c | 62 |
2 files changed, 69 insertions, 0 deletions
diff --git a/contrib/README b/contrib/README index 71dc8412..133c3875 100644 --- a/contrib/README +++ b/contrib/README @@ -45,3 +45,10 @@ to create a snapshot of the current sat view. ntpoffset generate an estimate of your GPS's offset from a peerstats file. For instructions on how to use this script, see the GPSD Time Service HOWTO in this distrubution. + +ppscheck watches a specified serial device for changes in handshake lines +CD, RI, and CTS by running ioctl(...., TIOCMIWAIT, ...) in a loop. When it +sees a state change it emits a timestamped line of output dumping the state +of the handshake signals. It's useful for checking whether a device is +emitting 1PPS. + diff --git a/contrib/ppscheck.c b/contrib/ppscheck.c new file mode 100644 index 00000000..6371639c --- /dev/null +++ b/contrib/ppscheck.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#ifndef S_SPLINT_S +#include <unistd.h> +#endif /* S_SPLINT_S */ +#include <fcntl.h> /* needed for open() and friends */ +#include <sys/ioctl.h> +#include <errno.h> +#include <time.h> + +struct assoc { + int mask; + char *string; +}; + +const static struct assoc hlines[] = { + {TIOCM_CD, "TIOCM_CD"}, + {TIOCM_RI, "TIOCM_RI"}, + {TIOCM_CTS, "TIOCM_CTS"}, +}; + + +int main(int argc, char *argv[]) +{ + struct timespec ts; + int fd = open(argv[1], O_RDONLY); + + if (fd == -1) { + (void)fprintf(stderr, + "open(%s) failed: %d %.40s\n", + argv[1], errno, strerror(errno)); + return 1; + } + + (void)printf("Beginning wait...\n"); + + for (;;) { + if (ioctl(fd, TIOCMIWAIT, TIOCM_CD|TIOCM_CAR|TIOCM_RI|TIOCM_CTS) != 0) { + (void)fprintf(stderr, + "PPS ioctl(TIOCMIWAIT) failed: %d %.40s\n", + errno, strerror(errno)); + break; + } else { + const struct assoc *sp; + int handshakes; + + clock_gettime(CLOCK_REALTIME, &ts); + ioctl(fd, TIOCMGET, &handshakes); + (void)fprintf(stdout, "%10ld %10ld", ts.tv_sec, ts.tv_nsec); + for (sp = hlines; + sp < hlines + sizeof(hlines)/sizeof(hlines[0]); + sp++) + if ((handshakes & sp->mask) != 0) { + (void)fputc(' ', stdout); + (void)fputs(sp->string, stdout); + } + (void)fputc('\n', stdout); + } + } +} |