Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger: new optional start delay time (SDLOG_DELAY_S) #20194

Draft
wants to merge 1 commit into
base: pr-logger_subscription_init_late
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/drivers/drv_hrt.h
Expand Up @@ -61,6 +61,8 @@ __BEGIN_DECLS
*/
typedef uint64_t hrt_abstime;

#define HRT_ABSTIME_INVALID UINT64_MAX

/**
* Callout function type.
*
Expand Down
29 changes: 26 additions & 3 deletions src/modules/logger/logger.cpp
Expand Up @@ -1127,20 +1127,41 @@ bool Logger::should_start_logging()
}
}

const bool delayed_start = (_param_sdlog_delay_s.get() > 0);

if (delayed_start && (_start_requested_time != HRT_ABSTIME_INVALID)) {
desired_state = true;
updated = true;
}

desired_state = desired_state || _manually_logging_override;

// only start/stop if this is a state transition
if (updated && _prev_state != desired_state) {
_prev_state = desired_state;

if (desired_state) {

if (_should_stop_file_log) { // happens on quick stop/start toggling
_should_stop_file_log = false;
stop_log_file(LogType::Full);
}

return true;
if (delayed_start) {
if (_start_requested_time == HRT_ABSTIME_INVALID) {
_start_requested_time = hrt_absolute_time();

PX4_INFO("Delayed start in %" PRIi32 " seconds", _param_sdlog_delay_s.get());
return false;

} else if (hrt_elapsed_time(&_start_requested_time) > _param_sdlog_delay_s.get() * 1_s) {
_start_requested_time = HRT_ABSTIME_INVALID; // reset
_prev_state = true;
return true;
}

} else {
_prev_state = true;
return true;
}

} else {
// delayed stop: we measure the process loads and then stop
Expand All @@ -1150,6 +1171,8 @@ bool Logger::should_start_logging()
if ((MissionLogType)_param_sdlog_mission.get() != MissionLogType::Disabled) {
stop_log_file(LogType::Mission);
}

_prev_state = false;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/modules/logger/logger.h
Expand Up @@ -332,6 +332,8 @@ class Logger : public ModuleBase<Logger>, public ModuleParams
bool _manually_logging_override{false};
bool _start_immediately{false};

hrt_abstime _start_requested_time{HRT_ABSTIME_INVALID};

Statistics _statistics[(int)LogType::Count];
hrt_abstime _last_sync_time{0}; ///< last time a sync msg was sent

Expand Down Expand Up @@ -381,7 +383,8 @@ class Logger : public ModuleBase<Logger>, public ModuleParams
(ParamInt<px4::params::SDLOG_PROFILE>) _param_sdlog_profile,
(ParamInt<px4::params::SDLOG_MISSION>) _param_sdlog_mission,
(ParamBool<px4::params::SDLOG_BOOT_BAT>) _param_sdlog_boot_bat,
(ParamBool<px4::params::SDLOG_UUID>) _param_sdlog_uuid
(ParamBool<px4::params::SDLOG_UUID>) _param_sdlog_uuid,
(ParamInt<px4::params::SDLOG_DELAY_S>) _param_sdlog_delay_s
#if defined(PX4_CRYPTO)
, (ParamInt<px4::params::SDLOG_ALGORITHM>) _param_sdlog_crypto_algorithm,
(ParamInt<px4::params::SDLOG_KEY>) _param_sdlog_crypto_key,
Expand Down
11 changes: 11 additions & 0 deletions src/modules/logger/params.c
Expand Up @@ -176,6 +176,17 @@ PARAM_DEFINE_INT32(SDLOG_DIRS_MAX, 0);
*/
PARAM_DEFINE_INT32(SDLOG_UUID, 1);

/**
* Start delay
*
* Start delay in seconds, only enabled if > 0.
*
* @unit s
* @min 0
* @group SD Logging
*/
PARAM_DEFINE_INT32(SDLOG_DELAY_S, 0);

/**
* Logfile Encryption algorithm
*
Expand Down