PeripheralSpecEventHandler

This is the interface of a peripheral event handler.

The implementation should respond to various events occurring on the mock peripheral, such as connection requests, read/write requests, etc.

For example, a mock Blinky device can handle requests to turn on an LED or send notifications when a button was clicked.

Each callback receives the MockPeripheral the event is for, so that the handler can simulate the behavior of the peripheral, e.g. call MockPeripheral.simulateDisconnection when it rejects a bonding request, without keeping a reference to the peripheral.

Functions

Link copied to clipboard
open fun onBondRequest(peripheral: MockPeripheral): BondResult

Called when a client requests bonding with the mock peripheral.

Link copied to clipboard
open fun onConnectionLost(peripheral: MockPeripheral, reason: DisconnectionReason)

Called when the connection is lost.

Link copied to clipboard

Called when a connection request is made to the mock peripheral.

Link copied to clipboard

Emulates an Execute Write request to the characteristic.

Link copied to clipboard
open fun onPrepareWriteRequest(peripheral: MockPeripheral, characteristic: MockRemoteCharacteristic, value: ByteArray): PrepareWriteResponse

Emulates a prepared write to a characteristic.

open fun onPrepareWriteRequest(peripheral: MockPeripheral, descriptor: MockRemoteDescriptor, value: ByteArray): PrepareWriteResponse

Emulates a prepared write to a characteristic descriptor.

Link copied to clipboard
open fun onReadRequest(peripheral: MockPeripheral, characteristic: MockRemoteCharacteristic): ReadResponse

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

open fun onReadRequest(peripheral: MockPeripheral, descriptor: MockRemoteDescriptor): ReadResponse

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

Link copied to clipboard
open fun onReset(peripheral: MockPeripheral)

Called when the peripheral is reset.

Link copied to clipboard

Called when a service discovery request is made to the mock peripheral.

Link copied to clipboard
open fun onWriteCommand(peripheral: MockPeripheral, characteristic: MockRemoteCharacteristic, value: ByteArray)

A callback called when the client sends a Write Command (write without response) to a characteristic.

Link copied to clipboard
open fun onWriteRequest(peripheral: MockPeripheral, characteristic: MockRemoteCharacteristic, value: ByteArray): WriteResponse

A callback called when the client sends a Write Request (write with response) to a characteristic.

open fun onWriteRequest(peripheral: MockPeripheral, descriptor: MockRemoteDescriptor, value: ByteArray): WriteResponse

A callback called when the client sends a Write Request (write with response) to a characteristic descriptor.