diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-04-16 09:43:16 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-04-16 09:43:16 -0400 |
commit | a48f7b85d096e68919b4eae8eba5607fe35e3c93 (patch) | |
tree | 95562c145e4fe3f29e314fc7e01dc2ca5342b875 | |
parent | 51c343c366942b073680b278091355369a126934 (diff) | |
download | gpsd-a48f7b85d096e68919b4eae8eba5607fe35e3c93.tar.gz |
Use t_time consistently for timestamps.
All regression tests pass. Livetesting with cgps looks good.
-rw-r--r-- | json.c | 2 | ||||
-rw-r--r-- | libgps_json.c | 56 | ||||
-rw-r--r-- | test_json.c | 15 |
3 files changed, 25 insertions, 48 deletions
@@ -281,6 +281,8 @@ static int json_internal_read_object(const char *cp, maxlen = (int)cursor->len - 1; else if (cursor->type == t_check) maxlen = (int)strlen(cursor->dflt.check); + else if (cursor->type == t_time) + maxlen = JSON_VAL_MAX; else if (cursor->map != NULL) maxlen = (int)sizeof(valbuf) - 1; pval = valbuf; diff --git a/libgps_json.c b/libgps_json.c index b1333fa3..cebd7961 100644 --- a/libgps_json.c +++ b/libgps_json.c @@ -34,8 +34,6 @@ PERMISSIONS static int json_tpv_read(const char *buf, struct gps_data_t *gpsdata, /*@null@*/ const char **endptr) { - int status; - char tbuf[JSON_DATE_MAX+1]; /*@ -fullinitblock @*/ const struct json_attr_t json_attrs_1[] = { /* *INDENT-OFF* */ @@ -44,8 +42,8 @@ static int json_tpv_read(const char *buf, struct gps_data_t *gpsdata, .len = sizeof(gpsdata->dev.path)}, {"tag", t_string, .addr.string = gpsdata->tag, .len = sizeof(gpsdata->tag)}, - {"time", t_string, .addr.string = tbuf, - .len = sizeof(tbuf)}, + {"time", t_time, .addr.real = &gpsdata->fix.time, + .dflt.real = NAN}, {"time", t_real, .addr.real = &gpsdata->fix.time, .dflt.real = NAN}, {"ept", t_real, .addr.real = &gpsdata->fix.ept, @@ -81,27 +79,12 @@ static int json_tpv_read(const char *buf, struct gps_data_t *gpsdata, }; /*@ +fullinitblock @*/ - tbuf[0] = '\0'; - status = json_read_object(buf, json_attrs_1, endptr); - - if (status == 0) { - /*@-usedef@*/ - if (isnan(gpsdata->fix.time)!=0) { - if (tbuf[0] == '\0') - gpsdata->fix.time = NAN; - else - gpsdata->fix.time = iso8601_to_unix(tbuf); - } - /*@+usedef@*/ - } - return status; + return json_read_object(buf, json_attrs_1, endptr); } static int json_noise_read(const char *buf, struct gps_data_t *gpsdata, /*@null@*/ const char **endptr) { - int status; - char tbuf[JSON_DATE_MAX+1]; /*@ -fullinitblock @*/ const struct json_attr_t json_attrs_1[] = { /* *INDENT-OFF* */ @@ -110,8 +93,8 @@ static int json_noise_read(const char *buf, struct gps_data_t *gpsdata, .len = sizeof(gpsdata->dev.path)}, {"tag", t_string, .addr.string = gpsdata->tag, .len = sizeof(gpsdata->tag)}, - {"time", t_string, .addr.string = tbuf, - .len = sizeof(tbuf)}, + {"time", t_time, .addr.real = &gpsdata->gst.utctime, + .dflt.real = NAN}, {"time", t_real, .addr.real = &gpsdata->gst.utctime, .dflt.real = NAN}, {"rms", t_real, .addr.real = &gpsdata->gst.rms_deviation, @@ -133,27 +116,13 @@ static int json_noise_read(const char *buf, struct gps_data_t *gpsdata, }; /*@ +fullinitblock @*/ - tbuf[0] = '\0'; - status = json_read_object(buf, json_attrs_1, endptr); - if (status != 0) - return status; - - /*@-usedef@*/ - if (isnan(gpsdata->fix.time)!=0) { - if (tbuf[0] == '\0') - gpsdata->gst.utctime = NAN; - else - gpsdata->gst.utctime = iso8601_to_unix(tbuf); - } - /*@+usedef@*/ - return 0; + return json_read_object(buf, json_attrs_1, endptr); } static int json_sky_read(const char *buf, struct gps_data_t *gpsdata, /*@null@*/ const char **endptr) { bool usedflags[MAXCHANNELS]; - char tbuf[JSON_DATE_MAX+1]; /*@ -fullinitblock @*/ const struct json_attr_t json_attrs_2_1[] = { /* *INDENT-OFF* */ @@ -172,8 +141,8 @@ static int json_sky_read(const char *buf, struct gps_data_t *gpsdata, .len = sizeof(gpsdata->dev.path)}, {"tag", t_string, .addr.string = gpsdata->tag, .len = sizeof(gpsdata->tag)}, - {"time", t_string, .addr.string = tbuf, - .len = sizeof(tbuf)}, + {"time", t_time, .addr.real = &gpsdata->skyview_time, + .dflt.real = NAN}, {"time", t_real, .addr.real = &gpsdata->skyview_time, .dflt.real = NAN}, {"hdop", t_real, .addr.real = &gpsdata->dop.hdop, @@ -205,19 +174,10 @@ static int json_sky_read(const char *buf, struct gps_data_t *gpsdata, usedflags[i] = false; } - tbuf[0] = '\0'; status = json_read_object(buf, json_attrs_2, endptr); if (status != 0) return status; - /*@-usedef@*/ - if (isnan(gpsdata->fix.time)!=0) { - if (tbuf[0] == '\0') - gpsdata->skyview_time = NAN; - else - gpsdata->skyview_time = iso8601_to_unix(tbuf); - } - /*@+usedef@*/ gpsdata->satellites_used = 0; gpsdata->satellites_visible = 0; (void)memset(gpsdata->used, '\0', sizeof(gpsdata->used)); diff --git a/test_json.c b/test_json.c index 38ad9d0c..2c365e6e 100644 --- a/test_json.c +++ b/test_json.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <string.h> #include <stddef.h> +#include <getopt.h> #include "gpsd.h" #include "gps_json.h" @@ -211,6 +212,20 @@ static const struct json_attr_t json_attrs_8[] = { int main(int argc UNUSED, char *argv[]UNUSED) { int status = 0; + int option; + + while ((option = getopt(argc, argv, "hD:?")) != -1) { + switch (option) { + case 'D': + gps_enable_debug(atoi(optarg), stdout); + break; + case '?': + case 'h': + default: + (void)fputs("usage: test_json [-D lvl]\n", stderr); + exit(1); + } + } (void)fprintf(stderr, "JSON unit test "); |