[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] gpspipe improvement: add option to exit after delay
From: |
Jean Pierre TOSONI |
Subject: |
[gpsd-dev] gpspipe improvement: add option to exit after delay |
Date: |
Thu, 7 Dec 2017 11:43:18 +0000 |
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.
---
This patch applies to version 3.16.
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -110,6 +110,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"
@@ -133,6 +134,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;
@@ -144,7 +146,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);
@@ -204,6 +206,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;
@@ -303,6 +308,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);
--
quilt
- [gpsd-dev] gpspipe improvement: add option to exit after delay,
Jean Pierre TOSONI <=