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
|
| check_time() {
| while [ 1 ]
| do
| uptime=`cat /proc/uptime | awk -F ' ' '{print $1}' | awk -F '.' '{print $1}'`
| echo uptime is $uptime
| if [ $uptime -lt 20 ]; then
| sleep 1
| else
| break
| fi
| done
| }
|
| check_time
|
| case "$1" in
| start)
|
| if pidof bluetoothd; then
| killall bluetoothd
| fi
|
| sleep 1
|
| if pidof gatt-service; then
| killall gatt-service
| fi
|
| hciconfig hci0 down
| sleep 1
| hciconfig hci0 up
|
| #hciconfig hci0 piscan &
|
| /usr/libexec/bluetooth/bluetoothd -C -E -d -n &
|
| #sleep 2
|
| /usr/bin/gatt-service &
|
| ;;
|
| stop)
|
| if pidof bluetoothd; then
| killall bluetoothd
| fi
|
| sleep 1
|
| if pidof gatt-service; then
| killall gatt-service
| fi
|
| ;;
|
| ok)
|
| while [ 1 ]
| do
| if ! pidof gatt-service; then
| killall bluetoothd
| break
| fi
| sleep 1
| done
|
| ;;
| *)
| esac
| exit 0
|
|