Browse Source

Merge pull request #4476 from NaterGator/tweaks

Improve release logging, deal with MAVLinkDecoder shutdown
QGC4.4
Don Gagne 8 years ago committed by GitHub
parent
commit
736eba1514
  1. 2
      QGCCommon.pri
  2. 7
      src/ui/MAVLinkDecoder.cc
  3. 4
      src/ui/MAVLinkDecoder.h
  4. 8
      src/ui/MainWindow.cc

2
QGCCommon.pri

@ -221,7 +221,7 @@ WindowsBuild {
# #
ReleaseBuild { ReleaseBuild {
DEFINES += QT_NO_DEBUG DEFINES += QT_NO_DEBUG QT_MESSAGELOGCONTEXT
CONFIG += force_debug_info # Enable debugging symbols on release builds CONFIG += force_debug_info # Enable debugging symbols on release builds
!iOSBuild { !iOSBuild {
CONFIG += ltcg # Turn on link time code generation CONFIG += ltcg # Turn on link time code generation

7
src/ui/MAVLinkDecoder.cc

@ -3,10 +3,9 @@
#include <QDebug> #include <QDebug>
MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) : MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol) :
QThread() QThread(), creationThread(QThread::currentThread())
{ {
Q_UNUSED(parent);
// We're doing it wrong - because the Qt folks got the API wrong: // We're doing it wrong - because the Qt folks got the API wrong:
// http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/ // http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/
moveToThread(this); moveToThread(this);
@ -52,6 +51,7 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) :
// textMessageFilter.insert(MAVLINK_MSG_ID_HIGHRES_IMU, false); // textMessageFilter.insert(MAVLINK_MSG_ID_HIGHRES_IMU, false);
connect(protocol, &MAVLinkProtocol::messageReceived, this, &MAVLinkDecoder::receiveMessage); connect(protocol, &MAVLinkProtocol::messageReceived, this, &MAVLinkDecoder::receiveMessage);
connect(this, &MAVLinkDecoder::finish, this, &QThread::quit);
start(LowPriority); start(LowPriority);
} }
@ -63,6 +63,7 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) :
void MAVLinkDecoder::run() void MAVLinkDecoder::run()
{ {
exec(); exec();
moveToThread(creationThread);
} }
void MAVLinkDecoder::receiveMessage(LinkInterface* link,mavlink_message_t message) void MAVLinkDecoder::receiveMessage(LinkInterface* link,mavlink_message_t message)

4
src/ui/MAVLinkDecoder.h

@ -8,13 +8,14 @@ class MAVLinkDecoder : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent = 0); MAVLinkDecoder(MAVLinkProtocol* protocol);
void run(); void run();
signals: signals:
void textMessageReceived(int uasid, int componentid, int severity, const QString& text); void textMessageReceived(int uasid, int componentid, int severity, const QString& text);
void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec); void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec);
void finish(); ///< Trigger a thread safe shutdown
public slots: public slots:
/** @brief Receive one message from the protocol and decode it */ /** @brief Receive one message from the protocol and decode it */
@ -35,6 +36,7 @@ protected:
quint64 onboardTimeOffset[cMessageIds]; ///< Offset of onboard time from Unix epoch (of the receiving GCS) quint64 onboardTimeOffset[cMessageIds]; ///< Offset of onboard time from Unix epoch (of the receiving GCS)
qint64 onboardToGCSUnixTimeOffsetAndDelay[cMessageIds]; ///< Offset of onboard time and GCS Unix time qint64 onboardToGCSUnixTimeOffsetAndDelay[cMessageIds]; ///< Offset of onboard time and GCS Unix time
quint64 firstOnboardTime[cMessageIds]; ///< First seen onboard time quint64 firstOnboardTime[cMessageIds]; ///< First seen onboard time
QThread* creationThread; ///< QThread on which the object is created
}; };
#endif // MAVLINKDECODER_H #endif // MAVLINKDECODER_H

8
src/ui/MainWindow.cc

@ -274,6 +274,11 @@ MainWindow::MainWindow()
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
// Enforce thread-safe shutdown of the mavlink decoder
mavlinkDecoder->finish();
mavlinkDecoder->wait(1000);
mavlinkDecoder->deleteLater();
// This needs to happen before we get into the QWidget dtor // This needs to happen before we get into the QWidget dtor
// otherwise the QML engine reads freed data and tries to // otherwise the QML engine reads freed data and tries to
// destroy MainWindow a second time. // destroy MainWindow a second time.
@ -290,8 +295,7 @@ QString MainWindow::_getWindowGeometryKey()
void MainWindow::_buildCommonWidgets(void) void MainWindow::_buildCommonWidgets(void)
{ {
// Add generic MAVLink decoder // Add generic MAVLink decoder
// TODO: This is never deleted mavlinkDecoder = new MAVLinkDecoder(qgcApp()->toolbox()->mavlinkProtocol());
mavlinkDecoder = new MAVLinkDecoder(qgcApp()->toolbox()->mavlinkProtocol(), this);
connect(mavlinkDecoder.data(), &MAVLinkDecoder::valueChanged, this, &MainWindow::valueChanged); connect(mavlinkDecoder.data(), &MAVLinkDecoder::valueChanged, this, &MainWindow::valueChanged);
// Log player // Log player

Loading…
Cancel
Save