Commit 5a341f55 authored by Vikrant More's avatar Vikrant More Committed by Johan Hedberg
Browse files

samples: mesh: nrf52: upgrade bound states publish mechanism



If user aggresively vary the state then previous mechanism
failed to publish status of other bounded states since it
has to publish multiple things back to back.
This PR repair the things.

Signed-off-by: default avatarVikrant More <vikrant8051@gmail.com>
parent f119ffed
Loading
Loading
Loading
Loading
+0 −45
Original line number Diff line number Diff line
@@ -171,51 +171,6 @@ K_TIMER_DEFINE(save_lightness_temp_last_state_timer,

static void no_transition_work_handler(struct k_work *work)
{
	u16_t publisher;

	/* publisher values is based on enum get_messages
	 * which is defined in device_configuration.h
	 */
	publisher = (get_msg << 8) | last_get_msg;

	switch (publisher) {
	case PUB_ONOFF_1:
	case PUB_ONOFF_2:
	case PUB_ONOFF_3:
		gen_onoff_publisher(&root_models[2]);
		break;
	case PUB_LEVEL_1:
	case PUB_LEVEL_2:
	case PUB_LEVEL_3:
		gen_level_publisher(&root_models[4]);
		break;
	case PUB_LIGHT_ACTUAL_1:
	case PUB_LIGHT_ACTUAL_2:
		light_lightness_publisher(&root_models[11]);
		break;
	case PUB_LIGHT_LINEAR_1:
	case PUB_LIGHT_LINEAR_2:
		light_lightness_linear_publisher(&root_models[11]);
		break;
	case PUB_LIGHT_CTL_1:
	case PUB_LIGHT_CTL_2:
		light_ctl_publisher(&root_models[14]);
		break;
	}

	if (!is_light_lightness_actual_state_published) {
		light_lightness_publisher(&root_models[11]);
	}

	if (!is_light_ctl_state_published) {
		light_ctl_publisher(&root_models[14]);
	}

	last_get_msg = NULL_GET;
	get_msg = NULL_GET;
	is_light_lightness_actual_state_published = false;
	is_light_ctl_state_published = false;

	/* If Lightness & Temperature values remains stable for
	 * 10 Seconds then & then only get stored on SoC flash.
	 */
+27 −37
Original line number Diff line number Diff line
@@ -122,9 +122,6 @@ static void gen_onoff_get(struct bt_mesh_model *model,

	if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
		printk("Unable to send GEN_ONOFF_SRV Status response\n");
	} else {
		last_get_msg = get_msg;
		get_msg = ONOFF_GET;
	}
}

@@ -280,9 +277,6 @@ static void gen_level_get(struct bt_mesh_model *model,

	if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
		printk("Unable to send GEN_LEVEL_SRV Status response\n");
	} else if (bt_mesh_model_elem(model)->addr == elements[0].addr) {
		last_get_msg = get_msg;
		get_msg = LEVEL_GET;
	}
}

@@ -887,9 +881,6 @@ static void light_lightness_get(struct bt_mesh_model *model,

	if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
		printk("Unable to send LightLightnessAct Status response\n");
	} else {
		last_get_msg = get_msg;
		get_msg = LIGHT_LIGHTNESS_ACTUAL_GET;
	}
}

@@ -1023,9 +1014,6 @@ static void light_lightness_linear_get(struct bt_mesh_model *model,

	if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
		printk("Unable to send LightLightnessLin Status response\n");
	} else {
		last_get_msg = get_msg;
		get_msg = LIGHT_LIGHTNESS_LINEAR_GET;
	}
}

@@ -1365,9 +1353,6 @@ static void light_ctl_get(struct bt_mesh_model *model,

	if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
		printk("Unable to send LightCTL Status response\n");
	} else {
		last_get_msg = get_msg;
		get_msg = LIGHT_CTL_GET;
	}
}

@@ -1397,8 +1382,6 @@ void light_ctl_publisher(struct bt_mesh_model *model)
		err = bt_mesh_model_publish(model);
		if (err) {
			printk("bt_mesh_model_publish err %d\n", err);
		} else {
			is_light_ctl_state_published = true;
		}
	}
}
@@ -1755,6 +1738,32 @@ static void light_ctl_temp_get(struct bt_mesh_model *model,
	}
}

void light_ctl_temp_publisher(struct bt_mesh_model *model)
{
	struct net_buf_simple *msg = model->pub->msg;
	struct light_ctl_state *state = model->user_data;

	if (model->pub->addr != BT_MESH_ADDR_UNASSIGNED) {
		int err;

		bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x66));
		net_buf_simple_add_le16(msg, state->temp);
		net_buf_simple_add_le16(msg, state->delta_uv);

		if (state->transition->counter) {
			calculate_rt(state->transition);
			net_buf_simple_add_le16(msg, state->target_temp);
			net_buf_simple_add_le16(msg, state->target_delta_uv);
			net_buf_simple_add_u8(msg, state->transition->rt);
		}

		err = bt_mesh_model_publish(model);
		if (err) {
			printk("bt_mesh_model_publish err %d\n", err);
		}
	}
}

static bool light_ctl_temp_setunack(struct bt_mesh_model *model,
				    struct bt_mesh_msg_ctx *ctx,
				    struct net_buf_simple *buf)
@@ -1763,7 +1772,6 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model,
	s16_t delta_uv;
	u16_t temp;
	s64_t now;
	struct net_buf_simple *msg = model->pub->msg;
	struct light_ctl_state *state = model->user_data;

	temp = net_buf_simple_pull_le16(buf);
@@ -1830,25 +1838,7 @@ static bool light_ctl_temp_setunack(struct bt_mesh_model *model,

	light_ctl_temp_handler(state);

	if (model->pub->addr != BT_MESH_ADDR_UNASSIGNED) {
		int err;

		bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x66));
		net_buf_simple_add_le16(msg, state->temp);
		net_buf_simple_add_le16(msg, state->delta_uv);

		if (state->transition->counter) {
			calculate_rt(state->transition);
			net_buf_simple_add_le16(msg, state->target_temp);
			net_buf_simple_add_le16(msg, state->target_delta_uv);
			net_buf_simple_add_u8(msg, state->transition->rt);
		}

		err = bt_mesh_model_publish(model);
		if (err) {
			printk("bt_mesh_model_publish err %d\n", err);
		}
	}
	light_ctl_temp_publisher(model);

	return true;
}
+1 −28
Original line number Diff line number Diff line
@@ -26,30 +26,6 @@
#define CANNOT_SET_RANGE_MIN		0x01
#define CANNOT_SET_RANGE_MAX		0x02

enum get_messages {
	NULL_GET = 0x00,
	ONOFF_GET,
	LEVEL_GET,
	LIGHT_LIGHTNESS_ACTUAL_GET,
	LIGHT_LIGHTNESS_LINEAR_GET,
	LIGHT_CTL_GET
};

enum status {
	PUB_ONOFF_1 = 0x0301,
	PUB_ONOFF_2 = 0x0401,
	PUB_ONOFF_3 = 0x0501,
	PUB_LEVEL_1 = 0x0302,
	PUB_LEVEL_2 = 0x0402,
	PUB_LEVEL_3 = 0x0502,
	PUB_LIGHT_ACTUAL_1 = 0x0403,
	PUB_LIGHT_ACTUAL_2 = 0x0503,
	PUB_LIGHT_LINEAR_1 = 0x0304,
	PUB_LIGHT_LINEAR_2 = 0x0504,
	PUB_LIGHT_CTL_1 = 0x0305,
	PUB_LIGHT_CTL_2 = 0x0405
};

enum lightness {
	ONPOWERUP = 0x01,
	ONOFF,
@@ -193,14 +169,11 @@ extern struct bt_mesh_model s0_models[];

extern const struct bt_mesh_comp comp;

extern u8_t get_msg, last_get_msg;
extern bool is_light_lightness_actual_state_published;
extern bool is_light_ctl_state_published;

void gen_onoff_publisher(struct bt_mesh_model *model);
void gen_level_publisher(struct bt_mesh_model *model);
void light_lightness_publisher(struct bt_mesh_model *model);
void light_lightness_linear_publisher(struct bt_mesh_model *model);
void light_ctl_publisher(struct bt_mesh_model *model);
void light_ctl_temp_publisher(struct bt_mesh_model *model);

#endif