Skip to content

Commit

Permalink
action: return invalid argument on wrong index (#2271)
Browse files Browse the repository at this point in the history
This catches the user error trying to set actuator 0 when it should
start at 1. And also adds a note in the docstring about it.

Signed-off-by: Julian Oes <julian@oes.ch>
  • Loading branch information
julianoes authored Apr 5, 2024
1 parent e4d6092 commit de90b23
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 73 deletions.
2 changes: 1 addition & 1 deletion proto
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/action/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ std::ostream& operator<<(std::ostream& str, Action::Result const& result)
return str << "Unsupported";
case Action::Result::Failed:
return str << "Failed";
case Action::Result::InvalidArgument:
return str << "Invalid Argument";
default:
return str << "Unknown";
}
Expand Down
7 changes: 7 additions & 0 deletions src/mavsdk/plugins/action/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ void ActionImpl::set_actuator_async(
break;
}
command.params.maybe_param7 = static_cast<float>(zero_based_index) / 6.0f;
} else {
if (callback) {
_system_impl->call_user_callback([temp_callback = callback]() {
temp_callback(Action::Result::InvalidArgument);
});
}
return;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/mavsdk/plugins/action/include/plugins/action/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Action : public PluginBase {
ParameterError, /**< @brief Error getting or setting parameter. */
Unsupported, /**< @brief Action not supported. */
Failed, /**< @brief Action failed. */
InvalidArgument, /**< @brief Invalid argument. */
};

/**
Expand Down Expand Up @@ -411,13 +412,17 @@ class Action : public PluginBase {
/**
* @brief Send command to set the value of an actuator.
*
* Note that the index of the actuator starts at 1 and that the value goes from -1 to 1.
*
* This function is non-blocking. See 'set_actuator' for the blocking counterpart.
*/
void set_actuator_async(int32_t index, float value, const ResultCallback callback);

/**
* @brief Send command to set the value of an actuator.
*
* Note that the index of the actuator starts at 1 and that the value goes from -1 to 1.
*
* This function is blocking. See 'set_actuator_async' for the non-blocking counterpart.
*
* @return Result of request.
Expand Down
6 changes: 6 additions & 0 deletions src/mavsdk_server/src/generated/action/action.grpc.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 70 additions & 69 deletions src/mavsdk_server/src/generated/action/action.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/mavsdk_server/src/generated/action/action.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/mavsdk_server/src/plugins/action/action_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class ActionServiceImpl final : public rpc::action::ActionService::Service {
return rpc::action::ActionResult_Result_RESULT_UNSUPPORTED;
case mavsdk::Action::Result::Failed:
return rpc::action::ActionResult_Result_RESULT_FAILED;
case mavsdk::Action::Result::InvalidArgument:
return rpc::action::ActionResult_Result_RESULT_INVALID_ARGUMENT;
}
}

Expand Down Expand Up @@ -156,6 +158,8 @@ class ActionServiceImpl final : public rpc::action::ActionService::Service {
return mavsdk::Action::Result::Unsupported;
case rpc::action::ActionResult_Result_RESULT_FAILED:
return mavsdk::Action::Result::Failed;
case rpc::action::ActionResult_Result_RESULT_INVALID_ARGUMENT:
return mavsdk::Action::Result::InvalidArgument;
}
}

Expand Down

0 comments on commit de90b23

Please sign in to comment.