summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--binding/hvac-demo-binding.c16
-rw-r--r--hvac.json5
2 files changed, 17 insertions, 4 deletions
diff --git a/binding/hvac-demo-binding.c b/binding/hvac-demo-binding.c
index 7b7ca25..5a6debd 100644
--- a/binding/hvac-demo-binding.c
+++ b/binding/hvac-demo-binding.c
@@ -139,6 +139,12 @@ struct led_paths {
.blue = BLUE
};
+struct can_device {
+ const char *name;
+} can_dev = {
+ .name = CAN_DEV
+};
+
static struct can_handler can_handler = { .socket = -1, .simulation = false, .send_msg = "SENDING CAN FRAME"};
static int open_can_dev_helper()
@@ -156,7 +162,7 @@ static int open_can_dev_helper()
else
{
// Attempts to open a socket to CAN bus
- strcpy(ifr.ifr_name, CAN_DEV);
+ strcpy(ifr.ifr_name, can_dev.name);
if(ioctl(can_handler.socket, SIOCGIFINDEX, &ifr) < 0)
{
AFB_ERROR("ioctl failed");
@@ -186,7 +192,7 @@ static int open_can_dev()
int rc = retry(open_can_dev_helper);
if(rc < 0)
{
- AFB_ERROR("Open of interface %s failed. Falling back to simulation mode", CAN_DEV);
+ AFB_ERROR("Open of interface %s failed. Falling back to simulation mode", can_dev.name);
can_handler.socket = 0;
can_handler.simulation = true;
can_handler.send_msg = "FAKE CAN FRAME";
@@ -245,6 +251,7 @@ static uint8_t read_fanspeed()
static int parse_config()
{
struct json_object *ledtemp = NULL;
+ struct json_object *candevice = NULL;
struct json_object *jobj = json_object_from_file("/etc/hvac.json");
// Check if .json file has been parsed as a json_object
@@ -270,6 +277,11 @@ static int parse_config()
}
}
+ // Extract can device
+ json_object_object_get_ex(jobj, "can_device", &candevice); {
+ can_dev.name = json_object_get_string(candevice);
+ }
+
// return 0 if all succeeded
return 0;
diff --git a/hvac.json b/hvac.json
index 6e7d0db..67827a7 100644
--- a/hvac.json
+++ b/hvac.json
@@ -3,5 +3,6 @@
"red": "/sys/class/leds/blinkm-3-9-red/brightness",
"green": "/sys/class/leds/blinkm-3-9-green/brightness",
"blue": "/sys/class/leds/blinkm-3-9-blue/brightness"
- }
-} \ No newline at end of file
+ },
+ "can_device": "vcan0"
+}