diff options
-rw-r--r-- | driver_rtcm2.c | 3 | ||||
-rw-r--r-- | json.c | 4 | ||||
-rw-r--r-- | json.h | 5 | ||||
-rw-r--r-- | rtcm2_json.c | 31 |
4 files changed, 33 insertions, 10 deletions
diff --git a/driver_rtcm2.c b/driver_rtcm2.c index 68dadcb0..8e014937 100644 --- a/driver_rtcm2.c +++ b/driver_rtcm2.c @@ -656,8 +656,7 @@ void rtcm2_json_dump(struct rtcm2_t *rtcm, /*@out@*/char buf[], size_t buflen) break; default: - (void)snprintf(buf + strlen(buf), buflen - strlen(buf), - "\"length\":%u,\"satellites\":[", rtcm->length); + (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]); @@ -495,8 +495,8 @@ const char *json_error_string(int err) "unsupported array element type", "error while string parsing", "check attribute not matched", - "invalid flag token", - "can't support strings in aparalle. arrays", + "can't support strings in parallel arrays", + "other data conversion error", }; if (err <= 0 || err >= (int)(sizeof(errors)/sizeof(errors[0]))) @@ -73,8 +73,9 @@ const char *json_error_string(int); #define JSON_ERR_SUBTYPE 14 /* unsupported array element type */ #define JSON_ERR_BADSTRING 15 /* error while string parsing */ #define JSON_ERR_CHECKFAIL 16 /* check attribute not matched */ -#define JSON_ERR_BADENUM 17 /* invalid flag token */ -#define JSON_ERR_NOPARSTR 18 /* can't support strings in aparalle. arrays */ +#define JSON_ERR_NOPARSTR 17 /* can't support strings in parallel arrays */ +#define JSON_ERR_MISC 18 /* other data conversion error */ + /* * Use the following macros to declare template initializers for structobject 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; |