Skip to content

Commit 1995b66

Browse files
nordicjmnashif
authored andcommitted
mgmt: mcumgr: grp: settings_mgmt: Allow saving single setting
Adds functionality that allows saving a single setting to NVM using the newly added function in the settings subsystem. This also replaces calling the subtree save function if it the underlying Kconfig is enabled to reduce code paths in settings mgmt Signed-off-by: Jamie McCrae <[email protected]>
1 parent 6c43b61 commit 1995b66

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/zephyr/mgmt/mcumgr/grp/settings_mgmt/settings_mgmt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ enum settings_mgmt_ret_code_t {
5858

5959
/** The provided key name does not support being saved. */
6060
SETTINGS_MGMT_ERR_SAVE_NOT_SUPPORTED,
61+
62+
/**
63+
* The provided key cannot be saved before the value is longer than the size of the
64+
* largest value that can safely be read
65+
* (CONFIG_SETTINGS_SAVE_SINGLE_SUBTREE_WITHOUT_MODIFICATION_VALUE_SIZE).
66+
*/
67+
SETTINGS_MGMT_ERR_SAVE_FAILED_VALUE_TOO_LONG_TO_READ,
6168
};
6269

6370
#ifdef __cplusplus

subsys/mgmt/mcumgr/grp/settings_mgmt/src/settings_mgmt.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,28 @@ static int settings_mgmt_save(struct smp_streamer *ctxt)
515515
}
516516

517517
if (save_subtree) {
518+
#ifdef CONFIG_SETTINGS_SAVE_SINGLE_SUBTREE_WITHOUT_MODIFICATION
519+
/*
520+
* This allows saving either a subtree or single setting, if a full setting name
521+
* is provided then the single setting will be saved, otherwise it will save the
522+
* subtree (assuming it is a valid setting subtree).
523+
*/
524+
rc = settings_save_subtree_or_single_without_modification(key_name, true, true);
525+
#else
518526
rc = settings_save_subtree(key_name);
527+
#endif
519528
} else {
520529
rc = settings_save();
521530
}
522531

523532
if (rc != 0) {
524533
switch (rc) {
534+
#ifdef CONFIG_SETTINGS_SAVE_SINGLE_SUBTREE_WITHOUT_MODIFICATION
535+
case -EDOM:
536+
rc = SETTINGS_MGMT_ERR_SAVE_FAILED_VALUE_TOO_LONG_TO_READ;
537+
break;
538+
case -ENOSYS:
539+
#endif
525540
case -ENOENT:
526541
case -ENOTSUP:
527542
rc = SETTINGS_MGMT_ERR_SAVE_NOT_SUPPORTED;

0 commit comments

Comments
 (0)