为什么onCharacteristicWrite回调中的status变成了GATT_INVALID_OFFSET?

Why does the status in onCharacteristicWrite callback becomes GATT_INVALID_OFFSET?

我正在 Android 中将一个字节数据数组写入 BLE 设备。在调用 mGatt.writeCharacteristic(characteristicToWrite); 之后调用 onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) 回调方法。如果写入操作成功,状态将是 0,即 GATT_SUCCESS = 0,而不是我收到状态 7,即 GATT_INVALID_OFFSET = 0x7。为什么会这样?有谁能够帮助我。在此先感谢同行。

因为外设运行GATT服务器写错了

我假设您有一个 "long" 值,这意味着一个大于一个 ATT 数据包的值。然后在以下情况下应该发回 Invalid Offset 错误:

If the prepare Value Offset is greater than the current length of the attribute value then all pending prepare write values shall be discarded for this client, the queue shall be cleared and then an Error Response shall be sent with the «Invalid Offset».

但是每当 Android 写入 Long 值时,它会将每个块的偏移量设置为先前块长度的累加和。

所以只要检查外围设备上发生了什么。