PeripheralSpec

A specification of a peripheral that can be simulated.

Use PeripheralSpec.simulatePeripheral to create a new peripheral specification.

Parameters

identifier

The peripheral identifier.

addressType

The address type of the peripheral.

initialProximity

The initial proximity of the peripheral.

activePhy

The PHYs (TX and RX) used by the connection the peripheral is initially connected with, or null if the peripheral is not initially connected.

isKnown

Whether the peripheral has been scanned before and its address type is cached. It is not possible to connect to an unknown device without scanning.

isBonded

Whether the phone has the bond information of the peripheral.

peripheralHasBond

Whether the peripheral has the bond information of the phone.

advertisingSets

List of advertisement configurations.

eventHandler

The event handler that will be called for every event emulating a real peripheral.

services

The services available after service discovery.

cachedServices

The services cached on the client side.

isServiceCacheValid

Whether the cached services are valid.

Types

Link copied to clipboard
class Builder<ID : Any>

The builder for the PeripheralSpec.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The address type of the peripheral.

Link copied to clipboard

The appearance of the peripheral, exposed with Appearance characteristic. See Bluetooth Assigned Numbers: link, 2.6 Appearance Values.

Link copied to clipboard
val bondState: StateFlow<MockBondState>

The bond state of the peripheral, as seen by the phone.

Link copied to clipboard

Current connection parameters.

Link copied to clipboard

The encryption of the link with the phone.

Link copied to clipboard
val events: SharedFlow<GattEvent>

A flow of GATT events emitted by the peripheral.

Link copied to clipboard

The peripheral identifier.

Link copied to clipboard
open override val isBonded: Boolean

Whether the phone has the bond information of the peripheral.

Link copied to clipboard
open override val isConnected: Boolean

Whether the peripheral is connected.

Link copied to clipboard

Whether the peripheral has been scanned before and its address type is cached.

Link copied to clipboard
var llMtu: Int?

Current Link Layer MTU.

Link copied to clipboard

The maximum supported ATT MTU (ATT layer Maximum Transfer Unit).

Link copied to clipboard

The maximum Link Layer MTU (Maximum Transfer Unit used on Link Layer using Data Length Extension (DLE)).

Link copied to clipboard
var mtu: Int?

Current ATT MTU.

Link copied to clipboard
val name: String?

The name of the peripheral, exposed with Device Name characteristic.

Link copied to clipboard

Whether the peripheral has the bond information of the phone.

Link copied to clipboard

The PHYs currently used by the connection: TX is the PHY used by the central to transmit, and RX is the PHY used to receive. They may differ.

Link copied to clipboard

The preferred connection interval range.

Link copied to clipboard

The preferred slave latency.

Link copied to clipboard

The preferred supervision timeout.

Link copied to clipboard

The proximity of the peripheral.

Link copied to clipboard

The set of supported PHYs.

Link copied to clipboard

The peripheral type.

Functions

Link copied to clipboard

Simulates the central removing the bond information associated with the peripheral.

Link copied to clipboard
open override fun simulateBondRequest()

Simulates bonding of the phone and the peripheral.

Link copied to clipboard

Simulates the situation when the device is scanned and advertisement data is received.

Link copied to clipboard
fun simulateConnection(phy: PrimaryPhy = PrimaryPhy.PHY_LE_1M, mtu: Int = maxAttMtu ?: ATT_MTU_DEFAULT)

Simulates the situation when another application on the device tries to connect to the device.

Link copied to clipboard

Simulates a connection parameters update request from the peripheral.

Link copied to clipboard
open override fun simulateDisconnection()

Simulates a situation when the peripheral is gracefully disconnecting from the device.

Link copied to clipboard
fun simulateMacChange(newIdentifier: ID, addressType: AddressType)

Simulates a change of the peripheral identifier (Device Address).

Link copied to clipboard
open override fun simulateMtuRequest(mtu: Int)

Simulates an MTU request from the peripheral.

Link copied to clipboard
open override fun simulatePeripheralBondLoss()

Simulates the peripheral forgetting the bond information, for example after a factory reset.

Link copied to clipboard

Simulates a change in the proximity of the peripheral.

Link copied to clipboard
open override fun simulateReset()

Simulates peripheral reset.

Link copied to clipboard
open override fun simulateServiceChange(newServices: MockServerScope.() -> Unit)

Simulates a change in the services offered by the peripheral.

Link copied to clipboard
open override fun simulateValueUpdate(handle: Int, value: ByteArray)

Simulates a characteristic value update on the peripheral.