ble_mesh: stack: Add clear hb_pub in settings

pull/5919/head
lly 2020-05-27 09:34:33 +08:00 zatwierdzone przez bot
rodzic 88cc07b6ca
commit 80b16c58bb
1 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

@ -550,13 +550,13 @@ static int hb_pub_set(const char *name)
BT_DBG("%s", __func__); BT_DBG("%s", __func__);
if (!hb_pub) { if (!hb_pub) {
BT_ERR("Invalid heartbeat pub"); BT_ERR("Invalid heartbeat publication");
return -EINVAL; return -EINVAL;
} }
err = bt_mesh_load_core_settings(name, (u8_t *)&hb_val, sizeof(hb_val), &exist); err = bt_mesh_load_core_settings(name, (u8_t *)&hb_val, sizeof(hb_val), &exist);
if (err) { if (err) {
BT_ERR("Failed to load heartbeat pub"); BT_ERR("Failed to load heartbeat publication");
hb_pub->dst = BLE_MESH_ADDR_UNASSIGNED; hb_pub->dst = BLE_MESH_ADDR_UNASSIGNED;
hb_pub->count = 0U; hb_pub->count = 0U;
hb_pub->ttl = 0U; hb_pub->ttl = 0U;
@ -1652,7 +1652,7 @@ static void store_pending_hb_pub(void)
struct hb_pub_val val = {0}; struct hb_pub_val val = {0};
if (!hb_pub) { if (!hb_pub) {
BT_WARN("NULL heartbeat publication"); BT_ERR("Invalid heartbeat publication");
return; return;
} }
@ -1666,6 +1666,12 @@ static void store_pending_hb_pub(void)
bt_mesh_save_core_settings("mesh/hb_pub", (const u8_t *)&val, sizeof(val)); bt_mesh_save_core_settings("mesh/hb_pub", (const u8_t *)&val, sizeof(val));
} }
static void clear_hb_pub(void)
{
BT_DBG("Clear heartbeat publication");
bt_mesh_erase_core_settings("mesh/hb_pub");
}
static void store_pending_cfg(void) static void store_pending_cfg(void)
{ {
struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
@ -2041,7 +2047,11 @@ static void store_pending(struct k_work *work)
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() && if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_HB_PUB_PENDING)) { bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_HB_PUB_PENDING)) {
store_pending_hb_pub(); if (bt_mesh_is_provisioned()) {
store_pending_hb_pub();
} else {
clear_hb_pub();
}
} }
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() && if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&