mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-13 07:27:34 +08:00
logger: new optional start delay time (SDLOG_DELAY_S)
- this can be useful when using PX4 as a standalone data logger
This commit is contained in:
@@ -61,6 +61,8 @@ __BEGIN_DECLS
|
||||
*/
|
||||
typedef uint64_t hrt_abstime;
|
||||
|
||||
#define HRT_ABSTIME_INVALID UINT64_MAX
|
||||
|
||||
/**
|
||||
* Callout function type.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -332,6 +332,8 @@ private:
|
||||
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
|
||||
|
||||
@@ -381,7 +383,8 @@ private:
|
||||
(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,
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user