Bluetooth: Mesh: Fix non-periodic Model Publication

The only generally available model supporting publication that's
convenient to be used for testing is the Health Server Model.
Unfortunately since this model supports period publication, the
non-periodic side got less attention and had some bugs.

The first thing that needs to be done is to verify that the period
returned by bt_mesh_model_pub_period_get() is positive. If it's zero
then no periodic publication should take place.

Another thing that this patch cleans up is the naming of the callback
used for periodic publishing. There's no need do require the callback
to call bt_mesh_model_publish() since this must happen no matter what,
so instead rename the callback from 'func' to 'update' and have the
access layer call bt_mesh_model_publish() if the callback was
successful.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-20 17:13:44 +02:00 committed by Johan Hedberg
commit 8f1541184f
6 changed files with 43 additions and 30 deletions

View file

@ -273,8 +273,8 @@ struct bt_mesh_model_pub {
/* Buffer containing the publication message */
struct net_buf_simple *msg;
/* Publish callback */
void (*func)(struct bt_mesh_model *mod);
/* Update callback for period publishing */
int (*update)(struct bt_mesh_model *mod);
/* Publish Period Timer */
struct k_delayed_work timer;
@ -343,7 +343,10 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
*
* Before calling this function, the user needs to ensure that the model
* publication message ('msg' member of struct bt_mesh_model_pub) contains
* a valid message to be sent.
* a valid message to be sent. Note that this API is only to be used
* for non-period publishing. For periodic publishing the app only needs
* to make sure that pub->msg contains a valid message whenever the
* pub->update callback is called.
*
* @param model Mesh (client) Model that's publishing the message.
*