Skip to content

Commit 29ae06d

Browse files
Michał Narajowskicarlescufi
authored andcommitted
samples: Update Mesh opcode handlers
Add return values to opcode handlers and update message length definitions. Signed-off-by: Michał Narajowski <[email protected]>
1 parent ca53e86 commit 29ae06d

File tree

5 files changed

+680
-521
lines changed

5 files changed

+680
-521
lines changed

samples/bluetooth/mesh/src/main.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@ static void onoff_timeout(struct k_work *work)
151151

152152
/* Generic OnOff Server message handlers */
153153

154-
static void gen_onoff_get(struct bt_mesh_model *model,
155-
struct bt_mesh_msg_ctx *ctx,
156-
struct net_buf_simple *buf)
154+
static int gen_onoff_get(struct bt_mesh_model *model,
155+
struct bt_mesh_msg_ctx *ctx,
156+
struct net_buf_simple *buf)
157157
{
158158
onoff_status_send(model, ctx);
159+
return 0;
159160
}
160161

161-
static void gen_onoff_set_unack(struct bt_mesh_model *model,
162-
struct bt_mesh_msg_ctx *ctx,
163-
struct net_buf_simple *buf)
162+
static int gen_onoff_set_unack(struct bt_mesh_model *model,
163+
struct bt_mesh_msg_ctx *ctx,
164+
struct net_buf_simple *buf)
164165
{
165166
uint8_t val = net_buf_simple_pull_u8(buf);
166167
uint8_t tid = net_buf_simple_pull_u8(buf);
@@ -177,12 +178,12 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
177178
*/
178179
if (tid == onoff.tid && ctx->addr == onoff.src) {
179180
/* Duplicate */
180-
return;
181+
return 0;
181182
}
182183

183184
if (val == onoff.val) {
184185
/* No change */
185-
return;
186+
return 0;
186187
}
187188

188189
printk("set: %s delay: %d ms time: %d ms\n", onoff_str[val], delay,
@@ -197,28 +198,32 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
197198
* transition time stored, so it can be applied in the timeout.
198199
*/
199200
k_work_reschedule(&onoff.work, K_MSEC(delay));
201+
202+
return 0;
200203
}
201204

202-
static void gen_onoff_set(struct bt_mesh_model *model,
203-
struct bt_mesh_msg_ctx *ctx,
204-
struct net_buf_simple *buf)
205+
static int gen_onoff_set(struct bt_mesh_model *model,
206+
struct bt_mesh_msg_ctx *ctx,
207+
struct net_buf_simple *buf)
205208
{
206-
gen_onoff_set_unack(model, ctx, buf);
209+
(void)gen_onoff_set_unack(model, ctx, buf);
207210
onoff_status_send(model, ctx);
211+
212+
return 0;
208213
}
209214

210215
static const struct bt_mesh_model_op gen_onoff_srv_op[] = {
211-
{ OP_ONOFF_GET, 0, gen_onoff_get },
212-
{ OP_ONOFF_SET, 2, gen_onoff_set },
213-
{ OP_ONOFF_SET_UNACK, 2, gen_onoff_set_unack },
216+
{ OP_ONOFF_GET, BT_MESH_LEN_EXACT(0), gen_onoff_get },
217+
{ OP_ONOFF_SET, BT_MESH_LEN_MIN(2), gen_onoff_set },
218+
{ OP_ONOFF_SET_UNACK, BT_MESH_LEN_MIN(2), gen_onoff_set_unack },
214219
BT_MESH_MODEL_OP_END,
215220
};
216221

217222
/* Generic OnOff Client */
218223

219-
static void gen_onoff_status(struct bt_mesh_model *model,
220-
struct bt_mesh_msg_ctx *ctx,
221-
struct net_buf_simple *buf)
224+
static int gen_onoff_status(struct bt_mesh_model *model,
225+
struct bt_mesh_msg_ctx *ctx,
226+
struct net_buf_simple *buf)
222227
{
223228
uint8_t present = net_buf_simple_pull_u8(buf);
224229

@@ -229,14 +234,16 @@ static void gen_onoff_status(struct bt_mesh_model *model,
229234

230235
printk("OnOff status: %s -> %s: (%d ms)\n", onoff_str[present],
231236
onoff_str[target], remaining_time);
232-
return;
237+
return 0;
233238
}
234239

235240
printk("OnOff status: %s\n", onoff_str[present]);
241+
242+
return 0;
236243
}
237244

238245
static const struct bt_mesh_model_op gen_onoff_cli_op[] = {
239-
{OP_ONOFF_STATUS, 1, gen_onoff_status},
246+
{OP_ONOFF_STATUS, BT_MESH_LEN_MIN(1), gen_onoff_status},
240247
BT_MESH_MODEL_OP_END,
241248
};
242249

samples/bluetooth/mesh_demo/src/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,24 @@ static struct bt_mesh_model root_models[] = {
8080
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
8181
};
8282

83-
static void vnd_button_pressed(struct bt_mesh_model *model,
83+
static int vnd_button_pressed(struct bt_mesh_model *model,
8484
struct bt_mesh_msg_ctx *ctx,
8585
struct net_buf_simple *buf)
8686
{
8787
printk("src 0x%04x\n", ctx->addr);
8888

8989
if (ctx->addr == bt_mesh_model_elem(model)->addr) {
90-
return;
90+
return 0;
9191
}
9292

9393
board_other_dev_pressed(ctx->addr);
9494
board_play("100G200 100G");
95+
96+
return 0;
9597
}
9698

9799
static const struct bt_mesh_model_op vnd_ops[] = {
98-
{ OP_VENDOR_BUTTON, 0, vnd_button_pressed },
100+
{ OP_VENDOR_BUTTON, BT_MESH_LEN_EXACT(0), vnd_button_pressed },
99101
BT_MESH_MODEL_OP_END,
100102
};
101103

samples/boards/nrf/mesh/onoff-app/src/main.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@
5454
#define BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03)
5555
#define BT_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04)
5656

57-
static void gen_onoff_set(struct bt_mesh_model *model,
58-
struct bt_mesh_msg_ctx *ctx,
59-
struct net_buf_simple *buf);
57+
static int gen_onoff_set(struct bt_mesh_model *model,
58+
struct bt_mesh_msg_ctx *ctx,
59+
struct net_buf_simple *buf);
6060

61-
static void gen_onoff_set_unack(struct bt_mesh_model *model,
62-
struct bt_mesh_msg_ctx *ctx,
63-
struct net_buf_simple *buf);
61+
static int gen_onoff_set_unack(struct bt_mesh_model *model,
62+
struct bt_mesh_msg_ctx *ctx,
63+
struct net_buf_simple *buf);
6464

65-
static void gen_onoff_get(struct bt_mesh_model *model,
66-
struct bt_mesh_msg_ctx *ctx,
67-
struct net_buf_simple *buf);
65+
static int gen_onoff_get(struct bt_mesh_model *model,
66+
struct bt_mesh_msg_ctx *ctx,
67+
struct net_buf_simple *buf);
6868

69-
static void gen_onoff_status(struct bt_mesh_model *model,
70-
struct bt_mesh_msg_ctx *ctx,
71-
struct net_buf_simple *buf);
69+
static int gen_onoff_status(struct bt_mesh_model *model,
70+
struct bt_mesh_msg_ctx *ctx,
71+
struct net_buf_simple *buf);
7272

7373
/*
7474
* Client Configuration Declaration
@@ -127,9 +127,9 @@ BT_MESH_MODEL_PUB_DEFINE(gen_onoff_pub_cli_s_2, NULL, 2 + 2);
127127
*/
128128

129129
static const struct bt_mesh_model_op gen_onoff_srv_op[] = {
130-
{ BT_MESH_MODEL_OP_GEN_ONOFF_GET, 0, gen_onoff_get },
131-
{ BT_MESH_MODEL_OP_GEN_ONOFF_SET, 2, gen_onoff_set },
132-
{ BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK, 2, gen_onoff_set_unack },
130+
{ BT_MESH_MODEL_OP_GEN_ONOFF_GET, BT_MESH_LEN_EXACT(0), gen_onoff_get },
131+
{ BT_MESH_MODEL_OP_GEN_ONOFF_SET, BT_MESH_LEN_EXACT(2), gen_onoff_set },
132+
{ BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK, BT_MESH_LEN_EXACT(2), gen_onoff_set_unack },
133133
BT_MESH_MODEL_OP_END,
134134
};
135135

@@ -138,7 +138,7 @@ static const struct bt_mesh_model_op gen_onoff_srv_op[] = {
138138
*/
139139

140140
static const struct bt_mesh_model_op gen_onoff_cli_op[] = {
141-
{ BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, gen_onoff_status },
141+
{ BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, BT_MESH_LEN_EXACT(1), gen_onoff_status },
142142
BT_MESH_MODEL_OP_END,
143143
};
144144

@@ -277,9 +277,9 @@ static uint16_t primary_net_idx;
277277
*
278278
*/
279279

280-
static void gen_onoff_get(struct bt_mesh_model *model,
281-
struct bt_mesh_msg_ctx *ctx,
282-
struct net_buf_simple *buf)
280+
static int gen_onoff_get(struct bt_mesh_model *model,
281+
struct bt_mesh_msg_ctx *ctx,
282+
struct net_buf_simple *buf)
283283
{
284284
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
285285
struct onoff_state *onoff_state = model->user_data;
@@ -292,11 +292,13 @@ static void gen_onoff_get(struct bt_mesh_model *model,
292292
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
293293
printk("Unable to send On Off Status response\n");
294294
}
295+
296+
return 0;
295297
}
296298

297-
static void gen_onoff_set_unack(struct bt_mesh_model *model,
298-
struct bt_mesh_msg_ctx *ctx,
299-
struct net_buf_simple *buf)
299+
static int gen_onoff_set_unack(struct bt_mesh_model *model,
300+
struct bt_mesh_msg_ctx *ctx,
301+
struct net_buf_simple *buf)
300302
{
301303
struct net_buf_simple *msg = model->pub->msg;
302304
struct onoff_state *onoff_state = model->user_data;
@@ -331,28 +333,34 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
331333
printk("bt_mesh_model_publish err %d\n", err);
332334
}
333335
}
336+
337+
return 0;
334338
}
335339

336-
static void gen_onoff_set(struct bt_mesh_model *model,
337-
struct bt_mesh_msg_ctx *ctx,
338-
struct net_buf_simple *buf)
340+
static int gen_onoff_set(struct bt_mesh_model *model,
341+
struct bt_mesh_msg_ctx *ctx,
342+
struct net_buf_simple *buf)
339343
{
340344
printk("gen_onoff_set\n");
341345

342-
gen_onoff_set_unack(model, ctx, buf);
343-
gen_onoff_get(model, ctx, buf);
346+
(void)gen_onoff_set_unack(model, ctx, buf);
347+
(void)gen_onoff_get(model, ctx, buf);
348+
349+
return 0;
344350
}
345351

346-
static void gen_onoff_status(struct bt_mesh_model *model,
347-
struct bt_mesh_msg_ctx *ctx,
348-
struct net_buf_simple *buf)
352+
static int gen_onoff_status(struct bt_mesh_model *model,
353+
struct bt_mesh_msg_ctx *ctx,
354+
struct net_buf_simple *buf)
349355
{
350356
uint8_t state;
351357

352358
state = net_buf_simple_pull_u8(buf);
353359

354360
printk("Node 0x%04x OnOff status from 0x%04x with state 0x%02x\n",
355361
bt_mesh_model_elem(model)->addr, ctx->addr, state);
362+
363+
return 0;
356364
}
357365

358366
static int output_number(bt_mesh_output_action_t action, uint32_t number)
@@ -487,7 +495,7 @@ static void button_pressed_worker(struct k_work *work)
487495
*/
488496

489497
net_buf_simple_add_u8(&msg, sw->onoff_state);
490-
gen_onoff_set_unack(mod_srv, &ctx, &msg);
498+
(void)gen_onoff_set_unack(mod_srv, &ctx, &msg);
491499
return;
492500
}
493501

0 commit comments

Comments
 (0)