-
Notifications
You must be signed in to change notification settings - Fork 2
/
monitor
executable file
·48 lines (38 loc) · 1.07 KB
/
monitor
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
#!/bin/bash
###
# 在tmux里打开所有ttyUSB的监视器
# 参数1(可选):部分匹配设备的全名,默认=CP2105
###
if [ "$(id -u)" -ne 0 ]; then
exec sudo "$0" "$@"
fi
NAME_INCLUDE="${1-CP2105}"
function createTab() {
$TMUX setenv -g -t $NAME HISTFILE "/dev/null"
$TMUX set-option mouse on
$TMUX new-window -n monitor-"$(basename "$1")"
$TMUX send-keys -t $NAME "python -m serial.tools.miniterm '$1' 115200" Enter
}
function getUsbTty() {
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" != "ttyUSB"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
if echo "$ID_SERIAL" | grep -q "${NAME_INCLUDE}" ; then
createTab "/dev/$devname"
fi
)
done
}
mkdir -p /var/run/my-tmux
TMUX="tmux -S /var/run/tmux-port"
NAME=usb-serial
if ! $TMUX has-session -t $NAME &>/dev/null ; then
$TMUX -2 new-session -d -s $NAME
getUsbTty
$TMUX kill-window -t 0
fi
$TMUX attach-session -t $NAME