我一直在尝试使用 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} 枚举对应于{“请求存储的记录”,“所有记录”}。
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() 回调。例如。启用通知(measurementChar) -> onDescriptorWrite() ->启用通知(racpChar) -> onDescriptorWrite() -> requestRecords()
谁能帮我找出问题所在吗?我不相信这是设备的问题,因为我的 iOS 设备能够成功检索记录。我知道有些手机不能很好地支持 BLE,因此为了记录起见,我正在使用 Samsung Galaxy S5 进行测试。如前所述,它能够从 BLE 设备接收新记录,因此希望该错误与设备无关。
最佳答案
在配置 RACP 指示之前,您必须启用血糖测量和血糖测量上下文的通知。某些血糖仪仅允许启用 RACP 指示,但作为一般做法,您应在写入记录访问控制点之前启用 (2) 测量通知和 (1) RACP 指示。
关于android - 写入特征后 GATT 内部错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29608481/