Skip to content

Commit

Permalink
AP_Mission: stop populating command with -1 on failure
Browse files Browse the repository at this point in the history
Just indicate in the comments that the contents are undefined after this call.
  • Loading branch information
peterbarker committed Sep 4, 2024
1 parent 4daca86 commit 7c8449e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
7 changes: 1 addition & 6 deletions libraries/AP_Mission/AP_Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,14 @@ bool AP_Mission::set_item(uint16_t index, mavlink_mission_item_int_t& src_packet
return AP_Mission::replace_cmd(index, cmd);
}

// the contents of ret_packet are undefined when this method returns false
bool AP_Mission::get_item(uint16_t index, mavlink_mission_item_int_t& ret_packet) const
{
// setting ret_packet.command = -1 and/or returning false
// means it contains invalid data after it leaves here.

// this is the on-storage format
AP_Mission::Mission_Command cmd {};

// can't handle request for anything bigger than the mission size...
if (index >= num_commands()) {
ret_packet.command = -1;
return false;
}

Expand All @@ -722,12 +719,10 @@ bool AP_Mission::get_item(uint16_t index, mavlink_mission_item_int_t& ret_packet

// retrieve mission from eeprom
if (!read_cmd_from_storage(ret_packet.seq, cmd)) {
ret_packet.command = -1;
return false;
}
// convert into mavlink-ish format for lua and friends.
if (!mission_cmd_to_mavlink_int(cmd, ret_packet)) {
ret_packet.command = -1;
return false;
}

Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Mission/AP_Mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ class AP_Mission
static const struct AP_Param::GroupInfo var_info[];

// allow lua to get/set any WP items in any order in a mavlink-ish kinda way.
// the contents of ret_packet are undefined when get_item returns false
bool get_item(uint16_t index, mavlink_mission_item_int_t& result) const ;
bool set_item(uint16_t index, mavlink_mission_item_int_t& source) ;

Expand Down

0 comments on commit 7c8449e

Please sign in to comment.