forked from greearb/lanforge-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtstack_runner.sh
More file actions
executable file
·71 lines (60 loc) · 1.83 KB
/
btstack_runner.sh
File metadata and controls
executable file
·71 lines (60 loc) · 1.83 KB
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
#! /usr/bin/bash
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
## btstack_runner.sh ##
## ##
## Use this script to start a Bluetooth Keyboard connection, ##
## via btstack operating on a USB dongle. ##
## ##
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
usage="$0 -u 01-02 -d f8:e3:22:b2:2c -e /home/lanforge/vr_conf/mgt_pipe_1_helper
-u: usb path of bluetooth dongle
-d: bluetooth mac of target device
-e: file for writing out important btstack events
"
OPTIONAL_ARGS=''
while getopts ":d:e:u:" opts; do
case "$opts" in
d) TARGET_DEVICE="$OPTARG";;
e) EVENTS_FNAME="$OPTARG";;
u) USB_PATH="$OPTARG";;
*) echo "Unknown Option [$opts]"
esac
done
[ -z "$TARGET_DEVICE" ] && {
echo -e "-d: TARGET DEVICE required\n"
echo "$usage"
exit 1
}
[ -z "$USB_PATH" ] && {
echo -e "-u USB PATH of controlling BT dongle required\n"
echo "$usage"
exit 1
}
if [ -n "$EVENTS_FNAME" ]; then
OPTIONAL_ARGS+="-e $EVENTS_FNAME"
fi
if [ ! -d "/home/lanforge/btstack/" ]; then
mkdir -p /home/lanforge/btstack
fi
CHILD_PID=''
#setup PIDF removal on-exit
PIDFNAME="./btstack/btstack-$TARGET_DEVICE.pid"
on_exit() {
kill -s SIGINT $CHILD_PID
rm $PIDFNAME
exit 0
}
trap on_exit SIGINT SIGTERM
#write out our PID
echo $$ > $PIDFNAME
for (( ; ; ))
do
# start btstack
CMD="btstack -u $USB_PATH -d $TARGET_DEVICE $OPTIONAL_ARGS"
echo "starting btstack w/ cmd: $CMD"
($CMD) &
CHILD_PID=$!
wait $!
echo "btstack exited - sleeping 3s before restarting"
sleep 3
done