GattServerAPI

interface GattServerAPI

Interface around native Android API. For real BLE connections it uses BluetoothGattServer, whereas for mock device it utilizes MockEngine.

Properties

Link copied to clipboard
abstract val event: SharedFlow<ServerGattEvent>

Flow which emits BLE events. For real BLE connections it collects events from BluetoothGattServerCallback under the hood, for mock device it gets events from MockEngine.

Functions

Link copied to clipboard
abstract fun cancelConnection(device: ClientDevice)

Disconnects an established connection, or cancels a connection attempt currently in progress.

Link copied to clipboard
abstract fun close()

Close this GATT server instance.

Link copied to clipboard
abstract fun connect(device: ClientDevice, autoConnect: Boolean)

Initiate a connection to a Bluetooth GATT capable device.

Link copied to clipboard
abstract fun notifyCharacteristicChanged(device: ClientDevice, characteristic: IBluetoothGattCharacteristic, confirm: Boolean, value: DataByteArray)

Send a notification or indication that a local characteristic has been updated.

Link copied to clipboard
abstract fun onEvent(event: ServerGattEvent)

Internal function for propagating events to event shared flow. For internal usage only.

Link copied to clipboard
abstract fun readPhy(device: ClientDevice)

Reads the current transmitter PHY and receiver PHY of the connection.

Link copied to clipboard
abstract fun requestPhy(device: ClientDevice, txPhy: BleGattPhy, rxPhy: BleGattPhy, phyOption: PhyOption)

Set the preferred connection PHY for this app. Please note that this is just a recommendation, whether the PHY change will happen depends on other applications preferences, local and remote controller capabilities. Controller can override these settings.

Link copied to clipboard
abstract fun sendResponse(device: ClientDevice, requestId: Int, status: Int, offset: Int, value: DataByteArray?)

Send a response to a read or write request to a remote device.