aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-10-31 12:59:24 -0700
committerpx4dev <px4@purgatory.org>2012-10-31 12:59:24 -0700
commit8bfceef89cc1fd2422863a99d99039d18a1301bc (patch)
tree3554d877eb32d57bea1c408cd68b265044c94a67
parent3c987d63680d153e4d954ad6249d24e5448e2204 (diff)
downloadpx4-firmware-8bfceef89cc1fd2422863a99d99039d18a1301bc.tar.gz
px4-firmware-8bfceef89cc1fd2422863a99d99039d18a1301bc.tar.bz2
px4-firmware-8bfceef89cc1fd2422863a99d99039d18a1301bc.zip
Remove the arbitrary limit on the path to the default parameter file. Add a verb to the param command to set the default parameter file.
-rw-r--r--apps/systemcmds/param/param.c21
-rw-r--r--apps/systemlib/param/param.c42
-rw-r--r--apps/systemlib/param/param.h29
3 files changed, 57 insertions, 35 deletions
diff --git a/apps/systemcmds/param/param.c b/apps/systemcmds/param/param.c
index 9cb280933..92313e45a 100644
--- a/apps/systemcmds/param/param.c
+++ b/apps/systemcmds/param/param.c
@@ -62,8 +62,6 @@ static void do_import(const char* param_file_name);
static void do_show(void);
static void do_show_print(void *arg, param_t param);
-static const char *param_file_name_default = "/eeprom/parameters";
-
int
param_main(int argc, char *argv[])
{
@@ -72,7 +70,7 @@ param_main(int argc, char *argv[])
if (argc >= 3) {
do_save(argv[2]);
} else {
- do_save(param_file_name_default);
+ do_save(param_get_default_file());
}
}
@@ -80,7 +78,7 @@ param_main(int argc, char *argv[])
if (argc >= 3) {
do_load(argv[2]);
} else {
- do_load(param_file_name_default);
+ do_load(param_get_default_file());
}
}
@@ -88,17 +86,26 @@ param_main(int argc, char *argv[])
if (argc >= 3) {
do_import(argv[2]);
} else {
- do_import(param_file_name_default);
+ do_import(param_get_default_file());
}
}
+ if (!strcmp(argv[1], "select")) {
+ if (argc >= 3) {
+ param_set_default_file(argv[2]);
+ } else {
+ param_set_default_file(NULL);
+ }
+ warnx("selected parameter file %s", param_get_default_file());
+ }
+
if (!strcmp(argv[1], "show")) {
do_show();
}
}
-
- errx(1, "expected a command, try 'load', 'import', 'show' or 'save'\n");
+
+ errx(1, "expected a command, try 'load', 'import', 'show', 'select' or 'save'");
}
static void
diff --git a/apps/systemlib/param/param.c b/apps/systemlib/param/param.c
index c63e7ca8d..9a00c91a5 100644
--- a/apps/systemlib/param/param.c
+++ b/apps/systemlib/param/param.c
@@ -481,38 +481,38 @@ param_reset_all(void)
param_notify_changes();
}
-static char param_default_file_name[50] = "/eeprom/parameters";
+static const char *param_default_file = "/eeprom/parameters";
+static char *param_user_file;
int
param_set_default_file(const char* filename)
{
- if (filename) {
- if (strlen(filename) < sizeof(param_default_file_name))
- {
- strcpy(param_default_file_name, filename);
- } else {
- warnx("param file name too long");
- return 1;
- }
- return 0;
- } else {
- warnx("no valid param file name");
- return 1;
+ if (param_user_file != NULL) {
+ free(param_user_file);
+ param_user_file = NULL;
}
+ if (filename)
+ param_user_file = strdup(filename);
return 0;
}
+const char *
+param_get_default_file(void)
+{
+ return (param_user_file != NULL) ? param_user_file : param_default_file;
+}
+
int
param_save_default(void)
{
/* delete the file in case it exists */
- unlink(param_default_file_name);
+ unlink(param_get_default_file());
/* create the file */
- int fd = open(param_default_file_name, O_WRONLY | O_CREAT | O_EXCL);
+ int fd = open(param_get_default_file(), O_WRONLY | O_CREAT | O_EXCL);
if (fd < 0) {
- warn("opening '%s' for writing failed", param_default_file_name);
+ warn("opening '%s' for writing failed", param_get_default_file());
return -1;
}
@@ -522,8 +522,8 @@ param_save_default(void)
close(fd);
if (result != 0) {
- unlink(param_default_file_name);
- warn("error exporting parameters to '%s'", param_default_file_name);
+ unlink(param_get_default_file());
+ warn("error exporting parameters to '%s'", param_get_default_file());
return -2;
}
@@ -536,12 +536,12 @@ param_save_default(void)
int
param_load_default(void)
{
- int fd = open(param_default_file_name, O_RDONLY);
+ int fd = open(param_get_default_file(), O_RDONLY);
if (fd < 0) {
/* no parameter file is OK, otherwise this is an error */
if (errno != ENOENT) {
- warn("open '%s' for reading failed", param_default_file_name);
+ warn("open '%s' for reading failed", param_get_default_file());
return -1;
}
return 1;
@@ -551,7 +551,7 @@ param_load_default(void)
close(fd);
if (result != 0) {
- warn("error reading parameters from '%s'", param_default_file_name);
+ warn("error reading parameters from '%s'", param_get_default_file());
return -2;
}
diff --git a/apps/systemlib/param/param.h b/apps/systemlib/param/param.h
index 64bb77834..6fa73b5a4 100644
--- a/apps/systemlib/param/param.h
+++ b/apps/systemlib/param/param.h
@@ -235,24 +235,39 @@ __EXPORT int param_load(int fd);
__EXPORT void param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_changed);
/**
- * Export parameters to the default file name.
+ * Set the default parameter file name.
*
+ * @param filename Path to the default parameter file. The file is not require to
+ * exist.
+ * @return Zero on success.
+ */
+__EXPORT int param_set_default_file(const char* filename);
+
+/**
+ * Get the default parameter file name.
*
- * @param
+ * @return The path to the current default parameter file; either as
+ * a result of a call to param_set_default_file, or the
+ * built-in default.
*/
-__EXPORT int param_save_default(void);
+__EXPORT const char *param_get_default_file(void);
/**
- * Set the default parameter file name.
+ * Save parameters to the default file.
+ *
+ * This function saves all parameters with non-default values.
+ *
+ * @return Zero on success.
*/
-__EXPORT int param_set_default_file(const char* filename);
+__EXPORT int param_save_default(void);
/**
- * Import parameters from the default file name.
+ * Load parameters from the default parameter file.
+ *
+ * @return Zero on success.
*/
__EXPORT int param_load_default(void);
-
/*
* Macros creating static parameter definitions.
*