3 ###############################################################
4 # This is a workaround for SPEC-1762/SPEC-1763
6 # THIS SCRIPT MUST BE REMOVED ONCE THE ABOVE ISSUES ARE SOLVED
10 # meta-audio-4a-framework/
12 # agl-service-audio-4a/
13 # agl-service-audio-4a_git.bb
15 # Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
16 ###############################################################
18 # time from script startup
21 function ts() { echo $(( $(date +%s) - ts0 )); }
23 function havetime() { [[ $(ts) -le ${1:-$LIMIT} ]] || return 1; }
26 # ensure bt modules are loaded (delay: 5s)
28 [[ -d /sys/module/bluetooth ]] && {
29 echo "bluetooth kernel module detected"
32 echo "waiting for bluetooth kernel module to be up"
35 havetime 4 || { echo "TIMEOUT REACHED"; return 1; }
37 # check that we have at least one controller
40 echo "detecting hci devices..."
41 for x in $(ls /sys/class/bluetooth/hci* 2>/dev/null); do
42 [[ -z "$HCIDEV" ]] && HCIDEV=$(basename $x)
44 [[ -n "$HCIDEV" ]] && {
45 echo "found HCI controller: $HCIDEV"
50 havetime 8 || { echo "TIMEOUT REACHED"; return 1; }
52 # wait for controller to be up and running
54 state=$(hciconfig $HCIDEV | grep -A 2 ^hci0 | tail -1)
55 [[ $state =~ UP ]] && [[ $state =~ RUNNING ]] && {
56 echo "HCI controller $HCIDEV state: $state"
59 echo "HCI controller $HCIDEV state: $state ... waiting for UP RUNNING"
62 havetime 15 || { echo "TIMEOUT REACHED"; return 1; }
63 echo "HCI device up and running after $(ts) seconds"
65 # wait for bluetooth-service to return something
67 res=$(afb-client-demo -d unix:/run/user/$UID/apis/ws/Bluetooth-Manager power true)
68 [[ "$res" =~ \"response\":(.*)}$ ]] && res=${BASH_REMATCH[1]}
69 [[ "$res" == '{"power":"on"}' ]] && {
70 echo "Bluetooth-Manager/power: $res"
73 echo "Bluetooth-Manager/power: not ready yet ($res)"
76 echo "Bluetooth-Manager ready after $(ts) seconds"
78 echo "4A now starting..."
81 waitloop 2>&1 | sed 's/^/4AWAITBT /' >&2