From f5e242dfba3aac24b8d9aceffa9442b1ca71a2b5 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 31 Aug 2017 13:05:39 -0700 Subject: binding: gps: add dop reporting Add dilution of precision report to JSON output to allow subscribers to judge if the 3D fix lock is good enough. If not user should fall back to the geoclue binding support. Bug-AGL: SPEC-844 Change-Id: If5a520d23c8b455583a022ab07a02dea03185705 Signed-off-by: Matt Ranostay --- binding/afm-gps-binding.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/binding/afm-gps-binding.c b/binding/afm-gps-binding.c index e7cbf8f..e00a317 100644 --- a/binding/afm-gps-binding.c +++ b/binding/afm-gps-binding.c @@ -36,6 +36,37 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define MSECS_TO_USECS(x) (x * 1000) +// struct dop_t item order +static const char *dop_names[] = { + "xdop", + "ydop", + "pdop", + "hdop", + "vdop", + "tdop", + "gdop", + NULL +}; + +static json_object *populate_json_dop_data(json_object *jresp, struct dop_t *dop) +{ + char **names = (char **) dop_names; + double *tmp = (double *) dop; + json_object *value = NULL; + + while (*names) { + double val = *tmp++; + + if (val != 0) { + value = json_object_new_double(val); + json_object_object_add(jresp, *names, value); + } + names++; + } + + return jresp; +} + static json_object *populate_json_data(json_object *jresp) { json_object *value = NULL; @@ -63,6 +94,8 @@ static json_object *populate_json_data(json_object *jresp) json_object_object_add(jresp, "speed", value); } + jresp = populate_json_dop_data(jresp, &data.dop); + return jresp; } -- cgit 1.2.3-korg