From e19da3488bbad485bca97aa7600aa055653c20ea Mon Sep 17 00:00:00 2001 From: Occup <33079118+Occup@users.noreply.github.com> Date: Tue, 30 Oct 2018 09:37:24 +0800 Subject: [PATCH 1/2] Create setcan.sh this could simplify the procedure of setup can adapter,you may need to modify the serial id string according to your own device,then run it as root --- setcan.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 setcan.sh diff --git a/setcan.sh b/setcan.sh new file mode 100644 index 0000000..98a6f9d --- /dev/null +++ b/setcan.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +setup() +{ + if [ -z "$*" ];then + spd='6' + br=500000 + echo "set to 500K Baudrate CAN Adapter as default option!" + else + case $1 in + 1000[Kk]* | 1[M]* ) + spd='8' + br=1000000 + echo "set to 1M Baudrate CAN Adapter!" + ;; + 125[Kk]* ) + spd='4' + br=125000 + echo "set to 125K Baudrate CAN Adapter!" + ;; + 500[Kk]* ) + spd='6' + br=500000 + echo "set to 500K Baudrate CAN Adapter!" + ;; + 800[Kk]* ) + spd='7' + br=800000 + echo "set to 800K Baudrate CAN Adapter!" + ;; + 100[Kk]* ) + spd='3' + br=100000 + echo "set to 100K Baudrate CAN Adapter!" + ;; + *) + echo "wrong canspeed config!" + echo "choose in 100k 125k 500k 800k 1000k and 500k by default" + exit 0 + esac + fi + dev=$(readlink -f /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_55731323935351715112-if00) + slcan_attach -f -s${spd} -o ${dev} + slcand -S 115200 $(echo ${dev} | sed -e 's/\/dev\///') CAN_UNO + ip link set CAN_UNO up + ip link show | ack CAN_UNO +} + +setdown() +{ + ip link set CAN_UNO down + killall slcand + echo "CAN_UNO down!" +} + +main() +{ + + if [ -z "$(ip link show | ack CAN_UNO)" ];then + if [ -e serial/by-id/usb-Arduino__www.arduino.cc__0043_55731323935351715112-if00 ];then + setup $@ + else + echo "Arduino UNO havn't been connected!" + fi + else + setdown + fi + + exit 0 +} + +main From 582fb4f15f829358b42faa0519973bbfc537c3e6 Mon Sep 17 00:00:00 2001 From: Occup <33079118+Occup@users.noreply.github.com> Date: Tue, 30 Oct 2018 09:52:28 +0800 Subject: [PATCH 2/2] Update setcan.sh --- setcan.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setcan.sh b/setcan.sh index 98a6f9d..f5b5cf8 100644 --- a/setcan.sh +++ b/setcan.sh @@ -57,7 +57,7 @@ main() { if [ -z "$(ip link show | ack CAN_UNO)" ];then - if [ -e serial/by-id/usb-Arduino__www.arduino.cc__0043_55731323935351715112-if00 ];then + if [ -e /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_55731323935351715112-if00 ];then setup $@ else echo "Arduino UNO havn't been connected!"