Android之Bluetooth日志

1.開發(fā)者選項(xiàng)->啟用藍(lán)牙HCI信息收集日志。

    private void writeBtHciSnoopLogOptions() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
        Settings.Secure.putInt(getActivity().getContentResolver(),
                Settings.Secure.BLUETOOTH_HCI_LOG,
                mBtHciSnoopLog.isChecked() ? 1 : 0);
    }
    
    藍(lán)牙默認(rèn)開關(guān)
    ./hardware/realtek/rtkbt/code/bt/conf/bt_stack.conf
    
    ./system/bt/conf/bt_stack.conf

2.android 8版本,默認(rèn)位置/data/misc/bluetooth/logs

/data/misc/bluetooth/logs # ls -l
total 3904
-rw-rw-r-- 1 bluetooth bluetooth      16 2019-04-25 17:27 btsnoop_hci.log
-rw-rw-r-- 1 bluetooth bluetooth      16 2019-04-25 17:27 btsnoop_hci.log.last
-rw-rw-r-- 1 bluetooth bluetooth 2755648 2019-04-25 18:16 hci_snoop20190425172740.cfa
-rw-rw-r-- 1 bluetooth bluetooth 1221959 2019-04-25 18:21 hci_snoop20190425173638.cfa

3.android 7, 默認(rèn)位置 /sdcard/

4.配置hci路徑:

cat /etc/bluetooth/bt_statck.conf
# BtSnoop log output file
BtSnoopFileName=/sdcard/btsnoop_hci.log

5.用wireshark等工具打開即可。

http://m.itdecent.cn/p/73f7366161d1
https://blog.csdn.net/feelinghappy/article/details/112846076
https://blog.csdn.net/qq_43824618/article/details/113878433

6.RSSI

RSSI(接收信號(hào)強(qiáng)度)Received Signal Strength Indicator
Rss=10logP,
只需將接受到的信號(hào)功率P代入就是接收信號(hào)強(qiáng)度(靈敏度)。
[例1] 如果發(fā)射功率P為1mw,折算為dBm后為0dBm。
[例2] 對(duì)于40W的功率,按dBm單位進(jìn)行折算后的值應(yīng)為:
10lg(40W/1mw)=10lg(40000)=10lg4+10lg10+10lg1000=46dBm。

Rssi和接收功率有關(guān),單位是dBm
一般為負(fù)值,反應(yīng)的是信號(hào)的衰減程度,理想狀態(tài)下(無衰減),Rssi = 0dBm,實(shí)際情況是,即使藍(lán)牙設(shè)備挨得非常近,Rssi也只有-50dBm的強(qiáng)度,在傳輸過程中,不可避免要損耗。

經(jīng)典藍(lán)牙強(qiáng)度:
-50 ~ 0dBm   信號(hào)強(qiáng)
-70 ~-50dBm  信號(hào)中
<-70dBm      信號(hào)弱

低功耗藍(lán)牙分四級(jí):
-60 ~  0   4
-70 ~ -60  3
-80 ~ -70  2
<-80       1

代碼用例
/**
 * A和n的值,需要根據(jù)實(shí)際環(huán)境進(jìn)行檢測(cè)得出
 */
public class RssiUtils {

    /** A 發(fā)射端和接收端相隔1米時(shí)的信號(hào)強(qiáng)度 */
    private static final double A_Value = 50;
    /** n 環(huán)境衰減因子 */
    private static final double n_Value = 2.5;

    /**
     * 根據(jù)Rssi的值,計(jì)算距離,單位m
     * @param rssi 信號(hào)強(qiáng)度,單位dB
     */
    public static double getLeDistance(int rssi) {
        double power = (Math.abs(rssi) - A_Value) / (10 * n_Value);
        return Math.pow(10, power);
    }

    /**
     * 經(jīng)典藍(lán)牙強(qiáng)度 
     * -50 ~ 0dBm  信號(hào)強(qiáng)
     * -70 ~ -50dBm    信號(hào)中
     * <-70dBm      信號(hào)弱
     */
    public static byte getBredrLevel(int rssi) {
        if(rssi > -50) {
            return 3;
        } else if(rssi > -70) {
            return 2;
        } else {
            return 1;
        }
    }

    /**
     * 低功耗藍(lán)牙分四級(jí)
     * -60 ~ 0     4
     * -70 ~ -60   3
     * -80 ~ -70   2
     * <-80         1
     */
    public static byte getLeLevel(int rssi) {
        if(rssi > -60) {
            return 4;
        } else if(rssi > -70) {
            return 3;
        } else if(rssi > -80) {
            return 2;
        } else {
            return 1;
        }
    }
}

7.gatt錯(cuò)誤碼

hardware/realtek/rtkbt/code/bt/stack/include/gatt_api.h
system/bt/stack/include/gatt_api.h


https://blog.csdn.net/weixin_30627381/article/details/101761801
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容