summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>2019-03-28 22:34:15 +0900
committerHarunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>2019-03-29 01:13:39 +0000
commitabc3514477ac4551e3edb427f6108f06116c86d2 (patch)
tree876a775758c1bbf3c486a7636c2e5be4413580ee
parent2570b8fb78d409033090eff24eb45467a78e4cb9 (diff)
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> (cherry picked from commit 8edd1d56d9d455c0c7b833e13d9b1b7861f5a4cc)
-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"
+}