我一直在尝试使用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特征的指示(和/或Measurement特征的通知)以接收记录。但是启用过程似乎正常工作,并且无论我使用哪种通知/指示组合(如果有),我都会收到相同的错误。所以我不认为该错误与之相关,但是为了完整起见,这里是通知/指示代码,它在记录请求代码之前运行:

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设备接收新记录,因此希望该错误与设备无关。

最佳答案

您必须先为“葡萄糖测量”和“葡萄糖测量上下文”启用通知,然后再为指示配置RACP。某些血糖仪仅允许启用RACP指示,但作为一般惯例,您应在写入记录访问控制点之前启用(2)测量通知和(1)RACP指示。

10-06 07:15