Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

開啟 Android BlueZ 的調試開關

編輯:關於 Android 程式設計

開啟 Android BlueZ 的調試開關

在移植或調試藍牙協議棧時,往往需要打開 BlueZ 的調試日志。下面提供兩種做法,都在 external/bluetooth/bluez/src/log.h 中修改。

方法一:重定義 DBG 宏

把 DBG 重新定義為通過 Android 的日志系統輸出,並引入 android/log.h:

#include <android/log.h>

#define DBG(fmt, arg...) \
    __android_log_print(ANDROID_LOG_DEBUG, "BlueZ", fmt, ## arg)

同時在日誌初始化相關的函數(如 __btd_log_init、__btd_toggle_debug)中,把原本基於 __start___debug / __stop___debug 段的遍歷邏輯註釋掉即可。

方法二:調整調試標志與輸出

第一步,引入日誌頭文件:

#include <cutils/logd.h>

第二步,把調試標志的默認值改為開啟:

#define BTD_DEBUG_FLAG_DEFAULT 1
#define BTD_DEBUG_FLAG_PRINT   1

第三步,把 DBG 宏的最終輸出改成 Android 日志:

#define DBG(fmt, arg...) do { \
    static struct btd_debug_desc __btd_debug_desc \
    __attribute__((used, section("__debug"), aligned(8))) = { \
        .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
    }; \
    if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
        __android_log_print(ANDROID_LOG_DEBUG, "BlueZ", fmt, ## arg); \
} while (0)

改完重新編譯,BlueZ 的調試信息就會通過 logcat 打印出來。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved