diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-11-03 06:46:14 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-11-03 06:46:14 -0500 |
commit | b684c9278f14f683f1d77e91d04cb040a4de6aa1 (patch) | |
tree | ae27c2dbf1a1b4b8229f351de1271c61fa1991f0 /libgps_json.c | |
parent | 0ce07b94de468b1ea2500511e9047f9a747d32eb (diff) | |
download | gpsd-b684c9278f14f683f1d77e91d04cb040a4de6aa1.tar.gz |
Support reading PPS messages in libgps.
Finally defines a message validity nask that won't fit in 32 bits, alas.
Defines a timedrift structure that we will use internally as well.
Diffstat (limited to 'libgps_json.c')
-rw-r--r-- | libgps_json.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libgps_json.c b/libgps_json.c index 8ffa3434..d5590c14 100644 --- a/libgps_json.c +++ b/libgps_json.c @@ -353,6 +353,44 @@ static int json_error_read(const char *buf, struct gps_data_t *gpsdata, return status; } +static int json_pps_read(const char *buf, struct gps_data_t *gpsdata, + /*@null@*/ const char **endptr) +{ + int real_sec, real_nsec, clock_sec, clock_nsec; + /*@ -fullinitblock @*/ + const struct json_attr_t json_attrs_pps[] = { + /* *INDENT-OFF* */ + {"class", t_check, .dflt.check = "PPS"}, + {"real_sec", t_integer, .addr.integer = &real_sec, + .dflt.integer = 0}, + {"real_nsec", t_integer, .addr.integer = &real_nsec, + .dflt.integer = 0}, + {"clock_sec", t_integer, .addr.integer = &clock_sec, + .dflt.integer = 0}, + {"clock_nsec",t_integer, .addr.integer = &clock_nsec, + .dflt.integer = 0}, + {NULL}, + /* *INDENT-ON* */ + }; + /*@ +fullinitblock @*/ + int status; + + memset(&gpsdata->timedrift, '\0', sizeof(gpsdata->timedrift)); + status = json_read_object(buf, json_attrs_pps, endptr); + /* + * This is theoretically dodgy, but in practice likely not + * to break until GPSes are obsolete. + */ + gpsdata->timedrift.real.tv_sec = (long)real_sec; + gpsdata->timedrift.real.tv_nsec = (time_t)real_nsec; + gpsdata->timedrift.clock.tv_sec = (long)clock_sec; + gpsdata->timedrift.clock.tv_nsec = (time_t)clock_nsec; + if (status != 0) + return status; + + return status; +} + int libgps_json_unpack(const char *buf, struct gps_data_t *gpsdata, const char **end) /* the only entry point - unpack a JSON object into gpsdata_t substructures */ @@ -481,6 +519,13 @@ int libgps_json_unpack(const char *buf, gpsdata->set |= ERROR_SET; } return status; + } else if (STARTSWITH(classtag, "\"class\":\"PPS\"")) { + status = json_pps_read(buf, gpsdata, end); + if (status == 0) { + gpsdata->set &= ~UNION_SET; + gpsdata->set |= TIMEDRIFT_SET; + } + return status; } else return -1; #undef STARTSWITH |