summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-04-21 05:42:43 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-04-21 05:42:43 -0400
commit279ddb6ebbb4c01a2ebf306bab227df09f12fb96 (patch)
treee8c3c5c36593df8cd748202b4a9cc6bcb1e6fd58
parent9fa0d5a5f41dd298d73051458189536dfe8f4ccd (diff)
downloadgpsd-279ddb6ebbb4c01a2ebf306bab227df09f12fb96.tar.gz
Inplement -t option of gpsdecode for type filtering.
Intended mainly for selective reports from very large AIS logs.
-rw-r--r--gpsdecode.c41
-rw-r--r--gpsdecode.xml7
2 files changed, 46 insertions, 2 deletions
diff --git a/gpsdecode.c b/gpsdecode.c
index 17501422..bb66501f 100644
--- a/gpsdecode.c
+++ b/gpsdecode.c
@@ -17,6 +17,8 @@
static int verbose = 0;
static bool scaled = true;
static bool json = true;
+static int ntypes = 0;
+static int typelist[32];
/**************************************************************************
*
@@ -36,7 +38,7 @@ void gpsd_report(int errlevel, const char *fmt, ...)
(void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt,
ap);
va_end(ap);
- (void)fputs(buf, stdout);
+ (void)fputs(buf, stderr);
}
}
@@ -358,6 +360,29 @@ static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen)
}
#endif
+static bool filter(gps_mask_t changed, struct gps_device_t *session)
+/* say whether a given message should be visible */
+{
+ if (ntypes == 0)
+ return true;
+ else {
+ int i, t;
+
+ if ((changed & AIS_SET)!=0)
+ t = session->gpsdata.ais.type;
+ else if ((changed & RTCM2_SET)!=0)
+ t = session->gpsdata.rtcm2.type;
+ else if ((changed & RTCM3_SET)!=0)
+ t = session->gpsdata.rtcm3.type;
+ else
+ return true;
+ for (i = 0; i < ntypes; i++)
+ if (t == typelist[i])
+ return true;
+ }
+ return false;
+}
+
/*@ -compdestroy -compdef -usedef -uniondef @*/
static void decode(FILE *fpin, FILE*fpout)
/* sensor data on fpin to dump format on fpout */
@@ -387,6 +412,8 @@ static void decode(FILE *fpin, FILE*fpout)
(void)fputs((char *)session.packet.outbuffer, fpout);
if ((changed & (REPORT_IS|SUBFRAME_SET|AIS_SET|RTCM2_SET|RTCM3_SET)) == 0)
continue;
+ if (!filter(changed, &session))
+ continue;
else if (json) {
json_data_report(changed,
&session.gpsdata, &policy,
@@ -441,7 +468,7 @@ int main(int argc, char **argv)
enum
{ doencode, dodecode } mode = dodecode;
- while ((c = getopt(argc, argv, "cdejpuvVD:")) != EOF) {
+ while ((c = getopt(argc, argv, "cdejpt:uvVD:")) != EOF) {
switch (c) {
case 'c':
json = false;
@@ -459,6 +486,16 @@ int main(int argc, char **argv)
json = true;
break;
+ case 't':
+ typelist[ntypes++] = atoi(strtok(optarg, ","));
+ for(;;) {
+ char *next = strtok(NULL, ",");
+ if (next == NULL)
+ break;
+ typelist[ntypes++] = atoi(next);
+ }
+ break;
+
case 'u':
scaled = false;
break;
diff --git a/gpsdecode.xml b/gpsdecode.xml
index b32488e6..70b49dc9 100644
--- a/gpsdecode.xml
+++ b/gpsdecode.xml
@@ -26,6 +26,7 @@ BSD terms apply: see the file COPYING in the distribution root for details.
<arg choice='opt'>-d</arg>
<arg choice='opt'>-e</arg>
<arg choice='opt'>-j</arg>
+ <arg choice='opt'>-t <replaceable>typelist</replaceable></arg>
<arg choice='opt'>-u</arg>
<arg choice='opt'>-v</arg>
<arg choice='opt'>-D <replaceable>debuglevel</replaceable></arg>
@@ -72,6 +73,12 @@ encode JSON on standard input to JSON on standard output. This option
is only useful for regression-testing of the JSON dumping and parsing
code.</para>
+<para>The <option>-t</option> accepts a comma-separated list of
+numeric types. Packets with a numeric AIS, RTCM2, or RTCM3 type are
+passed through and output only if they match a type in the
+list. Packets of other kinds (in particular GPS packets) are
+passed through unconditionally.</para>
+
<para>The <option>-u</option> suppresses scaling of AIS data to float
quantities and text expansion of numeric codes. A dump with this
option is lossless.</para>