mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 16:43:33 +08:00
mavlink: add logging of mavlink messages back
The logging into a text file was commented out in the recent changes but is added back in with this commit.
This commit is contained in:
@@ -374,6 +374,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;
|
||||||
|
FILE *fp = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink),
|
explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink),
|
||||||
@@ -392,55 +393,52 @@ protected:
|
|||||||
strncpy(msg.text, (const char*)mavlink_log.text, sizeof(msg.text));
|
strncpy(msg.text, (const char*)mavlink_log.text, sizeof(msg.text));
|
||||||
|
|
||||||
_mavlink->send_message(MAVLINK_MSG_ID_STATUSTEXT, &msg);
|
_mavlink->send_message(MAVLINK_MSG_ID_STATUSTEXT, &msg);
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add this again
|
/* write log messages in first instance to disk */
|
||||||
#if 0
|
if (_mavlink->get_instance_id() == 0) {
|
||||||
/* write log messages in first instance to disk */
|
if (fp) {
|
||||||
if (_mavlink->get_instance_id() == 0) {
|
if (EOF == fputs(msg.text, fp)) {
|
||||||
if (fp) {
|
write_err_count++;
|
||||||
if (EOF == fputs(msg.text, fp)) {
|
} else {
|
||||||
write_err_count++;
|
write_err_count = 0;
|
||||||
} else {
|
}
|
||||||
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[32] = "";
|
||||||
char log_file_path[70] = "";
|
char log_file_path[70] = "";
|
||||||
|
|
||||||
timespec ts;
|
timespec ts;
|
||||||
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
/* use GPS time for log file naming, e.g. /fs/microsd/2014-01-19/19_37_52.bin */
|
/* use GPS time for log file naming, e.g. /fs/microsd/2014-01-19/19_37_52.bin */
|
||||||
time_t gps_time_sec = ts.tv_sec + (ts.tv_nsec / 1e9);
|
time_t gps_time_sec = ts.tv_sec + (ts.tv_nsec / 1e9);
|
||||||
struct tm tt;
|
struct tm tt;
|
||||||
gmtime_r(&gps_time_sec, &tt);
|
gmtime_r(&gps_time_sec, &tt);
|
||||||
|
|
||||||
// XXX we do not want to interfere here with the SD log app
|
// XXX we do not want to interfere here with the SD log app
|
||||||
strftime(log_file_name, sizeof(log_file_name), "msgs_%Y_%m_%d_%H_%M_%S.txt", &tt);
|
strftime(log_file_name, sizeof(log_file_name), "msgs_%Y_%m_%d_%H_%M_%S.txt", &tt);
|
||||||
snprintf(log_file_path, sizeof(log_file_path), PX4_ROOTFSDIR"/fs/microsd/%s", log_file_name);
|
snprintf(log_file_path, sizeof(log_file_path), PX4_ROOTFSDIR"/fs/microsd/%s", log_file_name);
|
||||||
fp = fopen(log_file_path, "ab");
|
fp = fopen(log_file_path, "ab");
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
/* write first message */
|
/* write first message */
|
||||||
fputs(msg.text, fp);
|
fputs(msg.text, fp);
|
||||||
fputs("\n", fp);
|
fputs("\n", fp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
warn("Failed to open %s errno=%d", log_file_path, errno);
|
warn("Failed to open %s errno=%d", log_file_path, errno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user