Browse Source

Vehicle: handle MAVLINK_MSG_ID_CURRENT_MODE

QGC4.4
Beat Küng 2 years ago
parent
commit
968db69d9e
  1. 22
      src/Vehicle/Vehicle.cc
  2. 3
      src/Vehicle/Vehicle.h

22
src/Vehicle/Vehicle.cc

@ -775,6 +775,9 @@ void Vehicle::_mavlinkMessageReceived(LinkInterface* link, mavlink_message_t mes
} }
break; break;
} }
case MAVLINK_MSG_ID_CURRENT_MODE:
_handleCurrentMode(message);
break;
// Following are ArduPilot dialect messages // Following are ArduPilot dialect messages
#if !defined(NO_ARDUPILOT_DIALECT) #if !defined(NO_ARDUPILOT_DIALECT)
@ -1664,16 +1667,15 @@ EventHandler& Vehicle::_eventHandler(uint8_t compid)
// connect health and arming check updates // connect health and arming check updates
connect(eventHandler.data(), &EventHandler::healthAndArmingChecksUpdated, this, [compid, this]() { connect(eventHandler.data(), &EventHandler::healthAndArmingChecksUpdated, this, [compid, this]() {
// TODO: use user-intended mode instead of currently set mode
const QSharedPointer<EventHandler>& eventHandler = _events[compid]; const QSharedPointer<EventHandler>& eventHandler = _events[compid];
_healthAndArmingCheckReport.update(compid, eventHandler->healthAndArmingCheckResults(), _healthAndArmingCheckReport.update(compid, eventHandler->healthAndArmingCheckResults(),
eventHandler->getModeGroup(_custom_mode)); eventHandler->getModeGroup(_has_custom_mode_user_intention ? _custom_mode_user_intention : _custom_mode));
}); });
connect(this, &Vehicle::flightModeChanged, this, [compid, this]() { connect(this, &Vehicle::flightModeChanged, this, [compid, this]() {
const QSharedPointer<EventHandler>& eventHandler = _events[compid]; const QSharedPointer<EventHandler>& eventHandler = _events[compid];
if (eventHandler->healthAndArmingCheckResultsValid()) { if (eventHandler->healthAndArmingCheckResultsValid()) {
_healthAndArmingCheckReport.update(compid, eventHandler->healthAndArmingCheckResults(), _healthAndArmingCheckReport.update(compid, eventHandler->healthAndArmingCheckResults(),
eventHandler->getModeGroup(_custom_mode)); eventHandler->getModeGroup(_has_custom_mode_user_intention ? _custom_mode_user_intention : _custom_mode));
} }
}); });
} }
@ -1753,6 +1755,20 @@ void Vehicle::_handleHeartbeat(mavlink_message_t& message)
} }
} }
void Vehicle::_handleCurrentMode(mavlink_message_t& message)
{
mavlink_current_mode_t currentMode;
mavlink_msg_current_mode_decode(&message, &currentMode);
if (currentMode.intended_custom_mode != 0) { // 0 == unknown/not supplied
_has_custom_mode_user_intention = true;
bool changed = _custom_mode_user_intention != currentMode.intended_custom_mode;
_custom_mode_user_intention = currentMode.intended_custom_mode;
if (changed) {
emit flightModeChanged(flightMode());
}
}
}
void Vehicle::_handleRadioStatus(mavlink_message_t& message) void Vehicle::_handleRadioStatus(mavlink_message_t& message)
{ {

3
src/Vehicle/Vehicle.h

@ -1036,6 +1036,7 @@ private:
void _handlePing (LinkInterface* link, mavlink_message_t& message); void _handlePing (LinkInterface* link, mavlink_message_t& message);
void _handleHomePosition (mavlink_message_t& message); void _handleHomePosition (mavlink_message_t& message);
void _handleHeartbeat (mavlink_message_t& message); void _handleHeartbeat (mavlink_message_t& message);
void _handleCurrentMode (mavlink_message_t& message);
void _handleRadioStatus (mavlink_message_t& message); void _handleRadioStatus (mavlink_message_t& message);
void _handleRCChannels (mavlink_message_t& message); void _handleRCChannels (mavlink_message_t& message);
void _handleBatteryStatus (mavlink_message_t& message); void _handleBatteryStatus (mavlink_message_t& message);
@ -1181,6 +1182,8 @@ private:
bool _armed = false; ///< true: vehicle is armed bool _armed = false; ///< true: vehicle is armed
uint8_t _base_mode = 0; ///< base_mode from HEARTBEAT uint8_t _base_mode = 0; ///< base_mode from HEARTBEAT
uint32_t _custom_mode = 0; ///< custom_mode from HEARTBEAT uint32_t _custom_mode = 0; ///< custom_mode from HEARTBEAT
uint32_t _custom_mode_user_intention = 0; ///< custom_mode_user_intention from CURRENT_MODE
bool _has_custom_mode_user_intention = false;
/// Used to store a message being sent by sendMessageMultiple /// Used to store a message being sent by sendMessageMultiple
typedef struct { typedef struct {

Loading…
Cancel
Save