diff options
author | Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com> | 2019-03-28 22:34:15 +0900 |
---|---|---|
committer | Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com> | 2019-03-28 23:19:11 +0900 |
commit | 8edd1d56d9d455c0c7b833e13d9b1b7861f5a4cc (patch) | |
tree | 705b5a11b5f5aaebd5820ac3d37c2fed08b7ad91 /binding/hvac-demo-binding.c | |
parent | a97dd68d9a59dcf05ef114bcac2d1049c84f00e2 (diff) |
hvac-demo-binding : Set CAN device name from hvac.jsonhalibut_8.0.2halibut_8.0.1halibut_8.0.0halibut_7.99.3halibut_7.99.2halibut_7.99.1halibut/8.0.2halibut/8.0.1halibut/8.0.0halibut/7.99.3halibut/7.99.2halibut/7.99.18.0.28.0.18.0.07.99.37.99.27.99.1
Current CAN_DEV is set vcan0 as default and hardcoding.
Sometimes hvac uses lin or other type of can device.
User can set CAN device name from JSON file in /etc/hvac.json
Change-Id: I2c29fb16d7d4a48364cc1d35a9f5004afbdb477b
Signed-off-by: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>
Diffstat (limited to 'binding/hvac-demo-binding.c')
-rw-r--r-- | binding/hvac-demo-binding.c | 16 |
1 files changed, 14 insertions, 2 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; |