FakeDfuTransport

class FakeDfuTransport(val mtu: Int = 20) : DfuTransport

In-memory DfuTransport for testing DFU flows without BLE hardware.

Queue responses with enqueueResponse before the code-under-test calls sendCommand. After the DFU completes, inspect getCommandLog and getDataLog to verify the commands and data packets that were sent.

Usage

val transport = FakeDfuTransport(mtu = 64)
// Queue the expected DFU responses...
transport.enqueueResponse(selectResponse)
transport.enqueueResponse(createResponse)
// ...then run the protocol under test

Parameters

mtu

simulated maximum write payload size

Constructors

Link copied to clipboard
constructor(mtu: Int = 20)

Properties

Link copied to clipboard
open override val mtu: Int
Link copied to clipboard
open override val notifications: Flow<ByteArray>

Incoming notifications from the DFU Control Point characteristic.

Functions

Link copied to clipboard
suspend fun clearLogs()

Clear both command and data logs.

Link copied to clipboard
open override fun close()

Release transport resources synchronously.

Link copied to clipboard
suspend fun emitNotification(data: ByteArray)

Emit a notification as if it came from the DFU Control Point characteristic.

Link copied to clipboard
suspend fun enqueueResponse(response: ByteArray)

Queue a response that will be returned by the next sendCommand call.

Link copied to clipboard
suspend fun getCommandLog(): List<ByteArray>

Snapshot of all commands sent via sendCommand, in order.

Link copied to clipboard
suspend fun getDataLog(): List<ByteArray>

Snapshot of all data packets sent via sendData, in order.

Link copied to clipboard
open suspend override fun sendCommand(data: ByteArray): ByteArray

Write a command to the DFU Control Point and wait for the response notification.

Link copied to clipboard
open suspend override fun sendData(data: ByteArray)

Write firmware data to the peripheral.