@@ -833,15 +833,16 @@ static void gen_def_trans_time_publish(struct bt_mesh_model *model)
833833 }
834834}
835835
836- static bool gen_def_trans_time_setunack (struct bt_mesh_model * model ,
837- struct bt_mesh_msg_ctx * ctx ,
838- struct net_buf_simple * buf )
836+ static void gen_def_trans_time_set_unack (struct bt_mesh_model * model ,
837+ struct bt_mesh_msg_ctx * ctx ,
838+ struct net_buf_simple * buf )
839839{
840840 u8_t tt ;
841+
841842 tt = net_buf_simple_pull_u8 (buf );
842843
843844 if ((tt & 0x3F ) == 0x3F ) {
844- return false ;
845+ return ;
845846 }
846847
847848 if (ctl -> tt != tt ) {
@@ -851,27 +852,31 @@ static bool gen_def_trans_time_setunack(struct bt_mesh_model *model,
851852 gen_def_trans_time_publish (model );
852853 save_on_flash (GEN_DEF_TRANS_TIME_STATE );
853854 }
854-
855- return true;
856- }
857-
858- static void gen_def_trans_time_set_unack (struct bt_mesh_model * model ,
859- struct bt_mesh_msg_ctx * ctx ,
860- struct net_buf_simple * buf )
861- {
862- gen_def_trans_time_setunack (model , ctx , buf );
863855}
864856
865857static void gen_def_trans_time_set (struct bt_mesh_model * model ,
866858 struct bt_mesh_msg_ctx * ctx ,
867859 struct net_buf_simple * buf )
868860{
869- if (gen_def_trans_time_setunack (model , ctx , buf ) == true) {
870- gen_def_trans_time_get (model , ctx , buf );
861+ u8_t tt ;
862+
863+ tt = net_buf_simple_pull_u8 (buf );
864+
865+ if ((tt & 0x3F ) == 0x3F ) {
866+ return ;
871867 }
872- }
873868
869+ if (ctl -> tt != tt ) {
870+ ctl -> tt = tt ;
871+ default_tt = tt ;
874872
873+ gen_def_trans_time_get (model , ctx , buf );
874+ gen_def_trans_time_publish (model );
875+ save_on_flash (GEN_DEF_TRANS_TIME_STATE );
876+ } else {
877+ gen_def_trans_time_get (model , ctx , buf );
878+ }
879+ }
875880
876881/* Generic Default Transition Time Client message handlers */
877882static void gen_def_trans_time_status (struct bt_mesh_model * model ,
@@ -926,15 +931,16 @@ static void gen_onpowerup_publish(struct bt_mesh_model *model)
926931 }
927932}
928933
929- static bool gen_onpowerup_setunack (struct bt_mesh_model * model ,
930- struct bt_mesh_msg_ctx * ctx ,
931- struct net_buf_simple * buf )
934+ static void gen_onpowerup_set_unack (struct bt_mesh_model * model ,
935+ struct bt_mesh_msg_ctx * ctx ,
936+ struct net_buf_simple * buf )
932937{
933938 u8_t onpowerup ;
939+
934940 onpowerup = net_buf_simple_pull_u8 (buf );
935941
936942 if (onpowerup > STATE_RESTORE ) {
937- return false ;
943+ return ;
938944 }
939945
940946 if (ctl -> onpowerup != onpowerup ) {
@@ -943,22 +949,27 @@ static bool gen_onpowerup_setunack(struct bt_mesh_model *model,
943949 gen_onpowerup_publish (model );
944950 save_on_flash (GEN_ONPOWERUP_STATE );
945951 }
946-
947- return true;
948- }
949-
950- static void gen_onpowerup_set_unack (struct bt_mesh_model * model ,
951- struct bt_mesh_msg_ctx * ctx ,
952- struct net_buf_simple * buf )
953- {
954- gen_onpowerup_setunack (model , ctx , buf );
955952}
956953
957954static void gen_onpowerup_set (struct bt_mesh_model * model ,
958955 struct bt_mesh_msg_ctx * ctx ,
959956 struct net_buf_simple * buf )
960957{
961- if (gen_onpowerup_setunack (model , ctx , buf ) == true) {
958+ u8_t onpowerup ;
959+
960+ onpowerup = net_buf_simple_pull_u8 (buf );
961+
962+ if (onpowerup > STATE_RESTORE ) {
963+ return ;
964+ }
965+
966+ if (ctl -> onpowerup != onpowerup ) {
967+ ctl -> onpowerup = onpowerup ;
968+
969+ gen_onpowerup_get (model , ctx , buf );
970+ gen_onpowerup_publish (model );
971+ save_on_flash (GEN_ONPOWERUP_STATE );
972+ } else {
962973 gen_onpowerup_get (model , ctx , buf );
963974 }
964975}
@@ -1483,8 +1494,20 @@ static void light_lightness_default_set(struct bt_mesh_model *model,
14831494 struct bt_mesh_msg_ctx * ctx ,
14841495 struct net_buf_simple * buf )
14851496{
1486- light_lightness_default_set_unack (model , ctx , buf );
1487- light_lightness_default_get (model , ctx , buf );
1497+ u16_t lightness ;
1498+
1499+ lightness = net_buf_simple_pull_le16 (buf );
1500+ lightness = constrain_lightness (lightness );
1501+
1502+ if (ctl -> light -> def != lightness ) {
1503+ ctl -> light -> def = lightness ;
1504+
1505+ light_lightness_default_get (model , ctx , buf );
1506+ light_lightness_default_publish (model );
1507+ save_on_flash (DEF_STATES );
1508+ } else {
1509+ light_lightness_default_get (model , ctx , buf );
1510+ }
14881511}
14891512
14901513static void light_lightness_range_publish (struct bt_mesh_model * model )
@@ -1507,53 +1530,70 @@ static void light_lightness_range_publish(struct bt_mesh_model *model)
15071530 }
15081531}
15091532
1510- static bool light_lightness_range_setunack (struct bt_mesh_model * model ,
1511- struct bt_mesh_msg_ctx * ctx ,
1512- struct net_buf_simple * buf )
1533+ static void light_lightness_range_set_unack (struct bt_mesh_model * model ,
1534+ struct bt_mesh_msg_ctx * ctx ,
1535+ struct net_buf_simple * buf )
15131536{
15141537 u16_t min , max ;
15151538
15161539 min = net_buf_simple_pull_le16 (buf );
15171540 max = net_buf_simple_pull_le16 (buf );
15181541
15191542 if (min == 0U || max == 0U ) {
1520- return false;
1521- } else {
1522- if (min <= max ) {
1523- ctl -> light -> status_code = RANGE_SUCCESSFULLY_UPDATED ;
1543+ return ;
1544+ }
15241545
1525- if (ctl -> light -> range_min != min ||
1526- ctl -> light -> range_max != max ) {
1546+ if (min <= max ) {
1547+ ctl -> light -> status_code = RANGE_SUCCESSFULLY_UPDATED ;
15271548
1528- ctl -> light -> range_min = min ;
1529- ctl -> light -> range_max = max ;
1549+ if ( ctl -> light -> range_min ! = min ||
1550+ ctl -> light -> range_max ! = max ) {
15301551
1531- light_lightness_range_publish (model );
1532- save_on_flash (LIGHTNESS_RANGE );
1533- }
1534- } else {
1535- /* The provided value for Range Max cannot be set */
1536- ctl -> light -> status_code = CANNOT_SET_RANGE_MAX ;
1537- return false;
1552+ ctl -> light -> range_min = min ;
1553+ ctl -> light -> range_max = max ;
1554+
1555+ light_lightness_range_publish (model );
1556+ save_on_flash (LIGHTNESS_RANGE );
15381557 }
1558+ } else {
1559+ /* The provided value for Range Max cannot be set */
1560+ ctl -> light -> status_code = CANNOT_SET_RANGE_MAX ;
1561+ return ;
15391562 }
1540-
1541- return true;
1542- }
1543-
1544- static void light_lightness_range_set_unack (struct bt_mesh_model * model ,
1545- struct bt_mesh_msg_ctx * ctx ,
1546- struct net_buf_simple * buf )
1547- {
1548- light_lightness_range_setunack (model , ctx , buf );
15491563}
15501564
15511565static void light_lightness_range_set (struct bt_mesh_model * model ,
15521566 struct bt_mesh_msg_ctx * ctx ,
15531567 struct net_buf_simple * buf )
15541568{
1555- if (light_lightness_range_setunack (model , ctx , buf ) == true) {
1556- light_lightness_range_get (model , ctx , buf );
1569+ u16_t min , max ;
1570+
1571+ min = net_buf_simple_pull_le16 (buf );
1572+ max = net_buf_simple_pull_le16 (buf );
1573+
1574+ if (min == 0U || max == 0U ) {
1575+ return ;
1576+ }
1577+
1578+ if (min <= max ) {
1579+ ctl -> light -> status_code = RANGE_SUCCESSFULLY_UPDATED ;
1580+
1581+ if (ctl -> light -> range_min != min ||
1582+ ctl -> light -> range_max != max ) {
1583+
1584+ ctl -> light -> range_min = min ;
1585+ ctl -> light -> range_max = max ;
1586+
1587+ light_lightness_range_get (model , ctx , buf );
1588+ light_lightness_range_publish (model );
1589+ save_on_flash (LIGHTNESS_RANGE );
1590+ } else {
1591+ light_lightness_range_get (model , ctx , buf );
1592+ }
1593+ } else {
1594+ /* The provided value for Range Max cannot be set */
1595+ ctl -> light -> status_code = CANNOT_SET_RANGE_MAX ;
1596+ return ;
15571597 }
15581598}
15591599
@@ -1884,9 +1924,9 @@ static void light_ctl_default_publish(struct bt_mesh_model *model)
18841924 }
18851925}
18861926
1887- static bool light_ctl_default_setunack (struct bt_mesh_model * model ,
1888- struct bt_mesh_msg_ctx * ctx ,
1889- struct net_buf_simple * buf )
1927+ static void light_ctl_default_set_unack (struct bt_mesh_model * model ,
1928+ struct bt_mesh_msg_ctx * ctx ,
1929+ struct net_buf_simple * buf )
18901930{
18911931 u16_t lightness , temp ;
18921932 s16_t delta_uv ;
@@ -1896,7 +1936,7 @@ static bool light_ctl_default_setunack(struct bt_mesh_model *model,
18961936 delta_uv = (s16_t ) net_buf_simple_pull_le16 (buf );
18971937
18981938 if (temp < TEMP_MIN || temp > TEMP_MAX ) {
1899- return false ;
1939+ return ;
19001940 }
19011941
19021942 lightness = constrain_lightness (lightness );
@@ -1911,22 +1951,36 @@ static bool light_ctl_default_setunack(struct bt_mesh_model *model,
19111951 light_ctl_default_publish (model );
19121952 save_on_flash (DEF_STATES );
19131953 }
1914-
1915- return true;
1916- }
1917-
1918- static void light_ctl_default_set_unack (struct bt_mesh_model * model ,
1919- struct bt_mesh_msg_ctx * ctx ,
1920- struct net_buf_simple * buf )
1921- {
1922- light_ctl_default_setunack (model , ctx , buf );
19231954}
19241955
19251956static void light_ctl_default_set (struct bt_mesh_model * model ,
19261957 struct bt_mesh_msg_ctx * ctx ,
19271958 struct net_buf_simple * buf )
19281959{
1929- if (light_ctl_default_setunack (model , ctx , buf ) == true) {
1960+ u16_t lightness , temp ;
1961+ s16_t delta_uv ;
1962+
1963+ lightness = net_buf_simple_pull_le16 (buf );
1964+ temp = net_buf_simple_pull_le16 (buf );
1965+ delta_uv = (s16_t ) net_buf_simple_pull_le16 (buf );
1966+
1967+ if (temp < TEMP_MIN || temp > TEMP_MAX ) {
1968+ return ;
1969+ }
1970+
1971+ lightness = constrain_lightness (lightness );
1972+ temp = constrain_temperature (temp );
1973+
1974+ if (ctl -> light -> def != lightness || ctl -> temp -> def != temp ||
1975+ ctl -> duv -> def != delta_uv ) {
1976+ ctl -> light -> def = lightness ;
1977+ ctl -> temp -> def = temp ;
1978+ ctl -> duv -> def = delta_uv ;
1979+
1980+ light_ctl_default_get (model , ctx , buf );
1981+ light_ctl_default_publish (model );
1982+ save_on_flash (DEF_STATES );
1983+ } else {
19301984 light_ctl_default_get (model , ctx , buf );
19311985 }
19321986}
@@ -1951,9 +2005,9 @@ static void light_ctl_temp_range_publish(struct bt_mesh_model *model)
19512005 }
19522006}
19532007
1954- static bool light_ctl_temp_range_setunack (struct bt_mesh_model * model ,
1955- struct bt_mesh_msg_ctx * ctx ,
1956- struct net_buf_simple * buf )
2008+ static void light_ctl_temp_range_set_unack (struct bt_mesh_model * model ,
2009+ struct bt_mesh_msg_ctx * ctx ,
2010+ struct net_buf_simple * buf )
19572011{
19582012 u16_t min , max ;
19592013
@@ -1963,7 +2017,7 @@ static bool light_ctl_temp_range_setunack(struct bt_mesh_model *model,
19632017 /* This is as per 6.1.3.1 in Mesh Model Specification */
19642018 if (min < TEMP_MIN || min > TEMP_MAX ||
19652019 max < TEMP_MIN || max > TEMP_MAX ) {
1966- return false ;
2020+ return ;
19672021 }
19682022
19692023 if (min <= max ) {
@@ -1981,25 +2035,44 @@ static bool light_ctl_temp_range_setunack(struct bt_mesh_model *model,
19812035 } else {
19822036 /* The provided value for Range Max cannot be set */
19832037 ctl -> temp -> status_code = CANNOT_SET_RANGE_MAX ;
1984- return false ;
2038+ return ;
19852039 }
1986-
1987- return true;
1988- }
1989-
1990- static void light_ctl_temp_range_set_unack (struct bt_mesh_model * model ,
1991- struct bt_mesh_msg_ctx * ctx ,
1992- struct net_buf_simple * buf )
1993- {
1994- light_ctl_temp_range_setunack (model , ctx , buf );
19952040}
19962041
19972042static void light_ctl_temp_range_set (struct bt_mesh_model * model ,
19982043 struct bt_mesh_msg_ctx * ctx ,
19992044 struct net_buf_simple * buf )
20002045{
2001- if (light_ctl_temp_range_setunack (model , ctx , buf ) == true) {
2002- light_ctl_temp_range_get (model , ctx , buf );
2046+ u16_t min , max ;
2047+
2048+ min = net_buf_simple_pull_le16 (buf );
2049+ max = net_buf_simple_pull_le16 (buf );
2050+
2051+ /* This is as per 6.1.3.1 in Mesh Model Specification */
2052+ if (min < TEMP_MIN || min > TEMP_MAX ||
2053+ max < TEMP_MIN || max > TEMP_MAX ) {
2054+ return ;
2055+ }
2056+
2057+ if (min <= max ) {
2058+ ctl -> temp -> status_code = RANGE_SUCCESSFULLY_UPDATED ;
2059+
2060+ if (ctl -> temp -> range_min != min ||
2061+ ctl -> temp -> range_max != max ) {
2062+
2063+ ctl -> temp -> range_min = min ;
2064+ ctl -> temp -> range_max = max ;
2065+
2066+ light_ctl_temp_range_get (model , ctx , buf );
2067+ light_ctl_temp_range_publish (model );
2068+ save_on_flash (TEMPERATURE_RANGE );
2069+ } else {
2070+ light_ctl_temp_range_get (model , ctx , buf );
2071+ }
2072+ } else {
2073+ /* The provided value for Range Max cannot be set */
2074+ ctl -> temp -> status_code = CANNOT_SET_RANGE_MAX ;
2075+ return ;
20032076 }
20042077}
20052078
0 commit comments