【发布时间】:2015-06-18 22:47:41
【问题描述】:
我一直在尝试使用Glucose service 从 BLE 设备读取葡萄糖测量记录。我能够成功连接到设备并在获取新记录时读取它们,但是当我请求以前记录的列表时,我收到状态为 129 的回调(“GATT_INTERNAL_ERROR”)。之后没有其他回调发生,最终传输超时。
据我了解,要检索记录,我需要向Record Access Control Point characteristic 发送请求。收到请求后,设备应通过吐出请求的记录来响应。
我的请求代码如下:
private void requestRecords() {
byte[] requestValue = new byte[] {0x01, 0x01};
racpCharacteristic.setValue(requestValue);
bluetoothGatt.writeCharacteristic(racpCharacteristic);
}
其中 {0x01, 0x01} 枚举对应于 {"Request stored records", "All records"}。
setValue() 和 writeCharacteristic() 操作都返回 true,表示成功。然后,我的 BluetoothGattCallback 会收到 RACP 特性的 onCharacteristicWrite() 回调。但是,回调返回的状态是 129(内部错误)而不是预期的 0(成功)。
我认为我还需要启用 RACP 特性的指示(和/或测量特性的通知)才能接收记录。但是启用过程似乎可以正常工作,并且无论我使用哪种通知/指示组合(如果有),我都会收到相同的错误。所以我不认为错误是相关的,但为了完整起见,这里是通知/指示代码,它在记录请求代码之前运行:
private static final String DESCRIPTOR_UUID = "00002902-0000-1000-8000-00805f9b34fb";
...
private void enableNotifications(BluetoothGattCharacteristic char) {
bluetoothGatt.setCharacteristicNotification(char, true);
UUID uuid = UUID.fromString(DESCRIPTOR_UUID);
BluetoothGattDescriptor descriptor = char.getDescriptor(uuid);
boolean usesIndications = characteristicUsesIndications(char);
descriptor.setValue(usesIndications ?
BluetoothGattDescriptor.ENABLE_INDICATION_VALUE :
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothGatt.writeDescriptor(descriptor);
}
我确保在执行后续操作之前等待相应的 onDescriptorWrite() 回调。例如。 enableNotifications(measurementChar) -> onDescriptorWrite() -> enableNotifications(racpChar) -> onDescriptorWrite() -> requestRecords()
谁能帮我弄清楚出了什么问题?我不相信这是设备,因为我的 iOS 对应方能够成功检索记录。我知道有些手机不能很好地与 BLE 配合使用,所以为了记录,我正在使用三星 Galaxy S5 进行测试。如前所述,它能够从 BLE 设备接收新记录,因此希望该错误与设备无关。
【问题讨论】:
标签: android bluetooth-lowenergy android-bluetooth