in apps/blemesh_models_example_2/src/device_composition.c [200:268]
static int gen_onoff_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
uint8_t tid, onoff, tt, delay;
int64_t now;
int err;
struct generic_onoff_state *state = model->user_data;
onoff = net_buf_simple_pull_u8(buf);
tid = net_buf_simple_pull_u8(buf);
if (onoff > STATE_ON) {
return 0;
}
now = k_uptime_get();
if (state->last_tid == tid &&
state->last_src_addr == ctx->addr &&
state->last_dst_addr == ctx->recv_dst &&
(now - state->last_msg_timestamp <= K_SECONDS(6))) {
return 0;
}
switch (buf->om_len) {
case 0x00: /* No optional fields are available */
tt = default_tt;
delay = 0;
break;
case 0x02: /* Optional fields are available */
tt = net_buf_simple_pull_u8(buf);
if ((tt & 0x3F) == 0x3F) {
return 0;
}
delay = net_buf_simple_pull_u8(buf);
break;
default:
return 0;
}
*ptr_counter = 0;
os_callout_stop(ptr_timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
state->last_dst_addr = ctx->recv_dst;
state->last_msg_timestamp = now;
state->target_onoff = onoff;
if (state->target_onoff != state->onoff) {
onoff_tt_values(state, tt, delay);
} else {
return gen_onoff_publish(model);
}
/* For Instantaneous Transition */
if (state->transition->counter == 0) {
state->onoff = state->target_onoff;
}
state->transition->just_started = true;
err = gen_onoff_publish(model);
onoff_handler(state);
if (err) {
return err;
}
return 0;
}