summaryrefslogtreecommitdiff
path: root/cethcan/rpc.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-06-29 00:26:39 +0000
committerroot <root@beaglebone.local.sublab.org>2013-06-29 00:26:39 +0000
commitfa21bedc238b77a3c6bfe4a4a6a5b3a13f0a4b9a (patch)
treeb7469dd6b908ad2061e69df15fc231be77c373ef /cethcan/rpc.c
parent5f7a729e53bb84a190b67031769458898783552c (diff)
cethcan: light_{get,set} RPC
Diffstat (limited to 'cethcan/rpc.c')
-rw-r--r--cethcan/rpc.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/cethcan/rpc.c b/cethcan/rpc.c
index 57cb117..f9a47fc 100644
--- a/cethcan/rpc.c
+++ b/cethcan/rpc.c
@@ -9,8 +9,46 @@ static int rpc_ping(void *apparg, json_t *json_params, json_t **result)
return 0;
}
+static int rpc_light_set(void *apparg, json_t *json_params, json_t **result)
+{
+ struct light *l;
+ const char *name = json_string_value(json_array_get(json_params, 0));
+ unsigned val = json_integer_value(json_array_get(json_params, 1));
+
+ l = light_find(name);
+ if (!l) {
+ *result = jsonrpc_error_object(JSONRPC_INVALID_PARAMS,
+ json_string("cann't find specified light"));
+ return JSONRPC_INVALID_PARAMS;
+ }
+ *result = json_boolean(!light_set(l, val));
+ return 0;
+}
+
+static int rpc_light_get(void *apparg, json_t *json_params, json_t **result)
+{
+ struct light *l;
+ const char *name = json_string_value(json_array_get(json_params, 0));
+ unsigned set, actual;
+
+ l = light_find(name);
+ if (!l) {
+ *result = jsonrpc_error_object(JSONRPC_INVALID_PARAMS,
+ json_string("cannot find specified light"));
+ return JSONRPC_INVALID_PARAMS;
+ }
+
+ set = light_getset(l);
+ actual = light_getact(l);
+
+ *result = json_pack("{s:i,s:i}", "set", set, "actual", actual);
+ return 0;
+}
+
struct jsonrpc_method_entry_t method_table[] = {
{ "ping", rpc_ping, "" },
+ { "light_set", rpc_light_set, "[si]" },
+ { "light_get", rpc_light_get, "[s]" },
{ NULL, NULL, NULL },
};