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; }