summaryrefslogtreecommitdiff
path: root/driver_rtcm2.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-31 00:05:36 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-31 00:05:36 +0000
commita77868fdae57824e5fbd8b48a3320009a275864d (patch)
tree532f568c8806dcddaa77ab5ccfa1a4605b7c56b0 /driver_rtcm2.c
parent9714220e8d32fc6d5367652283646c0c1ce1c7f6 (diff)
downloadgpsd-a77868fdae57824e5fbd8b48a3320009a275864d.tar.gz
Arrange for double quotes in JSON string fields emitted by the daemon...
...to be properly backslash-escaped.
Diffstat (limited to 'driver_rtcm2.c')
-rw-r--r--driver_rtcm2.c127
1 files changed, 0 insertions, 127 deletions
diff --git a/driver_rtcm2.c b/driver_rtcm2.c
index fb1bdd43..b7d2ddff 100644
--- a/driver_rtcm2.c
+++ b/driver_rtcm2.c
@@ -453,13 +453,6 @@ enum isgpsstat_t rtcm2_decode(struct gps_packet_t *lexer, unsigned int c)
c);
}
-/*
- * Beware! Needs to stay synchronized with a JSON enumeration map in
- * the parser. This interpretation of NAVSYSTEM_GALILEO is assumed
- * from RTCM3, it's not actually documented in RTCM 2.1.
- */
-static char *navsysnames[] = {"GPS", "GLONASS", "GALILEO"};
-
void rtcm2_sager_dump(struct rtcm2_t *rtcm, /*@out@*/char buf[], size_t buflen)
/* dump the contents of a parsed RTCM104 message */
{
@@ -561,124 +554,4 @@ void rtcm2_sager_dump(struct rtcm2_t *rtcm, /*@out@*/char buf[], size_t buflen)
(void)strlcat(buf, ".\n", buflen);
}
-void rtcm2_json_dump(struct rtcm2_t *rtcm, /*@out@*/char buf[], size_t buflen)
-/* dump the contents of a parsed RTCM104 message as JSON */
-{
- unsigned int n;
-
- (void)snprintf(buf, buflen, "{\"class\":\"RTCM2\",\"type\":%u,\"station_id\":%u,\"zcount\":%0.1f,\"seqnum\":%u,\"length\":%u,\"station_health\":%u,",
- rtcm->type,
- rtcm->refstaid,
- rtcm->zcount,
- rtcm->seqnum,
- rtcm->length,
- rtcm->stathlth);
-
- switch (rtcm->type) {
- case 1:
- case 9:
- (void)strlcat(buf, "\"satellites\":[", buflen);
- for (n = 0; n < rtcm->ranges.nentries; n++) {
- struct rangesat_t *rsp = &rtcm->ranges.sat[n];
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "{\"ident\":%u,\"udre\":%u,\"issuedata\":%u,\"rangerr\":%0.3f,\"rangerate\":%0.3f},",
- rsp->ident,
- rsp->udre,
- rsp->issuedata,
- rsp->rangerr,
- rsp->rangerate);
- }
- if (buf[strlen(buf)-1] == ',')
- buf[strlen(buf)-1] = '\0';
- (void)strlcat(buf, "]", buflen);
- break;
-
- case 3:
- if (rtcm->ecef.valid)
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "\"x\":%.2f,\"y\":%.2f,\"z\":%.2f,",
- rtcm->ecef.x,
- rtcm->ecef.y,
- rtcm->ecef.z);
- break;
-
- case 4:
- if (rtcm->reference.valid) {
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "\"system\":\"%s\",\"sense\":%1d,\"datum\":%s,\"dx\":%.1f,\"dy\":%.1f,\"dz\":%.1f,",
- rtcm->reference.system >= NITEMS(navsysnames)
- ? "UNKNOWN"
- : navsysnames[rtcm->reference.system],
- rtcm->reference.sense,
- rtcm->reference.datum,
- rtcm->reference.dx,
- rtcm->reference.dy,
- rtcm->reference.dz);
- }
- break;
-
- case 5:
-#define JSON_BOOL(x) ((x)?"true":"false")
- (void)strlcat(buf, "\"satellites\":[", buflen);
- for (n = 0; n < rtcm->conhealth.nentries; n++) {
- struct consat_t *csp = &rtcm->conhealth.sat[n];
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "{\"ident\":%u,\"iodl\":%s,\"health\":%1u,\"snr\":%d,\"health_en\":%s,\"new_data\":%s,\"los_warning\":%s,\"tou\":%u},",
- csp->ident,
- JSON_BOOL(csp->iodl),
- (unsigned)csp->health,
- csp->snr,
- JSON_BOOL(csp->health_en),
- JSON_BOOL(csp->new_data),
- JSON_BOOL(csp->los_warning),
- csp->tou);
- }
-#undef JSON_BOOL
- if (buf[strlen(buf)-1] == ',')
- buf[strlen(buf)-1] = '\0';
- (void)strlcat(buf, "]", buflen);
- break;
-
- case 6: /* NOP msg */
- break;
-
- case 7:
- (void)strlcat(buf, "\"satellites\":[", buflen);
- for (n = 0; n < rtcm->almanac.nentries; n++) {
- struct station_t *ssp = &rtcm->almanac.station[n];
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "{\"lat\":%.4f,\"lon\":%.4f,\"range\":%u,\"frequency\":%.1f,\"health\":%u,\"station_id\":%u,\"bitrate\":%u},",
- ssp->latitude,
- ssp->longitude,
- ssp->range,
- ssp->frequency,
- ssp->health,
- ssp->station_id,
- ssp->bitrate);
- }
- if (buf[strlen(buf)-1] == ',')
- buf[strlen(buf)-1] = '\0';
- (void)strlcat(buf, "]", buflen);
- break;
- case 16:
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "\"message\":\"%s\"", rtcm->message);
- break;
-
- default:
- (void)strlcat(buf, "\"data\":[", buflen);
- for (n = 0; n < rtcm->length; n++)
- (void)snprintf(buf + strlen(buf), buflen - strlen(buf),
- "\"0x%08x\",", rtcm->words[n]);
- if (buf[strlen(buf)-1] == ',')
- buf[strlen(buf)-1] = '\0';
- (void)strlcat(buf, "]", buflen);
- break;
- }
-
- if (buf[strlen(buf)-1] == ',')
- buf[strlen(buf)-1] = '\0';
- (void)strlcat(buf, "}\r\n", buflen);
-}
-
#endif /* RTCM104V2_ENABLE */