summaryrefslogtreecommitdiff
path: root/gpsdecode.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-09-22 07:35:34 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-09-22 08:25:41 -0400
commit3fedfc96ff25ed799aed441c2ac702dd168a44e5 (patch)
tree0ae04297c1c3e1d4d45f0f100ac30cd302bb5629 /gpsdecode.c
parent80b291360fe68d9c4c5c09978a9654dfaee07fac (diff)
downloadgpsd-3fedfc96ff25ed799aed441c2ac702dd168a44e5.tar.gz
Add -n option to gpsdecode to dump pseudo-NMEA.
Required for testing the changes related to saellide-data representation. All regression tests pass.
Diffstat (limited to 'gpsdecode.c')
-rw-r--r--gpsdecode.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/gpsdecode.c b/gpsdecode.c
index 22e342f5..409d154d 100644
--- a/gpsdecode.c
+++ b/gpsdecode.c
@@ -18,6 +18,7 @@
static int verbose = 0;
static bool scaled = true;
static bool json = true;
+static bool pseudonmea = false;
static bool split24 = false;
static unsigned int ntypes = 0;
static unsigned int typelist[32];
@@ -510,6 +511,36 @@ static bool filter(gps_mask_t changed, struct gps_device_t *session)
return false;
}
+static void pseudonmea_report(gps_mask_t changed, struct gps_device_t *device)
+/* report pseudo-NMEA in appropriate circumstances */
+{
+ if (GPS_PACKET_TYPE(device->lexer.type)
+ && !TEXTUAL_PACKET_TYPE(device->lexer.type)) {
+ char buf[MAX_PACKET_LENGTH * 3 + 2];
+
+ if ((changed & REPORT_IS) != 0) {
+ nmea_tpv_dump(device, buf, sizeof(buf));
+ (void)fputs(buf, stdout);
+ }
+
+ if ((changed & SATELLITE_SET) != 0) {
+ nmea_sky_dump(device, buf, sizeof(buf));
+ (void)fputs(buf, stdout);
+ }
+
+ if ((changed & SUBFRAME_SET) != 0) {
+ nmea_subframe_dump(device, buf, sizeof(buf));
+ (void)fputs(buf, stdout);
+ }
+#ifdef AIVDM_ENABLE
+ if ((changed & AIS_SET) != 0) {
+ nmea_ais_dump(device, buf, sizeof(buf));
+ (void)fputs(buf, stdout);
+ }
+#endif /* AIVDM_ENABLE */
+ }
+}
+
/*@ -mustfreeonly -compdestroy -compdef -usedef -uniondef -immediatetrans -observertrans -statictrans @*/
static void decode(FILE *fpin, FILE*fpout)
/* sensor data on fpin to dump format on fpout */
@@ -525,6 +556,7 @@ static void decode(FILE *fpin, FILE*fpout)
memset(&policy, '\0', sizeof(policy));
policy.json = json;
policy.scaled = scaled;
+ policy.nmea = pseudonmea;
gpsd_time_init(&context, time(NULL));
context.readonly = true;
@@ -578,6 +610,8 @@ static void decode(FILE *fpin, FILE*fpout)
}
#endif /* AIVDM_ENABLE */
}
+ if (policy.nmea)
+ pseudonmea_report(changed, &session);
}
}
@@ -599,6 +633,7 @@ static void encode(FILE *fpin, FILE *fpout)
"stdin",
sizeof(session.gpsdata.dev.path));
policy.json = true;
+ policy.nmea = pseudonmea;
/* Parsing is always made in unscaled mode,
* this policy applies to the dumping */
policy.scaled = scaled;
@@ -628,12 +663,11 @@ static void encode(FILE *fpin, FILE *fpout)
int main(int argc, char **argv)
{
int c;
- enum
- { doencode, dodecode } mode = dodecode;
+ enum { doencode, dodecode } mode = dodecode;
gps_context_init(&context, "gpsdecode");
- while ((c = getopt(argc, argv, "cdejpst:uvVD:")) != EOF) {
+ while ((c = getopt(argc, argv, "cdejnpst:uvVD:")) != EOF) {
switch (c) {
case 'c':
json = false;
@@ -651,6 +685,10 @@ int main(int argc, char **argv)
json = true;
break;
+ case 'n':
+ pseudonmea = true;
+ break;
+
case 's':
split24 = true;
break;