param_import: add mark_saved argument

Behavior of the 'param import' command:
- if no file provided, parameters are marked as saved (differs from before)
- if a file is provided: parameters are not marked as saved
This commit is contained in:
Beat Küng
2020-10-12 15:22:26 +02:00
parent f6e8ddfaa0
commit 3e9692c5bd
6 changed files with 19 additions and 12 deletions
@@ -362,5 +362,5 @@ int flash_param_load()
int flash_param_import() int flash_param_import()
{ {
return param_import_internal(false); return param_import_internal(true);
} }
+2 -1
View File
@@ -308,10 +308,11 @@ __EXPORT int param_export(int fd, bool only_unsaved, param_filter_func filter);
* This function merges the imported parameters with the current parameter set. * This function merges the imported parameters with the current parameter set.
* *
* @param fd File descriptor to import from (-1 selects the FLASH storage). * @param fd File descriptor to import from (-1 selects the FLASH storage).
* @param mark_saved Whether to mark imported parameters as already saved
* @return Zero on success, nonzero if an error occurred during import. * @return Zero on success, nonzero if an error occurred during import.
* Note that in the failure case, parameters may be inconsistent. * Note that in the failure case, parameters may be inconsistent.
*/ */
__EXPORT int param_import(int fd); __EXPORT int param_import(int fd, bool mark_saved);
/** /**
* Load parameters from a file. * Load parameters from a file.
+2 -2
View File
@@ -1300,13 +1300,13 @@ param_import_internal(int fd, bool mark_saved)
} }
int int
param_import(int fd) param_import(int fd, bool mark_saved)
{ {
if (fd < 0) { if (fd < 0) {
return flash_param_import(); return flash_param_import();
} }
return param_import_internal(fd, false); return param_import_internal(fd, mark_saved);
} }
int int
+3 -3
View File
@@ -1073,7 +1073,7 @@ param_load_default_no_notify()
return 1; return 1;
} }
int result = param_import(fd_load); int result = param_import(fd_load, true);
close(fd_load); close(fd_load);
@@ -1351,10 +1351,10 @@ param_import_internal(int fd, bool mark_saved)
} }
int int
param_import(int fd) param_import(int fd, bool mark_saved)
{ {
#if !defined(FLASH_BASED_PARAMS) #if !defined(FLASH_BASED_PARAMS)
return param_import_internal(fd, false); return param_import_internal(fd, mark_saved);
#else #else
(void)fd; // unused (void)fd; // unused
// no need for locking here // no need for locking here
+9 -3
View File
@@ -83,7 +83,7 @@ enum class COMPARE_ERROR_LEVEL {
static int do_save(const char *param_file_name); static int do_save(const char *param_file_name);
static int do_save_default(); static int do_save_default();
static int do_load(const char *param_file_name); static int do_load(const char *param_file_name);
static int do_import(const char *param_file_name); static int do_import(const char *param_file_name = nullptr);
static int do_show(const char *search_string, bool only_changed); static int do_show(const char *search_string, bool only_changed);
static int do_show_for_airframe(); static int do_show_for_airframe();
static int do_show_all(); static int do_show_all();
@@ -213,7 +213,7 @@ param_main(int argc, char *argv[])
return do_import(argv[2]); return do_import(argv[2]);
} else { } else {
return do_import(param_get_default_file()); return do_import();
} }
} }
@@ -428,6 +428,12 @@ do_load(const char *param_file_name)
static int static int
do_import(const char *param_file_name) do_import(const char *param_file_name)
{ {
bool mark_saved = false;
if (param_file_name == nullptr) {
param_file_name = param_get_default_file();
mark_saved = true; // if imported from default storage, mark as saved
}
int fd = -1; int fd = -1;
if (param_file_name) { // passing NULL means to select the flash storage if (param_file_name) { // passing NULL means to select the flash storage
fd = open(param_file_name, O_RDONLY); fd = open(param_file_name, O_RDONLY);
@@ -438,7 +444,7 @@ do_import(const char *param_file_name)
} }
} }
int result = param_import(fd); int result = param_import(fd, mark_saved);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);
} }
+2 -2
View File
@@ -363,7 +363,7 @@ bool ParameterTest::exportImportAll()
return false; return false;
} }
int result = param_export(fd, false); int result = param_export(fd, false, nullptr);
if (result != PX4_OK) { if (result != PX4_OK) {
PX4_ERR("param_export failed"); PX4_ERR("param_export failed");
@@ -516,7 +516,7 @@ bool ParameterTest::exportImportAll()
return false; return false;
} }
result = param_import(fd); result = param_import(fd, false);
close(fd); close(fd);
if (result < 0) { if (result < 0) {