logger: Add support for logging only on bat power

Will not start logging from boot if battery is not connected

Signed-off-by: Tal Zaitsev <tal@corvus-robotics.com>
This commit is contained in:
tzai 2020-01-01 23:43:03 -05:00 committed by Kabir Mohammed
parent d1e3ff553b
commit 1c2f95697c
3 changed files with 42 additions and 1 deletions

View File

@ -49,6 +49,7 @@
#include <uORB/uORBTopics.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/vehicle_command_ack.h>
#include <uORB/topics/battery_status.h>
#include <drivers/drv_hrt.h>
#include <mathlib/math/Limits.hpp>
@ -374,6 +375,7 @@ Logger::Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_inte
_log_dirs_max = param_find("SDLOG_DIRS_MAX");
_sdlog_profile_handle = param_find("SDLOG_PROFILE");
_mission_log = param_find("SDLOG_MISSION");
_boot_bat_only = param_find("SDLOG_BOOT_BAT");
if (poll_topic_name) {
const orb_metadata *const *topics = orb_get_topics();
@ -518,6 +520,29 @@ void Logger::run()
{
PX4_INFO("logger started (mode=%s)", configured_backend_mode());
bool boot_logging_bat_only = false;
bool disable_boot_logging = false;
if (_boot_bat_only != PARAM_INVALID) {
param_get(_boot_bat_only, &boot_logging_bat_only);
}
if (boot_logging_bat_only) {
uORB::Subscription battery_status_sub{ORB_ID(battery_status)};
if (battery_status_sub.updated()) {
battery_status_s battery_status;
battery_status_sub.copy(&battery_status);
if (!battery_status.connected) {
disable_boot_logging = true;
}
} else {
PX4_WARN("battery_status not published. Logging anyway");
}
}
if (_writer.backend() & LogWriter::BackendFile) {
int mkdir_ret = mkdir(LOG_ROOT[(int)LogType::Full], S_IRWXU | S_IRWXG | S_IRWXO);
@ -602,7 +627,7 @@ void Logger::run()
px4_register_shutdown_hook(&Logger::request_stop_static);
if (_log_mode == LogMode::boot_until_disarm || _log_mode == LogMode::boot_until_shutdown) {
if ((_log_mode == LogMode::boot_until_disarm || _log_mode == LogMode::boot_until_shutdown) && !disable_boot_logging) {
start_log_file(LogType::Full);
}

View File

@ -338,6 +338,7 @@ private:
param_t _log_utc_offset{PARAM_INVALID};
param_t _log_dirs_max{PARAM_INVALID};
param_t _mission_log{PARAM_INVALID};
param_t _boot_bat_only{PARAM_INVALID};
};
} //namespace logger

View File

@ -66,6 +66,21 @@ PARAM_DEFINE_INT32(SDLOG_UTC_OFFSET, 0);
*/
PARAM_DEFINE_INT32(SDLOG_MODE, 0);
/**
* Battery-only Logging
*
* When enabled, logging will not start from boot if battery power is not detected
* (e.g. powered via USB on a test bench). This prevents extraneous flight logs from
* being created during bench testing.
*
* Note that this only applies to log-from-boot modes. This has no effect on arm-based
* modes.
*
* @boolean
* @group SD Logging
*/
PARAM_DEFINE_INT32(SDLOG_BOOT_BAT, 0);
/**
* Mission Log
*