Android 蓝牙:丢包
Android bluetooth: dropped packets
我们已经构建了一个可穿戴设备,它每 20 毫秒通过 BLE 将结果发送到 Android 设备。我们得到奇怪的结果,前 270 个数据包按时收到且没有丢失,但在 271 时事情变得奇怪。我们会给出5个包(准时)然后丢弃32个包,然后重复。
手机 phone 是装有 Android 7.1.1 的 Nexus 5X。该设备是 运行 具有 BLE 4.2 的 nRF51。我们正在使用基于模板应用程序的 Android nRF 工具箱 v2.4.0。
我们的一个假设是 ConnectionPriority 错误,我们需要设置更高的优先级。我们尝试在 BleManager 中添加以下内容:
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
但是没有区别。奇怪的是系统似乎可以找到前 270 个数据包。
有什么调试方法吗?
示例 logcat 下面。注意这里的包号是Android端收到的包号,不是设备端的包号:
Packet #258; SensorTime = 256.175sec; Delta = 018.8msec
Packet #259; SensorTime = 256.200sec; Delta = 025.0msec
Packet #260; SensorTime = 256.213sec; Delta = 012.5msec
Packet #261; SensorTime = 256.238sec; Delta = 025.0msec
Packet #262; SensorTime = 256.256sec; Delta = 018.8msec
Packet #263; SensorTime = 256.275sec; Delta = 018.8msec
Packet #264; SensorTime = 256.300sec; Delta = 025.0msec
Packet #265; SensorTime = 256.319sec; Delta = 018.8msec
Packet #266; SensorTime = 256.338sec; Delta = 018.8msec
Packet #267; SensorTime = 256.356sec; Delta = 018.7msec
Packet #268; SensorTime = 256.375sec; Delta = 018.8msec
Packet #269; SensorTime = 256.394sec; Delta = 018.8msec
Packet #270; SensorTime = 256.419sec; Delta = 025.0msec
Packet #271; SensorTime = 256.438sec; Delta = 018.8msec
=== Time Fault :: Time 256.656sec : Time delta = 218.8 msec; mTime since last fault = 0.000 sec
Packet #272; SensorTime = 256.656sec; Delta = 218.8msec
=== Time Fault :: Time 257.294sec : Time delta = 637.5 msec; mTime since last fault = 0.001 sec
Packet #273; SensorTime = 257.294sec; Delta = 637.5msec
Packet #274; SensorTime = 257.313sec; Delta = 018.8msec
=== Time Fault :: Time 257.938sec : Time delta = 625.0 msec; mTime since last fault = 0.639 sec
Packet #275; SensorTime = 257.938sec; Delta = 625.0msec
=== Time Fault :: Time 258.594sec : Time delta = 656.3 msec; mTime since last fault = 0.003 sec
Packet #276; SensorTime = 258.594sec; Delta = 656.3msec
Packet #277; SensorTime = 258.613sec; Delta = 018.8msec
Packet #278; SensorTime = 258.638sec; Delta = 025.0msec
Packet #279; SensorTime = 258.650sec; Delta = 012.5msec
Packet #280; SensorTime = 258.675sec; Delta = 025.0msec
=== Time Fault :: Time 259.231sec : Time delta = 556.2 msec; mTime since last fault = 0.639 sec
Packet #281; SensorTime = 259.231sec; Delta = 556.2msec
Packet #282; SensorTime = 259.256sec; Delta = 025.0msec
Packet #283; SensorTime = 259.275sec; Delta = 018.8msec
Packet #284; SensorTime = 259.294sec; Delta = 018.7msec
Packet #285; SensorTime = 259.313sec; Delta = 018.8msec
=== Time Fault :: Time 259.875sec : Time delta = 562.5 msec; mTime since last fault = 0.657 sec
Packet #286; SensorTime = 259.875sec; Delta = 562.5msec
Packet #287; SensorTime = 259.894sec; Delta = 018.8msec
Packet #288; SensorTime = 259.913sec; Delta = 018.8msec
Packet #289; SensorTime = 259.931sec; Delta = 018.8msec
Packet #290; SensorTime = 259.956sec; Delta = 025.0msec
=== Time Fault :: Time 260.513sec : Time delta = 556.2 msec; mTime since last fault = 0.636 sec
Packet #291; SensorTime = 260.513sec; Delta = 556.2msec
Packet #292; SensorTime = 260.531sec; Delta = 018.8msec
Packet #293; SensorTime = 260.550sec; Delta = 018.8msec
Packet #294; SensorTime = 260.569sec; Delta = 018.8msec
Packet #295; SensorTime = 260.594sec; Delta = 025.0msec
=== Time Fault :: Time 261.169sec : Time delta = 575.0 msec; mTime since last fault = 0.645 sec
Packet #296; SensorTime = 261.169sec; Delta = 575.0msec
Packet #297; SensorTime = 261.188sec; Delta = 018.8msec
Packet #298; SensorTime = 261.213sec; Delta = 025.0msec
Packet #299; SensorTime = 261.231sec; Delta = 018.7msec
Packet #300; SensorTime = 261.250sec; Delta = 018.8msec
=== Time Fault :: Time 261.806sec : Time delta = 556.3 msec; mTime since last fault = 0.645 sec
Packet #301; SensorTime = 261.806sec; Delta = 556.3msec
Packet #302; SensorTime = 261.831sec; Delta = 025.0msec
Packet #303; SensorTime = 261.850sec; Delta = 018.8msec
Packet #304; SensorTime = 261.869sec; Delta = 018.8msec
Packet #305; SensorTime = 261.894sec; Delta = 025.0msec
=== Time Fault :: Time 262.456sec : Time delta = 562.5 msec; mTime since last fault = 1.283 sec
Packet #306; SensorTime = 262.456sec; Delta = 562.5msec
Packet #307; SensorTime = 262.469sec; Delta = 012.5msec
Packet #308; SensorTime = 262.488sec; Delta = 018.8msec
Packet #309; SensorTime = 262.506sec; Delta = 018.8msec
Packet #310; SensorTime = 262.525sec; Delta = 018.8msec
=== Time Fault :: Time 263.106sec : Time delta = 581.2 msec; mTime since last fault = 0.658 sec
Packet #311; SensorTime = 263.106sec; Delta = 581.2msec
=== Time Fault :: Time 263.750sec : Time delta = 643.8 msec; mTime since last fault = 0.631 sec
Packet #312; SensorTime = 263.750sec; Delta = 643.8msec
=== Time Fault :: Time 264.388sec : Time delta = 637.5 msec; mTime since last fault = 0.003 sec
Packet #313; SensorTime = 264.388sec; Delta = 637.5msec
使用BLE嗅探器跟踪数据包后,我们发现,在设备端,有一对错误的常量:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(400, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(650, UNIT_1_25_MS)
更正如下:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(10, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS)
更正连接速率后,我们的罚款就付清了。最奇怪的是,有些设备和手机可以全速工作,但其他设备和手机会掉入上述不正确的连接优先级。
谢谢您的帮助。嗅探器是这里的关键!
我们已经构建了一个可穿戴设备,它每 20 毫秒通过 BLE 将结果发送到 Android 设备。我们得到奇怪的结果,前 270 个数据包按时收到且没有丢失,但在 271 时事情变得奇怪。我们会给出5个包(准时)然后丢弃32个包,然后重复。
手机 phone 是装有 Android 7.1.1 的 Nexus 5X。该设备是 运行 具有 BLE 4.2 的 nRF51。我们正在使用基于模板应用程序的 Android nRF 工具箱 v2.4.0。
我们的一个假设是 ConnectionPriority 错误,我们需要设置更高的优先级。我们尝试在 BleManager 中添加以下内容:
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
但是没有区别。奇怪的是系统似乎可以找到前 270 个数据包。
有什么调试方法吗?
示例 logcat 下面。注意这里的包号是Android端收到的包号,不是设备端的包号:
Packet #258; SensorTime = 256.175sec; Delta = 018.8msec
Packet #259; SensorTime = 256.200sec; Delta = 025.0msec
Packet #260; SensorTime = 256.213sec; Delta = 012.5msec
Packet #261; SensorTime = 256.238sec; Delta = 025.0msec
Packet #262; SensorTime = 256.256sec; Delta = 018.8msec
Packet #263; SensorTime = 256.275sec; Delta = 018.8msec
Packet #264; SensorTime = 256.300sec; Delta = 025.0msec
Packet #265; SensorTime = 256.319sec; Delta = 018.8msec
Packet #266; SensorTime = 256.338sec; Delta = 018.8msec
Packet #267; SensorTime = 256.356sec; Delta = 018.7msec
Packet #268; SensorTime = 256.375sec; Delta = 018.8msec
Packet #269; SensorTime = 256.394sec; Delta = 018.8msec
Packet #270; SensorTime = 256.419sec; Delta = 025.0msec
Packet #271; SensorTime = 256.438sec; Delta = 018.8msec
=== Time Fault :: Time 256.656sec : Time delta = 218.8 msec; mTime since last fault = 0.000 sec
Packet #272; SensorTime = 256.656sec; Delta = 218.8msec
=== Time Fault :: Time 257.294sec : Time delta = 637.5 msec; mTime since last fault = 0.001 sec
Packet #273; SensorTime = 257.294sec; Delta = 637.5msec
Packet #274; SensorTime = 257.313sec; Delta = 018.8msec
=== Time Fault :: Time 257.938sec : Time delta = 625.0 msec; mTime since last fault = 0.639 sec
Packet #275; SensorTime = 257.938sec; Delta = 625.0msec
=== Time Fault :: Time 258.594sec : Time delta = 656.3 msec; mTime since last fault = 0.003 sec
Packet #276; SensorTime = 258.594sec; Delta = 656.3msec
Packet #277; SensorTime = 258.613sec; Delta = 018.8msec
Packet #278; SensorTime = 258.638sec; Delta = 025.0msec
Packet #279; SensorTime = 258.650sec; Delta = 012.5msec
Packet #280; SensorTime = 258.675sec; Delta = 025.0msec
=== Time Fault :: Time 259.231sec : Time delta = 556.2 msec; mTime since last fault = 0.639 sec
Packet #281; SensorTime = 259.231sec; Delta = 556.2msec
Packet #282; SensorTime = 259.256sec; Delta = 025.0msec
Packet #283; SensorTime = 259.275sec; Delta = 018.8msec
Packet #284; SensorTime = 259.294sec; Delta = 018.7msec
Packet #285; SensorTime = 259.313sec; Delta = 018.8msec
=== Time Fault :: Time 259.875sec : Time delta = 562.5 msec; mTime since last fault = 0.657 sec
Packet #286; SensorTime = 259.875sec; Delta = 562.5msec
Packet #287; SensorTime = 259.894sec; Delta = 018.8msec
Packet #288; SensorTime = 259.913sec; Delta = 018.8msec
Packet #289; SensorTime = 259.931sec; Delta = 018.8msec
Packet #290; SensorTime = 259.956sec; Delta = 025.0msec
=== Time Fault :: Time 260.513sec : Time delta = 556.2 msec; mTime since last fault = 0.636 sec
Packet #291; SensorTime = 260.513sec; Delta = 556.2msec
Packet #292; SensorTime = 260.531sec; Delta = 018.8msec
Packet #293; SensorTime = 260.550sec; Delta = 018.8msec
Packet #294; SensorTime = 260.569sec; Delta = 018.8msec
Packet #295; SensorTime = 260.594sec; Delta = 025.0msec
=== Time Fault :: Time 261.169sec : Time delta = 575.0 msec; mTime since last fault = 0.645 sec
Packet #296; SensorTime = 261.169sec; Delta = 575.0msec
Packet #297; SensorTime = 261.188sec; Delta = 018.8msec
Packet #298; SensorTime = 261.213sec; Delta = 025.0msec
Packet #299; SensorTime = 261.231sec; Delta = 018.7msec
Packet #300; SensorTime = 261.250sec; Delta = 018.8msec
=== Time Fault :: Time 261.806sec : Time delta = 556.3 msec; mTime since last fault = 0.645 sec
Packet #301; SensorTime = 261.806sec; Delta = 556.3msec
Packet #302; SensorTime = 261.831sec; Delta = 025.0msec
Packet #303; SensorTime = 261.850sec; Delta = 018.8msec
Packet #304; SensorTime = 261.869sec; Delta = 018.8msec
Packet #305; SensorTime = 261.894sec; Delta = 025.0msec
=== Time Fault :: Time 262.456sec : Time delta = 562.5 msec; mTime since last fault = 1.283 sec
Packet #306; SensorTime = 262.456sec; Delta = 562.5msec
Packet #307; SensorTime = 262.469sec; Delta = 012.5msec
Packet #308; SensorTime = 262.488sec; Delta = 018.8msec
Packet #309; SensorTime = 262.506sec; Delta = 018.8msec
Packet #310; SensorTime = 262.525sec; Delta = 018.8msec
=== Time Fault :: Time 263.106sec : Time delta = 581.2 msec; mTime since last fault = 0.658 sec
Packet #311; SensorTime = 263.106sec; Delta = 581.2msec
=== Time Fault :: Time 263.750sec : Time delta = 643.8 msec; mTime since last fault = 0.631 sec
Packet #312; SensorTime = 263.750sec; Delta = 643.8msec
=== Time Fault :: Time 264.388sec : Time delta = 637.5 msec; mTime since last fault = 0.003 sec
Packet #313; SensorTime = 264.388sec; Delta = 637.5msec
使用BLE嗅探器跟踪数据包后,我们发现,在设备端,有一对错误的常量:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(400, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(650, UNIT_1_25_MS)
更正如下:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(10, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS)
更正连接速率后,我们的罚款就付清了。最奇怪的是,有些设备和手机可以全速工作,但其他设备和手机会掉入上述不正确的连接优先级。 谢谢您的帮助。嗅探器是这里的关键!