FsManagerKtx

class FsManagerKtx(val manager: FsManager)

A manager of the File System group of Mcu Manager, with suspending methods and flows. It wraps FsManager.

Every suspending method waits until the response is received, and throws a McuMgrException if the request fails, or a McuMgrErrorException if the device responds with an error, that is with a non-zero return code. Cancelling the calling coroutine stops waiting for the response, but does not cancel the request, which has already been sent.

The upload and the download of a file are long-running, and report their state using a Flow. See TransferState.

Use the manager to set a logger, the upload MTU, etc.

Constructors

Link copied to clipboard
constructor(manager: FsManager)
constructor(transport: McuMgrTransport)

Creates the manager using the given transport.

Properties

Link copied to clipboard

The manager of the Mcu Manager library, which sends the requests.

Functions

Link copied to clipboard
suspend fun closeAll(): McuMgrResponse

Closes all the files opened by the manager on the device.

Link copied to clipboard
suspend fun crc32(name: String): McuMgrFsCrc32Response

Calculates the CRC32 of a file.

suspend fun crc32(name: String, offset: Int, length: Int): McuMgrFsCrc32Response

Calculates the CRC32 of a part of a file.

Link copied to clipboard

Downloads a file from the device.

fun download(name: String, output: OutputStream): Flow<TransferState<Unit>>

Downloads a file from the device, writing it to the given stream.

Link copied to clipboard
suspend fun downloadChunk(name: String, offset: Int): McuMgrFsDownloadResponse

Reads a single packet of a file, starting from the given offset.

Link copied to clipboard

Calculates the SHA-256 of a file.

suspend fun sha256(name: String, offset: Int, length: Int): McuMgrFsSha256Response

Calculates the SHA-256 of a part of a file.

Link copied to clipboard

Reads the status of a file, such as its size.

Link copied to clipboard
fun upload(name: String, data: InputStream, totalBytes: Int): Flow<TransferState<Unit>>

Uploads a file to the device, reading it from the given stream.

fun upload(name: String, data: ByteArray, windowCapacity: Int = 1, memoryAlignment: Int = 1): Flow<TransferState<Unit>>

Uploads a file to the device.

Link copied to clipboard
suspend fun uploadChunk(name: String, data: ByteArray, offset: Int): McuMgrFsUploadResponse

Sends a single packet of a file, starting from the given offset.