samples: mesh: restriction to re-transmit publish messages
If Server receives re-transmitted message then it will not transmit corresponding publish message for it. Signed-off-by: Vikrant More <vikrant8051@gmail.com>
This commit is contained in:
parent
a61f7c39aa
commit
b5017ec7dc
1 changed files with 51 additions and 42 deletions
|
@ -169,7 +169,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -201,7 +201,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
|
||||||
if (state->target_onoff != state->onoff) {
|
if (state->target_onoff != state->onoff) {
|
||||||
onoff_tt_values(state, tt, delay);
|
onoff_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_onoff_publish(model);
|
gen_onoff_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,8 @@ static void gen_onoff_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
gen_onoff_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -267,7 +268,7 @@ static void gen_onoff_set(struct bt_mesh_model *model,
|
||||||
if (state->target_onoff != state->onoff) {
|
if (state->target_onoff != state->onoff) {
|
||||||
onoff_tt_values(state, tt, delay);
|
onoff_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_onoff_get(model, ctx, buf);
|
gen_onoff_get(model, ctx, buf);
|
||||||
gen_onoff_publish(model);
|
gen_onoff_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +362,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -393,7 +394,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model,
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_level_publish(model);
|
gen_level_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +434,8 @@ static void gen_level_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
gen_level_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -465,7 +467,7 @@ static void gen_level_set(struct bt_mesh_model *model,
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_level_get(model, ctx, buf);
|
gen_level_get(model, ctx, buf);
|
||||||
gen_level_publish(model);
|
gen_level_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -509,7 +511,7 @@ static void gen_delta_set_unack(struct bt_mesh_model *model,
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
|
|
||||||
if (state->last_delta == delta) {
|
if (state->last_delta == delta) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
tmp32 = state->last_level + delta;
|
tmp32 = state->last_level + delta;
|
||||||
|
|
||||||
|
@ -555,7 +557,7 @@ static void gen_delta_set_unack(struct bt_mesh_model *model,
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_level_publish(model);
|
gen_level_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +600,8 @@ static void gen_delta_set(struct bt_mesh_model *model,
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
|
|
||||||
if (state->last_delta == delta) {
|
if (state->last_delta == delta) {
|
||||||
goto ret;
|
gen_level_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
tmp32 = state->last_level + delta;
|
tmp32 = state->last_level + delta;
|
||||||
|
|
||||||
|
@ -644,7 +647,7 @@ static void gen_delta_set(struct bt_mesh_model *model,
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: gen_level_get(model, ctx, buf);
|
gen_level_get(model, ctx, buf);
|
||||||
gen_level_publish(model);
|
gen_level_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -741,7 +744,6 @@ static void gen_move_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
gen_level_move_publish(model);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,16 +784,18 @@ static void gen_move_set_unack(struct bt_mesh_model *model,
|
||||||
|
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
|
} else {
|
||||||
|
gen_level_move_publish(model);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->transition->counter == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->transition->just_started = true;
|
state->transition->just_started = true;
|
||||||
gen_level_move_publish(model);
|
gen_level_move_publish(model);
|
||||||
|
|
||||||
/* if (tt == 0) OR (delta == 0) */
|
|
||||||
if (state->transition->counter == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bt_mesh_model_elem(model)->addr == elements[0].addr) {
|
if (bt_mesh_model_elem(model)->addr == elements[0].addr) {
|
||||||
/* Root element */
|
/* Root element */
|
||||||
transition_type = LEVEL_TT_MOVE;
|
transition_type = LEVEL_TT_MOVE;
|
||||||
|
@ -822,7 +826,6 @@ static void gen_move_set(struct bt_mesh_model *model,
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
gen_level_move_get(model, ctx, buf);
|
gen_level_move_get(model, ctx, buf);
|
||||||
gen_level_move_publish(model);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,23 +866,25 @@ static void gen_move_set(struct bt_mesh_model *model,
|
||||||
|
|
||||||
if (state->target_level != state->level) {
|
if (state->target_level != state->level) {
|
||||||
level_tt_values(state, tt, delay);
|
level_tt_values(state, tt, delay);
|
||||||
|
} else {
|
||||||
|
gen_level_move_get(model, ctx, buf);
|
||||||
|
gen_level_move_publish(model);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->transition->counter == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->transition->just_started = true;
|
state->transition->just_started = true;
|
||||||
gen_level_move_get(model, ctx, buf);
|
gen_level_move_get(model, ctx, buf);
|
||||||
gen_level_move_publish(model);
|
gen_level_move_publish(model);
|
||||||
|
|
||||||
/* if (tt == 0) OR (delta == 0) */
|
|
||||||
if (state->transition->counter == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bt_mesh_model_elem(model)->addr == elements[0].addr) {
|
if (bt_mesh_model_elem(model)->addr == elements[0].addr) {
|
||||||
/* Root element */
|
/* Root element */
|
||||||
transition_type = LEVEL_TT_MOVE;
|
transition_type = LEVEL_TT_MOVE;
|
||||||
level_lightness_handler(state);
|
level_lightness_handler(state);
|
||||||
} else if (bt_mesh_model_elem(model)->addr ==
|
} else if (bt_mesh_model_elem(model)->addr == elements[1].addr) {
|
||||||
elements[1].addr) {
|
|
||||||
/* Secondary element */
|
/* Secondary element */
|
||||||
transition_type = LEVEL_TEMP_TT_MOVE;
|
transition_type = LEVEL_TEMP_TT_MOVE;
|
||||||
level_temp_handler(state);
|
level_temp_handler(state);
|
||||||
|
@ -1215,7 +1220,7 @@ static void light_lightness_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1254,7 +1259,7 @@ static void light_lightness_set_unack(struct bt_mesh_model *model,
|
||||||
if (state->target_actual != state->actual) {
|
if (state->target_actual != state->actual) {
|
||||||
light_lightness_actual_tt_values(state, tt, delay);
|
light_lightness_actual_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_lightness_publish(model);
|
light_lightness_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1285,7 +1290,8 @@ static void light_lightness_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
light_lightness_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1324,7 +1330,7 @@ static void light_lightness_set(struct bt_mesh_model *model,
|
||||||
if (state->target_actual != state->actual) {
|
if (state->target_actual != state->actual) {
|
||||||
light_lightness_actual_tt_values(state, tt, delay);
|
light_lightness_actual_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_lightness_get(model, ctx, buf);
|
light_lightness_get(model, ctx, buf);
|
||||||
light_lightness_publish(model);
|
light_lightness_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1405,7 +1411,7 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1437,7 +1443,7 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model,
|
||||||
if (state->target_linear != state->linear) {
|
if (state->target_linear != state->linear) {
|
||||||
light_lightness_linear_tt_values(state, tt, delay);
|
light_lightness_linear_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_lightness_linear_publish(model);
|
light_lightness_linear_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1468,7 +1474,8 @@ static void light_lightness_linear_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
light_lightness_linear_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1500,7 +1507,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model,
|
||||||
if (state->target_linear != state->linear) {
|
if (state->target_linear != state->linear) {
|
||||||
light_lightness_linear_tt_values(state, tt, delay);
|
light_lightness_linear_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_lightness_linear_get(model, ctx, buf);
|
light_lightness_linear_get(model, ctx, buf);
|
||||||
light_lightness_linear_publish(model);
|
light_lightness_linear_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1828,7 +1835,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1871,7 +1878,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model,
|
||||||
state->target_delta_uv != state->delta_uv) {
|
state->target_delta_uv != state->delta_uv) {
|
||||||
light_ctl_tt_values(state, tt, delay);
|
light_ctl_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_ctl_publish(model);
|
light_ctl_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1911,7 +1918,8 @@ static void light_ctl_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
light_ctl_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -1954,7 +1962,7 @@ static void light_ctl_set(struct bt_mesh_model *model,
|
||||||
state->target_delta_uv != state->delta_uv) {
|
state->target_delta_uv != state->delta_uv) {
|
||||||
light_ctl_tt_values(state, tt, delay);
|
light_ctl_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_ctl_get(model, ctx, buf);
|
light_ctl_get(model, ctx, buf);
|
||||||
light_ctl_publish(model);
|
light_ctl_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2296,7 +2304,7 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -2337,7 +2345,7 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model,
|
||||||
state->target_delta_uv != state->delta_uv) {
|
state->target_delta_uv != state->delta_uv) {
|
||||||
light_ctl_temp_tt_values(state, tt, delay);
|
light_ctl_temp_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_ctl_temp_publish(model);
|
light_ctl_temp_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2375,7 +2383,8 @@ static void light_ctl_temp_set(struct bt_mesh_model *model,
|
||||||
state->last_src_addr == ctx->addr &&
|
state->last_src_addr == ctx->addr &&
|
||||||
state->last_dst_addr == ctx->recv_dst &&
|
state->last_dst_addr == ctx->recv_dst &&
|
||||||
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
|
||||||
goto ret;
|
light_ctl_temp_get(model, ctx, buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buf->len) {
|
switch (buf->len) {
|
||||||
|
@ -2416,7 +2425,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model,
|
||||||
state->target_delta_uv != state->delta_uv) {
|
state->target_delta_uv != state->delta_uv) {
|
||||||
light_ctl_temp_tt_values(state, tt, delay);
|
light_ctl_temp_tt_values(state, tt, delay);
|
||||||
} else {
|
} else {
|
||||||
ret: light_ctl_temp_get(model, ctx, buf);
|
light_ctl_temp_get(model, ctx, buf);
|
||||||
light_ctl_temp_publish(model);
|
light_ctl_temp_publish(model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue