KableBleConnection

class KableBleConnection(scope: CoroutineScope, loggingConfig: BleLoggingConfig) : BleConnection(source)

BleConnection implementation using Kable for cross-platform BLE communication.

Manages peripheral lifecycle, connection state tracking, and GATT service profile access.

Connection attempts follow Kable's recommended pattern from the SensorTag sample: use a direct connect when a fresh advertisement is available, then fall back to autoConnect = true on failure. Advertisement-less devices start on the autoConnect path. At most two attempts are made per connect call — the caller (BleRadioTransport) owns the macro-level retry/backoff loop.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, loggingConfig: BleLoggingConfig)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val connectionState: StateFlow<BleConnectionState>

A flow of BleConnectionState changes. StateFlow semantics ensure the latest state is always observable and distinct-equals deduplication avoids spurious re-emissions.

Link copied to clipboard
open override val device: BleDevice?

The currently connected BleDevice, or null if not connected.

Link copied to clipboard
open override val deviceFlow: StateFlow<BleDevice?>

A flow of the current device. StateFlow semantics: replays the latest value to new collectors and conflates rapid updates.

Functions

Link copied to clipboard
open suspend override fun connect(device: BleDevice)

Connects to the given BleDevice.

Link copied to clipboard
open suspend override fun connectAndAwait(device: BleDevice, timeout: Duration): BleConnectionState

Connects to the given BleDevice and waits for a terminal state or timeout.

Link copied to clipboard
open suspend override fun disconnect()

Disconnects from the current device.

Link copied to clipboard
open override fun maximumWriteValueLength(writeType: BleWriteType): Int?

Returns the maximum write value length for the given write type, or null if unknown.

Link copied to clipboard
open suspend override fun <T> profile(serviceUuid: Uuid, timeout: Duration = 30.seconds, setup: suspend CoroutineScope.(BleService) -> T): T

Executes setup after the requested BLE profile is available. This is shared by radio, OTA, and DFU flows, so implementations should keep profile-entry setup bounded and avoid transfer-hot-path work here when a caller can reuse an already discovered BleService.

Link copied to clipboard

Requests the platform to return to balanced BLE connection priority (default ~30–50 ms interval). Call after latency-sensitive operations (initial config drain, DFU) to reduce ongoing battery draw. Default implementation returns false for platforms that don't support it.

Link copied to clipboard

Asks the platform to switch to a high-throughput / low-latency BLE connection priority for the duration of the connection. Used by latency-sensitive flows like firmware updates. Returns true if the request was issued. Default implementation returns false for platforms that don't support it.