From afc00fb5f5ad5da01e081c72b2351e33ebfc3bf1 Mon Sep 17 00:00:00 2001 From: lly Date: Tue, 17 Sep 2019 15:31:18 +0800 Subject: [PATCH] ble_mesh: add heartbeat message recv callback --- .../bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 8 ++++++ .../include/esp_ble_mesh_config_model_api.h | 4 +-- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 1e6bfbc76..39daedef0 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -1240,6 +1240,7 @@ typedef enum { ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT, /*!< Provisioner add local network key completion event */ ESP_BLE_MESH_SET_FAST_PROV_INFO_COMP_EVT, /*!< Set fast provisioning information (e.g. unicast address range, net_idx, etc.) completion event */ ESP_BLE_MESH_SET_FAST_PROV_ACTION_COMP_EVT, /*!< Set fast provisioning action completion event */ + ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT, /*!< Receive Heartbeat message event */ ESP_BLE_MESH_PROV_EVT_MAX, } esp_ble_mesh_prov_cb_event_t; @@ -1523,6 +1524,13 @@ typedef union { struct ble_mesh_set_fast_prov_action_comp_param { uint8_t status_action; /*!< Indicate the result of setting action of fast provisioning */ } set_fast_prov_action_comp; /*!< Event parameter of ESP_BLE_MESH_SET_FAST_PROV_ACTION_COMP_EVT */ + /** + * @brief ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT + */ + struct ble_mesh_heartbeat_msg_recv_param { + uint8_t hops; /*!< Heartbeat hops (InitTTL - RxTTL + 1) */ + uint16_t feature; /*!< Bit field of currently active features of the node */ + } heartbeat_msg_recv; /*!< Event parameter of ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT */ } esp_ble_mesh_prov_cb_param_t; /** diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h index 66f1d17d4..b6f04fdf3 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h @@ -79,8 +79,8 @@ typedef struct esp_ble_mesh_cfg_srv { uint8_t min_hops; /*!< Minimum hops when receiving Heartbeat messages */ uint8_t max_hops; /*!< Maximum hops when receiving Heartbeat messages */ - /** Optional subscription tracking function */ - void (*func)(uint8_t hops, uint16_t feature); + /** Optional heartbeat subscription tracking function */ + esp_ble_mesh_cb_t heartbeat_recv_cb; } heartbeat_sub; } esp_ble_mesh_cfg_srv_t; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 1cb989a42..cc1e366ef 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -31,6 +31,7 @@ #include "mesh_proxy.h" #include "cfg_cli.h" #include "health_cli.h" +#include "cfg_srv.h" #include "health_srv.h" #include "mesh.h" @@ -865,6 +866,29 @@ static void btc_ble_mesh_provisioner_prov_complete_cb( } #endif /* CONFIG_BLE_MESH_PROVISIONER */ +static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + btc_msg_t msg = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + mesh_param.heartbeat_msg_recv.hops = hops; + mesh_param.heartbeat_msg_recv.feature = feature; + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_PROV; + msg.act = ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT; + ret = btc_transfer_context(&msg, &mesh_param, + sizeof(esp_ble_mesh_prov_cb_param_t), NULL); + + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("%s btc_transfer_context failed", __func__); + } + return; +} + int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model) { __ASSERT(model && model->op, "%s, Invalid parameter", __func__); @@ -964,6 +988,10 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) switch (model->model_id) { case BLE_MESH_MODEL_ID_CFG_SRV: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_srv_op; + struct bt_mesh_cfg_srv *srv = (struct bt_mesh_cfg_srv *)model->user_data; + if (srv) { + srv->hb_sub.func = btc_ble_mesh_heartbeat_msg_recv_cb; + } break; } case BLE_MESH_MODEL_ID_CFG_CLI: {