diff options
-rw-r--r-- | json.c | 1 | ||||
-rw-r--r-- | json.h | 20 | ||||
-rw-r--r-- | rtcm2_json.c | 23 |
3 files changed, 30 insertions, 14 deletions
@@ -428,6 +428,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr, const char * return substatus; break; case integer: + case uinteger: case real: case boolean: case character: @@ -76,4 +76,24 @@ const char *json_error_string(int); #define JSON_ERR_BADENUM 17 /* invalid flag token */ #define JSON_ERR_NOPARSTR 18 /* can't support strings in aparalle. arrays */ +/* + * Use the following macros to declare template initializers for structobject + * arrays. Writing the equivalents out by hand is error-prone. + * + * STRUCTOBJECT takes a type t (one of the enumerated scalar field types + * above), a structure name s, and a fieldname f in s. + * + * STRUCTARRAY takes the name of a structure array, a pointer to a an + * initializer defining the subobject type, and the address of an integer to + * store the length in. + */ +#define STRUCTOBJECT(t, s, f) .type = t, .addr.offset = offsetof(s, f) +#define STRUCTARRAY(a, e, n) .type = array, \ + .addr.array.element_type = structobject, \ + .addr.array.arr.objects.subtype = e, \ + .addr.array.arr.objects.base = (char*)a, \ + .addr.array.arr.objects.stride = sizeof(a[0]), \ + .addr.array.count = n, \ + .addr.array.maxlen = NITEMS(a) + /* json.h ends here */ diff --git a/rtcm2_json.c b/rtcm2_json.c index 7bd7b7cd..912ca1a7 100644 --- a/rtcm2_json.c +++ b/rtcm2_json.c @@ -39,25 +39,19 @@ int json_rtcm2_read(const char *buf, {"length", uinteger, .addr.uinteger = &rtcm2->length}, \ {"station_health", uinteger, .addr.uinteger = &rtcm2->stathlth}, -#define STRUCTOBJECT(s, f) .addr.offset=offsetof(s, f) - int status, satcount; - const struct json_attr_t json_rtcm1_satellite[] = { - {"ident", uinteger, STRUCTOBJECT(struct rangesat_t, ident)}, - {"udre", uinteger, STRUCTOBJECT(struct rangesat_t, udre)}, - {"issuedata", real, STRUCTOBJECT(struct rangesat_t, issuedata)}, - {"rangerr", real, STRUCTOBJECT(struct rangesat_t, rangerr)}, - {"rangerate", real, STRUCTOBJECT(struct rangesat_t, rangerate)}, + const struct json_attr_t rtcm1_satellite[] = { + {"ident", STRUCTOBJECT(uinteger, struct rangesat_t, ident)}, + {"udre", STRUCTOBJECT(uinteger, struct rangesat_t, udre)}, + {"issuedata", STRUCTOBJECT(real, struct rangesat_t, issuedata)}, + {"rangerr", STRUCTOBJECT(real, struct rangesat_t, rangerr)}, + {"rangerate", STRUCTOBJECT(real, struct rangesat_t, rangerate)}, {NULL}, }; const struct json_attr_t json_rtcm1[] = { RTCM2_HEADER - {"satellites", array, .addr.array.element_type = structobject, - .addr.array.arr.objects.base = (char*)rtcm2->ranges.sat, - .addr.array.arr.objects.stride = sizeof(rtcm2->ranges.sat[0]), - .addr.array.arr.objects.subtype = json_rtcm1_satellite, - .addr.array.count = &satcount, - .addr.array.maxlen = NITEMS(rtcm2->ranges.sat)}, + {"satellites", STRUCTARRAY(rtcm2->ranges.sat, + rtcm1_satellite, &satcount)}, {NULL}, }; @@ -120,6 +114,7 @@ int json_rtcm2_read(const char *buf, {NULL}, }; +#undef STRUCTARRAY #undef STRUCTOBJECT #undef RTCM2_HEADER |