From 8a41132507516dd931853ec0c9682c18ebd531b8 Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 2 Sep 2019 15:37:10 +0800 Subject: [PATCH] ble_mesh: fix publication period timestamp initialization --- components/bt/esp_ble_mesh/mesh_core/access.c | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 17f4b88e5e..94374d98e6 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -220,7 +220,24 @@ static void publish_sent(int err, void *user_data) } } +static void publish_start(u16_t duration, int err, void *user_data) +{ + struct bt_mesh_model *mod = user_data; + struct bt_mesh_model_pub *pub = mod->pub; + + if (err) { + BT_ERR("Failed to publish: err %d", err); + return; + } + + /* Initialize the timestamp for the beginning of a new period */ + if (pub->count == BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit)) { + pub->period_start = k_uptime_get_32(); + } +} + static const struct bt_mesh_send_cb pub_sent_cb = { + .start = publish_start, .end = publish_sent, }; @@ -310,8 +327,6 @@ static void mod_publish(struct k_work *work) __ASSERT_NO_MSG(pub->update != NULL); - pub->period_start = k_uptime_get_32(); - /* Callback the model publish update event to the application layer. * In the event, users can update the context of the publish message * which will be published in the next period. @@ -856,7 +871,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) BT_DBG("%s", __func__); - if (!pub) { + if (!pub || !pub->msg) { BT_ERR("%s, Model has no publication support", __func__); return -ENOTSUP; } -- 2.40.0