diff options
-rw-r--r-- | gpsd_json.c | 39 | ||||
-rw-r--r-- | libgpsd_core.c | 2 |
2 files changed, 22 insertions, 19 deletions
diff --git a/gpsd_json.c b/gpsd_json.c index 6cd1571f..b3188e99 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -358,11 +358,30 @@ void json_device_dump(const struct gps_device_t *device, /*@out@*/ char *reply, size_t replylen) { struct classmap_t *cmp; + char buf1[JSON_VAL_MAX * 2 + 1]; + (void)strlcpy(reply, "{\"class\":\"DEVICE\",\"path\":\"", replylen); (void)strlcat(reply, device->gpsdata.dev.path, replylen); (void)strlcat(reply, "\",", replylen); + if (device->device_type != NULL) { + (void)strlcat(reply, "\"driver\":\"", replylen); + (void)strlcat(reply, device->device_type->type_name, replylen); + (void)strlcat(reply, "\",", replylen); + } + /*@-mustfreefresh@*/ + if (device->subtype[0] != '\0') { + (void)strlcat(reply, "\"subtype\":\"", replylen); + (void)strlcat(reply, + json_stringify(buf1, sizeof(buf1), device->subtype), + replylen); + (void)strlcat(reply, "\",", replylen); + } + /*@+mustfreefresh@*/ + /* + * There's an assumption here: Anything that we type service_sensor is + * a serial device with the usual control parameters. + */ if (device->gpsdata.online > 0) { - char buf1[JSON_VAL_MAX * 2 + 1]; (void)snprintf(reply + strlen(reply), replylen - strlen(reply), "\"activated\":\"%s\",", unix_to_iso8601(device->gpsdata.online, buf1, sizeof(buf1))); @@ -376,24 +395,6 @@ void json_device_dump(const struct gps_device_t *device, replylen - strlen(reply), "\"flags\":%d,", mask); } - if (device->device_type != NULL) { - (void)strlcat(reply, "\"driver\":\"", replylen); - (void)strlcat(reply, device->device_type->type_name, replylen); - (void)strlcat(reply, "\",", replylen); - } - /*@-mustfreefresh@*/ - if (device->subtype[0] != '\0') { - (void)strlcat(reply, "\"subtype\":\"", replylen); - (void)strlcat(reply, - json_stringify(buf1, sizeof(buf1), device->subtype), - replylen); - (void)strlcat(reply, "\",", replylen); - } - /*@+mustfreefresh@*/ - /* - * There's an assumption here: Anything that we type service_sensor is - * a serial device with the usual control parameters. - */ if (device->servicetype == service_sensor) { /* speed can be 0 if the device is not currently active */ speed_t speed = gpsd_get_speed(device); diff --git a/libgpsd_core.c b/libgpsd_core.c index 99c72547..b7673af6 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -323,6 +323,8 @@ void gpsd_deactivate(struct gps_device_t *session) gpsd_run_device_hook(session->context->debug, session->gpsdata.dev.path, "DEACTIVATE"); + /* mark it inactivated */ + session->gpsdata.online = (timestamp_t)0; } void gpsd_clear(struct gps_device_t *session) |