Commit 83b500d0 authored by DonLakeFlyer's avatar DonLakeFlyer

parent 63778dc4
...@@ -446,29 +446,40 @@ void APMFirmwarePlugin::_handleIncomingHeartbeat(Vehicle* vehicle, mavlink_messa ...@@ -446,29 +446,40 @@ void APMFirmwarePlugin::_handleIncomingHeartbeat(Vehicle* vehicle, mavlink_messa
{ {
bool flying = false; bool flying = false;
// We pull Vehicle::flying state from HEARTBEAT on ArduPilot. This is a firmware specific test.
if (vehicle->armed()) {
mavlink_heartbeat_t heartbeat; mavlink_heartbeat_t heartbeat;
mavlink_msg_heartbeat_decode(message, &heartbeat); mavlink_msg_heartbeat_decode(message, &heartbeat);
if (message->compid == MAV_COMP_ID_AUTOPILOT1) {
// We pull Vehicle::flying state from HEARTBEAT on ArduPilot. This is a firmware specific test.
if (vehicle->armed()) {
flying = heartbeat.system_status == MAV_STATE_ACTIVE; flying = heartbeat.system_status == MAV_STATE_ACTIVE;
if (!flying && vehicle->flying()) { if (!flying && vehicle->flying()) {
// If we were previously flying, and we go into critical or emergency assume we are still flying // If we were previously flying, and we go into critical or emergency assume we are still flying
flying = heartbeat.system_status == MAV_STATE_CRITICAL || heartbeat.system_status == MAV_STATE_EMERGENCY; flying = heartbeat.system_status == MAV_STATE_CRITICAL || heartbeat.system_status == MAV_STATE_EMERGENCY;
} }
} }
vehicle->_setFlying(flying); vehicle->_setFlying(flying);
}
// We need to know whether this component is part of the ArduPilot stack code or not so we can adjust mavlink quirks appropriately.
// If the component sends a heartbeat we can know that. If it's doesn't there is pretty much no way to know.
_ardupilotComponentMap[message->sysid][message->compid] = heartbeat.autopilot == MAV_AUTOPILOT_ARDUPILOTMEGA;
// Force the ESP8266 to be non-ArduPilot code (it doesn't send heartbeats)
_ardupilotComponentMap[message->sysid][MAV_COMP_ID_UDP_BRIDGE] = false;
} }
bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message)
{ {
// Only translate messages which come from the autopilot. All other components are expected to follow current mavlink spec. if (message->msgid == MAVLINK_MSG_ID_HEARTBEAT) {
if (message->compid != MAV_COMP_ID_AUTOPILOT1) { // We need to look at all heartbeats that go by from any component
_handleIncomingHeartbeat(vehicle, message);
return true; return true;
} }
// Only translate messages which come from ArduPilot code. All other components are expected to follow current mavlink spec.
if (_ardupilotComponentMap[vehicle->id()][message->compid]) {
switch (message->msgid) { switch (message->msgid) {
case MAVLINK_MSG_ID_PARAM_VALUE: case MAVLINK_MSG_ID_PARAM_VALUE:
_handleIncomingParamValue(vehicle, message); _handleIncomingParamValue(vehicle, message);
...@@ -477,9 +488,6 @@ bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_m ...@@ -477,9 +488,6 @@ bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_m
return _handleIncomingStatusText(vehicle, message, false /* longVersion */); return _handleIncomingStatusText(vehicle, message, false /* longVersion */);
case MAVLINK_MSG_ID_STATUSTEXT_LONG: case MAVLINK_MSG_ID_STATUSTEXT_LONG:
return _handleIncomingStatusText(vehicle, message, true /* longVersion */); return _handleIncomingStatusText(vehicle, message, true /* longVersion */);
case MAVLINK_MSG_ID_HEARTBEAT:
_handleIncomingHeartbeat(vehicle, message);
break;
case MAVLINK_MSG_ID_RC_CHANNELS: case MAVLINK_MSG_ID_RC_CHANNELS:
_handleRCChannels(vehicle, message); _handleRCChannels(vehicle, message);
break; break;
...@@ -487,22 +495,21 @@ bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_m ...@@ -487,22 +495,21 @@ bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_m
_handleRCChannelsRaw(vehicle, message); _handleRCChannelsRaw(vehicle, message);
break; break;
} }
}
return true; return true;
} }
void APMFirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message) void APMFirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message)
{ {
//-- Don't process messages to/from UDP Bridge. It doesn't suffer from these issues // Only translate messages which come from ArduPilot code. All other components are expected to follow current mavlink spec.
if (message->compid == MAV_COMP_ID_UDP_BRIDGE) { if (_ardupilotComponentMap[vehicle->id()][message->compid]) {
return;
}
switch (message->msgid) { switch (message->msgid) {
case MAVLINK_MSG_ID_PARAM_SET: case MAVLINK_MSG_ID_PARAM_SET:
_handleOutgoingParamSet(vehicle, outgoingLink, message); _handleOutgoingParamSet(vehicle, outgoingLink, message);
break; break;
} }
}
} }
QString APMFirmwarePlugin::_getMessageText(mavlink_message_t* message, bool longVersion) const QString APMFirmwarePlugin::_getMessageText(mavlink_message_t* message, bool longVersion) const
......
...@@ -137,6 +137,7 @@ private: ...@@ -137,6 +137,7 @@ private:
// Vehicle specific data should go into APMFirmwarePluginInstanceData // Vehicle specific data should go into APMFirmwarePluginInstanceData
QList<APMCustomMode> _supportedModes; QList<APMCustomMode> _supportedModes;
QMap<int /* vehicle id */, QMap<int /* componentId */, bool /* true: component is part of ArduPilot stack */>> _ardupilotComponentMap;
static const char* _artooIP; static const char* _artooIP;
static const int _artooVideoHandshakePort; static const int _artooVideoHandshakePort;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment