mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 10:30:34 +08:00
parameters: open export files O_TRUNC to discard previous data
- rcS parameter backup try to directly restore param (FRAM) from backup (in case SD card is removed before successful export) - rcS parameter backup logging rearrange to capture more logging output (param_import_fail.txt) - posix rcS try to keep param backup and restore roughly in sync with NuttX rcS - tinybson fix debug printf format - param_export_internal ensure file descriptor positioned at 0 (precaution)
This commit is contained in:
@@ -1116,7 +1116,7 @@ int param_save_default()
|
||||
|
||||
for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||
// write parameters to file
|
||||
int fd = ::open(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666);
|
||||
int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, PX4_O_MODE_666);
|
||||
|
||||
if (fd > -1) {
|
||||
perf_begin(param_export_perf);
|
||||
@@ -1155,7 +1155,7 @@ int param_save_default()
|
||||
|
||||
// backup file
|
||||
if (param_backup_file) {
|
||||
int fd_backup_file = ::open(param_backup_file, O_WRONLY | O_CREAT, PX4_O_MODE_666);
|
||||
int fd_backup_file = ::open(param_backup_file, O_WRONLY | O_CREAT | O_TRUNC, PX4_O_MODE_666);
|
||||
|
||||
if (fd_backup_file > -1) {
|
||||
int backup_export_ret = param_export_internal(fd_backup_file, nullptr);
|
||||
@@ -1374,6 +1374,11 @@ static int param_export_internal(int fd, param_filter_func filter)
|
||||
bson_encoder_s encoder{};
|
||||
uint8_t bson_buffer[256];
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) != 0) {
|
||||
PX4_ERR("export seek failed %d", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bson_encoder_init_buf_file(&encoder, fd, &bson_buffer, sizeof(bson_buffer)) != 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user