Linux蓝牙脚本冻结

时间:2017-10-23 18:25:09

标签: linux ubuntu bluetooth

我正在编写一个脚本,它将通过蓝牙接收命令并执行它。这是正常工作但在随机次数后,脚本将在蓝牙设备断开连接后挂起。

这是我目前正在运行测试的脚本。

#! /bin/bash

sudo hciconfig hci0 up
sudo hciconfig hci0 sspmode 0
sudo hciconfig hci0 piscan
sudo sdptool add --channel=22 SP
sudo rfcomm watch /dev/rfcomm0 22 &

while [ true ]
do
 echo starting loop
 while [ true ]
 do
  count=$(rfcomm -a | wc -l)
  if [ "$count" = "1" ];
  then
   break;
  fi
 done
 sleep 0.5
 echo "End of loop."

 device=$(rfcomm show /dev/rfcomm0 | awk '{print $4}')
 sudo cat /dev/rfcomm0 > myCommand
 sudo chmod 777 myCommand
 more myCommand
 possible=$(cat myCommand)
 if [ "$possible" = "exit" ]
 then
  sudo poweroff
  break;
 fi
 ./myCommand
 echo "Finished executing!"
 echo ""
done

这是我的一项测试的结果。它在写入Disconnected后挂起,并在第二次到第30次之后发生。

Serial Port service registered
starting loop 0
Waiting for connection on channel 22
Connection from 22:22:7C:8B:61:86 to /dev/rfcomm0
Press CTRL-C for hangup
End of loop.
Disconnected
Waiting for connection on channel 22
/home/ubuntu/Desktop/pan
Finished executing!

starting loop 1
Connection from 22:22:7C:8B:61:86 to /dev/rfcomm0
Press CTRL-C for hangup
End of loop.
Disconnected
Waiting for connection on channel 22
/home/ubuntu/Desktop/pan
Finished executing!

starting loop 2
Connection from 22:22:7C:8B:61:86 to /dev/rfcomm0
Press CTRL-C for hangup
End of loop.
Disconnected
Waiting for connection on channel 22
/home/ubuntu/Desktop/pan
Finished executing!

starting loop 3
Connection from 22:22:7C:8B:61:86 to /dev/rfcomm0
Press CTRL-C for hangup
End of loop.
Disconnected
Waiting for connection on channel 22
/home/ubuntu/Desktop/pan
Finished executing!

starting loop 4
Connection from 22:22:7C:8B:61:86 to /dev/rfcomm0
Press CTRL-C for hangup
End of loop.
Disconnected

*更新: 我注释掉第25行sudo chmod 777 myCommand,并且不再有任何消息冻结脚本。它现在正在获得一个分段错误,它正在改变引起它的行号。

./bluetooth.sh: line 36:  2753 Segmentation fault      sudo cat /dev/rfcomm0 > myCommand

0 个答案:

没有答案