summaryrefslogtreecommitdiff
path: root/rtcm2_json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-27 10:09:12 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-27 10:09:12 +0000
commita843dba83020d1eb4f3c74ea250107e9fb15a874 (patch)
tree404b16254630ba20727a29007d3e8460a09b77d3 /rtcm2_json.c
parent222c36d2fa933c6677f947bd7f976cb4d70bd9c5 (diff)
downloadgpsd-a843dba83020d1eb4f3c74ea250107e9fb15a874.tar.gz
First step towards RTCM2 JSON parsing.
Handles message types 3, 4, 6, and 16 (the easy ones). No unit test yet. Not ready for production.
Diffstat (limited to 'rtcm2_json.c')
-rw-r--r--rtcm2_json.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/rtcm2_json.c b/rtcm2_json.c
new file mode 100644
index 00000000..35f37360
--- /dev/null
+++ b/rtcm2_json.c
@@ -0,0 +1,133 @@
+/****************************************************************************
+
+NAME
+ rtcm2_json.c - deserialize RTCM2 JSON
+
+DESCRIPTION
+ This module uses the generic JSON parser to get data from RTCM2
+representations to libgps structures.
+
+***************************************************************************/
+
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#include "gpsd_config.h"
+#include "gpsd.h"
+#include "gps_json.h"
+
+/* common fields in every RTCM2 message */
+
+int json_rtcm2_read(const char *buf,
+ char *path, size_t pathlen,
+ struct rtcm2_t *rtcm2,
+ const char **endptr)
+{
+
+#define RTCM2_HEADER \
+ {"class", check, .dflt.check = "RTCM2"}, \
+ {"type", uinteger, .addr.uinteger = &rtcm2->type}, \
+ {"device", string, .addr.string = path, \
+ .len = pathlen}, \
+ {"station_id", uinteger, .addr.uinteger = &rtcm2->refstaid}, \
+ {"zcount", real, .addr.real = &rtcm2->zcount, \
+ .dflt.real = NAN}, \
+ {"seqnum", uinteger, .addr.uinteger = &rtcm2->seqnum}, \
+ {"length", uinteger, .addr.uinteger = &rtcm2->length}, \
+ {"station_health", uinteger, .addr.uinteger = &rtcm2->stathlth},
+
+ int status;
+ const struct json_attr_t json_rtcm1[] = {
+ // FIXME
+ RTCM2_HEADER
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm3[] = {
+ RTCM2_HEADER
+ {"valid", boolean, .addr.boolean = &rtcm2->reference.valid},
+ {"x", real, .addr.real = &rtcm2->ecef.x,
+ .dflt.real = NAN},
+ {"y", real, .addr.real = &rtcm2->ecef.y,
+ .dflt.real = NAN},
+ {"z", real, .addr.real = &rtcm2->ecef.z,
+ .dflt.real = NAN},
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm4[] = {
+ RTCM2_HEADER
+ {"valid", boolean, .addr.boolean = &rtcm2->reference.valid},
+ {"system", integer, .addr.integer = &rtcm2->reference.system},
+ {"sense", integer, .addr.integer = &rtcm2->reference.sense},
+ {"datum", string, .addr.string = rtcm2->reference.datum,
+ .len = sizeof(rtcm2->reference.datum)},
+ {"dx", real, .addr.real = &rtcm2->reference.dx,
+ .dflt.real = NAN},
+ {"dy", real, .addr.real = &rtcm2->reference.dy,
+ .dflt.real = NAN},
+ {"dz", real, .addr.real = &rtcm2->reference.dz,
+ .dflt.real = NAN},
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm5[] = {
+ // FIXME
+ RTCM2_HEADER
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm6[] = {
+ RTCM2_HEADER
+ // No-op or keepalive message
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm7[] = {
+ // FIXME
+ RTCM2_HEADER
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm16[] = {
+ RTCM2_HEADER
+ {"message", string, .addr.string = rtcm2->message,
+ .len = sizeof(rtcm2->message)},
+ {NULL},
+ };
+
+ const struct json_attr_t json_rtcm_fallback[] = {
+ // FIXME
+ RTCM2_HEADER
+ {NULL},
+ };
+
+#undef RTCM2_HEADER
+
+ memset(rtcm2, '\0', sizeof(struct rtcm2_t));
+
+ if (strstr(buf, "\"type\":1") != NULL || strstr(buf, "\"type\":9") != NULL)
+ status = json_read_object(buf, json_rtcm1, endptr);
+ else if (strstr(buf, "\"type\":3") != NULL)
+ status = json_read_object(buf, json_rtcm3, endptr);
+ else if (strstr(buf, "\"type\":4") != NULL) {
+ status = json_read_object(buf, json_rtcm4, endptr);
+ } else if (strstr(buf, "\"type\":5") != NULL)
+ status = json_read_object(buf, json_rtcm5, endptr);
+ else if (strstr(buf, "\"type\":6") != NULL)
+ status = json_read_object(buf, json_rtcm6, endptr);
+ else if (strstr(buf, "\"type\":7") != NULL)
+ status = json_read_object(buf, json_rtcm7, endptr);
+ 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);
+ if (status != 0)
+ return status;
+ return 0;
+}
+
+/* rtcm2_json.c ends here */