Bluetooth: Mesh: Redesign element and storage info for models
Keeping the model struct same sized, change the element pointer to two indexes, and add a flags member that will be used to track pending storage actions. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
b7078e1487
commit
8703ffad23
8 changed files with 66 additions and 14 deletions
|
@ -332,8 +332,10 @@ struct bt_mesh_model {
|
|||
} vnd;
|
||||
};
|
||||
|
||||
/* The Element this Model belongs to */
|
||||
struct bt_mesh_elem *elem;
|
||||
/* Internal information, mainly for persistent storage */
|
||||
u8_t elem_idx; /* Belongs to Nth element */
|
||||
u8_t mod_idx; /* Is the Nth model in the element */
|
||||
u16_t flags; /* Information about what has changed */
|
||||
|
||||
/* Model Publication */
|
||||
struct bt_mesh_model_pub * const pub;
|
||||
|
@ -396,6 +398,15 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
|
|||
*/
|
||||
int bt_mesh_model_publish(struct bt_mesh_model *model);
|
||||
|
||||
/**
|
||||
* @brief Get the element that a model belongs to.
|
||||
*
|
||||
* @param mod Mesh model.
|
||||
*
|
||||
* @return Pointer to the element that the given model belongs to.
|
||||
*/
|
||||
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod);
|
||||
|
||||
/** Node Composition */
|
||||
struct bt_mesh_comp {
|
||||
u16_t cid;
|
||||
|
|
|
@ -102,7 +102,7 @@ static void vnd_button_pressed(struct bt_mesh_model *model,
|
|||
{
|
||||
printk("src 0x%04x\n", ctx->addr);
|
||||
|
||||
if (ctx->addr == model->elem->addr) {
|
||||
if (ctx->addr == bt_mesh_model_elem(model)->addr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ static void gen_onoff_get(struct bt_mesh_model *model,
|
|||
struct onoff_state *onoff_state = model->user_data;
|
||||
|
||||
SYS_LOG_INF("addr 0x%04x onoff 0x%02x",
|
||||
model->elem->addr, onoff_state->current);
|
||||
bt_mesh_model_elem(model)->addr, onoff_state->current);
|
||||
bt_mesh_model_msg_init(&msg, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS);
|
||||
net_buf_simple_add_u8(&msg, onoff_state->current);
|
||||
|
||||
|
@ -338,7 +338,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
|
|||
|
||||
onoff_state->current = net_buf_simple_pull_u8(buf);
|
||||
SYS_LOG_INF("addr 0x%02x state 0x%02x",
|
||||
model->elem->addr, onoff_state->current);
|
||||
bt_mesh_model_elem(model)->addr, onoff_state->current);
|
||||
|
||||
/* Pin set low turns on LED's on the nrf52840-pca10056 board */
|
||||
gpio_pin_write(onoff_state->led_device,
|
||||
|
@ -389,7 +389,7 @@ static void gen_onoff_status(struct bt_mesh_model *model,
|
|||
state = net_buf_simple_pull_u8(buf);
|
||||
|
||||
SYS_LOG_INF("Node 0x%04x OnOff status from 0x%04x with state 0x%02x",
|
||||
model->elem->addr, ctx->addr, state);
|
||||
bt_mesh_model_elem(model)->addr, ctx->addr, state);
|
||||
}
|
||||
|
||||
static int output_number(bt_mesh_output_action_t action, uint32_t number)
|
||||
|
|
|
@ -157,7 +157,7 @@ static int publish_retransmit(struct bt_mesh_model *mod)
|
|||
};
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.ctx = &ctx,
|
||||
.src = mod->elem->addr,
|
||||
.src = bt_mesh_model_elem(mod)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
.friend_cred = pub->cred,
|
||||
};
|
||||
|
@ -233,13 +233,44 @@ static void mod_publish(struct k_work *work)
|
|||
}
|
||||
}
|
||||
|
||||
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
|
||||
{
|
||||
return &dev_comp->elem[mod->elem_idx];
|
||||
}
|
||||
|
||||
struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx)
|
||||
{
|
||||
struct bt_mesh_elem *elem;
|
||||
|
||||
if (elem_idx >= dev_comp->elem_count) {
|
||||
BT_ERR("Invalid element index %u", elem_idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
elem = &dev_comp->elem[elem_idx];
|
||||
|
||||
if (vnd) {
|
||||
if (mod_idx >= elem->vnd_model_count) {
|
||||
BT_ERR("Invalid vendor model index %u", mod_idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &elem->vnd_models[mod_idx];
|
||||
} else {
|
||||
if (mod_idx >= elem->model_count) {
|
||||
BT_ERR("Invalid SIG model index %u", mod_idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &elem->models[mod_idx];
|
||||
}
|
||||
}
|
||||
|
||||
static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary, void *user_data)
|
||||
{
|
||||
int i;
|
||||
|
||||
mod->elem = elem;
|
||||
|
||||
if (mod->pub) {
|
||||
mod->pub->mod = mod;
|
||||
k_delayed_work_init(&mod->pub->timer, mod_publish);
|
||||
|
@ -249,6 +280,14 @@ static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
|||
mod->keys[i] = BT_MESH_KEY_UNUSED;
|
||||
}
|
||||
|
||||
mod->flags = 0;
|
||||
mod->elem_idx = elem - dev_comp->elem;
|
||||
if (vnd) {
|
||||
mod->mod_idx = mod - elem->vnd_models;
|
||||
} else {
|
||||
mod->mod_idx = mod - elem->models;
|
||||
}
|
||||
|
||||
if (vnd) {
|
||||
return;
|
||||
}
|
||||
|
@ -597,7 +636,7 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
|
|||
struct bt_mesh_net_tx tx = {
|
||||
.sub = bt_mesh_subnet_get(ctx->net_idx),
|
||||
.ctx = ctx,
|
||||
.src = model->elem->addr,
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
.friend_cred = 0,
|
||||
};
|
||||
|
@ -614,7 +653,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
|||
};
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.ctx = &ctx,
|
||||
.src = model->elem->addr,
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
int err;
|
||||
|
|
|
@ -37,6 +37,8 @@ u16_t bt_mesh_primary_addr(void);
|
|||
|
||||
const struct bt_mesh_comp *bt_mesh_comp_get(void);
|
||||
|
||||
struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx);
|
||||
|
||||
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
||||
|
||||
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
|
||||
|
|
|
@ -64,7 +64,7 @@ static void hb_send(struct bt_mesh_model *model)
|
|||
struct bt_mesh_net_tx tx = {
|
||||
.sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx),
|
||||
.ctx = &ctx,
|
||||
.src = model->elem->addr,
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ static int fault_test(struct bt_mesh_model *model, uint8_t test_id,
|
|||
}
|
||||
|
||||
has_reg_fault = true;
|
||||
bt_mesh_fault_update(model->elem);
|
||||
bt_mesh_fault_update(bt_mesh_model_elem(model));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -654,7 +654,7 @@ static void model_send(u8_t *data, u16_t len)
|
|||
|
||||
/* Lookup source address */
|
||||
for (i = 0; i < ARRAY_SIZE(model_bound); i++) {
|
||||
if (model_bound[i].model->elem->addr == src) {
|
||||
if (bt_mesh_model_elem(model_bound[i].model)->addr == src) {
|
||||
model = model_bound[i].model;
|
||||
ctx.app_idx = model_bound[i].appkey_idx;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue