mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
MAVLink app: Save stack for file name handliling, log only when armed
This commit is contained in:
@@ -353,6 +353,13 @@ public:
|
||||
|
||||
bool is_usb_uart() { return _is_usb_uart; }
|
||||
|
||||
/**
|
||||
* Wether or not the system should be logging
|
||||
*/
|
||||
bool get_logging_enabled() { return _logging_enabled; }
|
||||
|
||||
void set_logging_enabled(bool logging) { _logging_enabled = logging; }
|
||||
|
||||
protected:
|
||||
Mavlink *next;
|
||||
|
||||
@@ -458,6 +465,8 @@ private:
|
||||
pthread_mutex_t _send_mutex;
|
||||
|
||||
bool _param_initialized;
|
||||
bool _logging_enabled;
|
||||
|
||||
param_t _param_system_id;
|
||||
param_t _param_component_id;
|
||||
param_t _param_radio_id;
|
||||
|
||||
@@ -412,7 +412,7 @@ protected:
|
||||
// TODO: the logging doesn't work on Snapdragon yet because of file paths.
|
||||
#ifndef __PX4_POSIX_EAGLE
|
||||
/* write log messages in first instance to disk */
|
||||
if (_mavlink->get_instance_id() == 0) {
|
||||
if (_mavlink->get_instance_id() == 0 && _mavlink->get_logging_enabled()) {
|
||||
if (fp) {
|
||||
if (EOF == fputs(msg.text, fp)) {
|
||||
write_err_count++;
|
||||
@@ -430,8 +430,8 @@ protected:
|
||||
|
||||
} else if (write_err_count < write_err_threshold) {
|
||||
/* string to hold the path to the log */
|
||||
char log_file_name[64];
|
||||
char log_file_path[128];
|
||||
log_file_path[0] = 0;
|
||||
|
||||
timespec ts;
|
||||
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
||||
@@ -440,9 +440,9 @@ protected:
|
||||
struct tm tt;
|
||||
gmtime_r(&gps_time_sec, &tt);
|
||||
|
||||
// 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);
|
||||
snprintf(log_file_path, sizeof(log_file_path), PX4_ROOTFSDIR"/fs/microsd/%s", log_file_name);
|
||||
/* store the log file in the root directory */
|
||||
int offs = snprintf(log_file_path, sizeof(log_file_path) - 1, PX4_ROOTFSDIR"/fs/microsd/");
|
||||
strftime(log_file_path + offs, sizeof(log_file_path), "msgs_%Y_%m_%d_%H_%M_%S.txt", &tt);
|
||||
fp = fopen(log_file_path, "ab");
|
||||
|
||||
if (fp != NULL) {
|
||||
@@ -451,7 +451,6 @@ protected:
|
||||
fputs("\n", fp);
|
||||
} else {
|
||||
PX4_WARN("Failed to open MAVLink log: %s errno=%d", log_file_path, errno);
|
||||
PX4_WARN("Filename: %s", log_file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -579,6 +578,14 @@ protected:
|
||||
const bool updated_status = _status_sub->update(&status);
|
||||
const bool updated_battery = _battery_status_sub->update(&battery_status);
|
||||
|
||||
if (updated_status) {
|
||||
if (status.arming_state >= vehicle_status_s::ARMING_STATE_ARMED) {
|
||||
_mavlink->set_logging_enabled(true);
|
||||
} else {
|
||||
_mavlink->set_logging_enabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (updated_status || updated_battery) {
|
||||
mavlink_sys_status_t msg;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user