int param_save_default(void) { int result; /* delete the file in case it exists */ struct stat buffer; if (stat(param_get_default_file(), &buffer) == 0) { result = unlink(param_get_default_file()); if (result != OK) warnx("unlinking file %s failed.", param_get_default_file()); } /* create the file */ int fd = open(param_get_default_file(), O_WRONLY | O_CREAT | O_EXCL); if (fd < 0) { warn("opening '%s' for writing failed", param_get_default_file()); return fd; } result = param_export(fd, false); close(fd); if (result != 0) { warn("error exporting parameters to '%s'", param_get_default_file()); unlink(param_get_default_file()); return result; } return 0; }
int param_save_default(void) { int res; int fd; const char *filename = param_get_default_file(); /* write parameters to temp file */ fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { warn("failed to open param file: %s", filename); return ERROR; } res = param_export(fd, false); if (res != OK) { warnx("failed to write parameters to file: %s", filename); } PARAM_CLOSE(fd); return res; }
static void eeprom_save(const char *name) { if (!started) errx(1, "must be started first"); if (!name) err(1, "missing argument for device name, try '/eeprom/parameters'"); warnx("WARNING: 'eeprom save_param' deprecated - use 'param save' instead"); /* delete the file in case it exists */ unlink(name); /* create the file */ int fd = open(name, O_WRONLY | O_CREAT | O_EXCL); if (fd < 0) err(1, "opening '%s' failed", name); int result = param_export(fd, false); close(fd); if (result < 0) { unlink(name); errx(1, "error exporting to '%s'", name); } exit(0); }
int param_save_default(void) { /* delete the file in case it exists */ unlink(param_get_default_file()); /* create the file */ int fd = open(param_get_default_file(), O_WRONLY | O_CREAT | O_EXCL); if (fd < 0) { warn("opening '%s' for writing failed", param_get_default_file()); return -1; } int result = param_export(fd, false); close(fd); if (result != 0) { warn("error exporting parameters to '%s'", param_get_default_file()); unlink(param_get_default_file()); return -2; } return 0; }
int param_save_default(void) { int res = OK; int fd = -1; bool is_locked = false; const char *filename = param_get_default_file(); if (get_shmem_lock(__FILE__, __LINE__) != 0) { PX4_ERR("Could not get shmem lock\n"); res = ERROR; goto exit; } is_locked = true; fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { PX4_ERR("failed to open param file: %s", filename); goto exit; } res = param_export(fd, false); if (res != OK) { PX4_ERR("failed to write parameters to file: %s", filename); goto exit; } PARAM_CLOSE(fd); fd = -1; exit: if (is_locked) { release_shmem_lock(); } if (fd >= 0) { close(fd); } if (res == OK) { PX4_INFO("saving params completed successfully\n"); } return res; }
static void do_save(const char* param_file_name) { /* create the file */ int fd = open(param_file_name, O_WRONLY | O_CREAT); if (fd < 0) err(1, "opening '%s' failed", param_file_name); int result = param_export(fd, false); close(fd); if (result < 0) { (void)unlink(param_file_name); errx(1, "error exporting to '%s'", param_file_name); } exit(0); }
int param_save_default(void) { int res = PX4_ERROR; #if !defined(FLASH_BASED_PARAMS) const char *filename = param_get_default_file(); /* write parameters to temp file */ int fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { PX4_ERR("failed to open param file: %s", filename); return ERROR; } int attempts = 5; while (res != OK && attempts > 0) { res = param_export(fd, false); attempts--; if (res != PX4_OK) { PX4_ERR("param_export failed, retrying %d", attempts); lseek(fd, 0, SEEK_SET); // jump back to the beginning of the file } } if (res != OK) { PX4_ERR("failed to write parameters to file: %s", filename); } PARAM_CLOSE(fd); #else param_lock_writer(); res = flash_param_save(); param_unlock_writer(); #endif return res; }
static int do_save(const char *param_file_name) { /* create the file */ int fd = px4_open(param_file_name, O_WRONLY | O_CREAT, 0x777); if (fd < 0) { warn("opening '%s' failed", param_file_name); return 1; } int result = param_export(fd, false); px4_close(fd); if (result < 0) { (void)unlink(param_file_name); warnx("error exporting to '%s'", param_file_name); return 1; } return 0; }
static void do_save(const char* param_file_name) { /* delete the parameter file in case it exists */ unlink(param_file_name); /* create the file */ int fd = open(param_file_name, O_WRONLY | O_CREAT | O_EXCL); if (fd < 0) err(1, "opening '%s' failed", param_file_name); int result = param_export(fd, false); close(fd); if (result < 0) { unlink(param_file_name); errx(1, "error exporting to '%s'", param_file_name); } exit(0); }
static int do_save(const char *param_file_name) { /* create the file */ int fd = open(param_file_name, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { PX4_ERR("open '%s' failed (%i)", param_file_name, errno); return 1; } int result = param_export(fd, false); close(fd); if (result < 0) { #ifndef __PX4_QURT (void)unlink(param_file_name); #endif PX4_ERR("exporting to '%s' failed (%i)", param_file_name, result); return 1; } return 0; }
int param_save_default(void) { int res; #if !defined(FLASH_BASED_PARAMS) int fd; const char *filename = param_get_default_file(); /* write parameters to temp file */ fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { warn("failed to open param file: %s", filename); return ERROR; } res = 1; int attempts = 5; while (res != OK && attempts > 0) { res = param_export(fd, false); attempts--; } if (res != OK) { warnx("failed to write parameters to file: %s", filename); } PARAM_CLOSE(fd); #else res = flash_param_save(); #endif return res; }
/** * @return 0 on success, -1 if device open failed, -2 if writing parameters failed */ static int mavlink_pm_save_eeprom() { /* delete the file in case it exists */ unlink(mavlink_parameter_file); /* create the file */ int fd = open(mavlink_parameter_file, O_WRONLY | O_CREAT | O_EXCL); if (fd < 0) { warn("opening '%s' for writing failed", mavlink_parameter_file); return -1; } int result = param_export(fd, false); close(fd); if (result != 0) { unlink(mavlink_parameter_file); warn("error exporting parameters to '%s'", mavlink_parameter_file); return -2; } return 0; }
bool ParameterTest::exportImportAll() { static constexpr float MAGIC_FLOAT_VAL = 0.217828f; // backup current parameters const char *param_file_name = PX4_STORAGEDIR "/param_backup"; int fd = open(param_file_name, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { PX4_ERR("open '%s' failed (%i)", param_file_name, errno); return false; } int result = param_export(fd, false); if (result != PX4_OK) { PX4_ERR("param_export failed"); close(fd); return false; } close(fd); bool ret = true; int N = param_count(); // set all params to corresponding param_t value for (unsigned i = 0; i < N; i++) { param_t p = param_for_index(i); if (p == PARAM_INVALID) { PX4_ERR("param invalid: %d(%d)", p, i); break; } if (param_type(p) == PARAM_TYPE_INT32) { const int32_t set_val = p; if (param_set_no_notification(p, &set_val) != PX4_OK) { PX4_ERR("param_set_no_notification failed for: %d", p); ut_assert("param_set_no_notification failed", false); } int32_t get_val = 0; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", p, get_val); } if (param_type(p) == PARAM_TYPE_FLOAT) { const float set_val = (float)p + MAGIC_FLOAT_VAL; if (param_set_no_notification(p, &set_val) != PX4_OK) { PX4_ERR("param_set_no_notification failed for: %d", p); ut_assert("param_set_no_notification failed", false); } float get_val = 0.0f; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", p, (float)p + MAGIC_FLOAT_VAL); } } // save if (param_save_default() != PX4_OK) { PX4_ERR("param_save_default failed"); return false; } // zero all params and verify, but don't save for (unsigned i = 0; i < N; i++) { param_t p = param_for_index(i); if (param_type(p) == PARAM_TYPE_INT32) { const int32_t set_val = 0; if (param_set_no_notification(p, &set_val) != PX4_OK) { PX4_ERR("param set failed: %d", p); ut_assert("param_set_no_notification failed", false); } int32_t get_val = -1; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", set_val, get_val); } if (param_type(p) == PARAM_TYPE_FLOAT) { float set_val = 0.0f; if (param_set_no_notification(p, &set_val) != PX4_OK) { PX4_ERR("param set failed: %d", p); ut_assert("param_set_no_notification failed", false); } float get_val = -1.0f; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", set_val, get_val); } } // load saved params if (param_load_default() != PX4_OK) { PX4_ERR("param_save_default failed"); ret = true; } // check every param for (unsigned i = 0; i < N; i++) { param_t p = param_for_index(i); if (param_type(p) == PARAM_TYPE_INT32) { int32_t get_val = 0; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", p, get_val); } if (param_type(p) == PARAM_TYPE_FLOAT) { float get_val = 0.0f; if (param_get(p, &get_val) != PX4_OK) { PX4_ERR("param_get failed for: %d", p); ut_assert("param_set_no_notification failed", false); } ut_compare("value for param doesn't match default value", p, (float)p + MAGIC_FLOAT_VAL); } } param_reset_all(); // restore original params fd = open(param_file_name, O_RDONLY); if (fd < 0) { PX4_ERR("open '%s' failed (%i)", param_file_name, errno); return false; } result = param_import(fd); close(fd); if (result < 0) { PX4_ERR("importing from '%s' failed (%i)", param_file_name, result); return false; } // save if (param_save_default() != PX4_OK) { PX4_ERR("param_save_default failed"); return false; } return ret; }