From b4bbf00688c424dcd8b176a70b1abd395b4568e9 Mon Sep 17 00:00:00 2001 From: bionade24 Date: Wed, 4 Aug 2021 00:39:41 +0200 Subject: [PATCH 1/2] Modify udev rule for USBtin USB to CAN converter and add systemd service so that on plugging in the slcan0 interface gets set up automatically and stopped when plugged out. --- studierbot/interface/can/77-evo-slcand.rules | 4 ++-- studierbot/interface/can/Makefile | 10 ++++++++++ studierbot/interface/can/slcand.service | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 studierbot/interface/can/Makefile create mode 100644 studierbot/interface/can/slcand.service diff --git a/studierbot/interface/can/77-evo-slcand.rules b/studierbot/interface/can/77-evo-slcand.rules index 6f96a6f..c414278 100644 --- a/studierbot/interface/can/77-evo-slcand.rules +++ b/studierbot/interface/can/77-evo-slcand.rules @@ -1,3 +1,3 @@ # USBtin module -ACTION=="add", ENV{SUBSYSTEM}=="tty", GROUP="dialout", MODE="0666", ATTRS{product}=="USBtin", RUN+="/usr/bin/logger [udev] USBtin detected, creating symlink ttyEvoCan ", SYMLINK+="ttyEvoCan" -ACTION=="remove", ENV{ID_SERIAL_SHORT}=="A0212656", RUN+="/usr/bin/pkill slcand" \ No newline at end of file +ACTION=="add", ENV{SUBSYSTEM}=="tty", GROUP="dialout", MODE="0666", ATTRS{product}=="USBtin", RUN+="/usr/bin/logger [udev] USBtin detected, creating symlink ttyEvoCan ", SYMLINK+="ttyEvoCan", ENV{SYSTEMD_WANTS}="slcand.service" +#ACTION=="remove", ENV{ID_SERIAL_SHORT}=="A0212656", RUN+="/usr/bin/pkill slcand" \ No newline at end of file diff --git a/studierbot/interface/can/Makefile b/studierbot/interface/can/Makefile new file mode 100644 index 0000000..491b083 --- /dev/null +++ b/studierbot/interface/can/Makefile @@ -0,0 +1,10 @@ +all: + echo 'No rule for make all existing. Please run "sudo make install" to install the udev rule and systemd service.' + +install: + install -D -m644 77-evo-slcand.rules /etc/udev/rules.d/77-evo-slcand.rules + install -D -m644 slcand.service /etc/systemd/system/slcand.service + +remove: + remove /etc/udev/rules.d/77-evo-slcand.rules + remove /etc/systemd/system/slcand.service \ No newline at end of file diff --git a/studierbot/interface/can/slcand.service b/studierbot/interface/can/slcand.service new file mode 100644 index 0000000..900ad11 --- /dev/null +++ b/studierbot/interface/can/slcand.service @@ -0,0 +1,10 @@ +[Unit] +BindsTo=dev-ttyEvoCan.device +After=dev-ttyEvoCan.device + +[Service] +Type=simple +ExecStart=/usr/bin/slcand -F -f -s6 -o -c /dev/ttyEvoCan +ExecStartPost=ip link set slcan0 up +User=root +Group=root \ No newline at end of file From e2916425f1eecc236e177dc628c362b9de9dc37d Mon Sep 17 00:00:00 2001 From: Noah Heckel Date: Wed, 4 Aug 2021 16:57:25 +0200 Subject: [PATCH 2/2] Fix slcand.service on old ubuntu version by calling ExecPostStart with full PATH --- studierbot/interface/can/slcand.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studierbot/interface/can/slcand.service b/studierbot/interface/can/slcand.service index 900ad11..d76a142 100644 --- a/studierbot/interface/can/slcand.service +++ b/studierbot/interface/can/slcand.service @@ -5,6 +5,6 @@ After=dev-ttyEvoCan.device [Service] Type=simple ExecStart=/usr/bin/slcand -F -f -s6 -o -c /dev/ttyEvoCan -ExecStartPost=ip link set slcan0 up +ExecStartPost=/bin/ip link set slcan0 up User=root Group=root \ No newline at end of file