Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More command result options #1793

Merged
merged 3 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/mavsdk/core/mavlink_command_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ void MavlinkCommandSender::queue_command_async(
CommandIdentification identification = identification_from_command(command);

for (const auto& work : _work_queue) {
if (work->identification == identification) {
if (work->identification == identification && callback == nullptr) {
if (_command_debugging) {
LogDebug() << "Dropping command " << static_cast<int>(identification.command)
<< " that is already being sent";
}
auto temp_callback = callback;
call_callback(temp_callback, Result::CommandDenied, NAN);
return;
}
}
Expand Down Expand Up @@ -115,7 +113,7 @@ void MavlinkCommandSender::queue_command_async(
<< " that is already being sent";
}
auto temp_callback = callback;
call_callback(temp_callback, Result::CommandDenied, NAN);
call_callback(temp_callback, Result::Denied, NAN);
return;
}
}
Expand Down Expand Up @@ -194,35 +192,44 @@ void MavlinkCommandSender::receive_command_ack(mavlink_message_t message)
case MAV_RESULT_DENIED:
LogWarn() << "command denied (" << work->identification.command << ").";
_parent.unregister_timeout_handler(work->timeout_cookie);
temp_result = {Result::CommandDenied, NAN};
temp_result = {Result::Denied, NAN};
_work_queue.erase(it);
break;

case MAV_RESULT_UNSUPPORTED:
LogWarn() << "command unsupported (" << work->identification.command << ").";
if (_command_debugging) {
LogDebug() << "command unsupported (" << work->identification.command << ").";
}
_parent.unregister_timeout_handler(work->timeout_cookie);
temp_result = {Result::Unsupported, NAN};
_work_queue.erase(it);
break;

case MAV_RESULT_TEMPORARILY_REJECTED:
LogWarn() << "command temporarily rejected (" << work->identification.command
<< ").";
if (_command_debugging) {
LogDebug() << "command temporarily rejected (" << work->identification.command
<< ").";
}
_parent.unregister_timeout_handler(work->timeout_cookie);
temp_result = {Result::CommandDenied, NAN};
temp_result = {Result::TemporarilyRejected, NAN};
_work_queue.erase(it);
break;

case MAV_RESULT_FAILED:
if (_command_debugging) {
LogDebug() << "command failed (" << work->identification.command << ").";
}
_parent.unregister_timeout_handler(work->timeout_cookie);
temp_result = {Result::CommandDenied, NAN};
temp_result = {Result::Failed, NAN};
_work_queue.erase(it);
break;

case MAV_RESULT_IN_PROGRESS:
if (static_cast<int>(command_ack.progress) != 255) {
LogInfo() << "progress: " << static_cast<int>(command_ack.progress) << " % ("
<< work->identification.command << ").";
if (_command_debugging) {
if (static_cast<int>(command_ack.progress) != 255) {
LogDebug() << "progress: " << static_cast<int>(command_ack.progress)
<< " % (" << work->identification.command << ").";
}
}
// If we get a progress update, we can raise the timeout
// to something higher because we know the initial command
Expand All @@ -241,6 +248,15 @@ void MavlinkCommandSender::receive_command_ack(mavlink_message_t message)
Result::InProgress, static_cast<float>(command_ack.progress) / 100.0f};
break;

case MAV_RESULT_CANCELLED:
if (_command_debugging) {
LogDebug() << "command cancelled (" << work->identification.command << ").";
}
_parent.unregister_timeout_handler(work->timeout_cookie);
temp_result = {Result::Cancelled, NAN};
_work_queue.erase(it);
break;

default:
LogWarn() << "Received unknown ack.";
break;
Expand Down
5 changes: 4 additions & 1 deletion src/mavsdk/core/mavlink_command_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ class MavlinkCommandSender {
NoSystem,
ConnectionError,
Busy,
CommandDenied,
Denied,
Unsupported,
Timeout,
InProgress,
TemporarilyRejected,
Failed,
Cancelled,
UnknownError
};

Expand Down
12 changes: 9 additions & 3 deletions src/mavsdk/core/request_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,21 @@ void RequestMessage::handle_command_result(uint32_t message_id, MavlinkCommandSe
// FALLTHROUGH
case MavlinkCommandSender::Result::ConnectionError:
// FALLTHROUGH
case MavlinkCommandSender::Result::UnknownError:
case MavlinkCommandSender::Result::Busy:
// FALLTHROUGH
case MavlinkCommandSender::Result::Denied:
// FALLTHROUGH
case MavlinkCommandSender::Result::Unsupported:
// FALLTHROUGH
case MavlinkCommandSender::Result::Timeout:
// FALLTHROUGH
case MavlinkCommandSender::Result::Busy:
case MavlinkCommandSender::Result::TemporarilyRejected:
// FALLTHROUGH
case MavlinkCommandSender::Result::Failed:
// FALLTHROUGH
case MavlinkCommandSender::Result::Cancelled:
// FALLTHROUGH
case MavlinkCommandSender::Result::CommandDenied: {
case MavlinkCommandSender::Result::UnknownError: {
// It looks like this did not work, and we can report the error
// No need to try again.
auto temp_callback = it->callback;
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/action/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ std::ostream& operator<<(std::ostream& str, Action::Result const& result)
return str << "Parameter Error";
case Action::Result::Unsupported:
return str << "Unsupported";
case Action::Result::Failed:
return str << "Failed";
default:
return str << "Unknown";
}
Expand Down
6 changes: 5 additions & 1 deletion src/mavsdk/plugins/action/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,12 @@ Action::Result ActionImpl::action_result_from_command_result(MavlinkCommandSende
return Action::Result::ConnectionError;
case MavlinkCommandSender::Result::Busy:
return Action::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// Fallthrough
case MavlinkCommandSender::Result::TemporarilyRejected:
return Action::Result::CommandDenied;
case MavlinkCommandSender::Result::Failed:
return Action::Result::Failed;
case MavlinkCommandSender::Result::Timeout:
return Action::Result::Timeout;
case MavlinkCommandSender::Result::Unsupported:
Expand Down
1 change: 1 addition & 0 deletions src/mavsdk/plugins/action/include/plugins/action/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Action : public PluginBase {
NoVtolTransitionSupport, /**< @brief Vehicle does not support hybrid/VTOL transitions. */
ParameterError, /**< @brief Error getting or setting parameter. */
Unsupported, /**< @brief Action not supported. */
Failed, /**< @brief Action failed. */
};

/**
Expand Down
20 changes: 16 additions & 4 deletions src/mavsdk/plugins/calibration/calibration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,19 @@ void CalibrationImpl::command_result_callback(
// FALLTHROUGH
case MavlinkCommandSender::Result::Busy:
// FALLTHROUGH
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// FALLTHROUGH
case MavlinkCommandSender::Result::Unsupported:
// FALLTHROUGH
case MavlinkCommandSender::Result::UnknownError:
case MavlinkCommandSender::Result::Timeout:
// FALLTHROUGH
case MavlinkCommandSender::Result::TemporarilyRejected:
// FALLTHROUGH
case MavlinkCommandSender::Result::Failed:
// FALLTHROUGH
case MavlinkCommandSender::Result::Cancelled:
// FALLTHROUGH
case MavlinkCommandSender::Result::Timeout: {
case MavlinkCommandSender::Result::UnknownError: {
// Report all error cases.
const auto timeout_result = calibration_result_from_command_result(command_result);
call_callback(_calibration_callback, timeout_result, Calibration::ProgressData());
Expand Down Expand Up @@ -336,8 +342,14 @@ CalibrationImpl::calibration_result_from_command_result(MavlinkCommandSender::Re
return Calibration::Result::ConnectionError;
case MavlinkCommandSender::Result::Busy:
return Calibration::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// Fallthrough
case MavlinkCommandSender::Result::TemporarilyRejected:
return Calibration::Result::CommandDenied;
case MavlinkCommandSender::Result::Failed:
return Calibration::Result::Failed;
case MavlinkCommandSender::Result::Cancelled:
return Calibration::Result::Cancelled;
case MavlinkCommandSender::Result::Timeout:
return Calibration::Result::Timeout;
case MavlinkCommandSender::Result::InProgress:
Expand Down
8 changes: 5 additions & 3 deletions src/mavsdk/plugins/camera/camera_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,14 @@ CameraImpl::camera_result_from_command_result(const MavlinkCommandSender::Result
case MavlinkCommandSender::Result::Success:
return Camera::Result::Success;
case MavlinkCommandSender::Result::NoSystem:
// FALLTHROUGH
// FALLTHROUGH
case MavlinkCommandSender::Result::ConnectionError:
// FALLTHROUGH
// FALLTHROUGH
case MavlinkCommandSender::Result::Busy:
return Camera::Result::Error;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// FALLTHROUGH
case MavlinkCommandSender::Result::TemporarilyRejected:
return Camera::Result::Denied;
case MavlinkCommandSender::Result::Timeout:
return Camera::Result::Timeout;
Expand Down
4 changes: 3 additions & 1 deletion src/mavsdk/plugins/failure/failure_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ FailureImpl::failure_result_from_command_result(MavlinkCommandSender::Result com
return Failure::Result::NoSystem;
case MavlinkCommandSender::Result::ConnectionError:
return Failure::Result::ConnectionError;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// Fallthrough
case MavlinkCommandSender::Result::TemporarilyRejected:
return Failure::Result::Denied;
case MavlinkCommandSender::Result::Unsupported:
return Failure::Result::Unsupported;
Expand Down
4 changes: 3 additions & 1 deletion src/mavsdk/plugins/follow_me/follow_me_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ FollowMe::Result FollowMeImpl::to_follow_me_result(MavlinkCommandSender::Result
return FollowMe::Result::ConnectionError;
case MavlinkCommandSender::Result::Busy:
return FollowMe::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// Fallthrough
case MavlinkCommandSender::Result::TemporarilyRejected:
return FollowMe::Result::CommandDenied;
case MavlinkCommandSender::Result::Timeout:
return FollowMe::Result::Timeout;
Expand Down
3 changes: 2 additions & 1 deletion src/mavsdk/plugins/gimbal/gimbal_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ GimbalImpl::gimbal_result_from_command_result(MavlinkCommandSender::Result comma
case MavlinkCommandSender::Result::NoSystem:
case MavlinkCommandSender::Result::ConnectionError:
case MavlinkCommandSender::Result::Busy:
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
case MavlinkCommandSender::Result::TemporarilyRejected:
default:
return Gimbal::Result::Error;
}
Expand Down
4 changes: 3 additions & 1 deletion src/mavsdk/plugins/manual_control/manual_control_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ ManualControlImpl::manual_control_result_from_command_result(MavlinkCommandSende
return ManualControl::Result::ConnectionError;
case MavlinkCommandSender::Result::Busy:
return ManualControl::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
// FALLTHROUGH
case MavlinkCommandSender::Result::TemporarilyRejected:
return ManualControl::Result::CommandDenied;
case MavlinkCommandSender::Result::Timeout:
return ManualControl::Result::Timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MavlinkPassthrough : public PluginBase {
CommandDenied, /**< @brief Command has been denied. */
CommandUnsupported, /**< @brief Command is not supported. */
CommandTimeout, /**< @brief A timeout happened. */
CommandTemporarilyRejected, /**< @brief Command has been rejected for now. */
CommandFailed, /**< @brief Command has failed. */
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ MavlinkPassthroughImpl::to_mavlink_passthrough_result_from_mavlink_commands_resu
return MavlinkPassthrough::Result::ConnectionError;
case MavlinkCommandSender::Result::Busy:
return MavlinkPassthrough::Result::CommandBusy;
case MavlinkCommandSender::Result::CommandDenied:
case MavlinkCommandSender::Result::Denied:
return MavlinkPassthrough::Result::CommandDenied;
case MavlinkCommandSender::Result::TemporarilyRejected:
return MavlinkPassthrough::Result::CommandTemporarilyRejected;
case MavlinkCommandSender::Result::Unsupported:
return MavlinkPassthrough::Result::CommandUnsupported;
case MavlinkCommandSender::Result::Failed:
return MavlinkPassthrough::Result::CommandFailed;
case MavlinkCommandSender::Result::Timeout:
return MavlinkPassthrough::Result::CommandTimeout;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class Mission : public PluginBase {
TransferCancelled, /**< @brief Mission transfer (upload or download) has been cancelled. */
NoSystem, /**< @brief No system connected. */
Next, /**< @brief Intermediate message showing progress. */
Denied, /**< @brief Request denied. */
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/mission/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ std::ostream& operator<<(std::ostream& str, Mission::Result const& result)
return str << "No System";
case Mission::Result::Next:
return str << "Next";
case Mission::Result::Denied:
return str << "Denied";
default:
return str << "Unknown";
}
Expand Down
12 changes: 7 additions & 5 deletions src/mavsdk/plugins/mission/mission_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,17 +806,19 @@ Mission::Result MissionImpl::command_result_to_mission_result(MavlinkCommandSend
case MavlinkCommandSender::Result::Success:
return Mission::Result::Success;
case MavlinkCommandSender::Result::NoSystem:
return Mission::Result::Error; // FIXME
return Mission::Result::NoSystem;
case MavlinkCommandSender::Result::ConnectionError:
return Mission::Result::Error; // FIXME
return Mission::Result::Error;
case MavlinkCommandSender::Result::Busy:
return Mission::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
return Mission::Result::Error; // FIXME
case MavlinkCommandSender::Result::TemporarilyRejected:
// FALLTHROUGH
case MavlinkCommandSender::Result::Denied:
return Mission::Result::Denied;
case MavlinkCommandSender::Result::Timeout:
return Mission::Result::Timeout;
case MavlinkCommandSender::Result::InProgress:
return Mission::Result::Busy; // FIXME
return Mission::Result::Busy;
case MavlinkCommandSender::Result::UnknownError:
return Mission::Result::Unknown;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class MissionRaw : public PluginBase {
FailedToOpenQgcPlan, /**< @brief Failed to open the QGroundControl plan. */
FailedToParseQgcPlan, /**< @brief Failed to parse the QGroundControl plan. */
NoSystem, /**< @brief No system connected. */
Denied, /**< @brief Request denied. */
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/mission_raw/mission_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ std::ostream& operator<<(std::ostream& str, MissionRaw::Result const& result)
return str << "Failed To Parse Qgc Plan";
case MissionRaw::Result::NoSystem:
return str << "No System";
case MissionRaw::Result::Denied:
return str << "Denied";
default:
return str << "Unknown";
}
Expand Down
12 changes: 7 additions & 5 deletions src/mavsdk/plugins/mission_raw/mission_raw_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,19 @@ MissionRawImpl::command_result_to_mission_result(MavlinkCommandSender::Result re
case MavlinkCommandSender::Result::Success:
return MissionRaw::Result::Success;
case MavlinkCommandSender::Result::NoSystem:
return MissionRaw::Result::Error; // FIXME
return MissionRaw::Result::NoSystem;
case MavlinkCommandSender::Result::ConnectionError:
return MissionRaw::Result::Error; // FIXME
return MissionRaw::Result::Error;
case MavlinkCommandSender::Result::Busy:
return MissionRaw::Result::Busy;
case MavlinkCommandSender::Result::CommandDenied:
return MissionRaw::Result::Error; // FIXME
case MavlinkCommandSender::Result::Denied:
// FALLTHROUGH
case MavlinkCommandSender::Result::TemporarilyRejected:
return MissionRaw::Result::Denied;
case MavlinkCommandSender::Result::Timeout:
return MissionRaw::Result::Timeout;
case MavlinkCommandSender::Result::InProgress:
return MissionRaw::Result::Busy; // FIXME
return MissionRaw::Result::Busy;
case MavlinkCommandSender::Result::UnknownError:
return MissionRaw::Result::Unknown;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class Offboard : public PluginBase {
CommandDenied, /**< @brief Command denied. */
Timeout, /**< @brief Request timed out. */
NoSetpointSet, /**< @brief Cannot start without setpoint set. */
Failed, /**< @brief Request failed. */
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/offboard/offboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ std::ostream& operator<<(std::ostream& str, Offboard::Result const& result)
return str << "Timeout";
case Offboard::Result::NoSetpointSet:
return str << "No Setpoint Set";
case Offboard::Result::Failed:
return str << "Failed";
default:
return str << "Unknown";
}
Expand Down
Loading