transferFirmware

open suspend override fun transferFirmware(firmware: ByteArray, onProgress: suspend (Float) -> Unit): Result<Unit>(source)

Drives the full upload sequence (START, init-packet brackets, PRN setup, firmware stream, validate, activate).

Sequence details:

  1. START_DFU [0x04] (APP image only).

  2. Image sizes payload on Packet char: [0u32, 0u32, firmware.size_u32].

  3. Await START response.

  4. INIT_PARAMS_START, init bytes on Packet, INIT_PARAMS_COMPLETE. Await init response.

  5. PRN_REQ [PRN_LE16]. (No response.)

  6. RECEIVE_FIRMWARE_IMAGE. (No response.)

  7. Stream firmware in MTU-sized chunks. Every PRN packets, await PacketReceipt(bytesReceived) and verify count.

  8. After last byte, await final response for RECEIVE_FIRMWARE_IMAGE.

  9. VALIDATE, await response.

  10. ACTIVATE_AND_RESET — an ordinary disconnect/write Exception may occur because the device resets before the acknowledgement; treat that operational Exception as expected success (structured cancellation and Error subtypes still propagate).


open suspend override fun transferFirmware(firmware: ByteArray, onPhase: suspend (DfuUploadPhase) -> Unit, onProgress: suspend (Float) -> Unit): Result<Unit>(source)

As transferFirmware, additionally reporting coarse DfuUploadPhase transitions so the UI can explain a wait that produces no progress (Legacy DFU erases the whole application region before it accepts a single byte). Transports without a meaningful prepare step keep the default, which never reports a phase.