apps/blemesh: fix build after introducing return codes in models

This applies to both blemesh, blemesh_models_example_1 and
blemesh_models_example_2
This commit is contained in:
Krzysztof Kopyściński
2021-11-10 06:24:00 +01:00
committed by Krzysztof Kopyściński
parent 82ccdbce6f
commit 489bb3a925
4 changed files with 377 additions and 233 deletions
+39 -19
View File
@@ -144,11 +144,12 @@ static struct bt_mesh_model_pub gen_onoff_pub;
static uint8_t gen_on_off_state;
static int16_t gen_level_state;
static void gen_onoff_status(struct bt_mesh_model *model,
static int gen_onoff_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(3);
uint8_t *status;
int rc;
console_printf("#mesh-onoff STATUS\n");
@@ -156,23 +157,25 @@ static void gen_onoff_status(struct bt_mesh_model *model,
status = net_buf_simple_add(msg, 1);
*status = gen_on_off_state;
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL);
if (rc) {
console_printf("#mesh-onoff STATUS: send status failed\n");
}
os_mbuf_free_chain(msg);
return rc;
}
static void gen_onoff_get(struct bt_mesh_model *model,
static int gen_onoff_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
console_printf("#mesh-onoff GET\n");
gen_onoff_status(model, ctx);
return gen_onoff_status(model, ctx);
}
static void gen_onoff_set(struct bt_mesh_model *model,
static int gen_onoff_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -181,10 +184,10 @@ static void gen_onoff_set(struct bt_mesh_model *model,
gen_on_off_state = buf->om_data[0];
hal_gpio_write(LED_2, !gen_on_off_state);
gen_onoff_status(model, ctx);
return gen_onoff_status(model, ctx);
}
static void gen_onoff_set_unack(struct bt_mesh_model *model,
static int gen_onoff_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -192,6 +195,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
gen_on_off_state = buf->om_data[0];
hal_gpio_write(LED_2, !gen_on_off_state);
return 0;
}
static const struct bt_mesh_model_op gen_onoff_op[] = {
@@ -201,48 +205,56 @@ static const struct bt_mesh_model_op gen_onoff_op[] = {
BT_MESH_MODEL_OP_END,
};
static void gen_level_status(struct bt_mesh_model *model,
static int gen_level_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(4);
int rc;
console_printf("#mesh-level STATUS\n");
bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x08));
net_buf_simple_add_le16(msg, gen_level_state);
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL);
if (rc) {
console_printf("#mesh-level STATUS: send status failed\n");
}
os_mbuf_free_chain(msg);
return rc;
}
static void gen_level_get(struct bt_mesh_model *model,
static int gen_level_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
console_printf("#mesh-level GET\n");
gen_level_status(model, ctx);
return gen_level_status(model, ctx);
}
static void gen_level_set(struct bt_mesh_model *model,
static int gen_level_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
int16_t level;
int rc;
level = (int16_t) net_buf_simple_pull_le16(buf);
console_printf("#mesh-level SET: level=%d\n", level);
gen_level_status(model, ctx);
rc = gen_level_status(model, ctx);
if (rc) {
return rc;
}
gen_level_state = level;
console_printf("#mesh-level: level=%d\n", gen_level_state);
return 0;
}
static void gen_level_set_unack(struct bt_mesh_model *model,
static int gen_level_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -253,9 +265,10 @@ static void gen_level_set_unack(struct bt_mesh_model *model,
gen_level_state = level;
console_printf("#mesh-level: level=%d\n", gen_level_state);
return 0;
}
static void gen_delta_set(struct bt_mesh_model *model,
static int gen_delta_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -268,9 +281,10 @@ static void gen_delta_set(struct bt_mesh_model *model,
gen_level_state += delta_level;
console_printf("#mesh-level: level=%d\n", gen_level_state);
return 0;
}
static void gen_delta_set_unack(struct bt_mesh_model *model,
static int gen_delta_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -281,18 +295,21 @@ static void gen_delta_set_unack(struct bt_mesh_model *model,
gen_level_state += delta_level;
console_printf("#mesh-level: level=%d\n", gen_level_state);
return 0;
}
static void gen_move_set(struct bt_mesh_model *model,
static int gen_move_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
return 0;
}
static void gen_move_set_unack(struct bt_mesh_model *model,
static int gen_move_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
return 0;
}
static const struct bt_mesh_model_op gen_level_op[] = {
@@ -317,11 +334,12 @@ static struct bt_mesh_model root_models[] = {
static struct bt_mesh_model_pub vnd_model_pub;
static void vnd_model_recv(struct bt_mesh_model *model,
static int vnd_model_recv(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(3);
int rc;
console_printf("#vendor-model-recv\n");
@@ -331,11 +349,13 @@ static void vnd_model_recv(struct bt_mesh_model *model,
bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_3(0x01, CID_VENDOR));
os_mbuf_append(msg, buf->om_data, buf->om_len);
rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL);
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
console_printf("#vendor-model-recv: send rsp failed\n");
}
os_mbuf_free_chain(msg);
return rc;
}
static const struct bt_mesh_model_op vnd_model_op[] = {
+27 -12
View File
@@ -68,19 +68,19 @@
#define BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03)
#define BT_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04)
static void gen_onoff_set(struct bt_mesh_model *model,
static int gen_onoff_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf);
static void gen_onoff_set_unack(struct bt_mesh_model *model,
static int gen_onoff_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf);
static void gen_onoff_get(struct bt_mesh_model *model,
static int gen_onoff_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf);
static void gen_onoff_status(struct bt_mesh_model *model,
static int gen_onoff_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf);
@@ -318,26 +318,29 @@ static uint16_t primary_net_idx;
*
*/
static void gen_onoff_get(struct bt_mesh_model *model,
static int gen_onoff_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 1 + 4);
struct onoff_state *state = model->user_data;
int rc;
BT_INFO("addr 0x%04x onoff 0x%02x",
bt_mesh_model_elem(model)->addr, state->current);
bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS);
net_buf_simple_add_u8(msg, state->current);
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL);
if (rc) {
BT_ERR("Unable to send On Off Status response");
}
os_mbuf_free_chain(msg);
return rc;
}
static void gen_onoff_set_unack(struct bt_mesh_model *model,
static int gen_onoff_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -372,23 +375,34 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
BT_MESH_MODEL_OP_GEN_ONOFF_STATUS);
net_buf_simple_add_u8(msg, state->current);
err = bt_mesh_model_publish(model);
if (err) {
if (err != 0) {
BT_ERR("bt_mesh_model_publish err %d", err);
return err;
}
}
return 0;
}
static void gen_onoff_set(struct bt_mesh_model *model,
static int gen_onoff_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
BT_INFO("");
int rc;
gen_onoff_set_unack(model, ctx, buf);
gen_onoff_get(model, ctx, buf);
rc = gen_onoff_set_unack(model, ctx, buf);
if (rc != 0) {
return rc;
}
rc = gen_onoff_get(model, ctx, buf);
if (rc != 0) {
return rc;
}
return 0;
}
static void gen_onoff_status(struct bt_mesh_model *model,
static int gen_onoff_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
@@ -398,6 +412,7 @@ static void gen_onoff_status(struct bt_mesh_model *model,
BT_INFO("Node 0x%04x OnOff status from 0x%04x with state 0x%02x",
bt_mesh_model_elem(model)->addr, ctx->addr, state);
return 0;
}
static int output_number(bt_mesh_output_action_t action, uint32_t number)
File diff suppressed because it is too large Load Diff
@@ -167,11 +167,11 @@ extern struct bt_mesh_model s0_models[];
extern const struct bt_mesh_comp comp;
void gen_onoff_publish(struct bt_mesh_model *model);
void gen_level_publish(struct bt_mesh_model *model);
void light_lightness_publish(struct bt_mesh_model *model);
void light_lightness_linear_publish(struct bt_mesh_model *model);
void light_ctl_publish(struct bt_mesh_model *model);
void light_ctl_temp_publish(struct bt_mesh_model *model);
int gen_onoff_publish(struct bt_mesh_model *model);
int gen_level_publish(struct bt_mesh_model *model);
int light_lightness_publish(struct bt_mesh_model *model);
int light_lightness_linear_publish(struct bt_mesh_model *model);
int light_ctl_publish(struct bt_mesh_model *model);
int light_ctl_temp_publish(struct bt_mesh_model *model);
#endif