mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 10:03:34 +08:00
Fix a param save issue where a state variable might preven the parameters from being saved (identified and fixed by ultrasystem)
This commit is contained in:
@@ -521,73 +521,15 @@ param_save_default(void)
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == OK) {
|
res = param_export(fd, false);
|
||||||
res = param_export(fd, false);
|
|
||||||
|
|
||||||
if (res != OK) {
|
if (res != OK) {
|
||||||
warnx("failed to write parameters to file: %s", filename);
|
warnx("failed to write parameters to file: %s", filename);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
#if 0
|
|
||||||
const char *filename_tmp = malloc(strlen(filename) + 5);
|
|
||||||
sprintf(filename_tmp, "%s.tmp", filename);
|
|
||||||
|
|
||||||
/* delete temp file if exist */
|
|
||||||
res = unlink(filename_tmp);
|
|
||||||
|
|
||||||
if (res != OK && errno == ENOENT)
|
|
||||||
res = OK;
|
|
||||||
|
|
||||||
if (res != OK)
|
|
||||||
warn("failed to delete temp file: %s", filename_tmp);
|
|
||||||
|
|
||||||
if (res == OK) {
|
|
||||||
/* write parameters to temp file */
|
|
||||||
fd = open(filename_tmp, O_WRONLY | O_CREAT | O_EXCL);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
warn("failed to open temp file: %s", filename_tmp);
|
|
||||||
res = ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == OK) {
|
|
||||||
res = param_export(fd, false);
|
|
||||||
|
|
||||||
if (res != OK)
|
|
||||||
warnx("failed to write parameters to file: %s", filename_tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == OK) {
|
|
||||||
/* delete parameters file */
|
|
||||||
res = unlink(filename);
|
|
||||||
|
|
||||||
if (res != OK && errno == ENOENT)
|
|
||||||
res = OK;
|
|
||||||
|
|
||||||
if (res != OK)
|
|
||||||
warn("failed to delete parameters file: %s", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == OK) {
|
|
||||||
/* rename temp file to parameters */
|
|
||||||
res = rename(filename_tmp, filename);
|
|
||||||
|
|
||||||
if (res != OK)
|
|
||||||
warn("failed to rename %s to %s", filename_tmp, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(filename_tmp);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ static void do_show(const char* search_string);
|
|||||||
static void do_show_print(void *arg, param_t param);
|
static void do_show_print(void *arg, param_t param);
|
||||||
static void do_set(const char* name, const char* val);
|
static void do_set(const char* name, const char* val);
|
||||||
static void do_compare(const char* name, const char* vals[], unsigned comparisons);
|
static void do_compare(const char* name, const char* vals[], unsigned comparisons);
|
||||||
|
static void do_reset();
|
||||||
|
|
||||||
int
|
int
|
||||||
param_main(int argc, char *argv[])
|
param_main(int argc, char *argv[])
|
||||||
@@ -130,6 +131,10 @@ param_main(int argc, char *argv[])
|
|||||||
errx(1, "not enough arguments.\nTry 'param compare PARAM_NAME 3'");
|
errx(1, "not enough arguments.\nTry 'param compare PARAM_NAME 3'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(argv[1], "reset")) {
|
||||||
|
do_reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
|
errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
|
||||||
@@ -402,3 +407,16 @@ do_compare(const char* name, const char* vals[], unsigned comparisons)
|
|||||||
|
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
do_reset()
|
||||||
|
{
|
||||||
|
param_reset_all();
|
||||||
|
|
||||||
|
if (param_save_default()) {
|
||||||
|
warnx("Param export failed.");
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user