McuMgrBleTransport

class McuMgrBleTransport @JvmOverloads constructor(centralManager: CentralManager, peripheral: Peripheral, scope: CoroutineScope, uuidConfig: UuidConfig = DefaultMcuMgrUuidConfig) : McuMgrTransport

An implementation of McuMgrTransport for the BLE scheme, built on the Kotlin BLE Library.

The transport owns the connection: it connects the device on the first request, attaches SmpProfile to it, and disconnects on release.

An application that manages the same Peripheral for other purposes can keep doing so - the profiles of the Kotlin BLE Library are independent of each other, so it may attach its own alongside this one. It cannot, however, hand the SMP service to this transport: switching a device to the Firmware Loader makes it advertise under a different address, which the transport has to find and connect itself, so the connection has to be its own.

Example

val peripheral = centralManager.getPeripheralById(address)!!
val transport = McuMgrBleTransport(centralManager, peripheral, scope)
val manager = DefaultManager(transport)

Parameters

centralManager

The central manager used to connect to the device.

peripheral

The peripheral to connect to and communicate with.

scope

The coroutine scope the connection and the requests run in.

Constructors

Link copied to clipboard
constructor(centralManager: CentralManager, peripheral: Peripheral, scope: CoroutineScope, uuidConfig: UuidConfig = DefaultMcuMgrUuidConfig)

Types

Link copied to clipboard
sealed interface State

The state of the transport.

Properties

Link copied to clipboard

The maximum length of an SMP packet the device can accept, or null when the transport is Disconnected.

Link copied to clipboard
val peripheral: Peripheral

The device this transport is talking to.

Link copied to clipboard
open override val scheme: McuMgrScheme
Link copied to clipboard

The current state of the transport.

Functions

Link copied to clipboard
open override fun addObserver(observer: McuMgrTransport.ConnectionObserver)
Link copied to clipboard
open override fun changeMode(name: String, callback: McuMgrTransport.ModeChangeCallback?): Boolean
Link copied to clipboard
suspend fun connect()

Connects the device and awaits the connection to be ready.

open override fun connect(callback: McuMgrTransport.ConnectionCallback?)
Link copied to clipboard
open override fun getScheme(): McuMgrScheme
Link copied to clipboard
open override fun release()
Link copied to clipboard
Link copied to clipboard
fun requestConnectionPriority(priority: ConnectionPriority = ConnectionPriority.HIGH)

Requests a connection priority, which is used to speed up a transfer.

Link copied to clipboard
open override fun <T : McuMgrResponse> send(payload: ByteArray, timeout: Long, responseType: Class<T>): T
open override fun <T : McuMgrResponse> send(payload: ByteArray, timeout: Long, responseType: Class<T>, callback: McuMgrCallback<T>)
Link copied to clipboard
fun setLogger(logger: Log.Sink<Category>?)

Sets the sink receiving the log entries emitted by this transport and the SMP service attached to the device.