aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2016-11-25 10:39:19 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2016-11-25 10:39:19 +0000
commit1d381ff91dc6c9448341259ff14510cb907e1490 (patch)
tree8356293d1faf181f63381d0a17d93c4ec0e40223
parent5351bddbde04acdd35a80ddc0977b2c758ef60a7 (diff)
Add a global set method to test. It will replaced all other set method
Change-Id: I3cd91641c76a9b873a33ab8c66b8e15f552f4d54 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--hvac-hybrid-qml-binding.c103
1 files changed, 70 insertions, 33 deletions
diff --git a/hvac-hybrid-qml-binding.c b/hvac-hybrid-qml-binding.c
index 634f12e..bceed82 100644
--- a/hvac-hybrid-qml-binding.c
+++ b/hvac-hybrid-qml-binding.c
@@ -31,8 +31,20 @@
const struct afb_binding_interface *interface;
-// Initialize CAN payload array that will be sent trough the socket
-__u8 can_payload[8] = {
+// Initialize CAN hvac array that will be sent trough the socket
+char *can_hvac_components[8] = {
+ "LeftTemperature",
+ "RightTemperature",
+ "Temperature",
+ "Unknow3",
+ "FanSpeed",
+ "Unknow5",
+ "Unknow6",
+ "Unknow7"
+};
+
+// Initialize CAN hvac array that will be sent trough the socket
+__u8 can_hvac_values[8] = {
21,
21,
21,
@@ -48,8 +60,6 @@ struct can_handler{
struct sockaddr_can txAddress;
};
-struct can_handler *ch;
-
/***************************************************************************************/
/***************************************************************************************/
/** **/
@@ -124,38 +134,40 @@ static void write_can(struct can_handler ch)
{
printf("Send CAN message\n");
- txCanFrame.data[0] = can_payload[0];
- txCanFrame.data[1] = can_payload[1];
- txCanFrame.data[2] = (can_payload[0] + can_payload[1]) & 0x02;
- txCanFrame.data[3] = can_payload[3];
- txCanFrame.data[4] = can_payload[4];
- txCanFrame.data[5] = can_payload[5];
- txCanFrame.data[6] = can_payload[6];
- txCanFrame.data[7] = can_payload[7];
+ txCanFrame.data[0] = can_hvac_values[0];
+ txCanFrame.data[1] = can_hvac_values[1];
+ txCanFrame.data[2] = (can_hvac_values[0] + can_hvac_values[1]) & 0x02;
+ txCanFrame.data[3] = can_hvac_values[3];
+ txCanFrame.data[4] = can_hvac_values[4];
+ txCanFrame.data[5] = can_hvac_values[5];
+ txCanFrame.data[6] = can_hvac_values[6];
+ txCanFrame.data[7] = can_hvac_values[7];
sendto(ch.socket, &txCanFrame, sizeof(struct can_frame), 0,
(struct sockaddr*)&ch.txAddress, sizeof(ch.txAddress));
+ return;
}
else
{
printf("Error: socket not initialized\n");
+ return;
}
printf("Error sending on CAN bus. Unexpected behavior");
}
-static int read_temp_left_zone()
+static __u8 read_temp_left_zone()
{
- return can_payload[0];
+ return can_hvac_values[0];
}
-static int read_temp_right_zone()
+static __u8 read_temp_right_zone()
{
- return can_payload[1];
+ return can_hvac_values[1];
}
-static int read_fanspeed()
+static __u8 read_fanspeed()
{
- return can_payload[4];
+ return can_hvac_values[4];
}
/***************************************************************************************/
@@ -191,7 +203,7 @@ static void ping (struct afb_req request)
static void get_fanspeed(struct afb_req request)
{
json_object *ret_json;
- int fanspeed = read_fanspeed();
+ __u8 fanspeed = read_fanspeed();
ret_json = json_object_new_object();
json_object_object_add(ret_json, "FanSpeed", json_object_new_int(fanspeed));
@@ -209,17 +221,17 @@ static void get_fanspeed(struct afb_req request)
static void set_fanspeed(struct afb_req request)
{
struct can_handler ch;
- int fanspeed = (int)afb_req_value(request, "FanSpeed");
+ __u8 fanspeed = *afb_req_value(request, "FanSpeed");
- // Set can_payload array with the new fan speed value
- can_payload[4] = fanspeed;
+ // Set can_hvac array with the new fan speed value
+ can_hvac_values[4] = fanspeed;
ch = open_can_dev();
write_can(ch);
close_can_dev(ch);
json_object *query = afb_req_json(request);
- afb_req_success_f(request, NULL, "Fanspeed=%d query=%s", can_payload[4], json_object_to_json_string(query));
+ afb_req_success_f(request, NULL, "Fanspeed=%d query=%s", can_hvac_values[4], json_object_to_json_string(query));
}
/*
@@ -231,7 +243,7 @@ static void set_fanspeed(struct afb_req request)
static void get_temp_right_zone(struct afb_req request)
{
json_object *ret_json;
- int temp = read_temp_right_zone();
+ __u8 temp = read_temp_right_zone();
ret_json = json_object_new_object();
json_object_object_add(ret_json, "RightTemperature", json_object_new_int(temp));
@@ -249,7 +261,7 @@ static void get_temp_right_zone(struct afb_req request)
static void get_temp_left_zone(struct afb_req request)
{
json_object *ret_json;
- int temp = read_temp_left_zone();
+ __u8 temp = read_temp_left_zone();
ret_json = json_object_new_object();
json_object_object_add(ret_json, "LeftTemperature", json_object_new_int(temp));
@@ -268,17 +280,17 @@ static void get_temp_left_zone(struct afb_req request)
static void set_temp_right_zone(struct afb_req request)
{
struct can_handler ch;
- int tempright = (int)afb_req_value(request, "RightTemperature");
+ __u8 tempright = *afb_req_value(request, "RightTemperature");
- // Set can_payload array with the new fan speed value
- can_payload[1] = tempright;
+ // Set can_hvac array with the new fan speed value
+ can_hvac_values[1] = tempright;
ch = open_can_dev();
write_can(ch);
close_can_dev(ch);
json_object *query = afb_req_json(request);
- afb_req_success_f(request, NULL, "Ping Binder Daemon fanspeed=%d query=%s", can_payload[4], json_object_to_json_string(query));
+ afb_req_success_f(request, NULL, "Ping Binder Daemon fanspeed=%d query=%s", can_hvac_values[4], json_object_to_json_string(query));
}
/*
@@ -290,17 +302,41 @@ static void set_temp_right_zone(struct afb_req request)
static void set_temp_left_zone(struct afb_req request)
{
struct can_handler ch;
- int templeft = (int)afb_req_value(request, "LeftTemperature");
+ __u8 templeft = *afb_req_value(request, "LeftTemperature");
+
+ // Set can_hvac array with the new fan speed value
+ can_hvac_values[0] = templeft;
+
+ ch = open_can_dev();
+ write_can(ch);
+ close_can_dev(ch);
+
+ json_object *query = afb_req_json(request);
+ afb_req_success_f(request, NULL, "Ping Binder Daemon fanspeed=%d query=%s", can_hvac_values[4], json_object_to_json_string(query));
+}
+
+static void set(struct afb_req request)
+{
+ struct can_handler ch;
+ const char *comp = afb_req_value(request, "component");
+ __u8 comp_val = *afb_req_value(request, "value");
- // Set can_payload array with the new fan speed value
- can_payload[0] = templeft;
+ int i;
+ for (i=0;i<8;i++)
+ {
+ if(strcmp(can_hvac_components[i], comp) == 0)
+ {
+ can_hvac_values[i] = comp_val;
+ break;
+ }
+ }
ch = open_can_dev();
write_can(ch);
close_can_dev(ch);
json_object *query = afb_req_json(request);
- afb_req_success_f(request, NULL, "Ping Binder Daemon fanspeed=%d query=%s", can_payload[4], json_object_to_json_string(query));
+ afb_req_success_f(request, NULL, "Set the %s=%d query=%s", can_hvac_components[i], can_hvac_values[i], json_object_to_json_string(query));
}
/*
@@ -331,6 +367,7 @@ static const struct afb_verb_desc_v1 verbs[]= {
{"set_fanspeed" , AFB_SESSION_NONE, set_fanspeed , "Set fanspeed"},
{"get_fanspeed" , AFB_SESSION_NONE, get_fanspeed , "Read fan speed"},
{"get_all" , AFB_SESSION_NONE, get_all , "Read all values"},
+ {"set" , AFB_SESSION_NONE, set , "Set a HVAC component value"},
{NULL}
};