mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/pro_recv_hb' into 'master'
provisioner receive heartbeat message See merge request espressif/esp-idf!14680
This commit is contained in:
commit
ce4a4be37f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -12,6 +12,8 @@ typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_str *set_state;
|
||||
struct arg_int *opcode;
|
||||
struct arg_int *count;
|
||||
struct arg_int *feature;
|
||||
struct arg_int *unicast_address;
|
||||
struct arg_int *appkey_index;
|
||||
struct arg_int *mod_id;
|
||||
@ -210,6 +212,7 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
esp_ble_mesh_cfg_default_ttl_set_t ttl_set;
|
||||
esp_ble_mesh_cfg_gatt_proxy_set_t proxy_set;
|
||||
esp_ble_mesh_cfg_app_key_add_t app_key_add;
|
||||
esp_ble_mesh_cfg_heartbeat_pub_set_t heartbeat_pub_set;
|
||||
esp_ble_mesh_cfg_model_pub_set_t mod_pub_set = {
|
||||
.company_id = 0xFFFF,
|
||||
.cred_flag = false,
|
||||
@ -253,6 +256,7 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
if (configuration_client_model_operation.net_idx->count != 0) {
|
||||
client_common.ctx.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
app_key_add.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
heartbeat_pub_set.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.unicast_address->count != 0) {
|
||||
@ -275,12 +279,14 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
ttl_set.ttl = configuration_client_model_operation.value->ival[0];
|
||||
proxy_set.gatt_proxy = configuration_client_model_operation.value->ival[0];
|
||||
mod_pub_set.publish_ttl = configuration_client_model_operation.value->ival[0];
|
||||
heartbeat_pub_set.ttl = configuration_client_model_operation.value->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.addr->count != 0) {
|
||||
mod_sub_del.sub_addr = configuration_client_model_operation.addr->ival[0];
|
||||
mod_sub_add.sub_addr = configuration_client_model_operation.addr->ival[0];
|
||||
mod_pub_set.publish_addr = configuration_client_model_operation.addr->ival[0];
|
||||
heartbeat_pub_set.dst = configuration_client_model_operation.addr->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.mod_id->count != 0) {
|
||||
@ -294,6 +300,7 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
if (configuration_client_model_operation.relay_statue->count != 0) {
|
||||
relay_set.relay = configuration_client_model_operation.relay_statue->ival[0];
|
||||
mod_pub_set.publish_period = configuration_client_model_operation.relay_statue->ival[0];
|
||||
heartbeat_pub_set.period = configuration_client_model_operation.relay_statue->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.relay_transmit->count != 0) {
|
||||
@ -308,6 +315,14 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
mod_pub_set.company_id = configuration_client_model_operation.cid->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.count->count != 0) {
|
||||
heartbeat_pub_set.count = configuration_client_model_operation.count->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.feature->count != 0) {
|
||||
heartbeat_pub_set.feature = configuration_client_model_operation.feature->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.action_type->count != 0) {
|
||||
if (strcmp(configuration_client_model_operation.action_type->sval[0], "get") == 0) {
|
||||
err = esp_ble_mesh_config_client_get_state(&client_common, &get_state);
|
||||
@ -338,6 +353,8 @@ int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&mod_pub_set);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "reset") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, NULL);
|
||||
}else if(strcmp(configuration_client_model_operation.set_state->sval[0], "hbpub") == 0){
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&heartbeat_pub_set);
|
||||
}
|
||||
}
|
||||
} else if (strcmp(configuration_client_model_operation.action_type->sval[0], "reg") == 0) {
|
||||
@ -369,6 +386,8 @@ void ble_mesh_register_configuration_client_model_command(void)
|
||||
configuration_client_model_operation.value = arg_int0("v", NULL, "<value>", "value");
|
||||
configuration_client_model_operation.addr = arg_int0("a", NULL, "<address>", "address");
|
||||
configuration_client_model_operation.mod_id = arg_int0("m", NULL, "<mod id>", "model id");
|
||||
configuration_client_model_operation.count = arg_int0("b", NULL, "<heartbeat count>", "heartbeat count");
|
||||
configuration_client_model_operation.feature = arg_int0("f", NULL, "<features>", "features");
|
||||
configuration_client_model_operation.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t client_stconfiguration_client_model_operationate_cmd = {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -16,15 +16,9 @@
|
||||
#include "ble_mesh_console_lib.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
#include "transaction.h"
|
||||
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#include "ble_mesh_console_decl.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *static_val;
|
||||
struct arg_int *static_val_len;
|
||||
@ -139,6 +133,17 @@ typedef struct {
|
||||
} ble_mesh_provisioner_bind_model_t;
|
||||
ble_mesh_provisioner_bind_model_t provisioner_local_bind;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_int *enable;
|
||||
struct arg_int *op;
|
||||
struct arg_int *hb_src;
|
||||
struct arg_int *hb_dst;
|
||||
struct arg_int *type;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_provisioner_heartbeat_t;
|
||||
static ble_mesh_provisioner_heartbeat_t heartbeat;
|
||||
|
||||
void ble_mesh_register_cmd(void);
|
||||
// Register callback function
|
||||
void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param);
|
||||
@ -332,6 +337,18 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
|
||||
case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->provisioner_add_net_key_comp.err_code, "Provisioner:NetKeyAdd");
|
||||
break;
|
||||
case ESP_BLE_MESH_PROVISIONER_ENABLE_HEARTBEAT_RECV_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->provisioner_enable_heartbeat_recv_comp.err_code, "Provisioner:EnHbRecv");
|
||||
break;
|
||||
case ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->provisioner_set_heartbeat_filter_type_comp.err_code, "Provisioner:SetHbFilterType");
|
||||
break;
|
||||
case ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_INFO_COMP_EVT:
|
||||
ble_mesh_callback_check_err_code(param->provisioner_set_heartbeat_filter_info_comp.err_code, "Provisioner:SetHbFilterInfo");
|
||||
break;
|
||||
case ESP_BLE_MESH_PROVISIONER_RECV_HEARTBEAT_MESSAGE_EVT:
|
||||
ESP_LOGI(TAG, "Provisioner:HbRecv,OK,%d,%d", param->provisioner_recv_heartbeat.hb_src, param->provisioner_recv_heartbeat.hb_dst);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
@ -585,6 +602,46 @@ int ble_mesh_init(int argc, char **argv)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ble_mesh_provisioner_heartbeat(int argc, char** argv)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
bool enable = 1;
|
||||
uint8_t type = 0;
|
||||
esp_ble_mesh_heartbeat_filter_info_t info;
|
||||
uint8_t op = 0;
|
||||
|
||||
ESP_LOGD(TAG, "enter %s\n", __func__);
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &heartbeat);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, heartbeat.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
arg_int_to_value(heartbeat.enable, enable, "enable/disable receiving heartbeat");
|
||||
arg_int_to_value(heartbeat.type, type, "heartbeat filter type");
|
||||
arg_int_to_value(heartbeat.hb_dst, info.hb_dst, "destination address");
|
||||
arg_int_to_value(heartbeat.hb_src, info.hb_src, "source address");
|
||||
arg_int_to_value(heartbeat.op, op, "op");
|
||||
|
||||
if (strcmp(heartbeat.action_type->sval[0], "recv") == 0){
|
||||
result = esp_ble_mesh_provisioner_recv_heartbeat(enable);
|
||||
}else if(strcmp(heartbeat.action_type->sval[0], "type") == 0){
|
||||
result = esp_ble_mesh_provisioner_set_heartbeat_filter_type(type);
|
||||
}else if(strcmp(heartbeat.action_type->sval[0], "info")== 0){
|
||||
result = esp_ble_mesh_provisioner_set_heartbeat_filter_info(op, &info);
|
||||
}
|
||||
|
||||
if(result == ESP_OK){
|
||||
ESP_LOGI(TAG, "provisioner:OK\n");
|
||||
}else{
|
||||
ESP_LOGE(TAG, "provisioner:ERROR\n");
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "exit %s\n", __func__);
|
||||
return result;
|
||||
}
|
||||
|
||||
int ble_mesh_node_enable_bearer(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err = 0;
|
||||
@ -722,13 +779,13 @@ int ble_mesh_node_enter_network_auto(int argc, char **argv)
|
||||
|
||||
ESP_LOGD(TAG, "enter %s\n", __func__);
|
||||
|
||||
err = get_value_string((char *)node_network_info.net_key->sval[0], (char *)info.net_key);
|
||||
err = get_value_string((char *)node_network_info.dev_key->sval[0], (char *)info.dev_key);
|
||||
err = get_value_string((char *)node_network_info.app_key->sval[0], (char *)info.app_key);
|
||||
arg_int_to_value(node_network_info.net_idx, info.net_idx, "network key index");
|
||||
arg_int_to_value(node_network_info.unicast_addr, info.unicast_addr, "unicast address");
|
||||
arg_int_to_value(node_network_info.app_idx, info.app_idx, "appkey index");
|
||||
arg_int_to_value(node_network_info.group_addr, info.group_addr, "group address");
|
||||
err = get_value_string((char *)node_network_info.net_key->sval[0], (char *)info.net_key);
|
||||
err = get_value_string((char *)node_network_info.dev_key->sval[0], (char *)info.dev_key);
|
||||
err = get_value_string((char *)node_network_info.app_key->sval[0], (char *)info.app_key);
|
||||
|
||||
err = bt_mesh_device_auto_enter_network(&info);
|
||||
if (err == ESP_OK) {
|
||||
@ -801,7 +858,7 @@ int ble_mesh_provisioner_add_key(int argc, char **argv)
|
||||
uint8_t key[16] = {0};
|
||||
esp_ble_mesh_prov_data_info_t info = {
|
||||
.net_idx = 1,
|
||||
.flag = NET_IDX_FLAG,
|
||||
.flag = PROV_DATA_NET_IDX_FLAG,
|
||||
};
|
||||
ESP_LOGD(TAG, " enter %s\n", __func__);
|
||||
|
||||
@ -1138,5 +1195,22 @@ void ble_mesh_register_cmd(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&node_network_info_cmd));
|
||||
|
||||
heartbeat.action_type = arg_str0("z", NULL, "<action type>", "action type");
|
||||
heartbeat.op = arg_int0("o", NULL, "<heartbeat filter>", "add or remove a heartbeat filter entry");
|
||||
heartbeat.hb_src = arg_int0("s", NULL, "<source address>", "Heartbeat source address");
|
||||
heartbeat.hb_dst = arg_int0("d", NULL, "<destination address>", "Heartbeat destination address");
|
||||
heartbeat.type = arg_int0("t", NULL, "<heartbeat filter>", "set the heartbeat filter type");
|
||||
heartbeat.enable = arg_int0("e", NULL, "<enable/disable>", "enable or disable receiving heartbeat messages");
|
||||
heartbeat.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t provisioner_heartbeat_cmd = {
|
||||
.command = "bmphb",
|
||||
.help = "ble mesh provisioner: support recv heartbeat",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_provisioner_heartbeat,
|
||||
.argtable = &heartbeat,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_heartbeat_cmd));
|
||||
|
||||
init_transactions();
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE=3
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
|
Loading…
Reference in New Issue
Block a user