summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2016-12-14 18:51:08 +0000
committerStéphane Desneux <stephane.desneux@iot.bzh>2016-12-14 19:33:25 +0000
commit351abd34616074dbc051d48df5f70ac7edaca788 (patch)
treeb318a63690d67df22add875adda45296b707a734 /binding
parent10dd3295b07ca5ba9fb0d801734e7c21a1e59133 (diff)
binding: handle integer or double values for fanSpeed or temperatures
Change-Id: I8e3db290422adc221fec931390bc934a78ec17af Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
Diffstat (limited to 'binding')
-rw-r--r--binding/hvac-demo-binding.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/binding/hvac-demo-binding.c b/binding/hvac-demo-binding.c
index fe20880..14af56b 100644
--- a/binding/hvac-demo-binding.c
+++ b/binding/hvac-demo-binding.c
@@ -24,6 +24,7 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/can.h>
+#include <math.h>
#include <json-c/json.h>
@@ -159,12 +160,17 @@ static int write_can()
txCanFrame.data[6] = 0;
txCanFrame.data[7] = 0;
+ DEBUG(interface, "%s: %d %d [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
#if defined(SIMULATE_HVAC)
- DEBUG(interface, "WRITING CAN: %d %d [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
+ "FAKE CAN FRAME",
+#else
+ "SENDING CAN FRAME",
+#endif
txCanFrame.can_id, txCanFrame.can_dlc,
txCanFrame.data[0], txCanFrame.data[1], txCanFrame.data[2], txCanFrame.data[3],
txCanFrame.data[4], txCanFrame.data[5], txCanFrame.data[6], txCanFrame.data[7]);
-#else
+
+#if !defined(SIMULATE_HVAC)
rc = sendto(can_handler.socket, &txCanFrame, sizeof(struct can_frame), 0,
(struct sockaddr*)&can_handler.txAddress, sizeof(can_handler.txAddress));
if (rc < 0)
@@ -269,6 +275,7 @@ static void get(struct afb_req request)
static void set(struct afb_req request)
{
int i, rc, x, changed;
+ double d;
struct json_object *query, *val;
uint8_t values[sizeof hvac_values / sizeof *hvac_values];
uint8_t saves[sizeof hvac_values / sizeof *hvac_values];
@@ -292,15 +299,21 @@ static void set(struct afb_req request)
DEBUG(interface, "Searching... query: %s, i: %d, comp: %s", json_object_to_json_string(query), i, hvac_values[i].name);
if (json_object_object_get_ex(query, hvac_values[i].name, &val))
{
- DEBUG(interface, "We got it. Tests if it is an int or not.");
- if (!json_object_is_type(val, json_type_int))
- {
+ DEBUG(interface, "We got it. Tests if it is an int or double.");
+ if (json_object_is_type(val, json_type_int)) {
+ x = json_object_get_int(val);
+ DEBUG(interface, "We get an int: %d",x);
+ }
+ else if (json_object_is_type(val, json_type_double)) {
+ d = json_object_get_double(val);
+ x = (int)round(d);
+ DEBUG(interface, "We get a double: %f => %d",d,x);
+ }
+ else {
afb_req_fail_f(request, "bad-request",
- "argument '%s' isn't integer", hvac_values[i].name);
+ "argument '%s' isn't integer or double", hvac_values[i].name);
return;
}
- DEBUG(interface, "We get an 'int'. Hail for the int: %d", x);
- x = json_object_get_int(val);
if (x < 0 || x > 255)
{
afb_req_fail_f(request, "bad-request",
@@ -310,9 +323,12 @@ static void set(struct afb_req request)
if (values[i] != x) {
values[i] = (uint8_t)x;
changed = 1;
+ DEBUG(interface,"%s changed to %d",hvac_values[i].name,x);
}
}
- DEBUG(interface, "Not found !");
+ else {
+ DEBUG(interface, "%s not found in query!",hvac_values[i].name);
+ }
}
/* attemps to set new values */