Skip to content
Permalink
Browse files

mesh: add generic level server to test/mesh, use bstack_assert, fix t…

…ime calculation
  • Loading branch information
mringwal committed Nov 12, 2019
1 parent 6445d71 commit 7ee2bdaeeff081021c24ef8edce9c16e8de22f2d
Showing with 40 additions and 48 deletions.
  1. +2 −0 src/mesh/mesh_foundation.h
  2. +25 −47 src/mesh/mesh_generic_level_server.c
  3. +13 −1 test/mesh/mesh_pts.c
@@ -57,6 +57,8 @@ extern "C"
#define MESH_SIG_MODEL_ID_HEALTH_CLIENT 0x0003u
#define MESH_SIG_MODEL_ID_GENERIC_ON_OFF_SERVER 0x1000u
#define MESH_SIG_MODEL_ID_GENERIC_ON_OFF_CLIENT 0x1001u
#define MESH_SIG_MODEL_ID_GENERIC_LEVEL_SERVER 0x1002u
#define MESH_SIG_MODEL_ID_GENERIC_LEVEL_CLIENT 0x1003u

// Foundation Model Operations
#define MESH_FOUNDATION_OPERATION_APPKEY_ADD 0x00
@@ -140,6 +140,7 @@ static void mesh_server_transition_step(mesh_transition_t * base_transition, tra
time_step_ms = current_timestamp - transition->base_transition.phase_start_ms;
if (transition->base_transition.remaining_delay_time_ms >= time_step_ms){
transition->base_transition.remaining_delay_time_ms -= time_step_ms;
transition->base_transition.phase_start_ms = current_timestamp;
} else {
transition->base_transition.remaining_delay_time_ms = 0;
mesh_server_transition_state_update(transition, current_timestamp);
@@ -151,6 +152,7 @@ static void mesh_server_transition_step(mesh_transition_t * base_transition, tra
if (transition->base_transition.remaining_transition_time_ms >= time_step_ms){
transition->base_transition.remaining_transition_time_ms -= time_step_ms;
mesh_server_transition_state_update_stepwise_value(transition);
transition->base_transition.phase_start_ms = current_timestamp;
} else {
transition->base_transition.remaining_transition_time_ms = 0;
mesh_server_transition_state_update(transition, current_timestamp);
@@ -188,14 +190,8 @@ static void mesh_server_transition_setup_transition_or_instantaneous_update_int1
// Generic Level State

void mesh_generic_level_server_register_packet_handler(mesh_model_t *generic_level_server_model, btstack_packet_handler_t transition_events_packet_handler){
if (transition_events_packet_handler == NULL){
log_error("mesh_generic_level_server_register_packet_handler called with NULL callback");
return;
}
if (generic_level_server_model == NULL){
log_error("mesh_generic_level_server_register_packet_handler called with NULL generic_level_server_model");
return;
}
btstack_assert(generic_level_server_model != NULL);
btstack_assert(transition_events_packet_handler != NULL);
generic_level_server_model->model_packet_handler = transition_events_packet_handler;
}

@@ -208,14 +204,8 @@ const mesh_access_message_t mesh_generic_level_status_instantaneous = {
};

static mesh_pdu_t * mesh_generic_level_status_message(mesh_model_t *generic_level_server_model){
if (generic_level_server_model->element == NULL){
log_error("generic_level_server_model->element == NULL");
}

mesh_generic_level_state_t * state = (mesh_generic_level_state_t *) generic_level_server_model->model_data;
if (state == NULL){
log_error("generic_level_status == NULL");
}
btstack_assert(state != NULL);

// setup message
mesh_transport_pdu_t * transport_pdu = NULL;
@@ -229,14 +219,8 @@ static mesh_pdu_t * mesh_generic_level_status_message(mesh_model_t *generic_leve
}

static void generic_level_handle_set_target_level_message(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
if (mesh_model == NULL){
log_error("mesh_model == NULL");
}
mesh_generic_level_state_t * generic_level_server_state = (mesh_generic_level_state_t *)mesh_model->model_data;

if (generic_level_server_state == NULL){
log_error("generic_level_server_state == NULL");
}
btstack_assert(generic_level_server_state != NULL);

mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
@@ -279,15 +263,9 @@ static void generic_level_handle_set_target_level_message(mesh_model_t *mesh_mod
}

static void generic_level_handle_set_move_message(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
if (mesh_model == NULL){
log_error("mesh_model == NULL");
}
mesh_generic_level_state_t * generic_level_server_state = (mesh_generic_level_state_t *)mesh_model->model_data;

if (generic_level_server_state == NULL){
log_error("generic_level_server_state == NULL");
}

btstack_assert(generic_level_server_state != NULL);

mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
int16_t increment_value = (int16_t)mesh_access_parser_get_u16(&parser);
@@ -328,15 +306,9 @@ static void generic_level_handle_set_move_message(mesh_model_t *mesh_model, mesh
}

static void generic_level_handle_set_delta_message(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
if (mesh_model == NULL){
log_error("mesh_model == NULL");
}
mesh_generic_level_state_t * generic_level_server_state = (mesh_generic_level_state_t *)mesh_model->model_data;

if (generic_level_server_state == NULL){
log_error("generic_level_server_state == NULL");
}

btstack_assert(generic_level_server_state != NULL);

mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
int16_t delta_value = (int16_t) mesh_access_parser_get_u16(&parser);
@@ -380,51 +352,57 @@ static void generic_level_handle_set_delta_message(mesh_model_t *mesh_model, mes
}
}


static void generic_level_get_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
mesh_transport_pdu_t * transport_pdu = (mesh_transport_pdu_t *) mesh_generic_level_status_message(generic_level_server_model);
if (!transport_pdu) return;
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
if (transport_pdu != NULL) {
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
}
mesh_access_message_processed(pdu);
}

static void generic_level_set_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_target_level_message(generic_level_server_model, pdu);

mesh_transport_pdu_t * transport_pdu = (mesh_transport_pdu_t *) mesh_generic_level_status_message(generic_level_server_model);
if (!transport_pdu) return;
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
if (transport_pdu != NULL) {
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
}
mesh_access_message_processed(pdu);
}

static void generic_level_set_unacknowledged_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_target_level_message(generic_level_server_model, pdu);
mesh_access_message_processed(pdu);
}

static void generic_delta_set_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_delta_message(generic_level_server_model, pdu);

mesh_transport_pdu_t * transport_pdu = (mesh_transport_pdu_t *) mesh_generic_level_status_message(generic_level_server_model);
if (!transport_pdu) return;
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
if (transport_pdu != NULL) {
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
}
mesh_access_message_processed(pdu);
}

static void generic_delta_set_unacknowledged_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_delta_message(generic_level_server_model, pdu);
mesh_access_message_processed(pdu);
}

static void generic_move_get_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_move_message(generic_level_server_model, pdu);

mesh_transport_pdu_t * transport_pdu = (mesh_transport_pdu_t *) mesh_generic_level_status_message(generic_level_server_model);
if (!transport_pdu) return;
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
if (transport_pdu != NULL) {
generic_server_send_message(mesh_access_get_element_address(generic_level_server_model), mesh_pdu_src(pdu), mesh_pdu_netkey_index(pdu), mesh_pdu_appkey_index(pdu), (mesh_pdu_t *) transport_pdu);
}
mesh_access_message_processed(pdu);
}

static void generic_move_set_unacknowledged_handler(mesh_model_t *generic_level_server_model, mesh_pdu_t * pdu){
generic_level_handle_set_move_message(generic_level_server_model, pdu);
mesh_access_message_processed(pdu);
}

// Generic On Off Message
@@ -59,6 +59,11 @@ static mesh_model_t mesh_vendor_model;

static mesh_model_t mesh_generic_on_off_server_model;
static mesh_generic_on_off_state_t mesh_generic_on_off_state;
static mesh_publication_model_t generic_on_off_server_publication;

static mesh_model_t mesh_generic_level_server_model;
static mesh_generic_level_state_t mesh_generic_level_state;
static mesh_publication_model_t generic_level_server_publication;

static char gap_name_buffer[30];
static char gap_name_prefix[] = "Mesh ";
@@ -87,7 +92,6 @@ static int ui_chars_for_pin;
static uint8_t ui_pin[17];
static int ui_pin_offset;

static mesh_publication_model_t generic_on_off_server_publication;

static mesh_health_fault_t health_fault;

@@ -634,6 +638,14 @@ int btstack_main(void)
mesh_generic_on_off_server_register_packet_handler(&mesh_generic_on_off_server_model, &mesh_state_update_message_handler);
mesh_generic_on_off_server_set_publication_model(&mesh_generic_on_off_server_model, &generic_on_off_server_publication);
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_generic_on_off_server_model);

// Setup Generic On/Off model
mesh_generic_level_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_GENERIC_LEVEL_SERVER);
mesh_generic_level_server_model.operations = mesh_generic_level_server_get_operations();
mesh_generic_level_server_model.model_data = (void *) &mesh_generic_level_state;
mesh_generic_level_server_register_packet_handler(&mesh_generic_level_server_model, &mesh_state_update_message_handler);
mesh_generic_level_server_set_publication_model(&mesh_generic_level_server_model, &generic_level_server_publication);
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_generic_level_server_model);

// Setup our custom model
mesh_vendor_model.model_identifier = mesh_model_get_model_identifier(BLUETOOTH_COMPANY_ID_BLUEKITCHEN_GMBH, MESH_BLUEKITCHEN_MODEL_ID_TEST_SERVER);

0 comments on commit 7ee2bda

Please sign in to comment.
You can’t perform that action at this time.