diff --git a/libraries/AP_Mission/AP_Mission.cpp b/libraries/AP_Mission/AP_Mission.cpp index 34ea0b5868..4294ec5891 100644 --- a/libraries/AP_Mission/AP_Mission.cpp +++ b/libraries/AP_Mission/AP_Mission.cpp @@ -164,6 +164,20 @@ bool AP_Mission::add_cmd(Mission_Command& cmd) return ret; } +/// replace_cmd - replaces the command at position 'index' in the command list with the provided cmd +/// replacing the current active command will have no effect until the command is restarted +/// returns true if successfully replaced, false on failure +bool AP_Mission::replace_cmd(uint16_t index, Mission_Command& cmd) +{ + // sanity check index + if (index >= _cmd_total) { + return false; + } + + // attempt to write the command to storage + return write_cmd_to_storage(index, cmd); +} + /// is_nav_cmd - returns true if the command's id is a "navigation" command, false if "do" or "conditional" command bool AP_Mission::is_nav_cmd(const Mission_Command& cmd) { diff --git a/libraries/AP_Mission/AP_Mission.h b/libraries/AP_Mission/AP_Mission.h index d862abe19b..720d9a008f 100644 --- a/libraries/AP_Mission/AP_Mission.h +++ b/libraries/AP_Mission/AP_Mission.h @@ -138,6 +138,11 @@ public: /// cmd.index is updated with it's new position in the mission bool add_cmd(Mission_Command& cmd); + /// replace_cmd - replaces the command at position 'index' in the command list with the provided cmd + /// replacing the current active command will have no effect until the command is restarted + /// returns true if successfully replaced, false on failure + bool replace_cmd(uint16_t index, Mission_Command& cmd); + /// is_nav_cmd - returns true if the command's id is a "navigation" command, false if "do" or "conditional" command static bool is_nav_cmd(const Mission_Command& cmd); @@ -153,7 +158,7 @@ public: /// accounts for do_jump commands bool get_next_nav_cmd(uint16_t start_index, Mission_Command& cmd); - /// get_active_do_cmd - returns active "do" command + /// get_current_do_cmd - returns active "do" command const Mission_Command& get_current_do_cmd() const { return _do_cmd; } // set_current_cmd - jumps to command specified by index