summaryrefslogtreecommitdiffstats
path: root/conf/files/usr/bin/candev.sh
blob: fc47cb648a7c8916e7b04d948a6ab1cca1c7ad72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash

function execProc(){
	dev=$1
	
	if [ "canCK" == ${dev:0:3}"CK" ]; then
		modprobe can
		ip link set $dev up type can bitrate 500000
	elif [ "vcanCK" == ${dev:0:4}"CK" ]; then
		modprobe vcan
		ip link add $dev type vcan
		ip link set $dev up
	elif [ "slcanCK" == ${dev:0:5}"CK" ]; then
		modprobe slcan
		systemctl start usbcan${dev:5:1}
		ip link set $dev up
		ip link
		ifconfig $dev txqueuelen 1000
	fi
}

if [ -e /etc/dev-mapping.conf ]; then
	hs=`cat /etc/dev-mapping.conf | grep hs | cut -d '"' -f 2`
	ls=`cat /etc/dev-mapping.conf | grep ls | cut -d '"' -f 2`
else
	echo -e "[CANbus-mapping]\nhs=\"vcan0\"\nls=\"vcan1\"\n" > /etc/dev-mapping.conf
	hs=vcan0
	ls=vcan1
fi

echo "candev "$hs
execProc $hs
if [ $hs != $ls  ]; then
    echo "candev "$ls
    execProc $ls
fi