diff options
Diffstat (limited to 'cethcan/light.c')
-rw-r--r-- | cethcan/light.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cethcan/light.c b/cethcan/light.c index 2bc6b2f..cb3e94f 100644 --- a/cethcan/light.c +++ b/cethcan/light.c @@ -14,6 +14,25 @@ struct light { struct value set, actual; }; +static void light_json_handler(void *arg, json_t *json, enum json_subtype type) +{ + struct light *l = arg; + json_t *lobj = json_object(); + + json_object_set_new(lobj, "klass", json_string("light")); + json_object_set_new(lobj, "addr", json_integer(l->logical_addr)); + + json_object_set_new(lobj, "actual", json_integer(l->actual.val)); + json_object_set_new(lobj, "actual_ts", json_integer(l->actual.valid)); + json_object_set_new(lobj, "actual_tschg", json_integer(l->actual.change)); + + json_object_set_new(lobj, "set", json_integer(l->set.val)); + json_object_set_new(lobj, "set_ts", json_integer(l->set.valid)); + json_object_set_new(lobj, "set_tschg", json_integer(l->set.change)); + + json_object_set_new(json, l->name, lobj); +} + static void light_can_handler(void *arg, struct can_message *msg) { struct light *l = arg; @@ -65,5 +84,6 @@ int light_init_conf(json_t *config) l->logical_addr = json_integer_value(json_object_get(config, "addr")); l->u = can_register_alloc(l, light_can_handler, "light[%s]", l->name); + l->u->json = light_json_handler; return 0; } |