Bluetooth: Mesh: Use bt_mesh_msg_ackd_send API in LCD Client

Use bt_mesh_msg_ackd_send API in LCD Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Pavel Vasilyev 2023-03-22 12:24:30 +01:00 committed by Carles Cufí
commit b99d4dbce2

View file

@ -18,6 +18,8 @@
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "msg.h"
#include <common/bt_str.h> #include <common/bt_str.h>
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
@ -115,35 +117,23 @@ const struct bt_mesh_model_cb _bt_mesh_large_comp_data_cli_cb = {
.init = large_comp_data_cli_init, .init = large_comp_data_cli_init,
}; };
static int cli_prepare(void *param, uint32_t op, uint16_t addr)
{
return bt_mesh_msg_ack_ctx_prepare(&cli.ack_ctx, op, addr, param);
}
int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page,
size_t offset, struct net_buf_simple *comp) size_t offset, struct net_buf_simple *comp)
{ {
BT_MESH_MODEL_BUF_DEFINE(msg, OP_LARGE_COMP_DATA_GET, 3); BT_MESH_MODEL_BUF_DEFINE(msg, OP_LARGE_COMP_DATA_GET, 3);
struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr);
int err; const struct bt_mesh_msg_rsp_ctx rsp = {
.ack = &cli.ack_ctx,
err = cli_prepare(comp, OP_LARGE_COMP_DATA_STATUS, addr); .op = OP_LARGE_COMP_DATA_STATUS,
if (err) { .user_data = comp,
return err; .timeout = msg_timeout,
} };
bt_mesh_model_msg_init(&msg, OP_LARGE_COMP_DATA_GET); bt_mesh_model_msg_init(&msg, OP_LARGE_COMP_DATA_GET);
net_buf_simple_add_u8(&msg, page); net_buf_simple_add_u8(&msg, page);
net_buf_simple_add_le16(&msg, offset); net_buf_simple_add_le16(&msg, offset);
err = bt_mesh_model_send(cli.model, &ctx, &msg, NULL, NULL); return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, comp ? &rsp : NULL);
if (err) {
LOG_ERR("model_send() failed (err %d)", err);
bt_mesh_msg_ack_ctx_clear(&cli.ack_ctx);
return err;
}
return bt_mesh_msg_ack_ctx_wait(&cli.ack_ctx, K_MSEC(msg_timeout));
} }
int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page, int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page,
@ -151,23 +141,16 @@ int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page,
{ {
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MODELS_METADATA_STATUS, 3); BT_MESH_MODEL_BUF_DEFINE(msg, OP_MODELS_METADATA_STATUS, 3);
struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr);
int err; const struct bt_mesh_msg_rsp_ctx rsp = {
.ack = &cli.ack_ctx,
err = cli_prepare(metadata, OP_MODELS_METADATA_STATUS, addr); .op = OP_MODELS_METADATA_STATUS,
if (err) { .user_data = metadata,
return err; .timeout = msg_timeout,
} };
bt_mesh_model_msg_init(&msg, OP_MODELS_METADATA_GET); bt_mesh_model_msg_init(&msg, OP_MODELS_METADATA_GET);
net_buf_simple_add_u8(&msg, page); net_buf_simple_add_u8(&msg, page);
net_buf_simple_add_le16(&msg, offset); net_buf_simple_add_le16(&msg, offset);
err = bt_mesh_model_send(cli.model, &ctx, &msg, NULL, NULL); return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, metadata ? &rsp : NULL);
if (err) {
LOG_ERR("model_send() failed (err %d)", err);
bt_mesh_msg_ack_ctx_clear(&cli.ack_ctx);
return err;
}
return bt_mesh_msg_ack_ctx_wait(&cli.ack_ctx, K_MSEC(msg_timeout));
} }