Android命令列下藍芽使用

來源:互聯網
上載者:User

標籤:bluetooth

注意:此部分只適用於broadcom 系列藍芽晶片,例如RK903, AP6xxx 系列

通過su 命令切換到root 使用者

1、先確認RFKILL 驅動已經載入

ls /sys/class/rfkill/rfkill0/

如果沒有找到rfkill0 這個目錄,說明藍牙堆疊有問題。

請檢查kernel 中的藍芽選項是否有勾選了

請查看kernel 的列印資訊中以“[BT_RFKILL]”打頭的資訊。

2、關閉藍芽:

A. 在Settings 介面中關閉藍芽

B. 給藍牙裝置下電:

echo 0 > /sys/class/rfkill/rfkill0/state

C. 關閉bluetoothd 和hciattach 這兩個service:

setprop ctl.stop bluetoothd

setprop ctl.stop hciattach

D. 對於Android4.2,還需要關閉進程com.android.bluetooth

busybox killall com.android.bluetooth

3、確定藍芽已經關閉之後,手動給藍芽上電:

echo 1 > /sys/class/rfkill/rfkill0/state

4、下載藍芽韌體

Broadcomd 系列晶片使用命令:

RK30:

brcm_patchram_plus --patchram bychip --baudrate 1500000 --enable_lpm --enable_hci /dev/ttyS0 -d &

RK29:

brcm_patchram_plus --patchram bychip --baudrate 1500000 --enable_lpm --enable_hci /dev/ttyS2 -d &

如果藍芽硬體及驅動沒有問題,那麼在這步執行完成後可以看到列印:

E/bluetooth_brcm( 402): Done setting line discpline

如果沒有出現這行列印,說明藍芽硬體或軟體方面存在問題。

Realtek RTL8723AS 使用命令:

/system/bin/hciattach -n -s 115200 /dev/ttyS0 rtk_h5

5、確認hci0 interface 已經建立:

# hciconfig -a

hci0: Type: BR/EDR Bus: UART

BD Address: 20:00:00:00:01:09 ACL MTU: 1021:7 SCO MTU: 64:1

DOWN

RX bytes:485 acl:0 sco:0 events:18 errors:0

TX bytes:95 acl:0 sco:0 commands:18 errors:0

Features: 0xff 0xff 0x8f 0xfe 0x9b 0xff 0x79 0x87

Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3

Link policy: RSWITCH HOLD SNIFF PARK

Link mode: SLAVE ACCEPT

6、啟用藍芽

# hciconfig hci0 up

7、確認藍芽啟用成功

# hcitool dev

Devices:

hci0 20:00:00:00:01:09

8、藍芽啟用成功後,可以開始掃描周圍的藍牙裝置

# hcitool scan

Scanning ...

90:C1:15:0F:C2:78 Xperia neo


其它:

1.開放檢測,允許周圍裝置檢測到

# hciconfig hciX piscan

2.串連藍芽

# hcitool cc A0:E9:DB:26:36:98

3. 配對

# hcitool auth A0:E9:DB:26:36:98


總結:原理是將bluedroid禁用,使能BlueZ然後就可以使用基於BluZ的hciconfig/hcitool等等調試工具來做簡單的測試了.嘗試通過這些工具進行後期配對等等實驗,但並沒有功能,其實到這一步也基本上可以認定本地的藍牙裝置工作正常了,更多關於工具的使用見藍芽調試工具hcitool的使用執行個體.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.