diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-11-02 12:49:46 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-11-02 12:49:46 +0100 |
commit | a5193ba8417d33c13298530d439eaca7bc861209 (patch) | |
tree | 7262af3b97fd84ea797f5f4470cb9c739113f0fb | |
parent | 6af2ea9fbc019b023e2b1201b788c9185690e193 (diff) | |
parent | 9b509310e6b3142dda08c4423a5b650de1ebae19 (diff) | |
download | px4-firmware-a5193ba8417d33c13298530d439eaca7bc861209.tar.gz px4-firmware-a5193ba8417d33c13298530d439eaca7bc861209.tar.bz2 px4-firmware-a5193ba8417d33c13298530d439eaca7bc861209.zip |
Merge branch 'master' of github.com:PX4/Firmware
-rw-r--r-- | apps/drivers/hmc5883/hmc5883.cpp | 18 | ||||
-rw-r--r-- | apps/systemcmds/param/param.c | 40 | ||||
-rw-r--r-- | apps/systemlib/param/param.c | 42 | ||||
-rw-r--r-- | apps/systemlib/param/param.h | 29 | ||||
-rw-r--r-- | nuttx/drivers/serial/serial.c | 2 |
5 files changed, 85 insertions, 46 deletions
diff --git a/apps/drivers/hmc5883/hmc5883.cpp b/apps/drivers/hmc5883/hmc5883.cpp index 2b4fab151..81bc8954b 100644 --- a/apps/drivers/hmc5883/hmc5883.cpp +++ b/apps/drivers/hmc5883/hmc5883.cpp @@ -66,6 +66,9 @@ #include <drivers/drv_mag.h> #include <drivers/drv_hrt.h> +#include <uORB/uORB.h> +#include <uORB/topics/subsystem_info.h> + #include <float.h> /* @@ -631,6 +634,7 @@ HMC5883::ioctl(struct file *filp, int cmd, unsigned long arg) case MAGIOCSSCALE: /* set new scale factors */ memcpy(&_scale, (mag_scale *)arg, sizeof(_scale)); + (void)check_calibration(); return 0; case MAGIOCGSCALE: @@ -1039,11 +1043,17 @@ int HMC5883::check_calibration() offset_valid = false; } - if (_calibrated && !(offset_valid && scale_valid)) { - warnx("warning: mag %s%s", (scale_valid) ? "" : "scale invalid. ", + if (_calibrated != (offset_valid && scale_valid)) { + warnx("warning: mag cal changed: %s%s", (scale_valid) ? "" : "scale invalid. ", (offset_valid) ? "" : "offset invalid."); - _calibrated = false; - // XXX Notify system via uORB + _calibrated = (offset_valid && scale_valid); + /* notify about state change */ + struct subsystem_info_s info = { + true, + true, + _calibrated, + SUBSYSTEM_TYPE_MAG}; + orb_advert_t pub = orb_advertise(ORB_ID(subsystem_info), &info); } return 0; } diff --git a/apps/systemcmds/param/param.c b/apps/systemcmds/param/param.c index 9cb280933..53f9c365e 100644 --- a/apps/systemcmds/param/param.c +++ b/apps/systemcmds/param/param.c @@ -59,11 +59,9 @@ __EXPORT int param_main(int argc, char *argv[]); static void do_save(const char* param_file_name); static void do_load(const char* param_file_name); static void do_import(const char* param_file_name); -static void do_show(void); +static void do_show(const char* search_string); 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,28 @@ 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], "show")) { - do_show(); + 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()); } - - } - errx(1, "expected a command, try 'load', 'import', 'show' or 'save'\n"); + if (!strcmp(argv[1], "show")) + if (argc >= 3) { + do_show(argv[2]); + } else { + do_show(NULL); + } + } + + errx(1, "expected a command, try 'load', 'import', 'show', 'select' or 'save'"); } static void @@ -163,10 +172,10 @@ do_import(const char* param_file_name) } static void -do_show(void) +do_show(const char* search_string) { printf(" + = saved, * = unsaved\n"); - param_foreach(do_show_print, NULL, false); + param_foreach(do_show_print, search_string, false); exit(0); } @@ -176,6 +185,11 @@ do_show_print(void *arg, param_t param) { int32_t i; float f; + const char *search_string = (const char*)arg; + + /* print nothing if search string valid and not matching */ + if (arg != NULL && (strcmp(search_string, param_name(param) != 0))) + return; printf("%c %s: ", param_value_unsaved(param) ? '*' : (param_value_is_default(param) ? ' ' : '+'), 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. * diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index b289bb80b..40011199b 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -328,7 +328,7 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t /* If the ONLCR flag is set, we should translate \n to \r\n */ ret = OK; - if ((ch == '\n') && (dev->termios_s.c_oflag && ONLCR)) + if ((ch == '\n') && (dev->termios_s.c_oflag & ONLCR)) { ret = uart_putxmitchar(dev, '\r'); } |