这是最新(主)开发分支的文档。如果您正在查找以前版本的文档,使用左侧的下拉菜单选择所需的版本。

BLOB 传输服务器

二进制型大对象(BLOB)传输服务器模型实现了大型二进制对象的可靠接收。它用作 固件更新服务器 的后端,但也可以用于接收其他二进制图像。

BLOBs

BLOB 传输模型 中所述,由 BLOB 传输模型传输的二进制对象被划分为块,块被划分为区块。由于传输由 BLOB 传输客户端模型控制,BLOB transfer Server 必须允许块以任何顺序出现。 块中的块也可以以任何顺序出现,但在启动下一个块之前,必须接收块中的所有块。

BLOB 传输服务器跟踪接收的块和区块,并且只处理每个块和区块一次。BLOB 传输服务器还确保 BLOB Transfer Client 重新发送任何丢失的块。

使用

BLOB 传输服务器在具有一组事件处理程序回调的元素上实例化:

static const struct bt_mesh_blob_srv_cb blob_cb = {
    /* Callbacks */
};

static struct bt_mesh_blob_srv blob_srv = {
    .cb = &blob_cb,
};

static const struct bt_mesh_model models[] = {
    BT_MESH_MODEL_BLOB_SRV(&blob_srv),
};

BLOB 传输服务器能够一次接收单个 BLOB 传送。在 BLOB 传输服务器可以接收传输之前,它必须由用户准备。 在 BLOB 传输客户端启动传输之前,必须通过 bt_mesh_BLOB_srv_recv()() 函数将传输 ID 传递给 BLOB transfer Server。 必须通过一些更高级别的过程(如特定于供应商的传输管理模型)在 BLOB 传输客户端和 BLOB 转移服务器之间共享 ID。

一旦在 BLOB 传输服务器上设置了传输,就可以接收 BLOB 了。通过事件处理程序回调将传输进度通知应用程序,并将 BLOB 数据发送到 BLOB 流。

BLOB 传输服务器、BLOB 流和应用程序之间的交互如下所示:

BLOB Transfer Server model interaction

BLOB 传输服务器模型交互

转移暂停

BLOB 传输服务器在传输期间保持一个运行计时器,该计时器在每个接收到的消息上重置。如果 BLOB 传输客户端在传输计时器到期之前未发送消息,则传输将被 BLOB Transfer Server 挂起。

BLOB 传输服务器通过调用 suspended 回调来通知用户暂停。如果 BLOB 传输服务器正在接收块,则丢弃该块。

BLOB 传输客户端可以通过启动新的块传输来恢复暂停的传输。BLOB 传输服务器通过调用 resume 回调来通知用户。

传输恢复

BLOB 传输的状态被持久存储。如果发生重新启动,BLOB 传输服务器将尝试恢复传输。 启动 Bluetooth Mesh 子系统时(例如,通过调用 bt_Mesh_init() ),BLOB 传输服务器将检查中止的传输, 并调用 recover 回调(如果存在)。在恢复回调中, 用户必须提供用于其余传输的 BLOB 流。如果恢复回调未成功返回或未提供 BLOB 流,则放弃传输。 如果未实现恢复回调,则在重新启动后总是放弃传输。

成功恢复传输后,BLOB 传输服务器进入挂起状态。它将保持挂起状态,直到 BLOB 传输客户端恢复传输或用户取消传输。

备注

发送传输的 BLOB 传输客户端必须支持传输恢复,才能完成传输。如果 BLOB 传输客户端已经放弃传输,则 BLOB Transfer Server 将保持挂起状态,直到应用程序调用 bt_mesh_BLOB_srv_cancel()

API 参考

group bt_mesh_blob_srv

Defines

BT_MESH_BLOB_BLOCKS_MAX

Max number of blocks in a single transfer.

BT_MESH_MODEL_BLOB_SRV(_srv)

BLOB Transfer Server model composition data entry.

参数:

Functions

int bt_mesh_blob_srv_recv(struct bt_mesh_blob_srv *srv, uint64_t id, const struct bt_mesh_blob_io *io, uint8_t ttl, uint16_t timeout_base)

Prepare BLOB Transfer Server for an incoming transfer.

Before a BLOB Transfer Server can receive a transfer, the transfer must be prepared through some application level mechanism. The BLOB Transfer Server will only accept incoming transfers with a matching BLOB ID.

参数:
  • srv – BLOB Transfer Server instance.

  • id – BLOB ID to accept.

  • io – BLOB stream to write the incoming BLOB to.

  • ttl – Time to live value to use in responses to the BLOB Transfer Client.

  • timeout_base – Extra time for the Client to respond in addition to the base 10 seconds, in 10-second increments.

返回:

0 on success, or (negative) error code on failure.

int bt_mesh_blob_srv_cancel(struct bt_mesh_blob_srv *srv)

Cancel the current BLOB transfer.

Tells the BLOB Transfer Client to drop this device from the list of Targets for the current transfer. Note that the client may continue sending the transfer to other Targets.

参数:

srv – BLOB Transfer Server instance.

返回:

0 on success, or (negative) error code on failure.

bool bt_mesh_blob_srv_is_busy(const struct bt_mesh_blob_srv *srv)

Get the current state of the BLOB Transfer Server.

参数:

srv – BLOB Transfer Server instance.

返回:

true if the BLOB Transfer Server is currently participating in a transfer, false otherwise.

uint8_t bt_mesh_blob_srv_progress(const struct bt_mesh_blob_srv *srv)

Get the current progress of the active transfer in percent.

参数:

srv – BLOB Transfer Server instance.

返回:

The current transfer progress, or 0 if no transfer is active.

struct bt_mesh_blob_srv_cb

BLOB Transfer Server model event handlers.

All callbacks are optional.

Public Members

int (*start)(struct bt_mesh_blob_srv *srv, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_blob_xfer *xfer)

Transfer start callback.

Called when the transfer has started with the prepared BLOB ID.

Param srv:

BLOB Transfer Server instance.

Param ctx:

Message context for the incoming start message. The entire transfer will be sent from the same source address.

Param xfer:

Transfer parameters.

Return:

0 on success, or (negative) error code to reject the transfer.

void (*end)(struct bt_mesh_blob_srv *srv, uint64_t id, bool success)

Transfer end callback.

Called when the transfer ends, either because it was cancelled, or because it finished successfully. A new transfer may be prepared.

备注

The transfer may end before it’s started if the start parameters are invalid.

Param srv:

BLOB Transfer Server instance.

Param id:

BLOB ID of the cancelled transfer.

Param success:

Whether the transfer was successful.

void (*suspended)(struct bt_mesh_blob_srv *srv)

Transfer suspended callback.

Called if the Server timed out while waiting for a transfer packet. A suspended transfer may resume later from the start of the current block. Any received chunks in the current block should be discarded, they will be received again if the transfer resumes.

The transfer will call resumed again when resuming.

备注

The BLOB Transfer Server does not run a timer in the suspended state, and it’s up to the application to determine whether the transfer should be permanently cancelled. Without interaction, the transfer will be suspended indefinitely, and the BLOB Transfer Server will not accept any new transfers.

Param srv:

BLOB Transfer Server instance.

void (*resume)(struct bt_mesh_blob_srv *srv)

Transfer resume callback.

Called if the transfer is resumed after being suspended.

Param srv:

BLOB Transfer Server instance.

int (*recover)(struct bt_mesh_blob_srv *srv, struct bt_mesh_blob_xfer *xfer, const struct bt_mesh_blob_io **io)

Transfer recovery callback.

Called when the Bluetooth mesh subsystem is started if the device is rebooted in the middle of a transfer.

Transfers will not be resumed after a reboot if this callback is not defined.

Param srv:

BLOB Transfer Server instance.

Param xfer:

Transfer to resume.

Param io:

BLOB stream return parameter. Must be set to a valid BLOB stream by the callback.

Return:

0 on success, or (negative) error code to abandon the transfer.

struct bt_mesh_blob_srv

BLOB Transfer Server instance.

Public Members

const struct bt_mesh_blob_srv_cb *cb

Event handler callbacks.

struct bt_mesh_blob_srv_state