/** * @return 0 on success, 1 if all params have not yet been stored, -1 if device open failed, -2 if writing parameters failed */ int param_load_default(void) { warnx("param_load_default\n"); int fd_load = PARAM_OPEN(param_get_default_file(), O_RDONLY); if (fd_load < 0) { /* no parameter file is OK, otherwise this is an error */ if (errno != ENOENT) { warn("open '%s' for reading failed", param_get_default_file()); return -1; } return 1; } int result = param_load(fd_load); PARAM_CLOSE(fd_load); if (result != 0) { warn("error reading parameters from '%s'", param_get_default_file()); return -2; } 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; }
/** * @return 0 on success, 1 if all params have not yet been stored, -1 if device open failed, -2 if writing parameters failed */ int param_load_default(void) { int res = 0; #if !defined(FLASH_BASED_PARAMS) int fd_load = PARAM_OPEN(param_get_default_file(), O_RDONLY); if (fd_load < 0) { /* no parameter file is OK, otherwise this is an error */ if (errno != ENOENT) { warn("open '%s' for reading failed", param_get_default_file()); return -1; } return 1; } int result = param_load(fd_load); PARAM_CLOSE(fd_load); if (result != 0) { warn("error reading parameters from '%s'", param_get_default_file()); return -2; } #else // no need for locking res = flash_param_load(); #endif return res; }
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; }
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; }
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; }