2121#include "foundation.h"
2222#include "mesh.h"
2323#include "sar_cfg_internal.h"
24+ #include "settings.h"
2425
2526#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
2627#include <zephyr/logging/log.h>
2728LOG_MODULE_REGISTER (bt_mesh_sar_cfg_srv );
2829
30+ static int sar_rx_store (struct bt_mesh_model * model , bool delete )
31+ {
32+ const void * data = delete ? NULL : & bt_mesh .sar_rx ;
33+ size_t len = delete ? 0 : sizeof (struct bt_mesh_sar_rx );
34+
35+ return bt_mesh_model_data_store (model , false, "sar_rx" , data , len );
36+ }
37+
38+ static int sar_tx_store (struct bt_mesh_model * model , bool delete )
39+ {
40+ const void * data = delete ? NULL : & bt_mesh .sar_tx ;
41+ size_t len = delete ? 0 : sizeof (struct bt_mesh_sar_tx );
42+
43+ return bt_mesh_model_data_store (model , false, "sar_tx" , data , len );
44+ }
45+
2946static void transmitter_status (struct bt_mesh_model * model ,
3047 struct bt_mesh_msg_ctx * ctx )
3148{
@@ -84,6 +101,10 @@ static int transmitter_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *
84101 bt_mesh_sar_tx_decode (buf , tx );
85102 transmitter_status (model , ctx );
86103
104+ if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
105+ sar_tx_store (model , false);
106+ }
107+
87108 return 0 ;
88109}
89110
@@ -107,6 +128,10 @@ static int receiver_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx
107128 bt_mesh_sar_rx_decode (buf , rx );
108129 receiver_status (model , ctx );
109130
131+ if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
132+ sar_rx_store (model , false);
133+ }
134+
110135 return 0 ;
111136}
112137
@@ -135,6 +160,42 @@ static int sar_cfg_srv_init(struct bt_mesh_model *model)
135160 return 0 ;
136161}
137162
163+ static void sar_cfg_srv_reset (struct bt_mesh_model * model )
164+ {
165+ struct bt_mesh_sar_tx sar_tx = BT_MESH_SAR_TX_INIT ;
166+ struct bt_mesh_sar_rx sar_rx = BT_MESH_SAR_RX_INIT ;
167+
168+ bt_mesh .sar_tx = sar_tx ;
169+ bt_mesh .sar_rx = sar_rx ;
170+
171+ if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
172+ sar_rx_store (model , true);
173+ sar_tx_store (model , true);
174+ }
175+ }
176+
177+ #ifdef CONFIG_BT_SETTINGS
178+ static int sar_cfg_srv_settings_set (struct bt_mesh_model * model , const char * name , size_t len_rd ,
179+ settings_read_cb read_cb , void * cb_data )
180+ {
181+ if (!strncmp (name , "sar_rx" , 5 )) {
182+ return bt_mesh_settings_set (read_cb , cb_data , & bt_mesh .sar_rx ,
183+ sizeof (bt_mesh .sar_rx ));
184+ }
185+
186+ if (!strncmp (name , "sar_tx" , 5 )) {
187+ return bt_mesh_settings_set (read_cb , cb_data , & bt_mesh .sar_tx ,
188+ sizeof (bt_mesh .sar_tx ));
189+ }
190+
191+ return 0 ;
192+ }
193+ #endif
194+
138195const struct bt_mesh_model_cb bt_mesh_sar_cfg_srv_cb = {
139196 .init = sar_cfg_srv_init ,
197+ .reset = sar_cfg_srv_reset ,
198+ #ifdef CONFIG_BT_SETTINGS
199+ .settings_set = sar_cfg_srv_settings_set
200+ #endif
140201};
0 commit comments