ble_mesh:example:Add command to test the function of duplicate exceptional list(v4.1)

This commit is contained in:
Yuan Hong Hui 2022-11-25 10:44:46 +08:00 committed by Jiang Jiang Jian
parent d1b3b6a577
commit 2fdc78b882
6 changed files with 107 additions and 16 deletions

View File

@ -175,7 +175,7 @@ int ble_mesh_node_statistics_init(uint16_t package_num)
ble_mesh_node_statistics.total_package_num = package_num;
if (ble_mesh_node_statistics.package_index == NULL) {
ESP_LOGE(TAG, " %s, %d malloc fail\n", __func__, __LINE__);
return 1;
return ESP_ERR_NO_MEM;
}
ble_mesh_node_statistics.package_num = 0;
@ -335,12 +335,13 @@ int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test
test_perf_statistics.time = malloc(test_num * sizeof(uint16_t));
if (test_perf_statistics.time == NULL) {
ESP_LOGE(TAG, " %s %d, malloc fail\n", __func__, __LINE__);
return 1;
return ESP_ERR_NO_MEM;
}
test_perf_statistics.package_index = malloc(test_num * sizeof(uint16_t));
if (test_perf_statistics.package_index == NULL) {
ESP_LOGE(TAG, " %s %d, malloc fail\n", __func__, __LINE__);
return ESP_ERR_NO_MEM;
}
for (i = 0; i < test_num; i++) {
test_perf_statistics.time[i] = 0;

View File

@ -24,6 +24,11 @@
#include "esp_console.h"
#include "argtable3/argtable3.h"
#ifndef MAC2STR
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
#endif
bool str_2_mac(uint8_t *str, uint8_t *dest);
int hexstr_2_bin(const char *hex, uint8_t *buf, uint32_t len);
int get_value_string(char *value_in, char *buf);

View File

@ -148,7 +148,7 @@ int ble_mesh_test_performance_client_model(int argc, char **argv)
profile_data->model = model;
if (profile_data == NULL) {
ESP_LOGE(TAG, " %s, %d malloc fail\n", __func__, __LINE__);
return 1;
return ESP_ERR_NO_MEM;
}
arg_int_to_value(test_perf_client_model.playload_byte, profile_data->length, "length");

View File

@ -28,6 +28,10 @@
#include "ble_mesh_console_decl.h"
#include "ble_mesh_model.h"
/* We include the internal header file mesh_bearer_adapt.h here
just for some specific test purpose, which is not recommended for the other applications. */
#include "mesh_bearer_adapt.h"
typedef struct {
struct arg_str *static_val;
struct arg_int *static_val_len;
@ -153,6 +157,16 @@ typedef struct {
} ble_mesh_provisioner_heartbeat_t;
static ble_mesh_provisioner_heartbeat_t heartbeat;
#ifdef CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
typedef struct {
struct arg_str *action_type;
struct arg_int *type;
struct arg_str *info;
struct arg_end *end;
} ble_mesh_exceptional_list_t;
static ble_mesh_exceptional_list_t exceptional_list_test;
#endif
extern void ble_mesh_generic_onoff_client_model_cb(esp_ble_mesh_generic_client_cb_event_t event,
esp_ble_mesh_generic_client_cb_param_t *param);
extern void ble_mesh_configuration_client_model_cb(esp_ble_mesh_cfg_client_cb_event_t event,
@ -308,12 +322,12 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
break;
#if (CONFIG_BLE_MESH_PROVISIONER)
case ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT:
ESP_LOGD(TAG, "Provisioner recv unprovisioned device beacon:");
ESP_LOG_BUFFER_HEX("Device UUID", param->provisioner_recv_unprov_adv_pkt.dev_uuid, 16);
ESP_LOG_BUFFER_HEX("Address", param->provisioner_recv_unprov_adv_pkt.addr, 6);
ESP_LOGD(TAG, "Address type 0x%x, oob_info 0x%04x, adv_type 0x%x, bearer 0x%x",
param->provisioner_recv_unprov_adv_pkt.addr_type, param->provisioner_recv_unprov_adv_pkt.oob_info,
param->provisioner_recv_unprov_adv_pkt.adv_type, param->provisioner_recv_unprov_adv_pkt.bearer);
ESP_LOGI(TAG, "Provisioner:%s,"MACSTR",0x%x,0x%04x,0x%x",
param->provisioner_recv_unprov_adv_pkt.bearer == ESP_BLE_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT",
MAC2STR(param->provisioner_recv_unprov_adv_pkt.addr),
param->provisioner_recv_unprov_adv_pkt.addr_type,
param->provisioner_recv_unprov_adv_pkt.oob_info,
param->provisioner_recv_unprov_adv_pkt.adv_type);
break;
case ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT:
ESP_LOGI(TAG, "Provisioner:LinkOpen,OK,%d", param->provisioner_prov_link_open.bearer);
@ -545,6 +559,7 @@ static int ble_mesh_load_oob(int argc, char **argv)
static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
return ESP_ERR_NO_MEM;
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.static_val = static_val;
@ -562,6 +577,7 @@ static int ble_mesh_load_oob(int argc, char **argv)
static_val = malloc(oob.static_val_len->ival[0] + 1);
if (static_val == NULL) {
ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
return ESP_ERR_NO_MEM;
}
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
prov.prov_static_oob_val = static_val;
@ -601,6 +617,7 @@ int ble_mesh_init(int argc, char **argv)
device_uuid = malloc((ESP_BLE_MESH_OCTET16_LEN + 1) * sizeof(uint8_t));
if (device_uuid == NULL) {
ESP_LOGE(TAG, "ble mesh malloc failed, %d\n", __LINE__);
return ESP_ERR_NO_MEM;
}
err = get_value_string((char *)component.dev_uuid->sval[0], (char *)device_uuid);
if (err == ESP_OK) {
@ -690,6 +707,53 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
return err;
}
#ifdef CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
int ble_mesh_exceptional_list_test(int argc, char **argv)
{
esp_err_t err = ESP_FAIL;
uint32_t type = BLE_MESH_EXCEP_INFO_MESH_BEACON;
uint8_t *info = NULL;
int nerrors = arg_parse(argc, argv, (void **) &exceptional_list_test);
if (nerrors != 0) {
arg_print_errors(stderr, exceptional_list_test.end, argv[0]);
return 1;
}
arg_int_to_value(exceptional_list_test.type, type, "device info type");
if (exceptional_list_test.info->count != 0) {
info = malloc((BD_ADDR_LEN + 1) * sizeof(uint8_t));
if (info == NULL) {
ESP_LOGE(TAG, "ble mesh malloc failed, %d\n", __LINE__);
return ESP_ERR_NO_MEM;
} else {
get_value_string((char *)exceptional_list_test.info->sval[0], (char *)info);
}
}
if (strcmp(exceptional_list_test.action_type->sval[0], "add") == 0) {
err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, type, info);
} else if (strcmp(exceptional_list_test.action_type->sval[0], "remove") == 0) {
err = bt_mesh_update_exceptional_list( BLE_MESH_EXCEP_LIST_REMOVE, type, info);
} else if (strcmp(exceptional_list_test.action_type->sval[0], "clean") == 0) {
err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_CLEAN, type, NULL);
}
if (err == ESP_OK) {
ESP_LOGI(TAG, "Bm:UpdateExcepList,OK\n");
} else {
ESP_LOGE(TAG, "Bm:UpdateExcepList,Fail\n");
}
if (info != NULL) {
free(info);
}
return err;
}
#endif
int ble_mesh_deinit(int argc, char **argv)
{
int err;
@ -1228,5 +1292,21 @@ void ble_mesh_register_cmd(void)
};
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_heartbeat_cmd));
#ifdef CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
exceptional_list_test.action_type = arg_str1("z", NULL, "<action type>", "action type");
exceptional_list_test.type = arg_int1("t", NULL, "<type>", "device info type");
exceptional_list_test.info = arg_str0("a", NULL, "<info>", "info");
exceptional_list_test.end = arg_end(1);
const esp_console_cmd_t ble_mesh_exceptional_list_test_cmd = {
.command = "bmel",
.help = "ble mesh: duplicate scan exceptional list test",
.hint = NULL,
.func = &ble_mesh_exceptional_list_test,
.argtable = &exceptional_list_test,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&ble_mesh_exceptional_list_test_cmd));
#endif
init_transactions();
}

View File

@ -55,7 +55,12 @@ int ble_mesh_module_publish_message(int argc, char **argv)
}
data = malloc(strlen(msg_publish.data->sval[0]));
if (data == NULL) {
ESP_LOGE(TAG, "ble mesh malloc failed, %d\n", __LINE__);
return ESP_ERR_NO_MEM;
} else {
get_value_string((char *)msg_publish.data->sval[0], (char *) data);
}
arg_int_to_value(msg_publish.role, device_role, "device role");
@ -90,8 +95,11 @@ int ble_mesh_module_publish_message(int argc, char **argv)
if (msg_publish.data->count != 0) {
length = strlen(msg_publish.data->sval[0]);
data = malloc((length + 1) * sizeof(uint8_t));
if (data != NULL) {
err = get_value_string((char *)msg_publish.data->sval[0], (char *) data);
if (data == NULL) {
ESP_LOGE(TAG, "ble mesh malloc failed, %d\n", __LINE__);
return ESP_ERR_NO_MEM;
} else {
get_value_string((char *)msg_publish.data->sval[0], (char *) data);
}
}

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "string.h"
#include "esp_console.h"
#include "ble_mesh_console_lib.h"
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#include "esp_bt_device.h"
@ -23,9 +23,6 @@
#include "host/ble_hs.h"
#endif
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
void register_ble_address(void);
void register_bluetooth(void)