onWriteRequest
A callback called when the client sends a Write Request (write with response) to a characteristic.
The maximum length of the value is guaranteed to be at most PeripheralSpec.mtu- 3 byte. 1 byte is consumed by the OpCode and 2 by the handle number.
For Long Write procedure and Reliable Write procedure, see onPrepareWriteRequest, which replies back the written value.
The response returned by this method will be delayed by one connection interval to emulate the time needed to send the response back to the client.
Read more in Bluetooth Code Specification 6.2, Vol 3 (Host), Part G (GATT), 4.9.3 Write 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 WriteResponse.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 write operation. This emulates a response received from the peripheral, and it will be delayed to the client by one connection interval.
Parameters
The peripheral the event is for. It can be used to simulate its behavior.
The characteristic to write to.
The value written to the characteristic.
See also
Throws
in case of a client error (reported without a delay).
A callback called when the client sends a Write Request (write with response) to a characteristic descriptor.
The maximum length of the value is guaranteed to be at most PeripheralSpec.mtu- 3 byte. 1 byte is consumed by the OpCode and 2 by the handle number.
For Long Write procedure and Reliable Write procedure, see onPrepareWriteRequest, which replies back the written value.
The response returned by this method will be delayed by one connection interval to emulate the time needed to send the response back to the client.
Read more in Bluetooth Code Specification 6.2, Vol 3 (Host), Part G (GATT), 4.9.3 Write Characteristic Value: link.
Client Characteristic Configuration descriptor
This method is also called when the client enables or disables notifications or indications by writing to the Client Characteristic Configuration descriptor (CCCD). The state of the CCCD is updated by the mock implementation only when WriteResponse.Success is returned. Return WriteResponse.Failure to reject the request, e.g. with OperationStatus.InsufficientAuthentication. Mind, that returning an error for unknown descriptors will also reject writes to the CCCD.
This method is called before the Write Response is sent to the client, so notifications sent from here using PeripheralSpec.simulateValueUpdate may be received by the client before the response.
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 WriteResponse.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 write operation. This emulates a response received from the peripheral, and it will be delayed to the client by one connection interval.
Parameters
The peripheral the event is for. It can be used to simulate its behavior.
The characteristic descriptor to write to.
The value written to the characteristic descriptor.
Throws
in case of a client error (reported without a delay).