|
18 | 18 | #include <zephyr/bluetooth/conn.h> |
19 | 19 | #include <zephyr/bluetooth/mesh.h> |
20 | 20 |
|
| 21 | +#include "msg.h" |
| 22 | + |
21 | 23 | #include <common/bt_str.h> |
22 | 24 |
|
23 | 25 | #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL |
@@ -115,59 +117,40 @@ const struct bt_mesh_model_cb _bt_mesh_large_comp_data_cli_cb = { |
115 | 117 | .init = large_comp_data_cli_init, |
116 | 118 | }; |
117 | 119 |
|
118 | | -static int cli_prepare(void *param, uint32_t op, uint16_t addr) |
119 | | -{ |
120 | | - return bt_mesh_msg_ack_ctx_prepare(&cli.ack_ctx, op, addr, param); |
121 | | -} |
122 | | - |
123 | 120 | int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, |
124 | 121 | size_t offset, struct net_buf_simple *comp) |
125 | 122 | { |
126 | 123 | BT_MESH_MODEL_BUF_DEFINE(msg, OP_LARGE_COMP_DATA_GET, 3); |
127 | 124 | struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); |
128 | | - int err; |
129 | | - |
130 | | - err = cli_prepare(comp, OP_LARGE_COMP_DATA_STATUS, addr); |
131 | | - if (err) { |
132 | | - return err; |
133 | | - } |
| 125 | + const struct bt_mesh_msg_rsp_ctx rsp = { |
| 126 | + .ack = &cli.ack_ctx, |
| 127 | + .op = OP_LARGE_COMP_DATA_STATUS, |
| 128 | + .user_data = comp, |
| 129 | + .timeout = msg_timeout, |
| 130 | + }; |
134 | 131 |
|
135 | 132 | bt_mesh_model_msg_init(&msg, OP_LARGE_COMP_DATA_GET); |
136 | 133 | net_buf_simple_add_u8(&msg, page); |
137 | 134 | net_buf_simple_add_le16(&msg, offset); |
138 | 135 |
|
139 | | - err = bt_mesh_model_send(cli.model, &ctx, &msg, NULL, NULL); |
140 | | - if (err) { |
141 | | - LOG_ERR("model_send() failed (err %d)", err); |
142 | | - bt_mesh_msg_ack_ctx_clear(&cli.ack_ctx); |
143 | | - return err; |
144 | | - } |
145 | | - |
146 | | - return bt_mesh_msg_ack_ctx_wait(&cli.ack_ctx, K_MSEC(msg_timeout)); |
| 136 | + return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, comp ? &rsp : NULL); |
147 | 137 | } |
148 | 138 |
|
149 | 139 | int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page, |
150 | 140 | size_t offset, struct net_buf_simple *metadata) |
151 | 141 | { |
152 | 142 | BT_MESH_MODEL_BUF_DEFINE(msg, OP_MODELS_METADATA_STATUS, 3); |
153 | 143 | struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); |
154 | | - int err; |
155 | | - |
156 | | - err = cli_prepare(metadata, OP_MODELS_METADATA_STATUS, addr); |
157 | | - if (err) { |
158 | | - return err; |
159 | | - } |
| 144 | + const struct bt_mesh_msg_rsp_ctx rsp = { |
| 145 | + .ack = &cli.ack_ctx, |
| 146 | + .op = OP_MODELS_METADATA_STATUS, |
| 147 | + .user_data = metadata, |
| 148 | + .timeout = msg_timeout, |
| 149 | + }; |
160 | 150 |
|
161 | 151 | bt_mesh_model_msg_init(&msg, OP_MODELS_METADATA_GET); |
162 | 152 | net_buf_simple_add_u8(&msg, page); |
163 | 153 | net_buf_simple_add_le16(&msg, offset); |
164 | 154 |
|
165 | | - err = bt_mesh_model_send(cli.model, &ctx, &msg, NULL, NULL); |
166 | | - if (err) { |
167 | | - LOG_ERR("model_send() failed (err %d)", err); |
168 | | - bt_mesh_msg_ack_ctx_clear(&cli.ack_ctx); |
169 | | - return err; |
170 | | - } |
171 | | - |
172 | | - return bt_mesh_msg_ack_ctx_wait(&cli.ack_ctx, K_MSEC(msg_timeout)); |
| 155 | + return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, metadata ? &rsp : NULL); |
173 | 156 | } |
0 commit comments