From 8da14d79fd960164147697c66620a38e2dbae407 Mon Sep 17 00:00:00 2001 From: Vikrant More Date: Thu, 15 Nov 2018 22:41:14 +0530 Subject: [PATCH] samples: mesh: nrf52: improvement in transition type reassignment Simplifies message handler for Servers & transition type reassignment. Signed-off-by: Vikrant More --- .../src/mesh/device_composition.c | 68 +++---------------- .../src/mesh/transition.c | 45 ++++++++++-- .../src/mesh/transition.h | 16 +++-- 3 files changed, 55 insertions(+), 74 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 7dbdd7a4c6a..39122358c4f 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 @@ -185,10 +185,6 @@ static bool gen_onoff_setunack(struct bt_mesh_model *model, return false; } - bound_states_transition_type_reassignment(ONOFF); - state->transition->tt = tt; - state->transition->delay = delay; - *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -197,9 +193,8 @@ static bool gen_onoff_setunack(struct bt_mesh_model *model, state->last_msg_timestamp = now; state->target_onoff = onoff; - state->transition->counter = 0; if (state->target_onoff != state->onoff) { - onoff_tt_values(state); + onoff_tt_values(state, tt, delay); } else { return true; } @@ -357,14 +352,6 @@ static bool gen_level_setunack(struct bt_mesh_model *model, 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); @@ -373,9 +360,8 @@ static bool gen_level_setunack(struct bt_mesh_model *model, state->last_msg_timestamp = now; state->target_level = level; - state->transition->counter = 0; if (state->target_level != state->level) { - level_tt_values(state); + level_tt_values(state, tt, delay); } else { return true; } @@ -459,14 +445,6 @@ static bool gen_delta_setunack(struct bt_mesh_model *model, 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); @@ -483,9 +461,8 @@ static bool gen_delta_setunack(struct bt_mesh_model *model, state->target_level = tmp32; - state->transition->counter = 0; if (state->target_level != state->level) { - level_tt_values(state); + level_tt_values(state, tt, delay); } else { return true; } @@ -562,14 +539,6 @@ static bool gen_move_setunack(struct bt_mesh_model *model, 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); @@ -587,9 +556,8 @@ static bool gen_move_setunack(struct bt_mesh_model *model, state->target_level = tmp32; - state->transition->counter = 0; if (state->target_level != state->level) { - level_tt_values(state); + level_tt_values(state, tt, delay); } else { if (delta == 0) { goto jump; @@ -959,10 +927,6 @@ static bool light_lightness_setunack(struct bt_mesh_model *model, return false; } - bound_states_transition_type_reassignment(ACTUAL); - state->transition->tt = tt; - state->transition->delay = delay; - *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -978,9 +942,8 @@ static bool light_lightness_setunack(struct bt_mesh_model *model, state->target_actual = actual; - state->transition->counter = 0; if (state->target_actual != state->actual) { - light_lightness_actual_tt_values(state); + light_lightness_actual_tt_values(state, tt, delay); } else { return true; } @@ -1093,10 +1056,6 @@ static bool light_lightness_linear_setunack(struct bt_mesh_model *model, return false; } - bound_states_transition_type_reassignment(LINEAR); - state->transition->tt = tt; - state->transition->delay = delay; - *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -1105,9 +1064,8 @@ static bool light_lightness_linear_setunack(struct bt_mesh_model *model, state->last_msg_timestamp = now; state->target_linear = linear; - state->transition->counter = 0; if (state->target_linear != state->linear) { - light_lightness_linear_tt_values(state); + light_lightness_linear_tt_values(state, tt, delay); } else { return true; } @@ -1448,10 +1406,6 @@ static bool light_ctl_setunack(struct bt_mesh_model *model, return false; } - bound_states_transition_type_reassignment(CTL); - state->transition->tt = tt; - state->transition->delay = delay; - *ptr_counter = 0; k_timer_stop(ptr_timer); @@ -1469,11 +1423,10 @@ static bool light_ctl_setunack(struct bt_mesh_model *model, state->target_temp = temp; state->target_delta_uv = delta_uv; - state->transition->counter = 0; if (state->target_lightness != state->lightness || state->target_temp != state->temp || state->target_delta_uv != state->delta_uv) { - light_ctl_tt_values(state); + light_ctl_tt_values(state, tt, delay); } else { return true; } @@ -1828,10 +1781,6 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model, 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); @@ -1848,10 +1797,9 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model, state->target_temp = temp; state->target_delta_uv = delta_uv; - state->transition->counter = 0; if (state->target_temp != state->temp || state->target_delta_uv != state->delta_uv) { - light_ctl_temp_tt_values(state); + light_ctl_temp_tt_values(state, tt, delay); } else { return true; } 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 34884f36170..72815ca039d 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 @@ -61,7 +61,7 @@ void calculate_rt(struct transition *transition) /* Function to calculate Remaining Time (End) */ -void bound_states_transition_type_reassignment(u8_t type) +static void bound_states_transition_type_reassignment(u8_t type) { switch (type) { case ONOFF: @@ -115,8 +115,12 @@ static void tt_values_calculator(struct transition *transition) ptr_counter = &transition->counter; } -void onoff_tt_values(struct generic_onoff_state *state) +void onoff_tt_values(struct generic_onoff_state *state, u8_t tt, u8_t delay) { + bound_states_transition_type_reassignment(ONOFF); + state->transition->tt = tt; + state->transition->delay = delay; + tt_values_calculator(state->transition); if (state->transition->counter == 0) { @@ -129,10 +133,18 @@ void onoff_tt_values(struct generic_onoff_state *state) } } -void level_tt_values(struct generic_level_state *state) +void level_tt_values(struct generic_level_state *state, u8_t tt, u8_t delay) { 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); + } + state->transition->tt = tt; + state->transition->delay = delay; + tt_values_calculator(state->transition); counter = state->transition->counter; @@ -154,10 +166,15 @@ void level_tt_values(struct generic_level_state *state) counter); } -void light_lightness_actual_tt_values(struct light_lightness_state *state) +void light_lightness_actual_tt_values(struct light_lightness_state *state, + u8_t tt, u8_t delay) { u32_t counter; + bound_states_transition_type_reassignment(ACTUAL); + state->transition->tt = tt; + state->transition->delay = delay; + tt_values_calculator(state->transition); counter = state->transition->counter; @@ -176,10 +193,15 @@ void light_lightness_actual_tt_values(struct light_lightness_state *state) counter); } -void light_lightness_linear_tt_values(struct light_lightness_state *state) +void light_lightness_linear_tt_values(struct light_lightness_state *state, + u8_t tt, u8_t delay) { u32_t counter; + bound_states_transition_type_reassignment(LINEAR); + state->transition->tt = tt; + state->transition->delay = delay; + tt_values_calculator(state->transition); counter = state->transition->counter; @@ -198,10 +220,14 @@ void light_lightness_linear_tt_values(struct light_lightness_state *state) counter); } -void light_ctl_tt_values(struct light_ctl_state *state) +void light_ctl_tt_values(struct light_ctl_state *state, u8_t tt, u8_t delay) { u32_t counter; + bound_states_transition_type_reassignment(CTL); + state->transition->tt = tt; + state->transition->delay = delay; + tt_values_calculator(state->transition); counter = state->transition->counter; @@ -228,10 +254,15 @@ void light_ctl_tt_values(struct light_ctl_state *state) counter); } -void light_ctl_temp_tt_values(struct light_ctl_state *state) +void light_ctl_temp_tt_values(struct light_ctl_state *state, + u8_t tt, u8_t delay) { u32_t counter; + bound_states_transition_type_reassignment(CTL_TEMP); + state->transition->tt = tt; + state->transition->delay = delay; + 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 b83fdc4106d..abf9503be5e 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 @@ -43,14 +43,16 @@ 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); -void light_lightness_linear_tt_values(struct light_lightness_state *state); -void light_ctl_tt_values(struct light_ctl_state *state); -void light_ctl_temp_tt_values(struct light_ctl_state *state); +void onoff_tt_values(struct generic_onoff_state *state, u8_t tt, u8_t delay); +void level_tt_values(struct generic_level_state *state, u8_t tt, u8_t delay); +void light_lightness_actual_tt_values(struct light_lightness_state *state, + u8_t tt, u8_t delay); +void light_lightness_linear_tt_values(struct light_lightness_state *state, + u8_t tt, u8_t delay); +void light_ctl_tt_values(struct light_ctl_state *state, u8_t tt, u8_t delay); +void light_ctl_temp_tt_values(struct light_ctl_state *state, + u8_t tt, u8_t delay); void onoff_handler(struct generic_onoff_state *state); void level_lightness_handler(struct generic_level_state *state);