From d598a55d7d09fca9f65ad4d4cee9875940f8b7d6 Mon Sep 17 00:00:00 2001 From: Ingar Kulbrandstad Date: Thu, 10 Aug 2023 10:50:27 +0200 Subject: [PATCH] Bluetoth: Mesh: Fixing Light LC SM conditions According to sections 6.2.3.5 of MshMDLd1.1r12, the value of the Light LC Ambient LuxLevel state is set to 0 at power-up and when the node is provisioned on the network. According to sections 6.2.5.12 and 6.2.5.7 the Occupancy On should not trigger any transition. Signed-off-by: Ingar Kulbrandstad --- include/bluetooth/mesh/light_ctrl_srv.h | 13 ++++++++--- subsys/bluetooth/mesh/light_ctrl_srv.c | 30 +++++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/bluetooth/mesh/light_ctrl_srv.h b/include/bluetooth/mesh/light_ctrl_srv.h index ad4889fa8e6..bfdc723150d 100644 --- a/include/bluetooth/mesh/light_ctrl_srv.h +++ b/include/bluetooth/mesh/light_ctrl_srv.h @@ -99,11 +99,18 @@ struct bt_mesh_light_ctrl_srv; /** Light Lightness Control Server state */ enum bt_mesh_light_ctrl_srv_state { - /** Standby state */ + /** Standby state, merges the Light LC State Machine states of OFF, + * STANDBY, FADE_STANDBY_AUTO and FADE_STANDBY_MANUAL in the Mesh Model + * Specification section 6.2.5. + */ LIGHT_CTRL_STATE_STANDBY, - /** On state */ + /** On state, merges the Light LC State Machine states of FADE_ON and + * RUN in the Mesh Model Specification section 6.2.5. + */ LIGHT_CTRL_STATE_ON, - /** Prolong state */ + /** Prolong state, merges the Light LC State Machine states of FADE and + * PROLONG in the Mesh Model Specification section 6.2.5. + */ LIGHT_CTRL_STATE_PROLONG, /** The number of states. */ diff --git a/subsys/bluetooth/mesh/light_ctrl_srv.c b/subsys/bluetooth/mesh/light_ctrl_srv.c index 2cc6bc9fe9a..cbe51707514 100644 --- a/subsys/bluetooth/mesh/light_ctrl_srv.c +++ b/subsys/bluetooth/mesh/light_ctrl_srv.c @@ -999,13 +999,29 @@ static int handle_sensor_status(struct bt_mesh_model *model, struct bt_mesh_msg_ /* Occupancy sensor */ - /* OCC_MODE must be enabled for the occupancy sensors to be - * able to turn on the light: - */ - if (srv->state == LIGHT_CTRL_STATE_STANDBY && - !atomic_test_bit(&srv->flags, FLAG_OCC_MODE) && - !(atomic_test_bit(&srv->flags, FLAG_TRANSITION) && - !atomic_test_bit(&srv->flags, FLAG_MANUAL))) { + if ((srv->state == LIGHT_CTRL_STATE_STANDBY && + /* According to the Mesh Model Specification section + * 6.2.5.6: When in the specifications STANDBY state, + * and the Auto Occupancy condition is false, the + * Occupancy On event should not be processed. + */ + ((!atomic_test_bit(&srv->flags, FLAG_OCC_MODE) && + !atomic_test_bit(&srv->flags, FLAG_TRANSITION) && + !atomic_test_bit(&srv->flags, FLAG_MANUAL)) + || + /* According to the Mesh Model Specification section + * 6.2.5.12: When in the specifications FADE STANDBY + * MANUAL state, the Occupancy On event should not be + * processed. + */ + (atomic_test_bit(&srv->flags, FLAG_TRANSITION) && + atomic_test_bit(&srv->flags, FLAG_MANUAL)))) || + /* According to the Mesh Model Specification section + * 6.2.5.7: When in the specifications FADE ON state, the + * Occupancy On event should not be processed. + */ + (srv->state == LIGHT_CTRL_STATE_ON && + atomic_test_bit(&srv->flags, FLAG_TRANSITION))) { continue; }