21
21
#include "foundation.h"
22
22
#include "mesh.h"
23
23
#include "sar_cfg_internal.h"
24
+ #include "settings.h"
24
25
25
26
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
26
27
#include <zephyr/logging/log.h>
27
28
LOG_MODULE_REGISTER (bt_mesh_sar_cfg_srv );
28
29
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
+
29
46
static void transmitter_status (struct bt_mesh_model * model ,
30
47
struct bt_mesh_msg_ctx * ctx )
31
48
{
@@ -84,6 +101,10 @@ static int transmitter_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *
84
101
bt_mesh_sar_tx_decode (buf , tx );
85
102
transmitter_status (model , ctx );
86
103
104
+ if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
105
+ sar_tx_store (model , false);
106
+ }
107
+
87
108
return 0 ;
88
109
}
89
110
@@ -107,6 +128,10 @@ static int receiver_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx
107
128
bt_mesh_sar_rx_decode (buf , rx );
108
129
receiver_status (model , ctx );
109
130
131
+ if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
132
+ sar_rx_store (model , false);
133
+ }
134
+
110
135
return 0 ;
111
136
}
112
137
@@ -135,6 +160,42 @@ static int sar_cfg_srv_init(struct bt_mesh_model *model)
135
160
return 0 ;
136
161
}
137
162
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
+
138
195
const struct bt_mesh_model_cb bt_mesh_sar_cfg_srv_cb = {
139
196
.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
140
201
};
0 commit comments