in apps/blemesh_models_example_2/src/device_composition.c [2054:2139]
static int light_ctl_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
uint8_t tid, tt, delay;
int16_t delta_uv;
uint16_t lightness, temp;
int64_t now;
struct light_ctl_state *state = model->user_data;
lightness = net_buf_simple_pull_le16(buf);
temp = net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temp < TEMP_MIN || temp > TEMP_MAX) {
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))) {
light_ctl_get(model, ctx, buf);
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_lightness = lightness;
if (temp < state->temp_range_min) {
temp = state->temp_range_min;
} else if (temp > state->temp_range_max) {
temp = state->temp_range_max;
}
state->target_temp = temp;
state->target_delta_uv = delta_uv;
if (state->target_lightness != state->lightness ||
state->target_temp != state->temp ||
state->target_delta_uv != state->delta_uv) {
light_ctl_tt_values(state, tt, delay);
} else {
light_ctl_get(model, ctx, buf);
light_ctl_publish(model);
return 0;
}
/* For Instantaneous Transition */
if (state->transition->counter == 0) {
state->lightness = state->target_lightness;
state->temp = state->target_temp;
state->delta_uv = state->target_delta_uv;
}
state->transition->just_started = true;
light_ctl_get(model, ctx, buf);
light_ctl_publish(model);
light_ctl_handler(state);
return 0;
}