gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [patch v2] gpspipe improvement: add option to exit after dela


From: Jean Pierre TOSONI
Subject: [gpsd-dev] [patch v2] gpspipe improvement: add option to exit after delay
Date: Tue, 12 Dec 2017 10:20:05 +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 a bound time, this patch adds an 
option to specify a timout, so that one 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.

Update the documentation accordingly.
---
V2:
Added documentation (gpspipe.1, gpspipe.xml).
This patch applies to version 3.17.
(note: not sure I must patch gpspipe.1, it appears in the download package but 
not in the git repo... I am working on a package downloaded from 
Savannah.non-gnu.org by the OpenWRT framework)

--- a/gpspipe.c
+++ b/gpspipe.c
@@ -126,6 +126,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"
@@ -149,6 +150,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;
@@ -160,7 +162,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);
@@ -220,6 +222,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;
@@ -319,6 +324,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);
--- a/gpspipe.1
+++ b/gpspipe.1
@@ -31,7 +31,7 @@
 gpspipe \- tool to connect to gpsd and retrieve sentences
 .SH "SYNOPSIS"
 .HP \w'\fBgpspipe\fR\ 'u
-\fBgpspipe\fR [\-h] [\-d] [\-l] [\-o\ \fIfilename\fR] [\-n\ \fIcount\fR] [\-r] 
[\-R] [\-s\ \fIserial\-device\fR] [\-t] [\-T\ \fItimestamp\-format\fR] [\-u] 
[\-p] [\-w] [\-S] [\-2] [\-v] [\-D\ \fIdebug\-level\fR] [\fIserver\fR 
[\fI:port\fR [\fI:device\fR]]]
+\fBgpspipe\fR [\-h] [\-d] [\-l] [\-o\ \fIfilename\fR] [\-n\ \fIcount\fR] [\-x\ 
\fIduration\fR] [\-r] [\-R] [\-s\ \fIserial\-device\fR] [\-t] [\-T\ 
\fItimestamp\-format\fR] [\-u] [\-p] [\-w] [\-S] [\-2] [\-v] [\-D\ 
\fIdebug\-level\fR] [\fIserver\fR [\fI:port\fR [\fI:device\fR]]]
 .SH "DESCRIPTION"
 .PP
 gpspipe
@@ -48,7 +48,7 @@ without causing problems\&.
 .PP
 The output will consist of one or both of the raw NMEA or native
 gpsd
-sentences\&. Each line can be optionally time stamped\&. There is also an 
option to exit gracefully after a given count of packets\&.
+sentences\&. Each line can be optionally time stamped\&. There are also 
options to exit gracefully after a given count of packets or a given delay\&.
 .PP
 Optionally a server, TCP/IP port number and remote device can be given\&. If 
omitted,
 gpspipe
@@ -108,6 +108,10 @@ for the available placeholders\&. Settin
 gpspipe
 will then exit gracefully\&.
 .PP
+\-x [duration] exits gracefully after given [duration], even if nothing was 
received\&.
+Duration is in seconds with a margin of about 1 second\&.
+This delay starts counting after the optional 10s initial sleep (option -l)\&.
+.PP
 \-v causes
 gpspipe
 to show a spinning activity indicator on stderr\&. This is useful if stdout is 
redirected into a file or a pipe\&. By default the spinner is advanced with 
every messages written; specifying \-v more than once will double the number of 
messages required to rotate the spinner\&.
--- a/gpspipe.xml
+++ b/gpspipe.xml
@@ -27,6 +27,7 @@ BSD terms apply: see the file COPYING in
       <arg choice='opt'>-l</arg>
       <arg choice='opt'>-o <replaceable>filename</replaceable></arg>
       <arg choice='opt'>-n <replaceable>count</replaceable></arg>
+      <arg choice='opt'>-x <replaceable>duration</replaceable></arg>
       <arg choice='opt'>-r</arg>
       <arg choice='opt'>-R</arg>
       <arg choice='opt'>-s <replaceable>serial-device</replaceable></arg>
@@ -61,8 +62,8 @@ to the local <application>gpsd</applicat
 
 <para>The output will consist of one or both of the raw NMEA or native
 <application>gpsd</application> sentences.  Each line can be optionally
-time stamped.  There is also an option to exit gracefully after a
-given count of packets.</para>
+time stamped.  There are also options to exit gracefully after a
+given count of packets or a given duration.</para>
 
 <para>Optionally a server, TCP/IP port number and remote device can be given.
 If omitted, <application>gpspipe</application> connects to localhost on
@@ -124,6 +125,10 @@ Default setting is "%F %T"</para>
 <para>-n [count] causes [count] sentences to be output.
 <application>gpspipe</application> will then exit gracefully.</para>
 
+<para>-x [duration] exits gracefully after given [duration], even if nothing 
was received.
+Duration is in seconds with a margin of about 1 second.
+This delay starts counting after the optional 10s initial sleep (option 
-l).</para>
+
 <para>-v causes <application>gpspipe</application> to show a spinning
 activity indicator on stderr. This is useful if stdout is redirected
 into a file or a pipe. By default the spinner is advanced with every
--
quilt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]