mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 17:53:34 +08:00
MAVLink: More robust string operations
This commit is contained in:
@@ -378,7 +378,7 @@ private:
|
|||||||
|
|
||||||
unsigned write_err_count = 0;
|
unsigned write_err_count = 0;
|
||||||
static const unsigned write_err_threshold = 5;
|
static const unsigned write_err_threshold = 5;
|
||||||
#ifndef __PX4_QURT
|
#ifndef __PX4_POSIX_EAGLE
|
||||||
FILE *fp = nullptr;
|
FILE *fp = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ protected:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
~MavlinkStreamStatustext() {
|
~MavlinkStreamStatustext() {
|
||||||
#ifndef __PX4_QURT
|
#ifndef __PX4_POSIX_EAGLE
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -405,33 +405,33 @@ protected:
|
|||||||
mavlink_statustext_t msg;
|
mavlink_statustext_t msg;
|
||||||
msg.severity = mavlink_log.severity;
|
msg.severity = mavlink_log.severity;
|
||||||
strncpy(msg.text, (const char *)mavlink_log.text, sizeof(msg.text));
|
strncpy(msg.text, (const char *)mavlink_log.text, sizeof(msg.text));
|
||||||
|
msg.text[sizeof(msg.text) - 1] = '\0';
|
||||||
|
|
||||||
_mavlink->send_message(MAVLINK_MSG_ID_STATUSTEXT, &msg);
|
_mavlink->send_message(MAVLINK_MSG_ID_STATUSTEXT, &msg);
|
||||||
|
|
||||||
|
|
||||||
// TODO: the logging doesn't work on Snapdragon yet because of file paths.
|
// TODO: the logging doesn't work on Snapdragon yet because of file paths.
|
||||||
#ifndef __PX4_POSIX_EAGLE
|
#ifndef __PX4_POSIX_EAGLE
|
||||||
/* write log messages in first instance to disk */
|
/* write log messages in first instance to disk */
|
||||||
if (_mavlink->get_instance_id() == 0) {
|
if (_mavlink->get_instance_id() == 0) {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
if (EOF == fputs(msg.text, fp)) {
|
if (EOF == fputs(msg.text, fp)) {
|
||||||
write_err_count++;
|
write_err_count++;
|
||||||
} else {
|
} else {
|
||||||
write_err_count = 0;
|
write_err_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_err_count >= write_err_threshold) {
|
if (write_err_count >= write_err_threshold) {
|
||||||
(void)fclose(fp);
|
(void)fclose(fp);
|
||||||
fp = nullptr;
|
fp = nullptr;
|
||||||
} else {
|
} else {
|
||||||
(void)fputs("\n", fp);
|
(void)fputs("\n", fp);
|
||||||
(void)fsync(fileno(fp));
|
(void)fsync(fileno(fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (write_err_count < write_err_threshold) {
|
} else if (write_err_count < write_err_threshold) {
|
||||||
/* string to hold the path to the log */
|
/* string to hold the path to the log */
|
||||||
char log_file_name[32] = "";
|
char log_file_name[64];
|
||||||
char log_file_path[70] = "";
|
char log_file_path[128];
|
||||||
|
|
||||||
timespec ts;
|
timespec ts;
|
||||||
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
@@ -450,7 +450,7 @@ protected:
|
|||||||
fputs(msg.text, fp);
|
fputs(msg.text, fp);
|
||||||
fputs("\n", fp);
|
fputs("\n", fp);
|
||||||
} else {
|
} else {
|
||||||
PX4_WARN("Failed to open %s errno=%d", log_file_path, errno);
|
PX4_WARN("Failed to open MAVLink log: %s errno=%d", log_file_path, errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user