rename some funcs related to settings, preparing to add commands for reading and writing the ini file.

This commit is contained in:
2017-12-24 22:12:42 +01:00
parent ad2e19d4fe
commit cc0bf107f0
11 changed files with 74 additions and 49 deletions
+10 -9
View File
@@ -182,6 +182,7 @@ void settings_save(void)
fls_printf("Final flush\r\n");
savebuf_flush(&pb, true);
}
fls_printf("Locking flash...\r\n");
hst = HAL_FLASH_Lock();
assert_param(hst == HAL_OK);
@@ -196,21 +197,21 @@ void settings_save(void)
/**
* Write system settings to INI (without section)
*/
void settings_write_ini(IniWriter *iw)
void settings_build_ini(IniWriter *iw)
{
// File header
iw_comment(iw, "CONFIG.INI");
iw_comment(iw, "Overwrite this file to change settings.");
iw_comment(iw, "Close the LOCK jumper to save them to Flash.");
systemsettings_write_ini(iw);
systemsettings_build_ini(iw);
iw_newline(iw);
ureg_export_combined(iw);
ureg_build_ini(iw);
}
void settings_read_ini_begin(void)
void settings_load_ini_begin(void)
{
SystemSettings.modified = true;
@@ -219,13 +220,13 @@ void settings_read_ini_begin(void)
ureg_remove_all_units();
}
void settings_read_ini(const char *restrict section, const char *restrict key, const char *restrict value)
void settings_load_ini_key(const char *restrict section, const char *restrict key, const char *restrict value)
{
// dbg("[%s] %s = %s", section, key, value);
if (streq(section, "SYSTEM")) {
// system is always at the top
systemsettings_read_ini(key, value);
systemsettings_load_ini(key, value);
}
else if (streq(section, "UNITS")) {
// this will always come before individual units config
@@ -236,14 +237,14 @@ void settings_read_ini(const char *restrict section, const char *restrict key, c
// all unit sections contain the colon character [TYPE:NAME]
const char *nameptr = strchr(section, ':');
if (nameptr) {
ureg_read_unit_ini(nameptr+1, key, value);
ureg_load_unit_ini_key(nameptr + 1, key, value);
} else {
dbg("! Bad config key: [%s] %s = %s", section, key, value);
}
}
}
void settings_read_ini_end(void)
void settings_load_ini_end(void)
{
if (!ureg_finalize_all_init()) {
dbg("Some units failed to init!!");
@@ -254,7 +255,7 @@ uint32_t settings_get_ini_len(void)
{
// this writer is configured to skip everything, so each written byte will decrement the skip count
IniWriter iw = iw_init(NULL, 0xFFFFFFFF, 1);
settings_write_ini(&iw);
settings_build_ini(&iw);
// now we just check how many bytes were skipped
return 0xFFFFFFFF - iw.skip;
}
+4 -4
View File
@@ -32,12 +32,12 @@ void settings_save(void);
* For this reason we don't commit it to flash immediately but require user to replace
* the LOCK jumper before unplugging the device. (TODO implement the LOCK jumper and this feature!!)
*/
void settings_read_ini_begin(void);
void settings_load_ini_begin(void);
/**
* Load settings from INI kv pair.
*/
void settings_read_ini(const char *restrict section, const char *restrict key, const char *restrict value);
void settings_load_ini_key(const char *restrict section, const char *restrict key, const char *restrict value);
/**
* Call this before any of the ini read stuff
@@ -48,13 +48,13 @@ void settings_read_ini(const char *restrict section, const char *restrict key, c
* For this reason we don't commit it to flash immediately but require user to replace
* the LOCK jumper before unplugging the device. (TODO implement the LOCK jumper and this feature!!)
*/
void settings_read_ini_end(void);
void settings_load_ini_end(void);
/**
* Write all settings to a iniwriter
* @param iw - writer handle
*/
void settings_write_ini(IniWriter *iw);
void settings_build_ini(IniWriter *iw);
/**
* Get total settings len (caution: this is expensive, works by dummy-printing everything)
+2 -2
View File
@@ -45,7 +45,7 @@ bool systemsettings_load(PayloadParser *pp)
/**
* Write system settings to INI (without section)
*/
void systemsettings_write_ini(IniWriter *iw)
void systemsettings_build_ini(IniWriter *iw)
{
iw_section(iw, "SYSTEM");
iw_comment(iw, "Data link accessible as virtual comport (Y, N)");
@@ -55,7 +55,7 @@ void systemsettings_write_ini(IniWriter *iw)
/**
* Load system settings from INI kv pair
*/
bool systemsettings_read_ini(const char *restrict key, const char *restrict value)
bool systemsettings_load_ini(const char *restrict key, const char *restrict value)
{
bool suc = true;
if (streq(key, "expose_vcom")) {
+2 -2
View File
@@ -43,13 +43,13 @@ bool systemsettings_load(PayloadParser *pp);
/**
* Write system settings to INI
*/
void systemsettings_write_ini(IniWriter *iw);
void systemsettings_build_ini(IniWriter *iw);
/**
* Load system settings from INI kv pair
*
* @return true on success
*/
bool systemsettings_read_ini(const char *restrict key, const char *restrict value);
bool systemsettings_load_ini(const char *restrict key, const char *restrict value);
#endif //GEX_SYSTEM_SETTINGS_H
+4 -4
View File
@@ -339,9 +339,9 @@ bool ureg_instantiate_by_ini(const char *restrict driver_name, const char *restr
return false;
}
bool ureg_read_unit_ini(const char *restrict name,
const char *restrict key,
const char *restrict value)
bool ureg_load_unit_ini_key(const char *restrict name,
const char *restrict key,
const char *restrict value)
{
UlistEntry *li = ulist_head;
while (li != NULL) {
@@ -431,7 +431,7 @@ void ureg_export_unit(uint32_t index, IniWriter *iw)
}
// unit to INI
void ureg_export_combined(IniWriter *iw)
void ureg_build_ini(IniWriter *iw)
{
UlistEntry *li;
UregEntry *re;
+4 -4
View File
@@ -70,7 +70,7 @@ void ureg_export_unit(uint32_t index, IniWriter *iw);
*
* @param iw
*/
void ureg_export_combined(IniWriter *iw);
void ureg_build_ini(IniWriter *iw);
/**
* Get number of instantiated units
@@ -98,9 +98,9 @@ bool ureg_instantiate_by_ini(const char *restrict driver_name, const char *restr
* @param value - value to set as string
* @return success
*/
bool ureg_read_unit_ini(const char *restrict name,
const char *restrict key,
const char *restrict value);
bool ureg_load_unit_ini_key(const char *restrict name,
const char *restrict key,
const char *restrict value);
/**
* Run init() for all unit instances.