Skip to content

Commit a2f01a9

Browse files
IlijaVorontsovalxelax
authored andcommitted
Bluetooth: Mesh: light_temp_srv added publication
Implemented model publication as specified in Mesh Model Specification v1.0.1, Section 6.4.4.1. Implemented similar to other publication services in Bt Mesh. Tested in company own testing environment. Co-authored-by: Aleksandr Khromykh <[email protected]> Signed-off-by: Ilija Vorontsov <[email protected]>
1 parent 32dc027 commit a2f01a9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/bluetooth/mesh/light_temp_srv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ struct bt_mesh_light_temp_srv {
150150
const struct bt_mesh_light_ctl_srv *ctl;
151151
/** Publish parameters. */
152152
struct bt_mesh_model_pub pub;
153+
/* Publication buffer */
154+
struct net_buf_simple pub_buf;
155+
/* Publication data */
156+
uint8_t pub_data[BT_MESH_MODEL_BUF_LEN(
157+
BT_MESH_LIGHT_CTL_STATUS, BT_MESH_LIGHT_CTL_MSG_MAXLEN_STATUS)];
153158
/** Transaction ID tracker for the set messages. */
154159
struct bt_mesh_tid_ctx prev_transaction;
155160
/** Handler function structure. */

subsys/bluetooth/mesh/light_temp_srv.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,29 @@ static void light_temp_srv_reset(struct bt_mesh_light_temp_srv *srv)
394394
srv->range.max = BT_MESH_LIGHT_TEMP_MAX;
395395
}
396396

397+
static int update_handler(const struct bt_mesh_model *model)
398+
{
399+
struct bt_mesh_light_temp_srv *srv = model->rt->user_data;
400+
struct bt_mesh_light_temp_status status = { 0 };
401+
402+
srv->handlers->get(srv, NULL, &status);
403+
encode_status(srv->pub.msg, &status);
404+
405+
return 0;
406+
}
407+
397408
static int bt_mesh_light_temp_srv_init(const struct bt_mesh_model *model)
398409
{
399410
struct bt_mesh_light_temp_srv *srv = model->rt->user_data;
400411
int err;
401412

402413
srv->model = model;
403414
light_temp_srv_reset(srv);
404-
net_buf_simple_init(srv->pub.msg, 0);
415+
416+
srv->pub.msg = &srv->pub_buf;
417+
srv->pub.update = update_handler;
418+
net_buf_simple_init_with_data(&srv->pub_buf, srv->pub_data,
419+
sizeof(srv->pub_data));
405420

406421
#if IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_EMDS)
407422
srv->emds_entry.entry.id = EMDS_MODEL_ID(model);

0 commit comments

Comments
 (0)