summaryrefslogtreecommitdiff
path: root/gpsdecode.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-01-29 11:10:04 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-01-29 11:22:17 -0500
commit72c060151ece2f3c85e124fdc97083c292256350 (patch)
tree330c418d8772ef7e6b1b5dbd14d2cf5a4812b771 /gpsdecode.c
parent663e292b8017142d0400ebc517e026867dd6af60 (diff)
downloadgpsd-72c060151ece2f3c85e124fdc97083c292256350.tar.gz
Add gpsdecode -m option for dumping minimum packet lengths.
Diffstat (limited to 'gpsdecode.c')
-rw-r--r--gpsdecode.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/gpsdecode.c b/gpsdecode.c
index f9d6965e..8f7ace12 100644
--- a/gpsdecode.c
+++ b/gpsdecode.c
@@ -21,6 +21,7 @@ static bool scaled = true;
static bool json = true;
static bool pseudonmea = false;
static bool split24 = false;
+static bool minlength = false;
static unsigned int ntypes = 0;
static unsigned int typelist[32];
static struct gps_context_t context;
@@ -534,9 +535,11 @@ static void decode(FILE *fpin, FILE*fpout)
{
struct gps_device_t session;
struct policy_t policy;
+ unsigned int minima[PACKET_TYPES+1];
#if defined(SOCKET_EXPORT_ENABLE) || defined(AIVDM_ENABLE)
char buf[GPS_JSON_RESPONSE_MAX * 4];
#endif
+ int i;
//This looks like a good idea, but it breaks regression tests
//(void)strlcpy(session.gpsdata.dev.path, "stdin", sizeof(session.gpsdata.dev.path));
@@ -554,6 +557,8 @@ static void decode(FILE *fpin, FILE*fpout)
(void)strlcpy(session.gpsdata.dev.path,
"stdin",
sizeof(session.gpsdata.dev.path));
+ for (i = 0; i < (int)(sizeof(minima)/sizeof(minima[0])); i++)
+ minima[i] = MAX_PACKET_LENGTH+1;
for (;;)
{
@@ -565,6 +570,8 @@ static void decode(FILE *fpin, FILE*fpout)
gpsd_set_century(&session);
if (verbose >= 1 && TEXTUAL_PACKET_TYPE(session.lexer.type))
(void)fputs((char *)session.lexer.outbuffer, fpout);
+ if (session.lexer.outbuflen < minima[session.lexer.type+1])
+ minima[session.lexer.type+1] = session.lexer.outbuflen;
/* mask should match what's in report_data() */
if ((changed & (REPORT_IS|GST_SET|SATELLITE_SET|SUBFRAME_SET|ATTITUDE_SET|RTCM2_SET|RTCM3_SET|AIS_SET|PASSTHROUGH_IS)) == 0)
continue;
@@ -600,6 +607,24 @@ static void decode(FILE *fpin, FILE*fpout)
if (policy.nmea)
pseudonmea_report(changed, &session);
}
+
+ if (minlength)
+ {
+ for (i = 0; i < (int)(sizeof(minima)/sizeof(minima[0])); i++) {
+ const struct gps_type_t **dp;
+ /* dump all minima, ignoring comments */
+ if (i != 1 && minima[i] < MAX_PACKET_LENGTH+1) {
+ char *np = "Unknown";
+ for (dp = gpsd_drivers; *dp; dp++) {
+ if ((*dp)->packet_type == i-1) {
+ np = (*dp)->type_name;
+ break;
+ }
+ }
+ printf("%s (%d): %d\n", np, i-1, minima[i]);
+ }
+ }
+ }
}
#ifdef SOCKET_EXPORT_ENABLE
@@ -654,7 +679,7 @@ int main(int argc, char **argv)
gps_context_init(&context, "gpsdecode");
- while ((c = getopt(argc, argv, "cdejnpst:uvVD:")) != EOF) {
+ while ((c = getopt(argc, argv, "cdejmnpst:uvVD:")) != EOF) {
switch (c) {
case 'c':
json = false;
@@ -672,6 +697,11 @@ int main(int argc, char **argv)
json = true;
break;
+ case 'm':
+ minlength = true;
+ json = false;
+ break;
+
case 'n':
pseudonmea = true;
break;