rename some funcs related to settings, preparing to add commands for reading and writing the ini file.
This commit is contained in:
@@ -60,7 +60,7 @@ typedef uint8_t TF_COUNT;
|
||||
// Frame ID listeners (wait for response / multi-part message)
|
||||
#define TF_MAX_ID_LST 4
|
||||
// Frame Type listeners (wait for frame with a specific first payload byte)
|
||||
#define TF_MAX_TYPE_LST 4
|
||||
#define TF_MAX_TYPE_LST 5
|
||||
// Generic listeners (fallback if no other listener catches it)
|
||||
#define TF_MAX_GEN_LST 1
|
||||
|
||||
|
||||
+26
-5
@@ -41,22 +41,43 @@ static TF_Result lst_unit(TinyFrame *tf, TF_Msg *msg)
|
||||
return TF_STAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all active unit callsigns, names and types
|
||||
*/
|
||||
static TF_Result lst_list_units(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
ureg_report_active_units(msg->frame_id);
|
||||
return TF_STAY;
|
||||
}
|
||||
|
||||
static TF_Result lst_ini_export(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
//
|
||||
return TF_STAY;
|
||||
}
|
||||
|
||||
static TF_Result lst_ini_import(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
//
|
||||
return TF_STAY;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void comm_init(void)
|
||||
{
|
||||
TF_InitStatic(comm, TF_SLAVE);
|
||||
TF_AddTypeListener(comm, MSG_PING, lst_ping);
|
||||
TF_AddTypeListener(comm, MSG_UNIT_REQUEST, lst_unit);
|
||||
TF_AddTypeListener(comm, MSG_LIST_UNITS, lst_list_units);
|
||||
|
||||
bool suc = true;
|
||||
|
||||
suc &= TF_AddTypeListener(comm, MSG_PING, lst_ping);
|
||||
suc &= TF_AddTypeListener(comm, MSG_UNIT_REQUEST, lst_unit);
|
||||
suc &= TF_AddTypeListener(comm, MSG_LIST_UNITS, lst_list_units);
|
||||
suc &= TF_AddTypeListener(comm, MSG_INI_READ, lst_ini_export);
|
||||
suc &= TF_AddTypeListener(comm, MSG_INI_WRITE, lst_ini_import);
|
||||
|
||||
// fall-through
|
||||
TF_AddGenericListener(comm, lst_default);
|
||||
suc &= TF_AddGenericListener(comm, lst_default);
|
||||
|
||||
assert_param(suc);
|
||||
}
|
||||
|
||||
+6
-4
@@ -15,7 +15,7 @@
|
||||
/**
|
||||
* Supported message types (TF_TYPE)
|
||||
*/
|
||||
enum TF_Types_ {
|
||||
enum Message_Types_ {
|
||||
// General, low level
|
||||
MSG_SUCCESS = 0x00, //!< Generic success response; used by default in all responses; payload is transaction-specific
|
||||
MSG_PING = 0x01, //!< Ping request (or response), used to test connection
|
||||
@@ -29,11 +29,13 @@ enum TF_Types_ {
|
||||
MSG_BULK_ABORT = 0x08, //!< Discard the ongoing transfer
|
||||
|
||||
// Unit messages
|
||||
MSG_UNIT_REQUEST = 0x10, //!< Command addressed to a particular unit
|
||||
MSG_UNIT_REPORT = 0x11, //!< Spontaneous report from a unit
|
||||
MSG_UNIT_REQUEST = 0x10, //!< Command addressed to a particular unit
|
||||
MSG_UNIT_REPORT = 0x11, //!< Spontaneous report from a unit
|
||||
|
||||
// System messages
|
||||
MSG_LIST_UNITS = 0x20, //!< Get all unit call-signs and names
|
||||
MSG_LIST_UNITS = 0x20, //!< Get all active unit call-signs, types and names
|
||||
MSG_INI_READ = 0x21, //!< Read the ini file via bulk
|
||||
MSG_INI_WRITE = 0x22, //!< Write the ini file via bulk
|
||||
};
|
||||
|
||||
extern TinyFrame *comm;
|
||||
|
||||
+10
-9
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
+3
-3
@@ -199,7 +199,7 @@ static bool detect_conf(const uint8_t *data, uint32_t size)
|
||||
|
||||
static void iniparser_cb(const char *section, const char *key, const char *value, void *userData)
|
||||
{
|
||||
settings_read_ini(section, key, value);
|
||||
settings_load_ini_key(section, key, value);
|
||||
}
|
||||
|
||||
static error_t open_conf(void *state)
|
||||
@@ -208,7 +208,7 @@ static error_t open_conf(void *state)
|
||||
conf->file_pos = 0;
|
||||
vfs_printf("\r\n---- INI OPEN! ----");
|
||||
|
||||
settings_read_ini_begin();
|
||||
settings_load_ini_begin();
|
||||
ini_parse_begin(iniparser_cb, NULL);
|
||||
|
||||
return E_SUCCESS;
|
||||
@@ -236,7 +236,7 @@ static error_t close_conf(void *state)
|
||||
vfs_printf("Close INI, total bytes = %d", conf->file_pos);
|
||||
|
||||
ini_parse_end();
|
||||
settings_read_ini_end();
|
||||
settings_load_ini_end();
|
||||
|
||||
// force a full remount to have the changes be visible
|
||||
vfs_mngr_fs_remount(true);
|
||||
|
||||
+12
-11
@@ -36,21 +36,21 @@ static uint32_t read_file_config_ini(uint32_t sector_offset, uint8_t *data, uint
|
||||
const uint32_t skip = sector_offset*VFS_SECTOR_SIZE;
|
||||
|
||||
IniWriter iw = iw_init((char *)data, skip, avail);
|
||||
settings_write_ini(&iw);
|
||||
settings_build_ini(&iw);
|
||||
|
||||
return avail - iw.count;
|
||||
}
|
||||
|
||||
|
||||
////
|
||||
//static void write_file_config_ini(uint32_t sector_offset, const uint8_t *data, uint32_t num_sectors)
|
||||
//{
|
||||
// vfs_printf("Write CONFIG.INI, so %d, ns %d", sector_offset, num_sectors);
|
||||
//
|
||||
static void write_file_config_ini(uint32_t sector_offset, const uint8_t *data, uint32_t num_sectors)
|
||||
{
|
||||
vfs_printf("Write CONFIG.INI, so %d, ns %d", sector_offset, num_sectors);
|
||||
|
||||
for(uint32_t i=0;i<num_sectors*VFS_SECTOR_SIZE;i++) {
|
||||
PRINTF("%c", data[i]);
|
||||
}
|
||||
}
|
||||
// for(uint32_t i=0;i<num_sectors*VFS_SECTOR_SIZE;i++) {
|
||||
// PRINTF("%c", data[i]);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
void vfs_user_build_filesystem(void)
|
||||
@@ -58,9 +58,10 @@ void vfs_user_build_filesystem(void)
|
||||
dbg("Rebuilding VFS...");
|
||||
|
||||
// Setup the filesystem based on target parameters
|
||||
vfs_init(daplink_drive_name, 0/*unused*/);
|
||||
vfs_init(daplink_drive_name, 0/*unused "disk size"*/);
|
||||
|
||||
vfs_create_file("CONFIG INI", read_file_config_ini, write_file_config_ini, settings_get_ini_len());
|
||||
// Write is done using a stream, this is never called
|
||||
vfs_create_file("CONFIG INI", read_file_config_ini, NULL, settings_get_ini_len());
|
||||
}
|
||||
|
||||
// Callback to handle changes to the root directory. Should be used with vfs_set_file_change_callback
|
||||
|
||||
Reference in New Issue
Block a user