diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-09-14 06:54:44 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-09-14 06:57:44 -0400 |
commit | 531f5384638b9fe3e21e542ce6eed9a39b98fdfb (patch) | |
tree | 8bb2f3db54e8243f874d61c7ea58f7a5a0e70041 /gpsd_json.c | |
parent | ea0b84da541fb6e69d03a9dc85c399c7e4fff4cd (diff) | |
download | gpsd-531f5384638b9fe3e21e542ce6eed9a39b98fdfb.tar.gz |
Split Type 24 reporting, including the -s option to gpsdecode.
All regression tests pass.
Diffstat (limited to 'gpsd_json.c')
-rw-r--r-- | gpsd_json.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/gpsd_json.c b/gpsd_json.c index 9f57c032..babbc1ac 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -423,13 +423,14 @@ void json_watch_dump(const struct policy_t *ccp, { /*@-compdef@*/ (void)snprintf(reply, replylen, - "{\"class\":\"WATCH\",\"enable\":%s,\"json\":%s,\"nmea\":%s,\"raw\":%d,\"scaled\":%s,\"timing\":%s,", + "{\"class\":\"WATCH\",\"enable\":%s,\"json\":%s,\"nmea\":%s,\"raw\":%d,\"scaled\":%s,\"timing\":%s,\"split24\":%s", ccp->watcher ? "true" : "false", ccp->json ? "true" : "false", ccp->nmea ? "true" : "false", ccp->raw, ccp->scaled ? "true" : "false", - ccp->timing ? "true" : "false"); + ccp->timing ? "true" : "false", + ccp->split24 ? "true" : "false"); if (ccp->devpath[0] != '\0') (void)snprintf(reply + strlen(reply), replylen - strlen(reply), "\"device\":\"%s\",", ccp->devpath); @@ -2963,37 +2964,50 @@ void json_aivdm_dump(const struct ais_t *ais, } break; case 24: /* Class B CS Static Data Report */ - (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"shipname\":\"%s\",", - json_stringify(buf1, sizeof(buf1), - ais->type24.shipname)); - if (scaled) { + if (ais->type24.part != both) { + static char *partnames[] = {"AB", "A", "B"}; (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"shiptype\":\"%s\",", - SHIPTYPE_DISPLAY(ais->type24.shiptype)); - } else { - (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"shiptype\":%u,", ais->type24.shiptype); + "\"part\":\"%s\",", + json_stringify(buf1, sizeof(buf1), + partnames[ais->type24.part])); } - (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"vendorid\":\"%s\",\"callsign\":\"%s\",", - json_stringify(buf1, sizeof(buf1), - ais->type24.vendorid), - json_stringify(buf2, sizeof(buf2), - ais->type24.callsign)); - if (AIS_AUXILIARY_MMSI(ais->mmsi)) { + if (ais->type24.part != part_b) (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"mothership_mmsi\":%u}\r\n", - ais->type24.mothership_mmsi); - } else { + "\"shipname\":\"%s\",", + json_stringify(buf1, sizeof(buf1), + ais->type24.shipname)); + if (ais->type24.part != part_a) { + if (scaled) { + (void)snprintf(buf + strlen(buf), buflen - strlen(buf), + "\"shiptype\":\"%s\",", + SHIPTYPE_DISPLAY(ais->type24.shiptype)); + } else { + (void)snprintf(buf + strlen(buf), buflen - strlen(buf), + "\"shiptype\":%u,", ais->type24.shiptype); + } (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"to_bow\":%u,\"to_stern\":%u," - "\"to_port\":%u,\"to_starboard\":%u}\r\n", - ais->type24.dim.to_bow, - ais->type24.dim.to_stern, - ais->type24.dim.to_port, - ais->type24.dim.to_starboard); + "\"vendorid\":\"%s\",\"callsign\":\"%s\",", + json_stringify(buf1, sizeof(buf1), + ais->type24.vendorid), + json_stringify(buf2, sizeof(buf2), + ais->type24.callsign)); + if (AIS_AUXILIARY_MMSI(ais->mmsi)) { + (void)snprintf(buf + strlen(buf), buflen - strlen(buf), + "\"mothership_mmsi\":%u}\r\n", + ais->type24.mothership_mmsi); + } else { + (void)snprintf(buf + strlen(buf), buflen - strlen(buf), + "\"to_bow\":%u,\"to_stern\":%u," + "\"to_port\":%u,\"to_starboard\":%u", + ais->type24.dim.to_bow, + ais->type24.dim.to_stern, + ais->type24.dim.to_port, + ais->type24.dim.to_starboard); + } } + if (buf[strlen(buf)-1] == ',') + buf[strlen(buf)-1] = '\0'; + strncat(buf, "}\r\n", buflen); break; case 25: /* Binary Message, Single Slot */ (void)snprintf(buf + strlen(buf), buflen - strlen(buf), |