16 :
WaitStateBase(QStringLiteral(
"RequestMessageState:%1").arg(messageId), parent, timeoutMsecs)
17 , _messageId(messageId)
18 , _messageHandler(std::move(messageHandler))
35 qCDebug(QGCStateMachineLog) <<
"Skipping request due to no primary link" <<
stateName();
41 if (sharedLink->linkConfiguration()->isHighLatency() || sharedLink->isLogReplay()) {
42 qCDebug(QGCStateMachineLog) <<
"Skipping request due to link type" <<
stateName();
48 qCDebug(QGCStateMachineLog) <<
"Requesting message id" << _messageId <<
stateName();
49 vehicle()->
requestMessage(_resultHandler,
this, _compId, _messageId, _param1, _param2, _param3, _param4, _param5);
54 qCDebug(QGCStateMachineLog) <<
"Timeout waiting for message" << _messageId <<
stateName();
59void RequestMessageState::_resultHandler(
void* resultHandlerData,
60 MAV_RESULT commandResult,
69 qCDebug(QGCStateMachineLog) <<
"Message received successfully" << state->stateName();
71 if (state->_messageHandler) {
72 state->_messageHandler(state->vehicle(), message);
75 emit state->messageReceived(message);
76 state->waitComplete();
80 qCDebug(QGCStateMachineLog) <<
"Command error" <<
commandResult << state->stateName();
83 qCDebug(QGCStateMachineLog) <<
"Command not acked" << state->stateName();
86 qCDebug(QGCStateMachineLog) <<
"Message not received" << state->stateName();
89 qCDebug(QGCStateMachineLog) <<
"Duplicate command" << state->stateName();
92 qCDebug(QGCStateMachineLog) <<
"Unknown failure" <<
failureCode << state->stateName();
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
struct __mavlink_message mavlink_message_t
QString stateName() const
Vehicle * vehicle() const
Requests a MAVLink message from the vehicle using MAV_CMD_REQUEST_MESSAGE.
void onWaitEntered() override
Called when the state is entered - subclasses should call base implementation.
MAV_RESULT commandResult() const
VehicleTypes::RequestMessageResultHandlerFailureCode_t failureCode() const
std::function< void(Vehicle *vehicle, const mavlink_message_t &message)> MessageHandler
void onWaitTimeout() override
Called when the timeout expires - default emits timeout(), subclasses can override.
RequestMessageState(QState *parent, uint32_t messageId, MessageHandler messageHandler=MessageHandler(), int compId=MAV_COMP_ID_AUTOPILOT1, int timeoutMsecs=5000, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f)
WeakLinkInterfacePtr primaryLink() const
VehicleLinkManager * vehicleLinkManager()
void requestMessage(RequestMessageResultHandler resultHandler, void *resultHandlerData, int compId, int messageId, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f)
Base class for states that wait for something with optional timeout.
virtual void onWaitTimeout()
Called when the timeout expires - default emits timeout(), subclasses can override.
virtual void onWaitEntered()
Called when the state is entered - subclasses should call base implementation.
RequestMessageResultHandlerFailureCode_t
@ RequestMessageFailureMessageNotReceived
@ RequestMessageFailureCommandNotAcked
@ RequestMessageFailureDuplicate
Exact duplicate request already active or queued for this component/message id.
@ RequestMessageFailureCommandError
@ RequestMessageNoFailure