1
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
28
29
33
34
35
36
37
38
39
40
41
42
43
44
45
49
50
62
63
64
119
120
126
127
128
129
130
131
132
133
134
135
139
140
141
146
147
148
151
154
157
160
163
166
167
168
169
170
171
172
173
177
178
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
217
218
219
220
221
224
225
226
238
239
247
248
249
250
251
252
253
260
261
262
266
269
272
273
274
275
278
279
280
281
282
283
284
285
288
289
290
302
303
304
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
328
329
330
331
332
335
336
337
349
350
358
359
360
361
362
363
364
365
366
370
373
376
377
378
379
382
383
384
385
386
387
388
389
392
393
394
397
398
399
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
420
421
422
423
424
432
433
442
443
446
447
448
449
450
451
452
453
454
455
456
460
461
462
463
464
469
470
471
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
502
503
506
507
510
511
515
516
517
518
521
522
523
524
525
526
527
528
529
530
531
532
533
537
538
550
551
552
553
554
555
556
557
563
564
565
578
593
594
595
596
602
603
604
610
611
612
618
619
620
621
622
623
624
625
626
627
631
632
655
656
657
662
663
680
681
682
683
684
685
686
690
691
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
739
740
741
742
743
744
745
749
750
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
778
779
780
781
782
783
784
785
786
787
790
791
794
795
796
797
798
799
802
807
808
809
810
813
814
815
816
817
818
819
820
823
824
825
830
831
832
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
854
855
856
857
858
859
863
864
865
875
876
877
878
881
882
885
886
887
888
889
890
895
896
897
898
901
902
903
904
905
906
907
908
909
910
911
915
916
917
918
919
920
921
922
927
928
929
938
939
946
947
950
951
954
955
959
960
961
962
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
983
984
985
986
987
988
992
993
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1020
1021
1022
1023
1024
1025
1026
1027
1028
1031
1032
1035
1036
1037
1038
1039
1042
1046
1047
1048
1049
1052
1053
1054
1055
1056
1057
1058
1059
1062
1063
1064
1068
1069
1070
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1093
1094
1106
1107
1108
1109
1110
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1169
1170
1171
1172
1173
1174
1179
1180
1181
1187
1188
1189
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1208
1209
1210
1211
1212
1216
1217
1218
1219
1220
1221
1225
1226
1227
1228
1229
1230
1234
1235
1236
1237
1240
1241
1242
1243
1248
1249
1250
1253
1256
1259
1262
1265
1268
1271
1272
1273
1274
1275
1276
1277
1278
1282
1283
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1338
1339
1340
1341
1342
1343
1344
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1372
1373
1374
1375
1376
1377
1378
1379
1384
1385
1390
1391
1392
1396
1397
1398
1401
1406
1407
1408
1409
1412
1413
1414
1415
1416
1417
1418
1419
1422
1423
1424
1429
1430
1431
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1452
1453
1454
1455
1456
1457
1458
1468
1469
1474
1475
1480
1481
1482
1483
1484
1485
1490
1491
1492
1493
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1510
1511
1512
1513
1514
1515
1516
1521
1522
1527
1528
1529
1540
1541
1542
1543
1544
1545
1546
1547
1553
1554
1555
1556
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1576
1577
1578
1579
1580
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1606
1607
1608
1609
1610
1611
1612
1617
1618
1619
1623
1626
1629
1630
1631
1632
1635
1636
1637
1638
1639
1640
1641
1642
1645
1646
1647
1650
1651
1652
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1676
1677
1678
1679
1680
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1706
1707
1708
1709
1710
1711
1712
1717
1718
1719
1723
1726
1729
1730
1731
1732
1735
1736
1737
1738
1739
1740
1741
1742
1745
1746
1747
1750
1751
1752
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1775
1776
1788
1789
1790
1791
1792
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1849
1850
1851
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1870
1871
1872
1877
1878
1879
1882
1885
1888
1891
1894
1895
1896
1897
1898
1899
1900
1901
1905
1906
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1945
1946
1947
1948
1949
1950
1951
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1979
1980
1981
1982
1983
1984
1985
1986
1991
1992
1997
1998
1999
2003
2004
2005
2008
2013
2014
2015
2016
2019
2020
2021
2022
2023
2024
2025
2026
2029
2030
2031
2036
2037
2038
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2059
2060
2061
2062
2063
2064
2065
2075
2076
2081
2082
2087
2088
2089
2090
2091
2092
2097
2098
2099
2100
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2117
2118
2119
2120
2121
2122
2123
2128
2129
2134
2135
2136
2147
2148
2149
2150
2151
2152
2153
2154
2160
2161
2162
2163
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2182
2183
2195
2196
2197
2219
2220
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2239
2240
2241
2246
2247
2261
2262
2263
2264
2265
2266
2267
2268
2269
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2288
2289
2290
2294
2295
2296
2304
2305
2306
2307
2310
2311
2312
2313
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2330
2331
2332
2336
2337
2338
2346
2347
2348
2349
2352
2353
2354
2355
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2375
2376
2377
2378
2379
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2405
2406
2407
2408
2409
2410
2411
2412
2413
2416
2419
2420
2421
2422
2425
2426
2427
2428
2429
2430
2431
2432
2435
2436
2437
2440
2441
2442
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2490
2491
2499
2500
2501
2509
2510
2511
2512
2513
2514
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2581
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2608
2611
2614
2617
2620
2623
2626
2629
2632
2635
2638
2641
2644
2647
2650
2653
2656
2659
2660
2661
2662
2663
2664
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2687
2688
2700
2701
2702
2703
2704
2705
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2724
2725
2726
2730
2731
2732
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2756
2757
2758
2762
2763
2772
2773
2774
2779
2780
2781
2785
2786
2787
2788
2792
2793
2794
2795
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2880
2881
2882
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2931
2932
2933
2934
2938
2939
2940
2941
2942
2946
2952
2953
2954
2955
2956
2957
2961
2962
2963
2964
2965
2966
2970
2974
2975
2976
2977
2978
2979
2983
2984
2985
2986
2987
2988
2992
2996
2997
2998
2999
3000
3001
3005
3009
3010
3011
3012
3013
3014
3018
3019
3020
3021
3022
3023
3027
3031
3032
3033
3034
3035
3036
3040
3044
3045
3046
3047
3048
3049
3053
3057
3058
3059
3060
3061
3062
3066
3067
3068
3069
3070
3071
3075
3079
3080
3081
3082
3083
3084
3088
3089
3090
3091
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3107
3108
3111
3112
3116
3117
3118
3119
3123
3124
3125
3126
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3144
3148
3149
3150
3151
3155
3156
3165
3166
3167
3168
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3187
3191
3192
3193
3194
3198
3199
3208
3209
3218
3219
3220
3221
3225
3226
3230
3231
3235
3236
3237
3238
3242
3243
3252
3253
3254
3255
3259
3260
3264
3265
3269
3270
3271
3272
3273
3274
3275
3279
3280
3281
3282
3283
3287
3293
3294
3295
3296
3297
3301
3305
3306
3307
3308
3309
3313
3317
3318
3319
3320
3321
3325
3329
3330
3331
3332
3333
3337
3341
3342
3343
3344
3345
3349
3353
3354
3355
3356
3357
3361
3365
3366
3367
3368
3369
3373
3377
3378
3379
3380
3381
3382
3383
3385
3388
3389
3390
3391
3392
3393
3394
3395
3404
3405
3409
3410
3419
3420
3424
3425
3434
3435
3444
3445
3449
3450
3459
3460
3469
3470
3479
3480
3484
3485
3494
3495
3504
3505
3506
3512
3513
3519
3520
3526
3527
3533
3534
3540
3541
3547
3548
3554
3555
3561
3562
3568
3569
3575
3576
3582
3583
3589
3590
3596
3597
/* ... */
#include <errno.h>
#include "btc_ble_mesh_lighting_model.h"
#include "mesh/config.h"
#include "access.h"
#include "transport.h"
#include "mesh/model_opcode.h"
#include "mesh/state_transition.h"
#include "mesh/device_property.h"8 includes
#if CONFIG_BLE_MESH_LIGHTING_SERVER
static bt_mesh_mutex_t light_server_lock;
void bt_mesh_light_server_lock(void)
{
bt_mesh_mutex_lock(&light_server_lock);
}{ ... }
void bt_mesh_light_server_unlock(void)
{
bt_mesh_mutex_unlock(&light_server_lock);
}{ ... }
static void send_light_lightness_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
bool publish, uint16_t opcode)
{
struct net_buf_simple *msg = NULL;
uint8_t length = 2 + 5;
if (ctx == NULL && publish == false) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, opcode);
switch (opcode) {
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_actual);
if (srv->actual_transition.counter) {
bt_mesh_server_calc_remain_time(&srv->actual_transition);
net_buf_simple_add_le16(msg, srv->state->target_lightness_actual);
net_buf_simple_add_u8(msg, srv->actual_transition.remain_time);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_linear);
if (srv->linear_transition.counter) {
bt_mesh_server_calc_remain_time(&srv->linear_transition);
net_buf_simple_add_le16(msg, srv->state->target_lightness_linear);
net_buf_simple_add_u8(msg, srv->linear_transition.remain_time);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_last);
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV) {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV) {
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
}{...}
break;...
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV) {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->lightness_range_min);
net_buf_simple_add_le16(msg, srv->state->lightness_range_max);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV) {
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->lightness_range_min);
net_buf_simple_add_le16(msg, srv->state->lightness_range_max);
}{...}
break;...
default:
BT_WARN("Unknown Light Lightness status opcode 0x%04x", opcode);
if (publish == false) {
bt_mesh_free_buf(msg);
}{...}
return;...
}{...}
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_lightness_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lightness_srv *srv = model->user_data;
uint16_t opcode = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
if (srv->rsp_ctrl.get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, NULL, 0);
return;
}{...}
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS;
break;...
default:
BT_WARN("Unknown Light Lightness Get opcode 0x%04x", ctx->recv_op);
return;...
}{...}
send_light_lightness_status(model, ctx, false, opcode);
}{ ... }
void light_lightness_publish(struct bt_mesh_model *model, uint16_t opcode)
{
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light Lightness Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV: {
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light Lightness Setup Server state");
return;
}{...}
break;
}{...}
... default:
BT_ERR("Invalid Light Lightness Server model 0x%04x", model->id);
return;...
}{...}
send_light_lightness_status(model, NULL, true, opcode);
}{ ... }
static void light_lightness_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lightness_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
bool optional = false;
uint16_t actual = 0U;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
actual = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lightness_set.op_en = optional,
.lightness_set.lightness = actual,
.lightness_set.tid = tid,
.lightness_set.trans_time = trans_time,
.lightness_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->actual_transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
if (actual) {
if (srv->state->lightness_range_min && actual < srv->state->lightness_range_min) {
actual = srv->state->lightness_range_min;
}{...} else if (srv->state->lightness_range_max && actual > srv->state->lightness_range_max) {
actual = srv->state->lightness_range_max;
}{...}
}{...}
srv->state->target_lightness_actual = actual;
/* ... */
if (srv->state->target_lightness_actual != srv->state->lightness_actual) {
light_lightness_actual_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.lightness_set.lightness = srv->state->lightness_actual,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->actual_transition.timer.work.user_data) {
memcpy(srv->actual_transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->actual_transition.counter == 0U) {
srv->state->lightness_actual = srv->state->target_lightness_actual;
/* ... */
if (srv->state->lightness_actual) {
srv->state->lightness_last = srv->state->lightness_actual;
}{...}
}{...}
srv->actual_transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->actual_transition);
}{ ... }
static void light_lightness_linear_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lightness_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
bool optional = false;
uint16_t linear = 0U;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
linear = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lightness_linear_set.op_en = optional,
.lightness_linear_set.lightness = linear,
.lightness_linear_set.tid = tid,
.lightness_linear_set.trans_time = trans_time,
.lightness_linear_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->linear_transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
srv->state->target_lightness_linear = linear;
/* ... */
if (srv->state->target_lightness_linear != srv->state->lightness_linear) {
light_lightness_linear_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.lightness_linear_set.lightness = srv->state->lightness_actual,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->linear_transition.timer.work.user_data) {
memcpy(srv->linear_transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->linear_transition.counter == 0U) {
srv->state->lightness_linear = srv->state->target_lightness_linear;
}{...}
srv->linear_transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->linear_transition);
}{ ... }
static void light_lightness_default_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
uint16_t lightness = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lightness_default_set.lightness = lightness,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (srv->state->lightness_default != lightness) {
srv->state->lightness_default = lightness;
bt_mesh_light_server_state_change_t change = {
.lightness_default_set.lightness = lightness,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
}{...}
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS);
}{ ... }
static void light_lightness_range_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
uint16_t range_min = 0U, range_max = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
range_min = net_buf_simple_pull_le16(buf);
range_max = net_buf_simple_pull_le16(buf);
if (range_min > range_max) {
BT_ERR("Range min 0x%04x is greater than range max 0x%04x",
range_min, range_max);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lightness_range_set.range_min = range_min,
.lightness_range_set.range_max = range_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
/* ... */
#if 0
srv->state->status_code = BLE_MESH_RANGE_UPDATE_SUCCESS;
#else
if (range_min == 0x0000) {
srv->state->status_code = BLE_MESH_CANNOT_SET_RANGE_MIN;
}{...} else if (range_max == 0x0000) {
srv->state->status_code = BLE_MESH_CANNOT_SET_RANGE_MAX;
}{...} else {
srv->state->status_code = BLE_MESH_RANGE_UPDATE_SUCCESS;
}{...}
#endif/* ... */
if (range_min && srv->state->lightness_range_min != range_min) {
srv->state->lightness_range_min = range_min;
}{...}
if (range_max && srv->state->lightness_range_max != range_max) {
srv->state->lightness_range_max = range_max;
}{...}
bt_mesh_light_server_state_change_t change = {
.lightness_range_set.range_min = srv->state->lightness_range_min,
.lightness_range_set.range_max = srv->state->lightness_range_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET) {
send_light_lightness_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS);
}{...}
send_light_lightness_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS);
}{ ... }
static void send_light_ctl_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
bool publish, uint16_t opcode)
{
struct net_buf_simple *msg = NULL;
uint8_t length = 2 + 9;
if (ctx == NULL && publish == false) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, opcode);
switch (opcode) {
case BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS: {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness);
net_buf_simple_add_le16(msg, srv->state->temperature);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_le16(msg, srv->state->target_lightness);
net_buf_simple_add_le16(msg, srv->state->target_temperature);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_CTL_SRV) {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->temperature_range_min);
net_buf_simple_add_le16(msg, srv->state->temperature_range_max);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV) {
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->temperature_range_min);
net_buf_simple_add_le16(msg, srv->state->temperature_range_max);
}{...}
break;...
case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS: {
if (model->id == BLE_MESH_MODEL_ID_LIGHT_CTL_SRV) {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->temperature_default);
net_buf_simple_add_le16(msg, srv->state->delta_uv_default);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV) {
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->temperature_default);
net_buf_simple_add_le16(msg, srv->state->delta_uv_default);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS: {
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->temperature);
net_buf_simple_add_le16(msg, srv->state->delta_uv);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_le16(msg, srv->state->target_temperature);
net_buf_simple_add_le16(msg, srv->state->target_delta_uv);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
break;
}{...}
... default:
BT_WARN("Unknown Light CTL status opcode 0x%04x", opcode);
if (publish == false) {
bt_mesh_free_buf(msg);
}{...}
return;...
}{...}
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_ctl_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_server_rsp_ctrl *rsp_ctrl = NULL;
uint16_t opcode = 0U;
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL Server state");
return;
}{...}
rsp_ctrl = &srv->rsp_ctrl;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: {
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL Temperature Server state");
return;
}{...}
rsp_ctrl = &srv->rsp_ctrl;
break;
}{...}
... default:
BT_ERR("Invalid Light CTL Server model 0x%04x", model->id);
return;...
}{...}
if (rsp_ctrl->get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, NULL, 0);
return;
}{...}
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_CTL_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS;
break;...
default:
BT_WARN("Unknown Light CTL Get opcode 0x%04x", ctx->recv_op);
return;...
}{...}
send_light_ctl_status(model, ctx, false, opcode);
}{ ... }
void light_ctl_publish(struct bt_mesh_model *model, uint16_t opcode)
{
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: {
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL Temperature Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV: {
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL Setup Server state");
return;
}{...}
break;
}{...}
... default:
BT_ERR("Invalid Light CTL Server model 0x%04x", model->id);
return;...
}{...}
send_light_ctl_status(model, NULL, true, opcode);
}{ ... }
static void light_ctl_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_ctl_srv *srv = model->user_data;
uint16_t lightness = 0U, temperature = 0U;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
int16_t delta_uv = 0;
bool optional = false;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
temperature = net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) {
BT_ERR("Invalid temperature 0x%04x", temperature);
return;
}{...}
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.ctl_set.op_en = optional,
.ctl_set.lightness = lightness,
.ctl_set.temperature = temperature,
.ctl_set.delta_uv = delta_uv,
.ctl_set.tid = tid,
.ctl_set.trans_time = trans_time,
.ctl_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
srv->state->target_lightness = lightness;
if (srv->state->temperature_range_min &&
srv->state->temperature_range_min != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature < srv->state->temperature_range_min) {
temperature = srv->state->temperature_range_min;
}{...} else if (srv->state->temperature_range_max &&
srv->state->temperature_range_max != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature > srv->state->temperature_range_max) {
temperature = srv->state->temperature_range_max;
}{...}
srv->state->target_temperature = temperature;
srv->state->target_delta_uv = delta_uv;
if (srv->state->target_lightness != srv->state->lightness ||
srv->state->target_temperature != srv->state->temperature ||
srv->state->target_delta_uv != srv->state->delta_uv) {
light_ctl_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.ctl_set.lightness = srv->state->lightness,
.ctl_set.temperature = srv->state->temperature,
.ctl_set.delta_uv = srv->state->delta_uv,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->lightness = srv->state->target_lightness;
srv->state->temperature = srv->state->target_temperature;
srv->state->delta_uv = srv->state->target_delta_uv;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void light_ctl_default_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
uint16_t lightness = 0U, temperature = 0U;
int16_t delta_uv = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
temperature = net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) {
BT_ERR("Invalid temperature 0x%04x", temperature);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.ctl_default_set.lightness = lightness,
.ctl_default_set.temperature = temperature,
.ctl_default_set.delta_uv = delta_uv,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (srv->state->temperature_range_min &&
srv->state->temperature_range_min != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature < srv->state->temperature_range_min) {
temperature = srv->state->temperature_range_min;
}{...} else if (srv->state->temperature_range_max &&
srv->state->temperature_range_max != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature > srv->state->temperature_range_max) {
temperature = srv->state->temperature_range_max;
}{...}
srv->state->lightness_default = lightness;
srv->state->temperature_default = temperature;
srv->state->delta_uv_default = delta_uv;
bt_mesh_light_server_state_change_t change = {
.ctl_default_set.lightness = srv->state->lightness_default,
.ctl_default_set.temperature = srv->state->temperature_default,
.ctl_default_set.delta_uv = srv->state->delta_uv_default,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS);
}{ ... }
static void light_ctl_temp_range_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
uint16_t min = 0U, max = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
min = net_buf_simple_pull_le16(buf);
max = net_buf_simple_pull_le16(buf);
if (min > max ||
min < BLE_MESH_TEMPERATURE_MIN || (min != BLE_MESH_TEMPERATURE_UNKNOWN && min > BLE_MESH_TEMPERATURE_MAX) ||
max < BLE_MESH_TEMPERATURE_MIN || (max != BLE_MESH_TEMPERATURE_UNKNOWN && max > BLE_MESH_TEMPERATURE_MAX)) {
BT_ERR("Invalid parameter, range min 0x%04x, range max 0x%04x",
min, max);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.ctl_temp_range_set.range_min = min,
.ctl_temp_range_set.range_max = max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (min == BLE_MESH_TEMPERATURE_UNKNOWN) {
srv->state->status_code = BLE_MESH_CANNOT_SET_RANGE_MIN;
}{...} else if (max == BLE_MESH_TEMPERATURE_UNKNOWN ) {
srv->state->status_code = BLE_MESH_CANNOT_SET_RANGE_MAX;
}{...} else {
srv->state->status_code = BLE_MESH_RANGE_UPDATE_SUCCESS;
}{...}
if (min != BLE_MESH_TEMPERATURE_UNKNOWN && srv->state->temperature_range_min != min) {
srv->state->temperature_range_min = min;
}{...}
if (max != BLE_MESH_TEMPERATURE_UNKNOWN && srv->state->temperature_range_max != max) {
srv->state->temperature_range_max = max;
}{...}
bt_mesh_light_server_state_change_t change = {
.ctl_temp_range_set.range_min = srv->state->temperature_range_min,
.ctl_temp_range_set.range_max = srv->state->temperature_range_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS);
}{ ... }
static void light_ctl_temp_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
uint16_t temperature = 0U;
int16_t delta_uv = 0;
bool optional = false;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
temperature = net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) {
BT_ERR("Invalid temperature 0x%04x", temperature);
return;
}{...}
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.ctl_temp_set.op_en = optional,
.ctl_temp_set.temperature = temperature,
.ctl_temp_set.delta_uv = delta_uv,
.ctl_temp_set.tid = tid,
.ctl_temp_set.trans_time = trans_time,
.ctl_temp_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
if (srv->state->temperature_range_min &&
srv->state->temperature_range_min != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature < srv->state->temperature_range_min) {
temperature = srv->state->temperature_range_min;
}{...} else if (srv->state->temperature_range_max &&
srv->state->temperature_range_max != BLE_MESH_TEMPERATURE_UNKNOWN &&
temperature > srv->state->temperature_range_max) {
temperature = srv->state->temperature_range_max;
}{...}
srv->state->target_temperature = temperature;
srv->state->target_delta_uv = delta_uv;
if (srv->state->target_temperature != srv->state->temperature ||
srv->state->target_delta_uv != srv->state->delta_uv) {
light_ctl_temp_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.ctl_temp_set.temperature = srv->state->temperature,
.ctl_temp_set.delta_uv = srv->state->delta_uv,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->temperature = srv->state->target_temperature;
srv->state->delta_uv = srv->state->target_delta_uv;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET) {
send_light_ctl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
}{...}
send_light_ctl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void send_light_hsl_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
bool publish, uint16_t opcode)
{
struct net_buf_simple *msg = NULL;
uint8_t length = 2 + 9;
if (ctx == NULL && publish == false) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, opcode);
switch (opcode) {
case BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS:
case BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS: {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
if (opcode == BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS) {
net_buf_simple_add_le16(msg, srv->state->lightness);
net_buf_simple_add_le16(msg, srv->state->hue);
net_buf_simple_add_le16(msg, srv->state->saturation);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
}{...} else if (opcode == BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS) {
net_buf_simple_add_le16(msg, srv->state->target_lightness);
net_buf_simple_add_le16(msg, srv->state->target_hue);
net_buf_simple_add_le16(msg, srv->state->target_saturation);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_HSL_SRV) {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->hue_default);
net_buf_simple_add_le16(msg, srv->state->saturation_default);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV) {
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->hue_default);
net_buf_simple_add_le16(msg, srv->state->saturation_default);
}{...}
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_HSL_SRV) {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->hue_range_min);
net_buf_simple_add_le16(msg, srv->state->hue_range_max);
net_buf_simple_add_le16(msg, srv->state->saturation_range_min);
net_buf_simple_add_le16(msg, srv->state->saturation_range_max);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV) {
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->hue_range_min);
net_buf_simple_add_le16(msg, srv->state->hue_range_max);
net_buf_simple_add_le16(msg, srv->state->saturation_range_min);
net_buf_simple_add_le16(msg, srv->state->saturation_range_max);
}{...}
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS: {
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->hue);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_le16(msg, srv->state->target_hue);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS: {
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->saturation);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_le16(msg, srv->state->target_saturation);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
break;
}{...}
... default:
BT_WARN("Unknown Light HSL status opcode 0x%04x", opcode);
if (publish == false) {
bt_mesh_free_buf(msg);
}{...}
return;...
}{...}
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_hsl_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_server_rsp_ctrl *rsp_ctrl = NULL;
uint16_t opcode = 0U;
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Server state");
return;
}{...}
rsp_ctrl = &srv->rsp_ctrl;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: {
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Hue Server state");
return;
}{...}
rsp_ctrl = &srv->rsp_ctrl;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: {
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Saturation Server state");
return;
}{...}
rsp_ctrl = &srv->rsp_ctrl;
break;
}{...}
... default:
BT_ERR("Invalid Light HSL Server model 0x%04x", model->id);
return;...
}{...}
if (rsp_ctrl->get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, NULL, 0);
return;
}{...}
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_HSL_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS;
break;...
default:
BT_WARN("Unknown Light HSL Get opcode 0x%04x", ctx->recv_op);
return;...
}{...}
send_light_hsl_status(model, ctx, false, opcode);
}{ ... }
void light_hsl_publish(struct bt_mesh_model *model, uint16_t opcode)
{
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: {
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Hue Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: {
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Saturation Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV: {
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL Setup Server state");
return;
}{...}
break;
}{...}
... default:
BT_ERR("Invalid Light HSL Server model 0x%04x", model->id);
return;...
}{...}
send_light_hsl_status(model, NULL, true, opcode);
}{ ... }
static void light_hsl_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_hsl_srv *srv = model->user_data;
uint16_t lightness = 0U, hue = 0U, saturation = 0U;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
bool optional = false;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
hue = net_buf_simple_pull_le16(buf);
saturation = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.hsl_set.op_en = optional,
.hsl_set.lightness = lightness,
.hsl_set.hue = hue,
.hsl_set.saturation = saturation,
.hsl_set.tid = tid,
.hsl_set.trans_time = trans_time,
.hsl_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
srv->state->target_lightness = lightness;
if (srv->state->hue_range_min && hue < srv->state->hue_range_min) {
hue = srv->state->hue_range_min;
}{...} else if (srv->state->hue_range_max && hue > srv->state->hue_range_max) {
hue = srv->state->hue_range_max;
}{...}
srv->state->target_hue = hue;
if (srv->state->saturation_range_min && saturation < srv->state->saturation_range_min) {
saturation = srv->state->saturation_range_min;
}{...} else if (srv->state->saturation_range_max && saturation > srv->state->saturation_range_max) {
saturation = srv->state->saturation_range_max;
}{...}
srv->state->target_saturation = saturation;
/* ... */
if (srv->state->target_lightness != srv->state->lightness ||
srv->state->target_hue != srv->state->hue ||
srv->state->target_saturation != srv->state->saturation) {
light_hsl_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.hsl_set.lightness = srv->state->lightness,
.hsl_set.hue = srv->state->hue,
.hsl_set.saturation = srv->state->saturation,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->lightness = srv->state->target_lightness;
srv->state->hue = srv->state->target_hue;
srv->state->saturation = srv->state->target_saturation;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void light_hsl_default_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
uint16_t lightness = 0U, hue = 0U, saturation = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
hue = net_buf_simple_pull_le16(buf);
saturation = net_buf_simple_pull_le16(buf);
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.hsl_default_set.lightness = lightness,
.hsl_default_set.hue = hue,
.hsl_default_set.saturation = saturation,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (srv->state->hue_range_min && hue < srv->state->hue_range_min) {
hue = srv->state->hue_range_min;
}{...} else if (srv->state->hue_range_max && hue > srv->state->hue_range_max) {
hue = srv->state->hue_range_max;
}{...}
if (srv->state->saturation_range_min && saturation < srv->state->saturation_range_min) {
saturation = srv->state->saturation_range_min;
}{...} else if (srv->state->saturation_range_max && saturation > srv->state->saturation_range_max) {
saturation = srv->state->saturation_range_max;
}{...}
srv->state->lightness_default = lightness;
srv->state->hue_default = hue;
srv->state->saturation_default = saturation;
bt_mesh_light_server_state_change_t change = {
.hsl_default_set.lightness = srv->state->lightness_default,
.hsl_default_set.hue = srv->state->hue_default,
.hsl_default_set.saturation = srv->state->saturation_default,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS);
}{ ... }
static void light_hsl_range_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
uint16_t hue_min = 0U, hue_max = 0U, saturation_min = 0U, saturation_max = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
hue_min = net_buf_simple_pull_le16(buf);
hue_max = net_buf_simple_pull_le16(buf);
saturation_min = net_buf_simple_pull_le16(buf);
saturation_max = net_buf_simple_pull_le16(buf);
if (hue_min > hue_max) {
BT_ERR("Invalid parameter, hue min 0x%04x, hue max 0x%04x",
hue_min, hue_max);
return;
}{...}
if (saturation_min > saturation_max) {
BT_ERR("Invalid parameter, saturation min 0x%04x, saturation max 0x%04x",
saturation_min, saturation_max);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.hsl_range_set.hue_range_min = hue_min,
.hsl_range_set.hue_range_max = hue_max,
.hsl_range_set.sat_range_min = saturation_min,
.hsl_range_set.sat_range_max = saturation_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
srv->state->status_code = BLE_MESH_RANGE_UPDATE_SUCCESS;
srv->state->hue_range_min = hue_min;
srv->state->hue_range_max = hue_max;
srv->state->saturation_range_min = saturation_min;
srv->state->saturation_range_max = saturation_max;
bt_mesh_light_server_state_change_t change = {
.hsl_range_set.hue_range_min = srv->state->hue_range_min,
.hsl_range_set.hue_range_max = srv->state->hue_range_max,
.hsl_range_set.sat_range_min = srv->state->saturation_range_min,
.hsl_range_set.sat_range_max = srv->state->saturation_range_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS);
}{ ... }
static void light_hsl_hue_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
bool optional = false;
uint16_t hue = 0U;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
hue = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.hsl_hue_set.op_en = optional,
.hsl_hue_set.hue = hue,
.hsl_hue_set.tid = tid,
.hsl_hue_set.trans_time = trans_time,
.hsl_hue_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
if (srv->state->hue_range_min && hue < srv->state->hue_range_min) {
hue = srv->state->hue_range_min;
}{...} else if (srv->state->hue_range_max && hue > srv->state->hue_range_max) {
hue = srv->state->hue_range_max;
}{...}
srv->state->target_hue = hue;
/* ... */
if (srv->state->target_hue != srv->state->hue) {
light_hsl_hue_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.hsl_hue_set.hue = srv->state->hue,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->hue = srv->state->target_hue;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void light_hsl_sat_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
uint16_t saturation = 0U;
bool optional = false;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
saturation = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.hsl_saturation_set.op_en = optional,
.hsl_saturation_set.saturation = saturation,
.hsl_saturation_set.tid = tid,
.hsl_saturation_set.trans_time = trans_time,
.hsl_saturation_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
if (srv->state->saturation_range_min && saturation < srv->state->saturation_range_min) {
saturation = srv->state->saturation_range_min;
}{...} else if (srv->state->saturation_range_max && saturation > srv->state->saturation_range_max) {
saturation = srv->state->saturation_range_max;
}{...}
srv->state->target_saturation = saturation;
/* ... */
if (srv->state->target_saturation != srv->state->saturation) {
light_hsl_sat_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.hsl_saturation_set.saturation = srv->state->saturation,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->saturation = srv->state->target_saturation;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET) {
send_light_hsl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
}{...}
send_light_hsl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void send_light_xyl_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
bool publish, uint16_t opcode)
{
struct net_buf_simple *msg = NULL;
uint8_t length = 2 + 9;
if (ctx == NULL && publish == false) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, opcode);
switch (opcode) {
case BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS:
case BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS: {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
if (opcode == BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS) {
net_buf_simple_add_le16(msg, srv->state->lightness);
net_buf_simple_add_le16(msg, srv->state->x);
net_buf_simple_add_le16(msg, srv->state->y);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
}{...} else if (opcode == BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS) {
net_buf_simple_add_le16(msg, srv->state->target_lightness);
net_buf_simple_add_le16(msg, srv->state->target_x);
net_buf_simple_add_le16(msg, srv->state->target_y);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
}{...}
break;
}{...}
... case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_XYL_SRV) {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->x_default);
net_buf_simple_add_le16(msg, srv->state->y_default);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV) {
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
net_buf_simple_add_le16(msg, srv->state->lightness_default);
net_buf_simple_add_le16(msg, srv->state->x_default);
net_buf_simple_add_le16(msg, srv->state->y_default);
}{...}
break;...
case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS:
if (model->id == BLE_MESH_MODEL_ID_LIGHT_XYL_SRV) {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->x_range_min);
net_buf_simple_add_le16(msg, srv->state->x_range_max);
net_buf_simple_add_le16(msg, srv->state->y_range_min);
net_buf_simple_add_le16(msg, srv->state->y_range_max);
}{...} else if (model->id == BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV) {
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
net_buf_simple_add_u8(msg, srv->state->status_code);
net_buf_simple_add_le16(msg, srv->state->x_range_min);
net_buf_simple_add_le16(msg, srv->state->x_range_max);
net_buf_simple_add_le16(msg, srv->state->y_range_min);
net_buf_simple_add_le16(msg, srv->state->y_range_max);
}{...}
break;...
default:
BT_WARN("Unknown Light xyL status opcode 0x%04x", opcode);
if (publish == false) {
bt_mesh_free_buf(msg);
}{...}
return;...
}{...}
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_xyl_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_xyl_srv *srv = model->user_data;
uint16_t opcode = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
if (srv->rsp_ctrl.get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, NULL, 0);
return;
}{...}
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_XYL_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS;
break;...
default:
BT_WARN("Unknown Light xyL Get opcode 0x%04x", ctx->recv_op);
return;...
}{...}
send_light_xyl_status(model, ctx, false, opcode);
}{ ... }
void light_xyl_publish(struct bt_mesh_model *model, uint16_t opcode)
{
if (model->user_data == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light xyL Server state");
return;
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV: {
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light xyL Setup Server state");
return;
}{...}
break;
}{...}
... default:
BT_ERR("Invalid Light xyL Server model 0x%04x", model->id);
return;...
}{...}
send_light_xyl_status(model, NULL, true, opcode);
}{ ... }
static void light_xyl_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_xyl_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
uint16_t lightness = 0U, x = 0U, y = 0U;
bool optional = false;
int64_t now = 0;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
x = net_buf_simple_pull_le16(buf);
y = net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.xyl_set.op_en = optional,
.xyl_set.lightness = lightness,
.xyl_set.x = x,
.xyl_set.y = y,
.xyl_set.tid = tid,
.xyl_set.trans_time = trans_time,
.xyl_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_XYL_SET) {
send_light_xyl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
}{...}
send_light_xyl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
srv->state->target_lightness = lightness;
if (srv->state->x_range_min && x < srv->state->x_range_min) {
x = srv->state->x_range_min;
}{...} else if (srv->state->x_range_max && x > srv->state->x_range_max) {
x = srv->state->x_range_max;
}{...}
srv->state->target_x = x;
if (srv->state->y_range_min && y < srv->state->y_range_min) {
y = srv->state->y_range_min;
}{...} else if (srv->state->y_range_max && y > srv->state->y_range_max) {
y = srv->state->y_range_max;
}{...}
srv->state->target_y = y;
/* ... */
if (srv->state->target_lightness != srv->state->lightness ||
srv->state->target_x != srv->state->x ||
srv->state->target_y != srv->state->y) {
light_xyl_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.xyl_set.lightness = srv->state->lightness,
.xyl_set.x = srv->state->x,
.xyl_set.y = srv->state->y,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_XYL_SET) {
send_light_xyl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
}{...}
send_light_xyl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->state->lightness = srv->state->target_lightness;
srv->state->x = srv->state->target_x;
srv->state->y = srv->state->target_y;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_XYL_SET) {
send_light_xyl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
}{...}
send_light_xyl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void light_xyl_default_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
uint16_t lightness = 0U, x = 0U, y = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
lightness = net_buf_simple_pull_le16(buf);
x = net_buf_simple_pull_le16(buf);
y = net_buf_simple_pull_le16(buf);
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.xyl_default_set.lightness = lightness,
.xyl_default_set.x = x,
.xyl_default_set.y = y,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (srv->state->x_range_min && x < srv->state->x_range_min) {
x = srv->state->x_range_min;
}{...} else if (srv->state->x_range_max && x > srv->state->x_range_max) {
x = srv->state->x_range_max;
}{...}
if (srv->state->y_range_min && y < srv->state->y_range_min) {
y = srv->state->y_range_min;
}{...} else if (srv->state->y_range_max && y > srv->state->y_range_max) {
y = srv->state->y_range_max;
}{...}
srv->state->lightness_default = lightness;
srv->state->x_default = x;
srv->state->y_default = y;
bt_mesh_light_server_state_change_t change = {
.xyl_default_set.lightness = srv->state->lightness_default,
.xyl_default_set.x = srv->state->x_default,
.xyl_default_set.y = srv->state->y_default,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET) {
send_light_xyl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS);
}{...}
send_light_xyl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS);
}{ ... }
static void light_xyl_range_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
uint16_t x_min = 0U, x_max = 0U, y_min = 0U, y_max = 0U;
if (srv == NULL || srv->state == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
x_min = net_buf_simple_pull_le16(buf);
x_max = net_buf_simple_pull_le16(buf);
y_min = net_buf_simple_pull_le16(buf);
y_max = net_buf_simple_pull_le16(buf);
if (x_min > x_max) {
BT_ERR("Invalid parameter, x min 0x%04x, x max 0x%04x",
x_min, x_max);
return;
}{...}
if (y_min > y_max) {
BT_ERR("Invalid parameter, y min 0x%04x, y max 0x%04x",
y_min, y_max);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.xyl_range_set.x_range_min = x_min,
.xyl_range_set.x_range_max = x_max,
.xyl_range_set.y_range_min = y_min,
.xyl_range_set.y_range_max = y_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
srv->state->status_code = BLE_MESH_RANGE_UPDATE_SUCCESS;
srv->state->x_range_min = x_min;
srv->state->x_range_max = x_max;
srv->state->y_range_min = y_min;
srv->state->y_range_max = y_max;
bt_mesh_light_server_state_change_t change = {
.xyl_range_set.x_range_min = srv->state->x_range_min,
.xyl_range_set.x_range_max = srv->state->x_range_max,
.xyl_range_set.y_range_min = srv->state->y_range_min,
.xyl_range_set.y_range_max = srv->state->y_range_max,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET) {
send_light_xyl_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS);
}{...}
send_light_xyl_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS);
}{ ... }
static void send_light_lc_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
bool publish, uint16_t opcode)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
struct net_buf_simple *msg = NULL;
uint8_t length = 2 + 3;
if (ctx == NULL && publish == false) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, opcode);
switch (opcode) {
case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS:
net_buf_simple_add_u8(msg, srv->lc->state.mode);
break;...
case BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS:
net_buf_simple_add_u8(msg, srv->lc->state.occupancy_mode);
break;...
case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS:
net_buf_simple_add_u8(msg, srv->lc->state.light_onoff);
if (srv->transition.counter) {
bt_mesh_server_calc_remain_time(&srv->transition);
net_buf_simple_add_u8(msg, srv->lc->state.target_light_onoff);
net_buf_simple_add_u8(msg, srv->transition.remain_time);
}{...}
break;...
default:
BT_WARN("Unknown Light LC status opcode 0x%04x", opcode);
if (publish == false) {
bt_mesh_free_buf(msg);
}{...}
return;...
}{...}
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_lc_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
uint16_t opcode = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
if (srv->rsp_ctrl.get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, NULL, 0);
return;
}{...}
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS;
break;...
case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET:
opcode = BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS;
break;...
default:
BT_WARN("Unknown Light LC Get opcode 0x%04x", ctx->recv_op);
return;...
}{...}
send_light_lc_status(model, ctx, false, opcode);
}{ ... }
void light_lc_publish(struct bt_mesh_model *model, uint16_t opcode)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
send_light_lc_status(model, NULL, true, opcode);
}{ ... }
static void light_lc_mode_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
uint8_t mode = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
mode = net_buf_simple_pull_u8(buf);
if (mode > BLE_MESH_STATE_ON) {
BT_ERR("Invalid LC Mode 0x%02x", mode);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lc_mode_set.mode = mode,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
srv->lc->state.mode = mode;
bt_mesh_light_server_state_change_t change = {
.lc_mode_set.mode = srv->lc->state.mode,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET) {
send_light_lc_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS);
}{...}
send_light_lc_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS);
}{ ... }
static void light_lc_om_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
uint8_t om = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
om = net_buf_simple_pull_u8(buf);
if (om > BLE_MESH_STATE_ON) {
BT_ERR("Invalid LC Occupancy Mode 0x%02x", om);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lc_om_set.mode = om,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
srv->lc->state.occupancy_mode = om;
bt_mesh_light_server_state_change_t change = {
.lc_om_set.mode = srv->lc->state.occupancy_mode,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET) {
send_light_lc_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS);
}{...}
send_light_lc_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS);
}{ ... }
static void light_lc_light_onoff_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_srv *srv = model->user_data;
uint8_t tid = 0U, trans_time = 0U, delay = 0U;
bool optional = false;
uint8_t onoff = 0U;
int64_t now = 0;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
onoff = net_buf_simple_pull_u8(buf);
tid = net_buf_simple_pull_u8(buf);
if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) {
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lc_light_onoff_set.op_en = optional,
.lc_light_onoff_set.light_onoff = onoff,
.lc_light_onoff_set.tid = tid,
.lc_light_onoff_set.trans_time = trans_time,
.lc_light_onoff_set.delay = delay,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
if (bt_mesh_is_server_recv_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now)) {
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET) {
send_light_lc_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
}{...}
send_light_lc_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
return;
}{...}
bt_mesh_light_server_lock();
bt_mesh_server_stop_transition(&srv->transition);
bt_mesh_server_update_last_msg(&srv->last, tid, ctx->addr, ctx->recv_dst, &now);
srv->lc->state.target_light_onoff = onoff;
if (srv->lc->state.target_light_onoff != srv->lc->state.light_onoff) {
light_lc_tt_values(srv, trans_time, delay);
}{...} else {
bt_mesh_light_server_state_change_t change = {
.lc_light_onoff_set.onoff = srv->lc->state.light_onoff,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET) {
send_light_lc_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
}{...}
send_light_lc_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
bt_mesh_light_server_unlock();
return;
}{...}
if (srv->transition.timer.work.user_data) {
memcpy(srv->transition.timer.work.user_data, ctx, sizeof(struct bt_mesh_msg_ctx));
}{...}
if (srv->transition.counter == 0U) {
srv->lc->state.light_onoff = srv->lc->state.target_light_onoff;
}{...}
srv->transition.just_started = true;
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET) {
send_light_lc_status(model, ctx, false, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
}{...}
send_light_lc_status(model, NULL, true, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS);
bt_mesh_light_server_unlock();
bt_mesh_server_start_transition(&srv->transition);
}{ ... }
static void light_lc_sensor_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
/* ... */
struct bt_mesh_light_lc_srv *srv = model->user_data;
bt_mesh_light_server_state_change_t change = {0};
uint16_t mpid = 0U, prop_id = 0U;
uint8_t length = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
if (srv->rsp_ctrl.status_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_status_msg_t status = {
.sensor_status.data = buf,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG,
model, ctx, (const uint8_t *)&status, sizeof(status));
return;
}{...}
mpid = net_buf_simple_pull_le16(buf);
if (mpid & BIT(0)) {
length = (uint8_t)((mpid & 0xff) >> 1);
uint8_t msb = net_buf_simple_pull_u8(buf);
prop_id = (uint16_t)(msb << 8) | (uint16_t)(mpid >> 8);
}{...} else {
length = (uint8_t)((mpid & 0x1f) >> 1);
prop_id = (uint16_t)(mpid >> 5);
}{...}
change.sensor_status.property_id = prop_id;
switch (prop_id) {
case BLE_MESH_MOTION_SENSED: {
if (length != BLE_MESH_MOTION_SENSED_LEN || length != buf->len) {
BT_WARN("Invalid Motion Sensed Property length %d", length);
return;
}{...}
uint8_t val = net_buf_simple_pull_u8(buf);
if (val > 0) {
srv->lc->state.occupancy = BLE_MESH_STATE_ON;
change.sensor_status.state.occupancy = srv->lc->state.occupancy;
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
}{...}
break;
}{...}
... case BLE_MESH_PEOPLE_COUNT: {
if (length != BLE_MESH_PEOPLE_COUNT_LEN || length != buf->len) {
BT_WARN("Invalid Motion Sensed Property length %d", length);
return;
}{...}
uint16_t val = net_buf_simple_pull_le16(buf);
if (val > 0) {
srv->lc->state.occupancy = BLE_MESH_STATE_ON;
change.sensor_status.state.occupancy = srv->lc->state.occupancy;
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
}{...}
break;
}{...}
... case BLE_MESH_PRESENCE_DETECTED: {
if (length != BLE_MESH_PRESENCE_DETECTED_LEN || length != buf->len) {
BT_WARN("Invalid Motion Sensed Property length %d", length);
return;
}{...}
uint8_t val = net_buf_simple_pull_u8(buf);
if (val > 0) {
srv->lc->state.occupancy = BLE_MESH_STATE_ON;
change.sensor_status.state.occupancy = srv->lc->state.occupancy;
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
}{...}
break;
}{...}
... case BLE_MESH_TIME_SINCE_MOTION_SENSED: {
if (length != BLE_MESH_TIME_SINCE_MOTION_SENSED_LEN || length != buf->len) {
BT_WARN("Invalid Motion Sensed Property length %d", length);
return;
}{...}
uint16_t val = net_buf_simple_pull_le16(buf);
if (val <= srv->lc->prop_state.time_occupancy_delay) {
srv->lc->prop_state.set_occupancy_to_1_delay =
srv->lc->prop_state.time_occupancy_delay - val;
change.sensor_status.state.set_occupancy_to_1_delay = srv->lc->prop_state.set_occupancy_to_1_delay;
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
}{...}
break;
}{...}
... case BLE_MESH_PRESENT_AMBIENT_LIGHT_LEVEL: {
/* ... */
if (buf->len < 3) {
BT_WARN("Invalid Motion Sensed Property length %d", buf->len);
return;
}{...}
uint16_t lsb = net_buf_simple_pull_le16(buf);
uint8_t msb = net_buf_simple_pull_u8(buf);
srv->lc->state.ambient_luxlevel = (msb << 16) | lsb;
change.sensor_status.state.ambient_luxlevel = srv->lc->state.ambient_luxlevel;
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
break;
}{...}
... default:
break;...
}{...}
}{ ... }
static uint8_t *get_light_lc_prop_val(struct bt_mesh_model *model, uint16_t prop_id)
{
struct bt_mesh_light_lc_setup_srv *srv = model->user_data;
uint8_t *val = NULL;
switch (prop_id) {
case BLE_MESH_LIGHT_CONTROL_TIME_OCCUPANCY_DELAY:
val = (uint8_t *)&srv->lc->prop_state.time_occupancy_delay;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_FADE_ON:
val = (uint8_t *)&srv->lc->prop_state.time_fade_on;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_RUN_ON:
val = (uint8_t *)&srv->lc->prop_state.time_run_on;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_FADE:
val = (uint8_t *)&srv->lc->prop_state.time_fade;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_PROLONG:
val = (uint8_t *)&srv->lc->prop_state.time_prolong;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_AUTO:
val = (uint8_t *)&srv->lc->prop_state.time_fade_standby_auto;
break;...
case BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_MANUAL:
val = (uint8_t *)&srv->lc->prop_state.time_fade_standby_manual;
break;...
case BLE_MESH_LIGHT_CONTROL_LIGHTNESS_ON:
val = (uint8_t *)&srv->lc->prop_state.lightness_on;
break;...
case BLE_MESH_LIGHT_CONTROL_LIGHTNESS_PROLONG:
val = (uint8_t *)&srv->lc->prop_state.lightness_prolong;
break;...
case BLE_MESH_LIGHT_CONTROL_LIGHTNESS_STANDBY:
val = (uint8_t *)&srv->lc->prop_state.lightness_standby;
break;...
case BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON:
val = (uint8_t *)&srv->lc->prop_state.ambient_luxlevel_on;
break;...
case BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_PROLONG:
val = (uint8_t *)&srv->lc->prop_state.ambient_luxlevel_prolong;
break;...
case BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_STANDBY:
val = (uint8_t *)&srv->lc->prop_state.ambient_luxlevel_standby;
break;...
case BLE_MESH_LIGHT_CONTROL_REGULATOR_KIU:
val = (uint8_t *)&srv->lc->prop_state.regulator_kiu;
break;...
case BLE_MESH_LIGHT_CONTROL_REGULATOR_KID:
val = (uint8_t *)&srv->lc->prop_state.regulator_kid;
break;...
case BLE_MESH_LIGHT_CONTROL_REGULATOR_KPU:
val = (uint8_t *)&srv->lc->prop_state.regulator_kpu;
break;...
case BLE_MESH_LIGHT_CONTROL_REGULATOR_KPD:
val = (uint8_t *)&srv->lc->prop_state.regulator_kpd;
break;...
case BLE_MESH_LIGHT_CONTROL_REGULATOR_ACCURACY:
val = (uint8_t *)&srv->lc->prop_state.regulator_accuracy;
break;...
}{...}
return val;
}{ ... }
uint8_t *bt_mesh_get_lc_prop_value(struct bt_mesh_model *model, uint16_t prop_id)
{
if (model == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return NULL;
}{...}
return get_light_lc_prop_val(model, prop_id);
}{ ... }
static void send_light_lc_prop_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
uint16_t prop_id, bool publish)
{
struct net_buf_simple *msg = NULL;
uint8_t length = 1 + 2 + 4;
uint8_t *prop_val = NULL;
prop_val = get_light_lc_prop_val(model, prop_id);
if (prop_val == NULL) {
BT_ERR("Failed to get Light LC Property value");
return;
}{...}
if (publish == false) {
msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE);
if (msg == NULL) {
BT_ERR("%s, Out of memory", __func__);
return;
}{...}
}{...} else {
msg = bt_mesh_server_get_pub_msg(model, length);
if (msg == NULL) {
return;
}{...}
}{...}
bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS);
net_buf_simple_add_le16(msg, prop_id);
net_buf_simple_add_mem(msg, prop_val, bt_mesh_get_dev_prop_len(prop_id));
if (publish == false) {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg);
}{...} else {
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_publish(model));
}{...}
}{ ... }
static void light_lc_prop_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_setup_srv *srv = model->user_data;
uint16_t prop_id = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
prop_id = net_buf_simple_pull_le16(buf);
if (prop_id < 0x002B || prop_id > 0x003C) {
BT_ERR("Invalid Light LC Property ID 0x%04x", prop_id);
return;
}{...}
if (srv->rsp_ctrl.get_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_get_msg_t get = {
.lc_property_get.id = net_buf_simple_pull_le16(buf),
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
model, ctx, (const uint8_t *)&get, sizeof(get));
return;
}{...}
send_light_lc_prop_status(model, ctx, prop_id, false);
}{ ... }
static void light_lc_prop_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_light_lc_setup_srv *srv = model->user_data;
uint8_t *prop_val = NULL, expect_len = 0U;
uint16_t prop_id = 0U;
if (srv == NULL || srv->lc == NULL) {
BT_ERR("%s, Invalid model user data", __func__);
return;
}{...}
prop_id = net_buf_simple_pull_le16(buf);
if (prop_id < 0x002B || prop_id > 0x003C) {
BT_ERR("Invalid Light LC Property ID 0x%04x", prop_id);
return;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) {
bt_mesh_light_server_recv_set_msg_t set = {
.lc_property_set.id = net_buf_simple_pull_le16(buf),
.lc_property_set.value = buf,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
model, ctx, (const uint8_t *)&set, sizeof(set));
return;
}{...}
expect_len = bt_mesh_get_dev_prop_len(prop_id);
if (buf->len != expect_len) {
BT_ERR("Invalid Light LC Property 0x%04x length, expect %d, actual %d",
prop_id, expect_len, buf->len);
return;
}{...}
prop_val = get_light_lc_prop_val(model, prop_id);
if (prop_val == NULL) {
BT_ERR("Failed to get Light LC Property value");
return;
}{...}
memcpy(prop_val, buf->data, buf->len);
bt_mesh_light_server_state_change_t change = {
.lc_property_set.id = prop_id,
.lc_property_set.value = buf,
}{...};
bt_mesh_lighting_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
model, ctx, (const uint8_t *)&change, sizeof(change));
if (ctx->recv_op == BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET) {
send_light_lc_prop_status(model, ctx, prop_id, false);
}{...}
send_light_lc_prop_status(model, ctx, prop_id, true);
}{ ... }
const struct bt_mesh_model_op bt_mesh_light_lightness_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET, 0, light_lightness_get },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET, 3, light_lightness_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK, 3, light_lightness_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET, 0, light_lightness_get },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET, 3, light_lightness_linear_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK, 3, light_lightness_linear_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET, 0, light_lightness_get },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET, 0, light_lightness_get },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET, 0, light_lightness_get },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_lightness_setup_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET, 2, light_lightness_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK, 2, light_lightness_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET, 4, light_lightness_range_set },
{ BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK, 4, light_lightness_range_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_ctl_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_CTL_GET, 0, light_ctl_get },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_SET, 7, light_ctl_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK, 7, light_ctl_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET, 0, light_ctl_get },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET, 0, light_ctl_get },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_ctl_setup_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET, 6, light_ctl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK, 6, light_ctl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET, 4, light_ctl_temp_range_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK, 4, light_ctl_temp_range_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_ctl_temp_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET, 0, light_ctl_get },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET, 5, light_ctl_temp_set },
{ BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK, 5, light_ctl_temp_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_hsl_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_HSL_GET, 0, light_hsl_get },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_SET, 7, light_hsl_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK, 7, light_hsl_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET, 0, light_hsl_get },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET, 0, light_hsl_get },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET, 0, light_hsl_get },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_hsl_setup_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET, 6, light_hsl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK, 6, light_hsl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET, 8, light_hsl_range_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK, 8, light_hsl_range_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_hsl_hue_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET, 0, light_hsl_get },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET, 3, light_hsl_hue_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK, 3, light_hsl_hue_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_hsl_sat_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET, 0, light_hsl_get },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET, 3, light_hsl_sat_set },
{ BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK, 3, light_hsl_sat_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_xyl_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_XYL_GET, 0, light_xyl_get },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_SET, 7, light_xyl_set },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK, 7, light_xyl_set },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET, 0, light_xyl_get },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET, 0, light_xyl_get },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET, 0, light_xyl_get },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_xyl_setup_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET, 6, light_xyl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK, 6, light_xyl_default_set },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET, 8, light_xyl_range_set },
{ BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK, 8, light_xyl_range_set },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_lc_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET, 0, light_lc_get },
{ BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET, 1, light_lc_mode_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK, 1, light_lc_mode_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET, 0, light_lc_get },
{ BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET, 1, light_lc_om_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK, 1, light_lc_om_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET, 0, light_lc_get },
{ BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET, 2, light_lc_light_onoff_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK, 2, light_lc_light_onoff_set },
{ BLE_MESH_MODEL_OP_SENSOR_STATUS, 3, light_lc_sensor_status },
BLE_MESH_MODEL_OP_END,
}{...};
const struct bt_mesh_model_op bt_mesh_light_lc_setup_srv_op[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET, 2, light_lc_prop_get },
{ BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, 3, light_lc_prop_set },
{ BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK, 3, light_lc_prop_set },
BLE_MESH_MODEL_OP_END,
}{...};
static int light_server_init(struct bt_mesh_model *model)
{
if (model->user_data == NULL) {
BT_ERR("Invalid Lighting Server user data, model id 0x%04x", model->id);
return -EINVAL;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light Lightness State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->actual_transition.timer.work);
bt_mesh_server_alloc_ctx(&srv->linear_transition.timer.work);
k_delayed_work_init(&srv->actual_transition.timer, light_lightness_actual_work_handler);
k_delayed_work_init(&srv->linear_transition.timer, light_lightness_linear_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV: {
struct bt_mesh_light_lightness_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light Lightness State");
return -EINVAL;
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_ctl_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV: {
struct bt_mesh_light_ctl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL State");
return -EINVAL;
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: {
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_ctl_temp_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_hsl_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV: {
struct bt_mesh_light_hsl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: {
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_hsl_hue_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: {
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_hsl_sat_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light xyL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_xyl_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV: {
struct bt_mesh_light_xyl_setup_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light xyL State");
return -EINVAL;
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LC_SRV: {
struct bt_mesh_light_lc_srv *srv = model->user_data;
if (srv->lc == NULL) {
BT_ERR("Invalid Light LC State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_alloc_ctx(&srv->transition.timer.work);
k_delayed_work_init(&srv->transition.timer, light_lc_work_handler);
}{...}
srv->model = model;
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV: {
struct bt_mesh_light_lc_setup_srv *srv = model->user_data;
if (srv->lc == NULL) {
BT_ERR("Invalid Light LC State");
return -EINVAL;
}{...}
srv->model = model;
break;
}{...}
... default:
BT_WARN("Unknown Light Server, model id 0x%04x", model->id);
return -EINVAL;...
}{...}
bt_mesh_mutex_create(&light_server_lock);
return 0;
}{ ... }
static int light_lightness_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light Lightness Server has no publication support");
return -EINVAL;
}{...}
/* ... */
struct bt_mesh_elem *element = bt_mesh_model_elem(model);
if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV) == NULL) {
BT_WARN("Light Lightness Setup Server not present");
}{...}
return light_server_init(model);
}{ ... }
static int light_lightness_setup_srv_init(struct bt_mesh_model *model)
{
return light_server_init(model);
}{ ... }
static int light_ctl_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light CTL Server has no publication support");
return -EINVAL;
}{...}
/* ... */
struct bt_mesh_elem *element = bt_mesh_model_elem(model);
if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV) == NULL) {
BT_WARN("Light CTL Setup Server not present");
}{...}
if (bt_mesh_elem_count() < 2) {
BT_WARN("Light CTL Server requires two elements");
}{...}
return light_server_init(model);
}{ ... }
static int light_ctl_setup_srv_init(struct bt_mesh_model *model)
{
return light_server_init(model);
}{ ... }
static int light_ctl_temp_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light CTL Temperature Server has no publication support");
return -EINVAL;
}{...}
return light_server_init(model);
}{ ... }
static int light_hsl_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Server has no publication support");
return -EINVAL;
}{...}
/* ... */
struct bt_mesh_elem *element = bt_mesh_model_elem(model);
if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV) == NULL) {
BT_WARN("Light HSL Setup Server not present");
}{...}
if (bt_mesh_elem_count() < 3) {
BT_WARN("Light HSL Server requires three elements");
}{...}
return light_server_init(model);
}{ ... }
static int light_hsl_setup_srv_init(struct bt_mesh_model *model)
{
return light_server_init(model);
}{ ... }
static int light_hsl_hue_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Hue Server has no publication support");
return -EINVAL;
}{...}
return light_server_init(model);
}{ ... }
static int light_hsl_sat_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Saturation Server has no publication support");
return -EINVAL;
}{...}
return light_server_init(model);
}{ ... }
static int light_xyl_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light xyL Server has no publication support");
return -EINVAL;
}{...}
/* ... */
struct bt_mesh_elem *element = bt_mesh_model_elem(model);
if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV) == NULL) {
BT_WARN("Light xyL Setup Server not present");
}{...}
return light_server_init(model);
}{ ... }
static int light_xyl_setup_srv_init(struct bt_mesh_model *model)
{
return light_server_init(model);
}{ ... }
static int light_lc_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light LC Server has no publication support");
return -EINVAL;
}{...}
return light_server_init(model);
}{ ... }
static int light_lc_setup_srv_init(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light LC Setup Server has no publication support");
return -EINVAL;
}{...}
/* ... */
struct bt_mesh_elem *element = bt_mesh_model_elem(model);
if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV) == NULL) {
BT_WARN("Light LC Setup Server not present");
}{...}
return light_server_init(model);
}{ ... }
#if CONFIG_BLE_MESH_DEINIT
static int light_server_deinit(struct bt_mesh_model *model)
{
if (model->user_data == NULL) {
BT_ERR("Invalid Lighting Server user data, model id 0x%04x", model->id);
return -EINVAL;
}{...}
switch (model->id) {
case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: {
struct bt_mesh_light_lightness_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light Lightness State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->actual_transition.timer.work);
bt_mesh_server_free_ctx(&srv->linear_transition.timer.work);
k_delayed_work_free(&srv->actual_transition.timer);
k_delayed_work_free(&srv->linear_transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: {
struct bt_mesh_light_ctl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: {
struct bt_mesh_light_ctl_temp_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light CTL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: {
struct bt_mesh_light_hsl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: {
struct bt_mesh_light_hsl_hue_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: {
struct bt_mesh_light_hsl_sat_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light HSL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: {
struct bt_mesh_light_xyl_srv *srv = model->user_data;
if (srv->state == NULL) {
BT_ERR("Invalid Light xyL State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LC_SRV: {
struct bt_mesh_light_lc_srv *srv = model->user_data;
if (srv->lc == NULL) {
BT_ERR("Invalid Light LC State");
return -EINVAL;
}{...}
if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) {
bt_mesh_server_free_ctx(&srv->transition.timer.work);
k_delayed_work_free(&srv->transition.timer);
}{...}
break;
}{...}
... case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV:
case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV:
case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV:
case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV:
case BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV:
break;...
default:
BT_WARN("Unknown Light Server, model id 0x%04x", model->id);
return -EINVAL;...
}{...}
bt_mesh_mutex_free(&light_server_lock);
return 0;
}{ ... }
static int light_lightness_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light Lightness Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_lightness_setup_srv_deinit(struct bt_mesh_model *model)
{
return light_server_deinit(model);
}{ ... }
static int light_ctl_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light CTL Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_ctl_setup_srv_deinit(struct bt_mesh_model *model)
{
return light_server_deinit(model);
}{ ... }
static int light_ctl_temp_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light CTL Temperature Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_hsl_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_hsl_setup_srv_deinit(struct bt_mesh_model *model)
{
return light_server_deinit(model);
}{ ... }
static int light_hsl_hue_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Hue Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_hsl_sat_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light HSL Saturation Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_xyl_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light xyL Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_xyl_setup_srv_deinit(struct bt_mesh_model *model)
{
return light_server_deinit(model);
}{ ... }
static int light_lc_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light LC Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
static int light_lc_setup_srv_deinit(struct bt_mesh_model *model)
{
if (model->pub == NULL) {
BT_ERR("Light LC Setup Server has no publication support");
return -EINVAL;
}{...}
return light_server_deinit(model);
}{ ... }
#endif/* ... */
const struct bt_mesh_model_cb bt_mesh_light_lightness_srv_cb = {
.init = light_lightness_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_lightness_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_lightness_setup_srv_cb = {
.init = light_lightness_setup_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_lightness_setup_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_ctl_srv_cb = {
.init = light_ctl_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_ctl_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_ctl_setup_srv_cb = {
.init = light_ctl_setup_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_ctl_setup_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_ctl_temp_srv_cb = {
.init = light_ctl_temp_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_ctl_temp_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_hsl_srv_cb = {
.init = light_hsl_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_hsl_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_hsl_setup_srv_cb = {
.init = light_hsl_setup_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_hsl_setup_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_hsl_hue_srv_cb = {
.init = light_hsl_hue_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_hsl_hue_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_hsl_sat_srv_cb = {
.init = light_hsl_sat_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_hsl_sat_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_xyl_srv_cb = {
.init = light_xyl_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_xyl_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_xyl_setup_srv_cb = {
.init = light_xyl_setup_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_xyl_setup_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_lc_srv_cb = {
.init = light_lc_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_lc_srv_deinit,
#endif
}{...};
const struct bt_mesh_model_cb bt_mesh_light_lc_setup_srv_cb = {
.init = light_lc_setup_srv_init,
#if CONFIG_BLE_MESH_DEINIT
.deinit = light_lc_setup_srv_deinit,
#endif
}{...};
/* ... */
#endif