-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevgp.sh
executable file
·123 lines (111 loc) · 2.76 KB
/
revgp.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Initialize variables
tty=""
btdev=""
slot=""
group=""
config=""
detection=""
detection_clean=""
detection_clean_all=""
get=""
put=""
uid=""
# Parse command line arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-d|--dev)
if [[ $2 == tty* ]]
then
tty="$2"
else
btdev="$2"
fi
shift
shift
;;
-s|--slot)
slot="$2"
shift
shift
;;
-sg|--slot-group)
group="$2"
shift
shift
;;
-sc|--slot-config)
config="$2"
shift
shift
;;
-dg|--detection-get)
detection="$2"
shift
shift
;;
-dc|--detection-clean)
detection_clean="true"
shift
;;
-dca|--detection-clean-all)
detection_clean_all="true"
shift
;;
-g|--get)
get="$2"
shift
shift
;;
-p|--put)
put="$2"
shift
shift
;;
-su|--set-uid)
uid="$2"
shift
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
serialport="/dev/$tty"
if [ "$btdev" != "" ];then
serialportName='rfcomm0'
serialport="/dev/$serialportName"
[ -c "$serialport" ] || (sudo rfcomm -r bind $serialportName "$btdev" && sleep 0.1)
fi
stty -F $serialport 0:0:18b2:0:0:0:0:0:0:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
chat -t 10 -f chatscripts/init.chat < $serialport > $serialport && sleep 0.1 || exit
if [ "$group" != "" ]; then
group=$group chat -E -t 10 -f chatscripts/group.chat < $serialport > $serialport && sleep 0.1 || exit
fi
if [ "$slot" != "" ]; then
slot=$slot chat -E -t 10 -f chatscripts/slot.chat < $serialport > $serialport && sleep 0.1 || exit
fi
if [ "$detection" != "" ];then
chat -t 10 -f chatscripts/detec.chat < $serialport > $serialport && sleep 0.1 && \
rx -X $detection < $serialport > $serialport && sleep 0.1
fi
if [ $detection_clean_all ];then
chat -E -t 10 -f chatscripts/detec_clear_all.chat < $serialport > $serialport && sleep 0.1 || exit
elif [ $detection_clean ];then
chat -E -t 10 -f chatscripts/detec_clear_activated.chat < $serialport > $serialport && sleep 0.1 || exit
fi
if [ "$get" != "" ]; then
chat -t 10 -f chatscripts/get.chat < $serialport > $serialport && sleep 0.1 && \
rx -X $get < $serialport > $serialport
fi
if [ "$put" != "" ]; then
chat -t 10 -f chatscripts/put.chat < $serialport > $serialport && sleep 0.1 && \
sx -X -b $put < $serialport > $serialport
fi
if [ "$uid" != "" ]; then
uid=$uid chat -E -t 10 -f chatscripts/uid.chat < $serialport > $serialport && sleep 0.1 || exit
fi