From b5017ec7dc695df13126e66f0a3d214aac48fca7 Mon Sep 17 00:00:00 2001 From: Vikrant More Date: Wed, 16 Jan 2019 13:44:34 +0530 Subject: [PATCH] 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 --- .../src/mesh/device_composition.c | 93 ++++++++++--------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/device_composition.c b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/device_composition.c index 677559e461a..20d69ba82db 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/device_composition.c +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/device_composition.c @@ -169,7 +169,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } switch (buf->len) { @@ -201,7 +201,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, if (state->target_onoff != state->onoff) { onoff_tt_values(state, tt, delay); } else { -ret: gen_onoff_publish(model); + gen_onoff_publish(model); return; } @@ -235,7 +235,8 @@ static void gen_onoff_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + gen_onoff_get(model, ctx, buf); + return; } switch (buf->len) { @@ -267,7 +268,7 @@ static void gen_onoff_set(struct bt_mesh_model *model, if (state->target_onoff != state->onoff) { onoff_tt_values(state, tt, delay); } else { -ret: gen_onoff_get(model, ctx, buf); + gen_onoff_get(model, ctx, buf); gen_onoff_publish(model); return; } @@ -361,7 +362,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } switch (buf->len) { @@ -393,7 +394,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model, if (state->target_level != state->level) { level_tt_values(state, tt, delay); } else { -ret: gen_level_publish(model); + gen_level_publish(model); return; } @@ -433,7 +434,8 @@ static void gen_level_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + gen_level_get(model, ctx, buf); + return; } switch (buf->len) { @@ -465,7 +467,7 @@ static void gen_level_set(struct bt_mesh_model *model, if (state->target_level != state->level) { level_tt_values(state, tt, delay); } else { -ret: gen_level_get(model, ctx, buf); + gen_level_get(model, ctx, buf); gen_level_publish(model); return; } @@ -509,7 +511,7 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, (now - state->last_msg_timestamp <= K_SECONDS(6))) { if (state->last_delta == delta) { - goto ret; + return; } 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) { level_tt_values(state, tt, delay); } else { -ret: gen_level_publish(model); + gen_level_publish(model); return; } @@ -598,7 +600,8 @@ static void gen_delta_set(struct bt_mesh_model *model, (now - state->last_msg_timestamp <= K_SECONDS(6))) { if (state->last_delta == delta) { - goto ret; + gen_level_get(model, ctx, buf); + return; } 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) { level_tt_values(state, tt, delay); } else { -ret: gen_level_get(model, ctx, buf); + gen_level_get(model, ctx, buf); gen_level_publish(model); return; } @@ -741,7 +744,6 @@ static void gen_move_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - gen_level_move_publish(model); return; } @@ -782,16 +784,18 @@ static void gen_move_set_unack(struct bt_mesh_model *model, if (state->target_level != state->level) { level_tt_values(state, tt, delay); + } else { + gen_level_move_publish(model); + return; + } + + if (state->transition->counter == 0) { + return; } state->transition->just_started = true; 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) { /* Root element */ 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 && (now - state->last_msg_timestamp <= K_SECONDS(6))) { gen_level_move_get(model, ctx, buf); - gen_level_move_publish(model); return; } @@ -863,23 +866,25 @@ static void gen_move_set(struct bt_mesh_model *model, if (state->target_level != state->level) { 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; gen_level_move_get(model, ctx, buf); 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) { /* Root element */ transition_type = LEVEL_TT_MOVE; level_lightness_handler(state); - } else if (bt_mesh_model_elem(model)->addr == - elements[1].addr) { + } else if (bt_mesh_model_elem(model)->addr == elements[1].addr) { /* Secondary element */ transition_type = LEVEL_TEMP_TT_MOVE; 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_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } switch (buf->len) { @@ -1254,7 +1259,7 @@ static void light_lightness_set_unack(struct bt_mesh_model *model, if (state->target_actual != state->actual) { light_lightness_actual_tt_values(state, tt, delay); } else { -ret: light_lightness_publish(model); + light_lightness_publish(model); return; } @@ -1285,7 +1290,8 @@ static void light_lightness_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + light_lightness_get(model, ctx, buf); + return; } switch (buf->len) { @@ -1324,7 +1330,7 @@ static void light_lightness_set(struct bt_mesh_model *model, if (state->target_actual != state->actual) { light_lightness_actual_tt_values(state, tt, delay); } else { -ret: light_lightness_get(model, ctx, buf); + light_lightness_get(model, ctx, buf); light_lightness_publish(model); 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_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } 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) { light_lightness_linear_tt_values(state, tt, delay); } else { -ret: light_lightness_linear_publish(model); + light_lightness_linear_publish(model); return; } @@ -1468,7 +1474,8 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + light_lightness_linear_get(model, ctx, buf); + return; } switch (buf->len) { @@ -1500,7 +1507,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, if (state->target_linear != state->linear) { light_lightness_linear_tt_values(state, tt, delay); } else { -ret: light_lightness_linear_get(model, ctx, buf); + light_lightness_linear_get(model, ctx, buf); light_lightness_linear_publish(model); return; } @@ -1828,7 +1835,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } 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) { light_ctl_tt_values(state, tt, delay); } else { -ret: light_ctl_publish(model); + light_ctl_publish(model); return; } @@ -1911,7 +1918,8 @@ static void light_ctl_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + light_ctl_get(model, ctx, buf); + return; } switch (buf->len) { @@ -1954,7 +1962,7 @@ static void light_ctl_set(struct bt_mesh_model *model, state->target_delta_uv != state->delta_uv) { light_ctl_tt_values(state, tt, delay); } else { -ret: light_ctl_get(model, ctx, buf); + light_ctl_get(model, ctx, buf); light_ctl_publish(model); 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_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + return; } 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) { light_ctl_temp_tt_values(state, tt, delay); } else { -ret: light_ctl_temp_publish(model); + light_ctl_temp_publish(model); return; } @@ -2375,7 +2383,8 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - goto ret; + light_ctl_temp_get(model, ctx, buf); + return; } 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) { light_ctl_temp_tt_values(state, tt, delay); } else { -ret: light_ctl_temp_get(model, ctx, buf); + light_ctl_temp_get(model, ctx, buf); light_ctl_temp_publish(model); return; }