summaryrefslogtreecommitdiffstats
path: root/can_samples/init_can.sh
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2017-01-30 13:55:48 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-01-30 13:34:57 +0000
commit79a4a3a13bb6058ecc9ad3137ccdd3a6ec737ee4 (patch)
tree64bc6bd303a6fa2386134694fec12d6bf65f4c99 /can_samples/init_can.sh
parentd3eea564254da43803c9ad9a105ef93cdd053227 (diff)
some can sample from a recent Ford Focus, using the OBDII connector
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'can_samples/init_can.sh')
-rwxr-xr-xcan_samples/init_can.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/can_samples/init_can.sh b/can_samples/init_can.sh
new file mode 100755
index 0000000..a790034
--- /dev/null
+++ b/can_samples/init_can.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+CAN_DEVICE=can0
+CAN_BITRATE=500000
+
+echo "Check if CAN module loaded:"
+lsmod | grep can > /dev/null
+if [ "$?" -ne "0" ]; then
+ echo -e "\tCAN module is not loaded, loading it..."
+ sudo modprobe can
+ if [ "$?" -ne "0" ]; then
+ echo -e "\tFAILED to load CAN module !"
+ exit 1
+ fi
+ echo -e "\tCAN module loaded."
+fi
+
+echo "Setup connection:"
+sudo ip link set $CAN_DEVICE type can bitrate $CAN_BITRATE
+if [ "$?" -ne 0 ]; then
+ echo -e "\tFAILED to configure $CAN_DEVICE interface !"
+ exit 2
+fi
+
+sudo ip link set up $CAN_DEVICE
+if [ "$?" -ne 0 ]; then
+ echo -e "\tFAILED to enable $CAN_DEVICE interface !"
+ exit 3
+fi
+
+echo "Ready to use $CAN_DEVICE !"
+