Confing#
Functions
-
int config_init(struct kvstore *nvs, config_save_cb_t cb, void *cb_ctx)#
Initializes the configuration module.
- Parameters:
nvs – [in] Handle to the non-volatile storage.
cb – [in] Callback function for configuration save events.
cb_ctx – [in] Context to be passed to the callback function.
- Returns:
0 on success, negative error code on failure.
-
int config_get(const char *key, void *buf, size_t bufsize)#
Reads a configuration value.
- Parameters:
key – [in] Configuration key string (e.g., “device.id”).
buf – [out] Buffer to store the retrieved value.
bufsize – [in] Size of the buffer.
- Returns:
0 on success, negative error code on failure.
-
int config_set(const char *key, const void *data, size_t datasize)#
Writes a configuration value.
- Parameters:
key – [in] Configuration key string (e.g., “device.id”).
data – [in] Data to be written.
datasize – [in] Size of the data to be written.
- Returns:
0 on success, negative error code on failure.
-
int config_read_all(struct config *cfg)#
Reads all configuration settings.
- Parameters:
cfg – [out] A pointer to the config structure where the settings will be stored.
- Returns:
int Returns 0 on success, or a negative error code on failure.
-
int config_write_all(const struct config *cfg)#
Writes all configuration settings.
- Parameters:
cfg – A pointer to the config structure containing the settings to be written.
- Returns:
int Returns 0 on success, or a negative error code on failure.
-
int config_save(void)#
Saves the modified configuration values.
- Returns:
0 on success, negative error code on failure.
-
int config_set_and_save(const char *key, const void *data, size_t datasize)#
Writes a configuration value and saves it.
This function sets the configuration value associated with the given key and saves the configuration to persistent storage.
- Parameters:
key – [in] Configuration key string (e.g., “device.id”).
data – [in] Data to be written.
datasize – [in] Size of the data to be written.
- Returns:
0 on success, negative error code on failure.
-
int config_reset(const char *key)#
Resets a specific configuration key to its default value.
- Parameters:
key – [in] Configuration key to reset (NULL resets all configurations).
- Returns:
0 on success, negative error code on failure.
-
int config_update_json(const char *json, size_t json_len)#
Updates configuration values using a JSON string.
- Parameters:
json – [in] JSON-formatted configuration string.
json_len – [in] Length of the JSON string.
- Returns:
0 on success, negative error code on failure.
-
bool config_is_zeroed(const char *key)#
Checks if the configuration setting for the given key is zeroed.
This function does not support custom settings. If the key corresponds to a custom setting, the function will return false.
Warning
Be cautious when using this function to determine initialization status, as the actual configuration value might be zero.
- Parameters:
key – [in] The key of the configuration setting to check.
- Returns:
bool Returns true if the configuration setting is zeroed, false otherwise.
Typedefs
-
typedef void (*config_save_cb_t)(void *ctx)#
-
struct config_charger#
- #include <config.h>
-
struct config_net#
- #include <config.h>
-
struct config_ocpp#
- #include <config.h>
-
struct config#
- #include <config.h>
Public Members
-
uint32_t version#
-
char device_id[CONFIG_DEVICE_ID_MAXLEN]#
-
char device_name[CONFIG_DEVICE_NAME_MAXLEN]#
-
uint8_t device_mode#
-
uint8_t log_mode#
-
uint8_t log_level#
-
bool dfu_reboot_manually#
-
struct config_charger charger#
-
struct config_net net#
-
struct config_ocpp ocpp#
-
uint32_t crc#
-
uint32_t version#