mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-04 09:10:34 +08:00
@@ -687,7 +687,7 @@ int commander_thread_main(int argc, char *argv[])
|
||||
|
||||
bool updated = false;
|
||||
|
||||
bool rc_calibration_ok = (OK == rc_calibration_check());
|
||||
bool rc_calibration_ok = (OK == rc_calibration_check(mavlink_fd));
|
||||
|
||||
/* Subscribe to safety topic */
|
||||
int safety_sub = orb_subscribe(ORB_ID(safety));
|
||||
@@ -802,7 +802,7 @@ int commander_thread_main(int argc, char *argv[])
|
||||
status_changed = true;
|
||||
|
||||
/* re-check RC calibration */
|
||||
rc_calibration_ok = (OK == rc_calibration_check());
|
||||
rc_calibration_ok = (OK == rc_calibration_check(mavlink_fd));
|
||||
|
||||
/* navigation parameters */
|
||||
param_get(_param_takeoff_alt, &takeoff_alt);
|
||||
|
||||
@@ -508,64 +508,63 @@ param_get_default_file(void)
|
||||
int
|
||||
param_save_default(void)
|
||||
{
|
||||
int result;
|
||||
unsigned retries = 0;
|
||||
|
||||
/* delete the file in case it exists */
|
||||
struct stat buffer;
|
||||
if (stat(param_get_default_file(), &buffer) == 0) {
|
||||
|
||||
do {
|
||||
result = unlink(param_get_default_file());
|
||||
if (result != 0) {
|
||||
retries++;
|
||||
usleep(1000 * retries);
|
||||
}
|
||||
} while (result != OK && retries < 10);
|
||||
|
||||
if (result != OK)
|
||||
warnx("unlinking file %s failed.", param_get_default_file());
|
||||
}
|
||||
|
||||
/* create the file */
|
||||
int res;
|
||||
int fd;
|
||||
|
||||
do {
|
||||
/* do another attempt in case the unlink call is not synced yet */
|
||||
fd = open(param_get_default_file(), O_WRONLY | O_CREAT | O_EXCL);
|
||||
const char *filename = param_get_default_file();
|
||||
const char *filename_tmp = malloc(strlen(filename) + 5);
|
||||
sprintf(filename_tmp, "%s.tmp", filename);
|
||||
|
||||
/* delete temp file if exist */
|
||||
res = unlink(filename_tmp);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete temp file: %s", filename_tmp);
|
||||
|
||||
if (res == OK) {
|
||||
/* write parameters to temp file */
|
||||
fd = open(filename_tmp, O_WRONLY | O_CREAT | O_EXCL);
|
||||
|
||||
if (fd < 0) {
|
||||
retries++;
|
||||
usleep(1000 * retries);
|
||||
warn("failed to open temp file: %s", filename_tmp);
|
||||
res = ERROR;
|
||||
}
|
||||
|
||||
} while (fd < 0 && retries < 10);
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
|
||||
if (fd < 0) {
|
||||
|
||||
warn("opening '%s' for writing failed", param_get_default_file());
|
||||
return fd;
|
||||
}
|
||||
|
||||
do {
|
||||
result = param_export(fd, false);
|
||||
|
||||
if (result != OK) {
|
||||
retries++;
|
||||
usleep(1000 * retries);
|
||||
if (res != OK)
|
||||
warnx("failed to write parameters to file: %s", filename_tmp);
|
||||
}
|
||||
|
||||
} while (result != 0 && retries < 10);
|
||||
|
||||
|
||||
close(fd);
|
||||
|
||||
if (result != OK) {
|
||||
warn("error exporting parameters to '%s'", param_get_default_file());
|
||||
(void)unlink(param_get_default_file());
|
||||
return result;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (res == OK) {
|
||||
/* delete parameters file */
|
||||
res = unlink(filename);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete parameters file: %s", filename);
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
/* rename temp file to parameters */
|
||||
res = rename(filename_tmp, filename);
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to rename %s to %s", filename_tmp, filename);
|
||||
}
|
||||
|
||||
free(filename_tmp);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,14 +47,12 @@
|
||||
#include <mavlink/mavlink_log.h>
|
||||
#include <uORB/topics/rc_channels.h>
|
||||
|
||||
int rc_calibration_check(void) {
|
||||
int rc_calibration_check(int mavlink_fd) {
|
||||
|
||||
char nbuf[20];
|
||||
param_t _parameter_handles_min, _parameter_handles_trim, _parameter_handles_max,
|
||||
_parameter_handles_rev, _parameter_handles_dz;
|
||||
|
||||
int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0);
|
||||
|
||||
float param_min, param_max, param_trim, param_rev, param_dz;
|
||||
|
||||
/* first check channel mappings */
|
||||
|
||||
@@ -47,6 +47,6 @@
|
||||
* @return 0 / OK if RC calibration is ok, index + 1 of the first
|
||||
* channel that failed else (so 1 == first channel failed)
|
||||
*/
|
||||
__EXPORT int rc_calibration_check(void);
|
||||
__EXPORT int rc_calibration_check(int mavlink_fd);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -140,7 +140,7 @@ int preflight_check_main(int argc, char *argv[])
|
||||
|
||||
/* ---- RC CALIBRATION ---- */
|
||||
|
||||
bool rc_ok = (OK == rc_calibration_check());
|
||||
bool rc_ok = (OK == rc_calibration_check(mavlink_fd));
|
||||
|
||||
/* warn */
|
||||
if (!rc_ok)
|
||||
@@ -227,4 +227,4 @@ static int led_off(int leds, int led)
|
||||
static int led_on(int leds, int led)
|
||||
{
|
||||
return ioctl(leds, LED_ON, led);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user