Skip to content

Commit 98c4ea8

Browse files
DavidsastresasDonLakeFlyer
authored andcommitted
Vehicle: implement custom handler for request operator control command:
fixes #12552
1 parent bdba49a commit 98c4ea8

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/Vehicle/Vehicle.cc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4016,20 +4016,53 @@ void Vehicle::requestOperatorControl(bool allowOverride, int requestTimeoutSecs)
40164016
// If out of limits use default value
40174017
safeRequestTimeoutSecs = SettingsManager::instance()->flyViewSettings()->requestControlTimeout()->cookedDefaultValue().toInt();
40184018
}
4019-
sendMavCommand(_defaultComponentId,
4020-
MAV_CMD_REQUEST_OPERATOR_CONTROL,
4021-
false, // Don't show errors, as per Mavlink control protocol Autopilot will report result failed prior to forwarding the request to the GCS in control.
4022-
0, // System ID of GCS requesting control, 0 if it is this GCS
4023-
1, // Action - 0: Release control, 1: Request control.
4024-
allowOverride ? 1 : 0, // Allow takeover - Enable automatic granting of ownership on request. 0: Ask current owner and reject request, 1: Allow automatic takeover.
4025-
safeRequestTimeoutSecs); // Timeout in seconds before a request to a GCS to allow takeover is assumed to be rejected. This is used to display the timeout graphically on requestor and GCS in control.
4019+
4020+
const MavCmdAckHandlerInfo_t handlerInfo = {&Vehicle::_requestOperatorControlAckHandler, this, nullptr, nullptr};
4021+
sendMavCommandWithHandler(
4022+
&handlerInfo,
4023+
_defaultComponentId,
4024+
MAV_CMD_REQUEST_OPERATOR_CONTROL,
4025+
0, // System ID of GCS requesting control, 0 if it is this GCS
4026+
1, // Action - 0: Release control, 1: Request control.
4027+
allowOverride ? 1 : 0, // Allow takeover - Enable automatic granting of ownership on request. 0: Ask current owner and reject request, 1: Allow automatic takeover.
4028+
safeRequestTimeoutSecs // Timeout in seconds before a request to a GCS to allow takeover is assumed to be rejected. This is used to display the timeout graphically on requestor and GCS in control.
4029+
);
40264030

40274031
// If this is a request we sent to other GCS, start timer so User can not keep sending requests until the current timeout expires
40284032
if (requestTimeoutSecs > 0) {
40294033
requestOperatorControlStartTimer(requestTimeoutSecs * 1000);
40304034
}
40314035
}
40324036

4037+
void Vehicle::_requestOperatorControlAckHandler(void* resultHandlerData, int compId, const mavlink_command_ack_t& ack, MavCmdResultFailureCode_t failureCode)
4038+
{
4039+
// For the moment, this will always come from an autopilot, compid 1
4040+
Q_UNUSED(compId);
4041+
4042+
// If duplicated or no response, show popup to user. Otherwise only log it.
4043+
switch (failureCode) {
4044+
case MavCmdResultFailureDuplicateCommand:
4045+
qgcApp()->showAppMessage(tr("Waiting for previous operator control request"));
4046+
return;
4047+
case MavCmdResultFailureNoResponseToCommand:
4048+
qgcApp()->showAppMessage(tr("No response to operator control request"));
4049+
return;
4050+
default:
4051+
break;
4052+
}
4053+
4054+
Vehicle* vehicle = static_cast<Vehicle*>(resultHandlerData);
4055+
if (!vehicle) {
4056+
return;
4057+
}
4058+
4059+
if (ack.result == MAV_RESULT_ACCEPTED) {
4060+
qCDebug(VehicleLog) << "Operator control request accepted";
4061+
} else {
4062+
qCDebug(VehicleLog) << "Operator control request rejected";
4063+
}
4064+
}
4065+
40334066
void Vehicle::requestOperatorControlStartTimer(int requestTimeoutMsecs)
40344067
{
40354068
// First flag requests not allowed

src/Vehicle/Vehicle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ private slots:
13351335
private:
13361336
void _handleControlStatus(const mavlink_message_t& message);
13371337
void _handleCommandRequestOperatorControl(const mavlink_command_long_t commandLong);
1338+
static void _requestOperatorControlAckHandler(void* resultHandlerData, int compId, const mavlink_command_ack_t& ack, MavCmdResultFailureCode_t failureCode);
13381339

13391340
Q_PROPERTY(uint8_t sysidInControl READ sysidInControl NOTIFY gcsControlStatusChanged)
13401341
Q_PROPERTY(bool gcsControlStatusFlags_SystemManager READ gcsControlStatusFlags_SystemManager NOTIFY gcsControlStatusChanged)

0 commit comments

Comments
 (0)