#!/usr/bin/env bash
[ $# -eq 1 ] || {
echo "Usage: can_sitl.sh DEVICE"
echo "for example can_sitl.sh /dev/serial/by-id/usb-Zubax_Robotics_Zubax_Babel_3700330018514D563935392000000000-if00"
exit 1
}
DEVPATH="$1"
if readlink $DEVPATH > /dev/null; then
DEVNAME=$(basename $(readlink $DEVPATH))
else
DEVNAME=$(basename $DEVPATH)
fi
set -e
sudo killall -9 slcand 2> /dev/null || true
for m in slcan can-gw vcan can_raw can; do
sudo rmmod $m 2> /dev/null || true
done
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
sudo ip link set vcan0 mtu 72
sudo modprobe slcan
sudo modprobe can-gw
sudo slcan_attach -f -s8 -o "$DEVPATH"
sudo slcand "$DEVNAME" slcan0
sudo ifconfig slcan0 up
sudo cangw -A -s vcan0 -d slcan0 -e
sudo cangw -A -s slcan0 -d vcan0 -e
echo "slcan0 setup"
ifconfig slcan0