static int light_lightness_set_unack()

in apps/blemesh_models_example_2/src/device_composition.c [1314:1383]


static int light_lightness_set_unack(struct bt_mesh_model *model,
				      struct bt_mesh_msg_ctx *ctx,
				      struct os_mbuf *buf)
{
	uint8_t tid, tt, delay;
	uint16_t actual;
	int64_t now;
	struct light_lightness_state *state = model->user_data;

	actual = net_buf_simple_pull_le16(buf);
	tid = net_buf_simple_pull_u8(buf);

	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;

	if (actual > 0 && actual < state->light_range_min) {
		actual = state->light_range_min;
	} else if (actual > state->light_range_max) {
		actual = state->light_range_max;
	}

	state->target_actual = actual;

	if (state->target_actual != state->actual) {
		light_lightness_actual_tt_values(state, tt, delay);
	} else {
		light_lightness_publish(model);
		return 0;
	}

	/* For Instantaneous Transition */
	if (state->transition->counter == 0) {
		state->actual = state->target_actual;
	}

	state->transition->just_started = true;
	light_lightness_publish(model);
	light_lightness_actual_handler(state);
    return 0;
}