Browse Source

Fix create/destroy ordering problems between LinkManager and MAVLinkProtocol

QGC4.4
Don Gagne 11 years ago
parent
commit
58eef4b27d
  1. 8
      src/comm/LinkManager.cc
  2. 10
      src/comm/MAVLinkProtocol.cc
  3. 6
      src/comm/MAVLinkProtocol.h

8
src/comm/LinkManager.cc

@ -68,10 +68,12 @@ LinkManager::LinkManager(QObject* parent, bool registerSingleton) : @@ -68,10 +68,12 @@ LinkManager::LinkManager(QObject* parent, bool registerSingleton) :
_connectionsSuspended(false),
_mavlink(NULL)
{
Q_ASSERT(_instance == NULL);
_instance = this;
if (registerSingleton) {
Q_ASSERT(_instance == NULL);
_instance = this;
}
_mavlink = new MAVLinkProtocol;
_mavlink = new MAVLinkProtocol(this);
Q_CHECK_PTR(_mavlink);
}

10
src/comm/MAVLinkProtocol.cc

@ -39,7 +39,7 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext @@ -39,7 +39,7 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext
* The default constructor will create a new MAVLink object sending heartbeats at
* the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links.
*/
MAVLinkProtocol::MAVLinkProtocol() :
MAVLinkProtocol::MAVLinkProtocol(LinkManager* linkMgr) :
heartbeatTimer(NULL),
heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE),
m_heartbeatsEnabled(true),
@ -58,8 +58,8 @@ MAVLinkProtocol::MAVLinkProtocol() : @@ -58,8 +58,8 @@ MAVLinkProtocol::MAVLinkProtocol() :
_logSuspendReplay(false),
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)),
_protocolStatusMessageConnected(false),
_saveTempFlightDataLogConnected(false)
_saveTempFlightDataLogConnected(false),
_linkMgr(linkMgr)
{
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
@ -452,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) @@ -452,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
if (m_multiplexingEnabled)
{
// Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinks();
QList<LinkInterface*> links = _linkMgr->getLinks();
// Emit message on all links that are currently connected
foreach (LinkInterface* currLink, links)
@ -497,7 +497,7 @@ int MAVLinkProtocol::getComponentId() @@ -497,7 +497,7 @@ int MAVLinkProtocol::getComponentId()
void MAVLinkProtocol::sendMessage(mavlink_message_t message)
{
// Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinks();
QList<LinkInterface*> links = _linkMgr->getLinks();
// Emit message on all links that are currently connected
QList<LinkInterface*>::iterator i;

6
src/comm/MAVLinkProtocol.h

@ -43,6 +43,8 @@ This file is part of the QGROUNDCONTROL project @@ -43,6 +43,8 @@ This file is part of the QGROUNDCONTROL project
#include "QGC.h"
#include "QGCTemporaryFile.h"
class LinkManager;
/**
* @brief MAVLink micro air vehicle protocol reference implementation.
*
@ -55,7 +57,7 @@ class MAVLinkProtocol : public QThread @@ -55,7 +57,7 @@ class MAVLinkProtocol : public QThread
Q_OBJECT
public:
MAVLinkProtocol();
MAVLinkProtocol(LinkManager *linkMgr);
~MAVLinkProtocol();
/** @brief Get the human-friendly name of this protocol */
@ -297,6 +299,8 @@ private: @@ -297,6 +299,8 @@ private:
bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected
bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected
LinkManager* _linkMgr;
};
#endif // MAVLINKPROTOCOL_H_

Loading…
Cancel
Save