【问题标题】:Android AOSP - Definition of scan interval and scan window in android source codeAndroid AOSP - android源码中扫描间隔和扫描窗口的定义
【发布时间】:2015-01-06 05:36:29
【问题描述】:

我已经下载了 Lollipop 5.0 的 AOSP 源代码。在 api 级别 21 中,在蓝牙低功耗扫描设置下,有三个用于扫描 ble 设备的选项-SCAN_MODE_BALANCED, SCAN_MODE_LOW_LATENCY, SCAN_MODE_LOW_POWER。是否基于不同的扫描间隔和扫描窗口值?如果是这样,我在哪里可以找到源代码目录中为这些宏定义的值。

【问题讨论】:

    标签: android bluetooth-lowenergy android-source


    【解决方案1】:

    在搜索关键字“SCAN_MODE_BALANCED”时,我在http://androidxref.com/5.0.0_r2/xref/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/ScanManager.java 中发现了以下值:

        /**
         * Scan params corresponding to regular scan setting
         */
        private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 500;
        private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 5000;
        private static final int SCAN_MODE_BALANCED_WINDOW_MS = 2000;
        private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
        private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000;
        private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;
    
        /**
         * Scan params corresponding to batch scan setting
         */
        private static final int SCAN_MODE_BATCH_LOW_POWER_WINDOW_MS = 1500;
        private static final int SCAN_MODE_BATCH_LOW_POWER_INTERVAL_MS = 150000;
        private static final int SCAN_MODE_BATCH_BALANCED_WINDOW_MS = 1500;
        private static final int SCAN_MODE_BATCH_BALANCED_INTERVAL_MS = 15000;
        private static final int SCAN_MODE_BATCH_LOW_LATENCY_WINDOW_MS = 1500;
        private static final int SCAN_MODE_BATCH_LOW_LATENCY_INTERVAL_MS = 5000;
    

    还可以查看 ScanManager.ScanNative.configureRegularScanParams()。根据扫描设置(ScanSettings.SCAN_MODE_LOW_POWER、ScanSettings.SCAN_MODE_BALANCED、ScanSettings.SCAN_MODE_LOW_LATENCY)设置两个参数scanWindow和scanInterval,转换成BLE单元,然后传递给gattSetScanParametersNative()。

    希望这会有所帮助。

    【讨论】:

    • 如果我说我将 ScanSettings 设置为 SCAN_MODE_LOW_LATENCY 到底是什么意思?它是否说它每 5 秒扫描 5 秒,然后再次开始扫描 - 我不认为是这种情况,因为我有一个更新速度比每 5 秒快的应用程序。您能否详细解释一下这些值?
    【解决方案2】:

    我不确定这是否准确,或者您是否可以使用它来找到所需的值,但我找到了一些 code from Google regarding scanning settings:

      // Constants for Scan Cycle
      // Low Power: 2.5 minute period with 1.5 seconds active (1% duty cycle)
      /* @VisibleForTesting */ static final int LOW_POWER_IDLE_MILLIS = 148500;
      /* @VisibleForTesting */ static final int LOW_POWER_ACTIVE_MILLIS = 1500;
    
      // Balanced: 15 second period with 1.5 second active (10% duty cycle)
      /* @VisibleForTesting */ static final int BALANCED_IDLE_MILLIS = 13500;
      /* @VisibleForTesting */ static final int BALANCED_ACTIVE_MILLIS = 1500;
    
      // Low Latency: 1.67 second period with 1.5 seconds active (90% duty cycle)
      /* @VisibleForTesting */ static final int LOW_LATENCY_IDLE_MILLIS = 167;
      /* @VisibleForTesting */ static final int LOW_LATENCY_ACTIVE_MILLIS = 1500;
    

    【讨论】:

    • 谢谢蒂姆。但我在 google android 源代码中找不到这种定义。在驱动程序级别搜索后,我在这里找到了类似 androidxref.com/5.0.0_r2/xref/external/bluetooth/bluedroid/… #define BTM_BLE_GAP_DISC_SCAN_INT 18 /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms / #define BTM_BLE_GAP_DISC_SCAN_WIN 18 / scan_window = 11.25 ms= 0x0010 * 0.625 ms */
    • 是上面对应的扫描窗口和扫描间隔。但我想知道他们如何定义 SCAN_MODE_BALANCED、SCAN_MODE_LOW_LATENCY、SCAN_MODE_LOW_POWER 的值!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多