logger: refactor start_stop_logging

Cleans up function by reducing duplicate code and local variable count

Signed-off-by: Tal Zaitsev <tal@corvus-robotics.com>
This commit is contained in:
tzai
2020-01-01 23:36:45 -05:00
committed by Kabir Mohammed
parent 718ca1dc50
commit fb0bf26787
+35 -49
View File
@@ -929,76 +929,62 @@ bool Logger::get_disable_boot_logging()
bool Logger::start_stop_logging(MissionLogType mission_log_type) bool Logger::start_stop_logging(MissionLogType mission_log_type)
{ {
bool bret = false; bool updated = false;
bool want_start = false; bool desired_state = false;
bool want_stop = false;
if (_log_mode == LogMode::rc_aux1) { if (_log_mode == LogMode::rc_aux1) {
// aux1-based logging // aux1-based logging
manual_control_setpoint_s manual_sp; manual_control_setpoint_s manual_sp;
if (_manual_control_sp_sub.update(&manual_sp)) { if (_manual_control_sp_sub.update(&manual_sp)) {
bool should_start = ((manual_sp.aux1 > 0.3f) || _manually_logging_override); desired_state = (manual_sp.aux1 > 0.3f);
updated = true;
if (_prev_state != should_start) {
_prev_state = should_start;
if (should_start) {
want_start = true;
} else {
want_stop = true;
}
}
} }
} else { } else if (_log_mode != LogMode::boot_until_shutdown) {
// arming-based logging // arming-based logging
vehicle_status_s vehicle_status; vehicle_status_s vehicle_status;
if (_vehicle_status_sub.update(&vehicle_status)) { if (_vehicle_status_sub.update(&vehicle_status)) {
bool armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) || _manually_logging_override; desired_state = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED);
updated = true;
}
}
if (_prev_state != armed && _log_mode != LogMode::boot_until_shutdown) { desired_state = desired_state || _manually_logging_override;
_prev_state = armed;
if (armed) { // only start/stop if this is a state transition
want_start = true; if (updated && _prev_state != desired_state) {
_prev_state = desired_state;
} else { if (desired_state) {
want_stop = true; if (_should_stop_file_log) { // happens on quick stop/start toggling
} _should_stop_file_log = false;
stop_log_file(LogType::Full);
}
start_log_file(LogType::Full);
if (mission_log_type != MissionLogType::Disabled) {
start_log_file(LogType::Mission);
}
return true;
} else {
// delayed stop: we measure the process loads and then stop
initialize_load_output(PrintLoadReason::Postflight);
_should_stop_file_log = true;
if (mission_log_type != MissionLogType::Disabled) {
stop_log_file(LogType::Mission);
} }
} }
} }
if (want_start) { return false;
if (_should_stop_file_log) { // happens on quick stop/start toggling
_should_stop_file_log = false;
stop_log_file(LogType::Full);
}
start_log_file(LogType::Full);
bret = true;
if (mission_log_type != MissionLogType::Disabled) {
start_log_file(LogType::Mission);
}
} else if (want_stop) {
// delayed stop: we measure the process loads and then stop
initialize_load_output(PrintLoadReason::Postflight);
_should_stop_file_log = true;
if (mission_log_type != MissionLogType::Disabled) {
stop_log_file(LogType::Mission);
}
}
return bret;
} }
void Logger::handle_vehicle_command_update() void Logger::handle_vehicle_command_update()