From 0cb49559e1fe16c07b0a9bc5816f6094ee769e1b Mon Sep 17 00:00:00 2001 From: muramura Date: Thu, 2 May 2024 04:25:14 +0900 Subject: [PATCH] AP_Mission: Change the IF statement to a SWITCH statement --- libraries/AP_Mission/AP_Mission.cpp | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/libraries/AP_Mission/AP_Mission.cpp b/libraries/AP_Mission/AP_Mission.cpp index 89691085d3..0a707ff9b9 100644 --- a/libraries/AP_Mission/AP_Mission.cpp +++ b/libraries/AP_Mission/AP_Mission.cpp @@ -414,10 +414,17 @@ bool AP_Mission::start_command(const Mission_Command& cmd) } - if (cmd.id == MAV_CMD_DO_JUMP || cmd.id == MAV_CMD_JUMP_TAG || cmd.id == MAV_CMD_DO_JUMP_TAG) { + switch (cmd.id) { + case MAV_CMD_DO_JUMP: + case MAV_CMD_JUMP_TAG: + case MAV_CMD_DO_JUMP_TAG: GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Mission: %u %s %u", cmd.index, cmd.type(), (unsigned)cmd.p1); - } else { + break; + + default: GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Mission: %u %s", cmd.index, cmd.type()); + break; + } switch (cmd.id) { @@ -550,13 +557,18 @@ int32_t AP_Mission::get_next_ground_course_cd(int32_t default_angle) return default_angle; } // special handling for nav commands with no target location - if (cmd.id == MAV_CMD_NAV_GUIDED_ENABLE || - cmd.id == MAV_CMD_NAV_DELAY) { + switch (cmd.id) { + case MAV_CMD_NAV_GUIDED_ENABLE: + case MAV_CMD_NAV_DELAY: return default_angle; - } - if (cmd.id == MAV_CMD_NAV_SET_YAW_SPEED) { + + case MAV_CMD_NAV_SET_YAW_SPEED: return (_nav_cmd.content.set_yaw_speed.angle_deg * 100); + + default: + break; } + return _nav_cmd.content.location.get_bearing_to(cmd.content.location); } @@ -570,11 +582,17 @@ bool AP_Mission::set_current_cmd(uint16_t index) // read command to check for DO_LAND_START and DO_RETURN_PATH_START Mission_Command cmd; if (read_cmd_from_storage(index, cmd)) { - if (cmd.id == MAV_CMD_DO_LAND_START) { + switch (cmd.id) { + case MAV_CMD_DO_LAND_START: _flags.in_landing_sequence = true; + break; - } else if (cmd.id == MAV_CMD_DO_RETURN_PATH_START) { + case MAV_CMD_DO_RETURN_PATH_START: _flags.in_return_path = true; + break; + + default: + break; } }