mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/ble_mesh_console_memory_leak_test_forv4.2' into 'release/v4.2'
ble_mesh:example:fix memory leak(v4.2) See merge request espressif/esp-idf!20040
This commit is contained in:
commit
713d058c61
@ -86,7 +86,7 @@ esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id)
|
||||
return comp;
|
||||
}
|
||||
|
||||
void ble_mesh_node_init(void)
|
||||
int ble_mesh_init_node_prestore_params(void)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
@ -94,11 +94,14 @@ void ble_mesh_node_init(void)
|
||||
ble_mesh_node_prestore_params[i].net_idx = ESP_BLE_MESH_KEY_UNUSED;
|
||||
ble_mesh_node_prestore_params[i].unicast_addr = ESP_BLE_MESH_ADDR_UNASSIGNED;
|
||||
}
|
||||
|
||||
ble_mesh_node_sema = xSemaphoreCreateMutex();
|
||||
if (!ble_mesh_node_sema) {
|
||||
ESP_LOGE(TAG, "%s init fail, mesh node semaphore create fail", __func__);
|
||||
if(ble_mesh_node_sema == NULL) {
|
||||
ble_mesh_node_sema = xSemaphoreCreateMutex();
|
||||
if (!ble_mesh_node_sema) {
|
||||
ESP_LOGE(TAG, "%s init fail, mesh node semaphore create fail", __func__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr)
|
||||
@ -114,6 +117,14 @@ void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_a
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
}
|
||||
|
||||
void ble_mesh_deinit_node_prestore_params(void)
|
||||
{
|
||||
if (ble_mesh_node_sema != NULL) {
|
||||
vSemaphoreDelete(ble_mesh_node_sema);
|
||||
ble_mesh_node_sema = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ble_mesh_node_statistics_get(void)
|
||||
{
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
|
||||
|
@ -116,7 +116,8 @@ extern SemaphoreHandle_t ble_mesh_node_sema;
|
||||
} \
|
||||
}while(0) \
|
||||
|
||||
void ble_mesh_node_init(void);
|
||||
int ble_mesh_init_node_prestore_params(void);
|
||||
void ble_mesh_deinit_node_prestore_params(void);
|
||||
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr);
|
||||
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id);
|
||||
void ble_mesh_node_statistics_get(void);
|
||||
|
@ -69,6 +69,7 @@ void app_main(void)
|
||||
repl_config.prompt = "esp32>";
|
||||
|
||||
// init console REPL environment
|
||||
repl_config.max_history_len = 1;
|
||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
||||
|
||||
/* Register commands */
|
||||
|
@ -92,7 +92,7 @@ ble_mesh_node_status node_status = {
|
||||
.previous = 0x0,
|
||||
.current = 0x0,
|
||||
};
|
||||
SemaphoreHandle_t ble_mesh_node_sema;
|
||||
SemaphoreHandle_t ble_mesh_node_sema = NULL;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *add_del;
|
||||
@ -174,7 +174,6 @@ void ble_mesh_register_mesh_node(void)
|
||||
int ble_mesh_register_cb(int argc, char** argv)
|
||||
{
|
||||
ESP_LOGD(TAG, "enter %s\n", __func__);
|
||||
ble_mesh_node_init();
|
||||
esp_ble_mesh_register_prov_callback(ble_mesh_prov_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(ble_mesh_model_cb);
|
||||
esp_ble_mesh_register_generic_server_callback(ble_mesh_generic_server_model_cb);
|
||||
@ -258,6 +257,9 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
|
||||
case ESP_BLE_MESH_PROV_REGISTER_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Bm:Init");
|
||||
break;
|
||||
case ESP_BLE_MESH_DEINIT_MESH_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->deinit_mesh_comp.err_code, "Bm:DeInit");
|
||||
break;
|
||||
case ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->node_prov_enable_comp.err_code, "Node:EnBearer");
|
||||
break;
|
||||
@ -414,7 +416,7 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c
|
||||
outcome = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
|
||||
sizeof(status), &status);
|
||||
if (outcome != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Node:SendMsg,Fal");
|
||||
ESP_LOGE(TAG, "Node:SendMsg,Fail");
|
||||
}
|
||||
} else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET) {
|
||||
ble_mesh_node_set_state(param->model_operation.msg[0]);
|
||||
@ -422,7 +424,7 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c
|
||||
outcome = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
|
||||
sizeof(status), param->model_operation.msg);
|
||||
if (outcome != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Node:SendMsg,Fal");
|
||||
ESP_LOGE(TAG, "Node:SendMsg,Fail");
|
||||
}
|
||||
} else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK) {
|
||||
ble_mesh_node_set_state(param->model_operation.msg[0]);
|
||||
@ -586,6 +588,12 @@ int ble_mesh_init(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = ble_mesh_init_node_prestore_params();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Bm:NodeInitPreParam,Fail\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "enter %s, module %x\n", __func__, component.model_type->ival[0]);
|
||||
local_component = ble_mesh_get_component(component.model_type->ival[0]);
|
||||
|
||||
@ -608,10 +616,6 @@ int ble_mesh_init(int argc, char **argv)
|
||||
}
|
||||
|
||||
err = esp_ble_mesh_init(&prov, local_component);
|
||||
if (err) {
|
||||
ESP_LOGI(TAG, "Bm:Init,OK\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
free(device_uuid);
|
||||
ESP_LOGD(TAG, "exit %s\n", __func__);
|
||||
@ -698,17 +702,13 @@ int ble_mesh_deinit(int argc, char **argv)
|
||||
arg_print_errors(stderr, deinit.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ble_mesh_deinit_node_prestore_params();
|
||||
|
||||
if (deinit.action->count != 0) {
|
||||
param.erase_flash = deinit.action->ival[0];
|
||||
err = esp_ble_mesh_deinit(¶m);
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Bm:DeInit,OK,%d,\n", deinit.action->ival[0]);
|
||||
}
|
||||
else{
|
||||
ESP_LOGI(TAG, "Bm:DeInit,Fail\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
ESP_LOGD(TAG, "exit %s\n", __func__);
|
||||
|
Loading…
Reference in New Issue
Block a user