mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-23 11:43:24 +00:00
mesh/health_server: update period_divisor of publication model on Health Fast Period Divisor change
This commit is contained in:
parent
45f04363db
commit
b7c449ec05
@ -73,6 +73,28 @@ static mesh_health_fault_t * mesh_health_server_fault_for_company_id(mesh_model_
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
static mesh_health_fault_t * mesh_health_server_active_fault(mesh_model_t *mesh_model){
|
||||||
|
mesh_health_state_t * state = (mesh_health_state_t *) mesh_model->model_data;
|
||||||
|
btstack_linked_list_iterator_t it;
|
||||||
|
btstack_linked_list_iterator_init(&it, &state->faults);
|
||||||
|
while (btstack_linked_list_iterator_has_next(&it)){
|
||||||
|
mesh_health_fault_t * fault = (mesh_health_fault_t *) btstack_linked_list_iterator_next(&it);
|
||||||
|
if (fault->num_current_faults > 0) return fault;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mesh_health_server_update_publication_model_period_divisor(mesh_model_t * mesh_model){
|
||||||
|
if (mesh_model->publication_model == NULL) return;
|
||||||
|
mesh_health_fault_t * fault = mesh_health_server_active_fault(mesh_model);
|
||||||
|
mesh_health_state_t * health_state = (mesh_health_state_t *) mesh_model->model_data;
|
||||||
|
if (fault == NULL){
|
||||||
|
mesh_model->publication_model->period_divisor = health_state->fast_period_divisor;
|
||||||
|
} else {
|
||||||
|
mesh_model->publication_model->period_divisor = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Health State
|
// Health State
|
||||||
const mesh_access_message_t mesh_foundation_health_period_status = {
|
const mesh_access_message_t mesh_foundation_health_period_status = {
|
||||||
@ -230,11 +252,9 @@ static void process_message_period_set(mesh_model_t *mesh_model, mesh_pdu_t * pd
|
|||||||
uint8_t fast_period_divisor = mesh_access_parser_get_u8(&parser);
|
uint8_t fast_period_divisor = mesh_access_parser_get_u8(&parser);
|
||||||
|
|
||||||
mesh_health_state_t * state = (mesh_health_state_t *) mesh_model->model_data;
|
mesh_health_state_t * state = (mesh_health_state_t *) mesh_model->model_data;
|
||||||
|
|
||||||
if (state->fast_period_divisor != fast_period_divisor){
|
|
||||||
state->fast_period_divisor = fast_period_divisor;
|
state->fast_period_divisor = fast_period_divisor;
|
||||||
// TODO: update model publication
|
|
||||||
}
|
mesh_health_server_update_publication_model_period_divisor(mesh_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void health_period_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
|
static void health_period_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
|
||||||
@ -294,21 +314,11 @@ static void health_attention_set_unacknowledged_handler(mesh_model_t *mesh_model
|
|||||||
}
|
}
|
||||||
|
|
||||||
static mesh_pdu_t * mesh_health_server_publish_state_fn(struct mesh_model * mesh_model){
|
static mesh_pdu_t * mesh_health_server_publish_state_fn(struct mesh_model * mesh_model){
|
||||||
// iterate over fault states and yield if fault state with current state that has fault registered
|
|
||||||
mesh_health_state_t * state = (mesh_health_state_t *) mesh_model->model_data;
|
|
||||||
btstack_linked_list_iterator_t it;
|
|
||||||
btstack_linked_list_iterator_init(&it, &state->faults);
|
|
||||||
uint16_t company_id = mesh_node_get_company_id();
|
uint16_t company_id = mesh_node_get_company_id();
|
||||||
bool active_fault = false;
|
mesh_health_fault_t * fault = mesh_health_server_active_fault(mesh_model);
|
||||||
while (btstack_linked_list_iterator_has_next(&it)){
|
if (fault != NULL){
|
||||||
mesh_health_fault_t * fault = (mesh_health_fault_t *) btstack_linked_list_iterator_next(&it);
|
|
||||||
if (fault->num_current_faults > 0){
|
|
||||||
active_fault = true;
|
|
||||||
company_id = fault->company_id;
|
company_id = fault->company_id;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// create current status
|
// create current status
|
||||||
return health_fault_status(mesh_model, MESH_FOUNDATION_OPERATION_HEALTH_CURRENT_STATUS, company_id, false);
|
return health_fault_status(mesh_model, MESH_FOUNDATION_OPERATION_HEALTH_CURRENT_STATUS, company_id, false);
|
||||||
}
|
}
|
||||||
@ -377,13 +387,8 @@ void mesh_health_server_set_fault(mesh_model_t *mesh_model, uint16_t company_id,
|
|||||||
fault->num_current_faults++;
|
fault->num_current_faults++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh_model->publication_model == NULL) return;
|
// update publication model
|
||||||
|
mesh_health_server_update_publication_model_period_divisor(mesh_model);
|
||||||
// update model publication period
|
|
||||||
if (add_current_fault && (fault->num_current_faults == 1)){
|
|
||||||
mesh_health_state_t * health_state = (mesh_health_state_t *) mesh_model->model_data;
|
|
||||||
mesh_model->publication_model->period_divisor = health_state->fast_period_divisor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mesh_health_server_clear_fault(mesh_model_t *mesh_model, uint16_t company_id, uint8_t fault_code){
|
void mesh_health_server_clear_fault(mesh_model_t *mesh_model, uint16_t company_id, uint8_t fault_code){
|
||||||
@ -409,11 +414,8 @@ void mesh_health_server_clear_fault(mesh_model_t *mesh_model, uint16_t company_i
|
|||||||
fault->num_current_faults--;
|
fault->num_current_faults--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update model publication period
|
// update publication model
|
||||||
if (shift_faults && (fault->num_current_faults == 0)){
|
mesh_health_server_update_publication_model_period_divisor(mesh_model);
|
||||||
mesh_health_state_t * health_state = (mesh_health_state_t *) mesh_model->model_data;
|
|
||||||
mesh_model->publication_model->period_divisor = health_state->fast_period_divisor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mesh_health_server_set_publication_model(mesh_model_t * mesh_model, mesh_publication_model_t * publication_model){
|
void mesh_health_server_set_publication_model(mesh_model_t * mesh_model, mesh_publication_model_t * publication_model){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user