summaryrefslogtreecommitdiff
path: root/gpspipe.c
diff options
context:
space:
mode:
authorJean Pierre TOSONI <jp.tosoni@acksys.fr>2017-12-07 11:43:18 +0000
committerGary E. Miller <gem@rellim.com>2018-06-17 14:21:42 -0700
commitabc014e31d2babbec0bac80c8f815807812bef79 (patch)
tree15d8f49364f21b785cbfec9c1e83565488615dfd /gpspipe.c
parent79f3beef99a8f97e579b988bd8396d3ceaac99ed (diff)
downloadgpsd-abc014e31d2babbec0bac80c8f815807812bef79.tar.gz
gpspipe improvement: add option to exit after delay
If the GPS receiver cease to supply data to gpsd, gpspipe hangs indefinitely waiting for gpsd. This can happen if the GPS is turned off by external means, e.g. by an AT command on the command port of a cellular card. In order to use gpspipe to get a fix within bounded time, this patch adds an option to specify a timout, so that I can do things like: $x=$(gpspipe -x 5 -w|sed -n '/TPV/{p;q}') And get either the first TPV or an empty string if no fix is available. Signed-off-by: Gary E. Miller <gem@rellim.com>
Diffstat (limited to 'gpspipe.c')
-rw-r--r--gpspipe.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/gpspipe.c b/gpspipe.c
index 9c2e2438..6a9c2237 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -128,6 +128,7 @@ static void usage(void)
"-u usec time stamp, implies -t. Use -uu to output sec.usec\n"
"-s [serial dev] emulate a 4800bps NMEA GPS on serial port (use with '-r').\n"
"-n [count] exit after count packets.\n"
+ "-x [seconds] Exit after given delay.\n"
"-v Print a little spinner.\n"
"-p Include profiling info in the JSON.\n"
"-P Include PPS JSON in NMEA or raw mode.\n"
@@ -151,6 +152,7 @@ int main(int argc, char **argv)
bool profile = false;
int option_u = 0; // option to show uSeconds
long count = -1;
+ time_t exit_timer = 0;
int option;
unsigned int vflag = 0, l = 0;
FILE *fp;
@@ -162,7 +164,7 @@ int main(int argc, char **argv)
char *outfile = NULL;
flags = WATCH_ENABLE;
- while ((option = getopt(argc, argv, "?dD:lhrRwStT:vVn:s:o:pPu2")) != -1) {
+ while ((option = getopt(argc, argv, "?dD:lhrRwStT:vVx:n:s:o:pPu2")) != -1) {
switch (option) {
case 'D':
debug = atoi(optarg);
@@ -222,6 +224,9 @@ int main(int argc, char **argv)
(void)fprintf(stderr, "%s: %s (revision %s)\n",
argv[0], VERSION, REVISION);
exit(EXIT_SUCCESS);
+ case 'x':
+ exit_timer = time(NULL) + strtol(optarg, 0, 0);
+ break;
case 's':
serialport = optarg;
break;
@@ -321,6 +326,8 @@ int main(int argc, char **argv)
FD_SET(gpsdata.gps_fd, &fds);
errno = 0;
r = select(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv);
+ if (r >= 0 && exit_timer && time(NULL) >= exit_timer)
+ break;
if (r == -1 && errno != EINTR) {
(void)fprintf(stderr, "gpspipe: select error %s(%d)\n",
strerror(errno), errno);