-
Notifications
You must be signed in to change notification settings - Fork 25
/
can-set-rate
54 lines (44 loc) · 1.36 KB
/
can-set-rate
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /bin/sh
dev=$1
rate=$2
bitrate_easysolar() {
case $dev:$1 in
can0:500000)
echo tq 200 prop-seg 3 phase-seg1 4 phase-seg2 2
return
;;
esac
echo bitrate $1
}
bitrate() {
case $(board-compat) in
victronenergy,easysolar-a10)
bitrate_easysolar "$@"
return
;;
esac
echo bitrate $1
}
# Preferably the tx queue is not increased, but many programs
# fail to work properly without it.
#
# See e.g. https://rtime.felk.cvut.cz/can/socketcan-qdisc-final.pdf
# "3.4. Blocking the application when the queue is full"
up() {
# note: the can driver depends on the can_dev module, but not on the can module.
# As a consequence the frames received between the time the device is up and
# actually used are counted as dropped. Since can-busses shouldn't drop frames,
# that counter is important, so make sure the can module is loaded before upping
# the interface so the rx dropped count stays at 0.
modprobe can
# note: this is not done at once on purpose; some drivers don't support some
# properties, e.g. the vcan will bail out when trying to set the bitrate.
ip link set $dev type can $(bitrate $rate)
ip link set $dev type can restart-ms 100
ip link set $dev up txqueuelen 100
}
down() {
ip link set $dev down
}
down
test $rate -gt 0 && up