From afb75aeb519a2bbea6c1d081c936b1393c87b0a0 Mon Sep 17 00:00:00 2001 From: "Gary E. Miller" Date: Wed, 24 Oct 2018 18:46:57 -0700 Subject: Add RAW json messaage class for raw measurements. Which bumps the JSON minor rev. --- gps.h | 4 +++- gps_json.h | 1 + gpsd.h | 3 ++- gpsd_json.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/gps.h b/gps.h index a4e6ed12..2469a9f5 100644 --- a/gps.h +++ b/gps.h @@ -41,8 +41,10 @@ extern "C" { * increased length of devconfig_t.subtype * add gnssid:svid:sigid to satellite_t * add mtime to attitude_t + * changed MAXCHANNELS + * 8.0 - Change shape of rawdata_t. */ -#define GPSD_API_MAJOR_VERSION 7 /* bump on incompatible changes */ +#define GPSD_API_MAJOR_VERSION 8 /* bump on incompatible changes */ #define GPSD_API_MINOR_VERSION 0 /* bump on compatible changes */ #define MAXCHANNELS 120 /* u-blox 9 tracks 140 signals */ diff --git a/gps_json.h b/gps_json.h index 95c1abe3..6bb61600 100644 --- a/gps_json.h +++ b/gps_json.h @@ -24,6 +24,7 @@ char *json_stringify(char *, size_t, const char *); void json_tpv_dump(const struct gps_device_t *, const struct gps_policy_t *, char *, size_t); void json_noise_dump(const struct gps_data_t *, char *, size_t); +void json_raw_dump(const struct gps_data_t *, char *, size_t); void json_sky_dump(const struct gps_data_t *, char *, size_t); void json_att_dump(const struct gps_data_t *, char *, size_t); void json_oscillator_dump(const struct gps_data_t *, char *, size_t); diff --git a/gpsd.h b/gpsd.h index a1bd1c31..265f1580 100644 --- a/gpsd.h +++ b/gpsd.h @@ -52,10 +52,11 @@ extern "C" { * 3.12 OSC message added to repertoire. * 3.13 gnssid:svid added to SAT * time added to ATT + * 3.14 Added RAW message class. */ /* Keep in sync with api_major_version and api_minor gps/__init__.py */ #define GPSD_PROTO_MAJOR_VERSION 3 /* bump on incompatible changes */ -#define GPSD_PROTO_MINOR_VERSION 13 /* bump on compatible changes */ +#define GPSD_PROTO_MINOR_VERSION 14 /* bump on compatible changes */ #define JSON_DATE_MAX 24 /* ISO8601 timestamp with 2 decimal places */ diff --git a/gpsd_json.c b/gpsd_json.c index 3e7ff9aa..d999b3b3 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -718,6 +718,67 @@ void json_subframe_dump(const struct gps_data_t *datap, (void)strlcat(buf, "}\r\n", buflen); } +/* RAW dump */ +void json_raw_dump(const struct gps_data_t *gpsdata, + char *reply, size_t replylen) +{ + int i; + + assert(replylen > sizeof(char *)); + (void)strlcpy(reply, "{\"class\":\"RAW\",", replylen); + if (gpsdata->dev.path[0] != '\0') + str_appendf(reply, replylen, "\"device\":\"%s\",", gpsdata->dev.path); + + (void)strlcat(reply, "\"rawdata\":[", replylen); + for (i = 0; i < MAXCHANNELS; i++) { + bool comma = false; + if (0 == gpsdata->raw[i].mtime) { + continue; + } + (void)strlcat(reply, "{", replylen); + if (0 != isfinite(gpsdata->raw[i].codephase)) { + str_appendf(reply, replylen, "\"codephase\":\"%f\"", + gpsdata->raw[i].codephase); + comma = true; + } + if (0 != isfinite(gpsdata->raw[i].carrierphase)) { + if (comma) + (void)strlcat(reply, ",", replylen); + str_appendf(reply, replylen, "\"carrierphase\":\"%f\"", + gpsdata->raw[i].carrierphase); + comma = true; + } + if (0 != isfinite(gpsdata->raw[i].pseudorange)) { + if (comma) + (void)strlcat(reply, ",", replylen); + str_appendf(reply, replylen, "\"pseudorange\":\"%f\"", + gpsdata->raw[i].pseudorange); + comma = true; + } + if (0 != isfinite(gpsdata->raw[i].deltarange)) { + if (comma) + (void)strlcat(reply, ",", replylen); + str_appendf(reply, replylen, "\"deltarange\":\"%f\"", + gpsdata->raw[i].deltarange); + comma = true; + } + if (0 != isfinite(gpsdata->raw[i].doppler)) { + if (comma) + (void)strlcat(reply, ",", replylen); + str_appendf(reply, replylen, "\"doppler\":\"%f\"", + gpsdata->raw[i].doppler); + comma = true; + } + + (void)strlcat(reply, "},", replylen); + } + str_rstrip_char(reply, ','); + (void)strlcat(reply, "]", replylen); + + str_rstrip_char(reply, ','); + (void)strlcat(reply, "}\r\n", replylen); +} + #if defined(RTCM104V2_ENABLE) void json_rtcm2_dump(const struct rtcm2_t *rtcm, const char *device, @@ -3466,6 +3527,10 @@ void json_data_report(const gps_mask_t changed, json_subframe_dump(datap, buf+strlen(buf), buflen-strlen(buf)); } + if ((changed & RAW_IS) != 0) { + json_raw_dump(datap, buf+strlen(buf), buflen-strlen(buf)); + } + #ifdef COMPASS_ENABLE if ((changed & ATTITUDE_SET) != 0) { json_att_dump(datap, buf+strlen(buf), buflen-strlen(buf)); -- cgit v1.2.1