onReadRequest

open fun onReadRequest(characteristic: MockRemoteCharacteristic): ReadResponse

A callback called when the client sends Read request to a characteristic.

This method should return the value to be sent to the client. The value will be truncated to 512 bytes, which is the maximum length of a GATT attribute value.

The returned response will be delayed by one or more connection interval to emulate the time needed to send the response back to the client.

Note, that this callback is invoked for both Read Characteristic Value procedure and Read Long Characteristic Value procedure. Instead of returning each blob separately, the implementation should return the full value.

See Bluetooth Code Specification 6.2, Vol 3 (Host), Part G (GATT), 4.8.1 Read Characteristic Value: link.

Exceptions

Exceptions thrown by this method are rethrown immediately, without the simulated transfer time, emulating a failure on the client side (e.g. OperationFailedException, or SecurityException).

Simulated error on the peripheral side should be reported by returning ReadResponse.Failure, which is delayed by one connection interval to emulate the time needed to send the error response.

Any exception other than OperationFailedException will be wrapped into BluetoothException.

Return

The response of the read operation. This emulates a response received from the peripheral, and it will be delayed to the client by one or more connection interval.

Parameters

characteristic

The characteristic that was read.

Throws

in case of a client error (reported without a delay).


open fun onReadRequest(descriptor: MockRemoteDescriptor): ReadResponse

A callback called when the client sends Read request to a characteristic descriptor.

This method should return the value to be sent to the client. The value will be truncated to 512 bytes, which is the maximum length of a GATT attribute value.

The returned response will be delayed by one or more connection interval to emulate the time needed to send the response back to the client.

Note, that this callback is invoked for both Read Characteristic Descriptor procedure and Read Long Characteristic Descriptor procedure. Instead of returning each blob separately, the implementation should return the full value.

See Bluetooth Code Specification 6.2, Vol 3 (Host), Part G (GATT), 4.12.1 Read Characteristic Descriptor: link.

Exceptions

Exceptions thrown by this method are rethrown immediately, without the simulated transfer time, emulating a failure on the client side (e.g. OperationFailedException, or SecurityException).

Simulated error on the peripheral side should be reported by returning ReadResponse.Failure, which is delayed by one connection interval to emulate the time needed to send the error response.

Any exception other than OperationFailedException will be wrapped into BluetoothException.

Return

The response of the read operation. This emulates a response received from the peripheral, and it will be delayed to the client by one or more connection interval.

Parameters

descriptor

The characteristic descriptor that was read.

Throws

in case of a client error (reported without a delay).