From 21f7bad75186c97b856e21ea46d90b14c78aca85 Mon Sep 17 00:00:00 2001 From: Vikrant More Date: Thu, 15 Nov 2018 14:50:48 +0530 Subject: [PATCH] samples: mesh: nrf52: Removed bug in reassignment of transition type This PR will solve bug in reassignment of transition type to Server. Signed-off-by: Vikrant More --- .../src/mesh/device_composition.c | 116 ++++++++++++------ .../src/mesh/transition.c | 18 +-- .../src/mesh/transition.h | 2 + 3 files changed, 79 insertions(+), 57 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 52337b32827..7dbdd7a4c6a 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 @@ -151,7 +151,7 @@ static bool gen_onoff_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, onoff, tt; + u8_t tid, onoff, tt, delay; s64_t now; struct generic_onoff_state *state = model->user_data; @@ -170,8 +170,8 @@ static bool gen_onoff_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -179,13 +179,16 @@ static bool gen_onoff_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + bound_states_transition_type_reassignment(ONOFF); + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -323,7 +326,7 @@ static bool gen_level_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; s16_t level; s64_t now; struct generic_level_state *state = model->user_data; @@ -339,8 +342,8 @@ static bool gen_level_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -348,13 +351,20 @@ static bool gen_level_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + if (bt_mesh_model_elem(model)->addr == elements[0].addr) { + bound_states_transition_type_reassignment(LEVEL); + } else if (bt_mesh_model_elem(model)->addr == elements[1].addr) { + bound_states_transition_type_reassignment(LEVEL_TEMP); + } + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -410,7 +420,7 @@ static bool gen_delta_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; s32_t tmp32, delta; s64_t now; struct generic_level_state *state = model->user_data; @@ -434,8 +444,8 @@ static bool gen_delta_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -443,13 +453,20 @@ static bool gen_delta_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + if (bt_mesh_model_elem(model)->addr == elements[0].addr) { + bound_states_transition_type_reassignment(LEVEL); + } else if (bt_mesh_model_elem(model)->addr == elements[1].addr) { + bound_states_transition_type_reassignment(LEVEL_TEMP); + } + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -513,7 +530,7 @@ static bool gen_move_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; s16_t delta; s32_t tmp32; s64_t now; @@ -530,8 +547,8 @@ static bool gen_move_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -539,13 +556,20 @@ static bool gen_move_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + if (bt_mesh_model_elem(model)->addr == elements[0].addr) { + bound_states_transition_type_reassignment(LEVEL); + } else if (bt_mesh_model_elem(model)->addr == elements[1].addr) { + bound_states_transition_type_reassignment(LEVEL_TEMP); + } + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -904,7 +928,7 @@ static bool light_lightness_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; u16_t actual; s64_t now; struct light_lightness_state *state = model->user_data; @@ -920,8 +944,8 @@ static bool light_lightness_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -929,13 +953,16 @@ static bool light_lightness_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + bound_states_transition_type_reassignment(ACTUAL); + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -1035,7 +1062,7 @@ static bool light_lightness_linear_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; u16_t linear; s64_t now; struct light_lightness_state *state = model->user_data; @@ -1051,8 +1078,8 @@ static bool light_lightness_linear_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -1060,13 +1087,16 @@ static bool light_lightness_linear_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + bound_states_transition_type_reassignment(LINEAR); + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -1380,7 +1410,7 @@ static bool light_ctl_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; s16_t delta_uv; u16_t lightness, temp; s64_t now; @@ -1403,8 +1433,8 @@ static bool light_ctl_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -1412,13 +1442,16 @@ static bool light_ctl_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + bound_states_transition_type_reassignment(CTL); + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -1758,7 +1791,7 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u8_t tid, tt; + u8_t tid, tt, delay; s16_t delta_uv; u16_t temp; s64_t now; @@ -1780,8 +1813,8 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model, switch (buf->len) { case 0x00: /* No optional fields are available */ - state->transition->tt = default_tt; - state->transition->delay = 0; + tt = default_tt; + delay = 0; break; case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); @@ -1789,13 +1822,16 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model, return false; } - state->transition->tt = tt; - state->transition->delay = net_buf_simple_pull_u8(buf); + delay = net_buf_simple_pull_u8(buf); break; default: return false; } + bound_states_transition_type_reassignment(CTL_TEMP); + state->transition->tt = tt; + state->transition->delay = delay; + *ptr_counter = 0; k_timer_stop(ptr_timer); diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.c b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.c index c39a5955135..e9f91799acc 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.c +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.c @@ -62,7 +62,7 @@ void calculate_rt(struct transition *transition) /* Function to calculate Remaining Time (End) */ -static void bound_states_transition_type_reassignment(u8_t type) +void bound_states_transition_type_reassignment(u8_t type) { switch (type) { case ONOFF: @@ -118,8 +118,6 @@ static void tt_values_calculator(struct transition *transition) void onoff_tt_values(struct generic_onoff_state *state) { - bound_states_transition_type_reassignment(ONOFF); - tt_values_calculator(state->transition); if (state->transition->counter == 0) { @@ -136,12 +134,6 @@ void level_tt_values(struct generic_level_state *state) { u32_t counter; - if (state == &gen_level_srv_root_user_data) { - bound_states_transition_type_reassignment(LEVEL); - } else if (state == &gen_level_srv_s0_user_data) { - bound_states_transition_type_reassignment(LEVEL_TEMP); - } - tt_values_calculator(state->transition); counter = state->transition->counter; @@ -167,8 +159,6 @@ void light_lightness_actual_tt_values(struct light_lightness_state *state) { u32_t counter; - bound_states_transition_type_reassignment(ACTUAL); - tt_values_calculator(state->transition); counter = state->transition->counter; @@ -191,8 +181,6 @@ void light_lightness_linear_tt_values(struct light_lightness_state *state) { u32_t counter; - bound_states_transition_type_reassignment(LINEAR); - tt_values_calculator(state->transition); counter = state->transition->counter; @@ -215,8 +203,6 @@ void light_ctl_tt_values(struct light_ctl_state *state) { u32_t counter; - bound_states_transition_type_reassignment(CTL); - tt_values_calculator(state->transition); counter = state->transition->counter; @@ -247,8 +233,6 @@ void light_ctl_temp_tt_values(struct light_ctl_state *state) { u32_t counter; - bound_states_transition_type_reassignment(CTL_TEMP); - tt_values_calculator(state->transition); counter = state->transition->counter; diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.h b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.h index 38f2f4bff32..a33cc2eadbe 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.h +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/mesh/transition.h @@ -41,6 +41,8 @@ extern struct k_timer dummy_timer; void calculate_rt(struct transition *transition); +void bound_states_transition_type_reassignment(u8_t type); + void onoff_tt_values(struct generic_onoff_state *state); void level_tt_values(struct generic_level_state *state); void light_lightness_actual_tt_values(struct light_lightness_state *state);