ble_mesh: add heartbeat message recv callback

This commit is contained in:
lly 2019-09-17 15:31:18 +08:00
parent 805bc06127
commit eaeb36375a
3 changed files with 38 additions and 2 deletions

View File

@ -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;
/**

View File

@ -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;

View File

@ -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: {