mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 16:20:19 +00:00
mesh: extract base transition struct
This commit is contained in:
parent
27a2526ec0
commit
617a1deb87
@ -91,9 +91,9 @@ static void mesh_generic_on_off_status_message(mesh_model_t *generic_on_off_serv
|
|||||||
mesh_transport_pdu_t * transport_pdu = NULL;
|
mesh_transport_pdu_t * transport_pdu = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (state->transition_data.remaining_transition_time_ms != 0) {
|
if (state->transition_data.base_transition.remaining_transition_time_ms != 0) {
|
||||||
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_transition, state->transition_data.current_value,
|
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_transition, state->transition_data.current_value,
|
||||||
state->transition_data.target_value, state->transition_data.remaining_transition_time_ms);
|
state->transition_data.target_value, state->transition_data.base_transition.remaining_transition_time_ms);
|
||||||
} else {
|
} else {
|
||||||
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_instantaneous, state->transition_data.current_value);
|
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_instantaneous, state->transition_data.current_value);
|
||||||
}
|
}
|
||||||
@ -179,8 +179,8 @@ static void generic_on_off_set_handler(mesh_model_t *generic_on_off_server_model
|
|||||||
generic_on_off_server_state->transition_data.current_value = on_off_value;
|
generic_on_off_server_state->transition_data.current_value = on_off_value;
|
||||||
generic_on_off_server_state->transition_data.target_value = on_off_value;
|
generic_on_off_server_state->transition_data.target_value = on_off_value;
|
||||||
generic_on_off_server_state->transaction_identifier = tid;
|
generic_on_off_server_state->transaction_identifier = tid;
|
||||||
generic_on_off_server_state->transition_data.remaining_transition_time_ms = 0;
|
generic_on_off_server_state->transition_data.base_transition.remaining_transition_time_ms = 0;
|
||||||
generic_on_off_server_state->transition_data.remaining_delay_time_ms = 0;
|
generic_on_off_server_state->transition_data.base_transition.remaining_delay_time_ms = 0;
|
||||||
mesh_generic_on_off_status_message(generic_on_off_server_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), mesh_pdu_appkey_index(pdu));
|
mesh_generic_on_off_status_message(generic_on_off_server_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), mesh_pdu_appkey_index(pdu));
|
||||||
mesh_access_message_processed(pdu);
|
mesh_access_message_processed(pdu);
|
||||||
|
|
||||||
@ -211,8 +211,8 @@ void mesh_generic_on_off_server_set_value(mesh_model_t *generic_on_off_server_mo
|
|||||||
mesh_generic_on_off_state_t * generic_on_off_server_state = (mesh_generic_on_off_state_t *)generic_on_off_server_model->model_data;
|
mesh_generic_on_off_state_t * generic_on_off_server_state = (mesh_generic_on_off_state_t *)generic_on_off_server_model->model_data;
|
||||||
|
|
||||||
generic_on_off_server_state->transition_data.target_value = on_off_value;
|
generic_on_off_server_state->transition_data.target_value = on_off_value;
|
||||||
generic_on_off_server_state->transition_data.remaining_transition_time_ms = transition_time_ms;
|
generic_on_off_server_state->transition_data.base_transition.remaining_transition_time_ms = transition_time_ms;
|
||||||
generic_on_off_server_state->transition_data.remaining_delay_time_ms = delay_ms;
|
generic_on_off_server_state->transition_data.base_transition.remaining_delay_time_ms = delay_ms;
|
||||||
|
|
||||||
// TODO implement transition
|
// TODO implement transition
|
||||||
// TODO implement publication
|
// TODO implement publication
|
||||||
@ -232,24 +232,24 @@ uint8_t mesh_generic_on_off_server_get_value(mesh_model_t *generic_on_off_server
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mesh_server_transition_bool_init(mesh_transition_bool_t * transition){
|
static void mesh_server_transition_bool_init(mesh_transition_bool_t * transition){
|
||||||
transition->state = MESH_TRANSITION_STATE_IDLE;
|
transition->base_transition.state = MESH_TRANSITION_STATE_IDLE;
|
||||||
transition->remaining_transition_time_ms = 0;
|
transition->base_transition.remaining_transition_time_ms = 0;
|
||||||
transition->remaining_delay_time_ms = 0;
|
transition->base_transition.remaining_delay_time_ms = 0;
|
||||||
transition->phase_start_ms = 0;
|
transition->base_transition.phase_start_ms = 0;
|
||||||
transition->target_value = transition->current_value;
|
transition->target_value = transition->current_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mesh_server_transition_state_update(mesh_transition_bool_t * transition, uint32_t current_timestamp_ms){
|
static void mesh_server_transition_state_update(mesh_transition_bool_t * transition, uint32_t current_timestamp_ms){
|
||||||
if (transition->remaining_delay_time_ms != 0){
|
if (transition->base_transition.remaining_delay_time_ms != 0){
|
||||||
transition->state = MESH_TRANSITION_STATE_DELAYED;
|
transition->base_transition.state = MESH_TRANSITION_STATE_DELAYED;
|
||||||
transition->remaining_delay_time_ms = 0;
|
transition->base_transition.remaining_delay_time_ms = 0;
|
||||||
transition->phase_start_ms = current_timestamp_ms;
|
transition->base_transition.phase_start_ms = current_timestamp_ms;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transition->remaining_transition_time_ms != 0){
|
if (transition->base_transition.remaining_transition_time_ms != 0){
|
||||||
transition->state = MESH_TRANSITION_STATE_ACTIVE;
|
transition->base_transition.state = MESH_TRANSITION_STATE_ACTIVE;
|
||||||
transition->phase_start_ms = current_timestamp_ms;
|
transition->base_transition.phase_start_ms = current_timestamp_ms;
|
||||||
if (transition->target_value == 1){
|
if (transition->target_value == 1){
|
||||||
transition->current_value = 1;
|
transition->current_value = 1;
|
||||||
// TODO: emit event
|
// TODO: emit event
|
||||||
@ -258,7 +258,7 @@ static void mesh_server_transition_state_update(mesh_transition_bool_t * transit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transition->current_value = transition->target_value;
|
transition->current_value = transition->target_value;
|
||||||
transition->remaining_transition_time_ms = 0;
|
transition->base_transition.remaining_transition_time_ms = 0;
|
||||||
// TODO: emit event
|
// TODO: emit event
|
||||||
mesh_server_transition_bool_init(transition);
|
mesh_server_transition_bool_init(transition);
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ static void mesh_server_transition_state_update(mesh_transition_bool_t * transit
|
|||||||
void mesh_server_transition_step_bool(mesh_transition_bool_t * transition, transition_event_t event, uint32_t current_timestamp){
|
void mesh_server_transition_step_bool(mesh_transition_bool_t * transition, transition_event_t event, uint32_t current_timestamp){
|
||||||
uint32_t time_step_ms;
|
uint32_t time_step_ms;
|
||||||
|
|
||||||
switch (transition->state){
|
switch (transition->base_transition.state){
|
||||||
case MESH_TRANSITION_STATE_IDLE:
|
case MESH_TRANSITION_STATE_IDLE:
|
||||||
if (event != TRANSITION_START) break;
|
if (event != TRANSITION_START) break;
|
||||||
mesh_server_transition_state_update(transition, current_timestamp);
|
mesh_server_transition_state_update(transition, current_timestamp);
|
||||||
@ -277,11 +277,11 @@ void mesh_server_transition_step_bool(mesh_transition_bool_t * transition, trans
|
|||||||
mesh_server_transition_state_update(transition, current_timestamp);
|
mesh_server_transition_state_update(transition, current_timestamp);
|
||||||
break;
|
break;
|
||||||
case TRANSITION_UPDATE:
|
case TRANSITION_UPDATE:
|
||||||
time_step_ms = current_timestamp - transition->phase_start_ms;
|
time_step_ms = current_timestamp - transition->base_transition.phase_start_ms;
|
||||||
if (transition->remaining_delay_time_ms >= time_step_ms){
|
if (transition->base_transition.remaining_delay_time_ms >= time_step_ms){
|
||||||
transition->remaining_delay_time_ms -= time_step_ms;
|
transition->base_transition.remaining_delay_time_ms -= time_step_ms;
|
||||||
} else {
|
} else {
|
||||||
transition->remaining_delay_time_ms = 0;
|
transition->base_transition.remaining_delay_time_ms = 0;
|
||||||
mesh_server_transition_state_update(transition, current_timestamp);
|
mesh_server_transition_state_update(transition, current_timestamp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -295,11 +295,11 @@ void mesh_server_transition_step_bool(mesh_transition_bool_t * transition, trans
|
|||||||
mesh_server_transition_state_update(transition, current_timestamp);
|
mesh_server_transition_state_update(transition, current_timestamp);
|
||||||
break;
|
break;
|
||||||
case TRANSITION_UPDATE:
|
case TRANSITION_UPDATE:
|
||||||
time_step_ms = current_timestamp - transition->phase_start_ms;
|
time_step_ms = current_timestamp - transition->base_transition.phase_start_ms;
|
||||||
if (transition->remaining_transition_time_ms >= time_step_ms){
|
if (transition->base_transition.remaining_transition_time_ms >= time_step_ms){
|
||||||
transition->remaining_transition_time_ms -= time_step_ms;
|
transition->base_transition.remaining_transition_time_ms -= time_step_ms;
|
||||||
} else {
|
} else {
|
||||||
transition->remaining_transition_time_ms = 0;
|
transition->base_transition.remaining_transition_time_ms = 0;
|
||||||
mesh_server_transition_state_update(transition, current_timestamp);
|
mesh_server_transition_state_update(transition, current_timestamp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -65,17 +65,28 @@ typedef enum {
|
|||||||
MESH_TRANSITION_STATE_ACTIVE
|
MESH_TRANSITION_STATE_ACTIVE
|
||||||
} mesh_transition_state_t;
|
} mesh_transition_state_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct mesh_transition {
|
||||||
|
btstack_linked_item_t item;
|
||||||
|
|
||||||
mesh_transition_state_t state;
|
mesh_transition_state_t state;
|
||||||
uint8_t current_value;
|
|
||||||
uint8_t target_value;
|
|
||||||
|
|
||||||
uint32_t phase_start_ms;
|
uint32_t phase_start_ms;
|
||||||
uint32_t remaining_delay_time_ms;
|
uint32_t remaining_delay_time_ms;
|
||||||
uint32_t remaining_transition_time_ms;
|
uint32_t remaining_transition_time_ms;
|
||||||
|
|
||||||
// to send events and/or publish changes
|
// to send events and/or publish changes
|
||||||
mesh_model_t * mesh_model;
|
mesh_model_t * mesh_model;
|
||||||
|
|
||||||
|
// to execute transition
|
||||||
|
void (* transition_callback)(struct mesh_transition * transition, transition_event_t event, uint32_t current_timestamp);
|
||||||
|
|
||||||
|
} mesh_transition_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mesh_transition_t base_transition;
|
||||||
|
|
||||||
|
uint8_t current_value;
|
||||||
|
uint8_t target_value;
|
||||||
} mesh_transition_bool_t;
|
} mesh_transition_bool_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user