From 8d6bf5eb544edf1d4ed9377d41142f11c83b1001 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 12 Jul 2019 16:27:33 +0200 Subject: [PATCH] mesh: extract mesh_node_setup_default_models --- test/mesh/mesh.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/test/mesh/mesh.c b/test/mesh/mesh.c index 7c0a207cb..9984f5256 100644 --- a/test/mesh/mesh.c +++ b/test/mesh/mesh.c @@ -75,10 +75,6 @@ static void mesh_pts_dump_mesh_options(void); static btstack_packet_callback_registration_t hci_event_callback_registration; static int provisioned; -static mesh_configuration_server_model_context_t mesh_configuration_server_model_context; - -static mesh_model_t mesh_configuration_server_model; -static mesh_model_t mesh_health_server_model; static mesh_model_t mesh_vendor_model; static mesh_model_t mesh_generic_on_off_server_model; @@ -605,6 +601,23 @@ static void stdin_process(char cmd){ } } +static mesh_model_t mesh_configuration_server_model; +static mesh_model_t mesh_health_server_model; + +static mesh_configuration_server_model_context_t mesh_configuration_server_model_context; + +static void mesh_node_setup_default_models(void){ + // configure Config Server + mesh_configuration_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER); + mesh_configuration_server_model.model_data = &mesh_configuration_server_model_context; + mesh_configuration_server_model.operations = mesh_configuration_server_get_operations(); + mesh_element_add_model(mesh_node_get_primary_element(), &mesh_configuration_server_model); + + // Config Health Server + mesh_health_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_HEALTH_SERVER); + mesh_element_add_model(mesh_node_get_primary_element(), &mesh_health_server_model); +} + int btstack_main(void); int btstack_main(void) { @@ -674,29 +687,21 @@ int btstack_main(void) // Node Configuration mesh_node_init(); + // Setup default models on primary element + mesh_node_setup_default_models(); + // Loc - bottom - https://www.bluetooth.com/specifications/assigned-numbers/gatt-namespace-descriptors mesh_node_set_element_location(mesh_node_get_primary_element(), 0x103); - // Setup models - mesh_configuration_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER); - mesh_model_reset_appkeys(&mesh_configuration_server_model); - mesh_configuration_server_model.model_data = &mesh_configuration_server_model_context; - mesh_configuration_server_model.operations = mesh_configuration_server_get_operations(); - mesh_element_add_model(mesh_node_get_primary_element(), &mesh_configuration_server_model); - - mesh_health_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_HEALTH_SERVER); - mesh_model_reset_appkeys(&mesh_health_server_model); - mesh_element_add_model(mesh_node_get_primary_element(), &mesh_health_server_model); - + // Setup Generic On/Off model mesh_generic_on_off_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_GENERIC_ON_OFF_SERVER); - mesh_model_reset_appkeys(&mesh_generic_on_off_server_model); mesh_generic_on_off_server_model.operations = mesh_generic_on_off_server_get_operations(); - mesh_element_add_model(mesh_node_get_primary_element(), &mesh_generic_on_off_server_model); mesh_generic_on_off_server_model.model_data = (void *) &mesh_generic_on_off_state; mesh_generic_on_off_server_register_packet_handler(&mesh_generic_on_off_server_model, &mesh_state_update_message_handler); + mesh_element_add_model(mesh_node_get_primary_element(), &mesh_generic_on_off_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); - mesh_model_reset_appkeys(&mesh_vendor_model); mesh_element_add_model(mesh_node_get_primary_element(), &mesh_vendor_model); // Enable PROXY