Bluetooth: Mesh: Common comp page parse func
Create common composition page parser function. Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
This commit is contained in:
parent
2e3ae017e3
commit
65f029e185
4 changed files with 30 additions and 42 deletions
|
@ -2562,3 +2562,30 @@ void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod)
|
||||||
mod->flags |= BT_MESH_MOD_DATA_PENDING;
|
mod->flags |= BT_MESH_MOD_DATA_PENDING;
|
||||||
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING);
|
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf)
|
||||||
|
{
|
||||||
|
uint8_t page = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
|
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
|
||||||
|
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
||||||
|
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
||||||
|
page = 130U;
|
||||||
|
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
|
||||||
|
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
||||||
|
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
||||||
|
page = 129U;
|
||||||
|
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
||||||
|
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
||||||
|
page = 128U;
|
||||||
|
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
|
||||||
|
page = 2U;
|
||||||
|
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
|
||||||
|
page = 1U;
|
||||||
|
} else if (page != 0U) {
|
||||||
|
LOG_DBG("Composition page %u not available", page);
|
||||||
|
page = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||||
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
|
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
|
||||||
int bt_mesh_comp_store(void);
|
int bt_mesh_comp_store(void);
|
||||||
int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page);
|
int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page);
|
||||||
|
uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf);
|
||||||
|
|
||||||
int bt_mesh_models_metadata_store(void);
|
int bt_mesh_models_metadata_store(void);
|
||||||
int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset);
|
int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset);
|
||||||
|
|
|
@ -59,27 +59,7 @@ static int dev_comp_data_get(struct bt_mesh_model *model,
|
||||||
LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx,
|
LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx,
|
||||||
ctx->addr, buf->len, bt_hex(buf->data, buf->len));
|
ctx->addr, buf->len, bt_hex(buf->data, buf->len));
|
||||||
|
|
||||||
page = net_buf_simple_pull_u8(buf);
|
page = bt_mesh_comp_parse_page(buf);
|
||||||
|
|
||||||
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
|
|
||||||
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 130U;
|
|
||||||
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
|
|
||||||
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 129U;
|
|
||||||
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 128U;
|
|
||||||
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
|
|
||||||
page = 2U;
|
|
||||||
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
|
|
||||||
page = 1U;
|
|
||||||
} else if (page != 0U) {
|
|
||||||
LOG_DBG("Composition page %u not available", page);
|
|
||||||
page = 0U;
|
|
||||||
}
|
|
||||||
LOG_DBG("Preparing Composition data page %d", page);
|
LOG_DBG("Preparing Composition data page %d", page);
|
||||||
|
|
||||||
bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS);
|
bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS);
|
||||||
|
|
|
@ -53,32 +53,12 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes
|
||||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||||
bt_hex(buf->data, buf->len));
|
bt_hex(buf->data, buf->len));
|
||||||
|
|
||||||
page = net_buf_simple_pull_u8(buf);
|
page = bt_mesh_comp_parse_page(buf);
|
||||||
offset = net_buf_simple_pull_le16(buf);
|
offset = net_buf_simple_pull_le16(buf);
|
||||||
|
|
||||||
LOG_DBG("page %u offset %u", page, offset);
|
LOG_DBG("page %u offset %u", page, offset);
|
||||||
|
|
||||||
bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS);
|
bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS);
|
||||||
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
|
|
||||||
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 130U;
|
|
||||||
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
|
|
||||||
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 129U;
|
|
||||||
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
|
|
||||||
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
|
|
||||||
page = 128U;
|
|
||||||
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
|
|
||||||
page = 2U;
|
|
||||||
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
|
|
||||||
page = 1U;
|
|
||||||
} else if (page != 0U) {
|
|
||||||
LOG_DBG("Composition page %u not available", page);
|
|
||||||
page = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
net_buf_simple_add_u8(&rsp, page);
|
net_buf_simple_add_u8(&rsp, page);
|
||||||
net_buf_simple_add_le16(&rsp, offset);
|
net_buf_simple_add_le16(&rsp, offset);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue