diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-08-28 03:00:39 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-08-28 03:00:39 +0000 |
commit | 7d6ca7d03b94f4ab37812d08f2d68b2c1f8f52fa (patch) | |
tree | 30970bcac55e781f53016d052f150cfa29a3fae9 /rtcm2_json.c | |
parent | 9f142925c22535ec6ad06e3ba69f5c6416956739 (diff) | |
download | gpsd-7d6ca7d03b94f4ab37812d08f2d68b2c1f8f52fa.tar.gz |
RTCM2 JSON parser is feature-complete and ready for test.
Diffstat (limited to 'rtcm2_json.c')
-rw-r--r-- | rtcm2_json.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/rtcm2_json.c b/rtcm2_json.c index e43d7802..d864c897 100644 --- a/rtcm2_json.c +++ b/rtcm2_json.c @@ -27,6 +27,10 @@ int json_rtcm2_read(const char *buf, const char **endptr) { + static char *stringptrs[NITEMS(rtcm2->words)]; + static char stringstore[sizeof(rtcm2->words)*2]; + static int stringcount; + #define RTCM2_HEADER \ {"class", check, .dflt.check = "RTCM2"}, \ {"type", uinteger, .addr.uinteger = &rtcm2->type}, \ @@ -131,9 +135,14 @@ int json_rtcm2_read(const char *buf, {NULL}, }; - const struct json_attr_t json_rtcm_fallback[] = { - // FIXME + const struct json_attr_t json_rtcm2_fallback[] = { RTCM2_HEADER + {"data", array, .addr.array.element_type = string, + .addr.array.arr.strings.ptrs = stringptrs, + .addr.array.arr.strings.store = stringstore, + .addr.array.arr.strings.storelen = sizeof(stringstore), + .addr.array.count = &stringcount, + .addr.array.maxlen = NITEMS(stringptrs)}, {NULL}, }; @@ -163,8 +172,22 @@ int json_rtcm2_read(const char *buf, rtcm2->almanac.nentries = (unsigned)satcount; else if (strstr(buf, "\"type\":16") != NULL) status = json_read_object(buf, json_rtcm16, endptr); - else - status = json_read_object(buf, json_rtcm_fallback, endptr); + else { + int n; + status = json_read_object(buf, json_rtcm2_fallback, endptr); + for (n = 0; n < NITEMS(rtcm2->words); n++) + if (n >= stringcount) { + rtcm2->words[n] = 0; + } else { + unsigned int u; + int fldcount = sscanf(stringptrs[n], "U\t0x%08x\n", &u); + if (fldcount != 1) + return JSON_ERR_MISC; + else + rtcm2->words[n] = (isgps30bits_t)u; + } + + } if (status != 0) return status; return 0; |