我已经下载了Lollipop 5.0的AOSP源代码。在api级别21中,在蓝牙低能量扫描设置下,有三种扫描设备的选项 - SCAN_MODE_BALANCED, SCAN_MODE_LOW_LATENCY, SCAN_MODE_LOW_POWER
。是基于不同的扫描间隔和扫描窗口值?如果是这样,我在哪里可以找到在源代码目录中为这些宏定义的值。
答案 0 :(得分:7)
在greping关键字“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()。根据扫描设置(scanWindow
,scanInterval
,ScanSettings.SCAN_MODE_LOW_POWER
)设置两个参数ScanSettings.SCAN_MODE_BALANCED
和ScanSettings.SCAN_MODE_LOW_LATENCY
,转换为BLE单位,然后传递给gattSetScanParametersNative ()。
希望这有帮助。
答案 1 :(得分:1)
我不确定这是否准确,或者您是否可以使用它来查找所需的值,但我找到了一些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;