diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index f6a8c560ca659cb18fd655cf1ec820da8ee39775..82bfc7900e5b30e1cc91333d14b027b0b441f1cc 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -208,7 +208,8 @@ FORMS += src/ui/MainWindow.ui \ src/ui/mission/QGCMissionDoWidget.ui \ src/ui/mission/QGCMissionConditionWidget.ui \ src/ui/map/QGCMapTool.ui \ - src/ui/map/QGCMapToolBar.ui + src/ui/map/QGCMapToolBar.ui \ + src/ui/QGCMAVLinkInspector.ui INCLUDEPATH += src \ src/ui \ src/ui/linechart \ @@ -320,7 +321,8 @@ HEADERS += src/MG.h \ src/ui/map/QGCMapToolBar.h \ src/libs/qextserialport/qextserialenumerator.h \ src/QGCGeo.h \ - src/ui/QGCToolBar.h + src/ui/QGCToolBar.h \ + src/ui/QGCMAVLinkInspector.h # Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler macx|win32-msvc2008|win32-msvc2010::HEADERS += src/ui/map3D/QGCGoogleEarthView.h @@ -444,7 +446,8 @@ SOURCES += src/main.cc \ src/ui/map/Waypoint2DIcon.cc \ src/ui/map/QGCMapTool.cc \ src/ui/map/QGCMapToolBar.cc \ - src/ui/QGCToolBar.cc + src/ui/QGCToolBar.cc \ + src/ui/QGCMAVLinkInspector.cc # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler macx|win32-msvc2008|win32-msvc2010::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 33de0dfc43bce207ec2c8f38a5d7de7478cdca6c..b156ab250b91fec4c591f4a0ec19999ff792d40f 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -376,6 +376,14 @@ void MainWindow::buildCommonWidgets() addToToolsMenu(logPlayerDockWidget, tr("MAVLink Log Replay"), SLOT(showToolWidget(bool)), MENU_MAVLINK_LOG_PLAYER, Qt::RightDockWidgetArea); } + if (!mavlinkInspectorWidget) + { + mavlinkInspectorWidget = new QDockWidget(tr("MAVLink Message Inspector"), this); + mavlinkInspectorWidget->setWidget( new QGCMAVLinkInspector(mavlink, this) ); + mavlinkInspectorWidget->setObjectName("MAVLINK_INSPECTOR_DOCKWIDGET"); + addToToolsMenu(mavlinkInspectorWidget, tr("MAVLink Inspector"), SLOT(showToolWidget(bool)), MENU_MAVLINK_INSPECTOR, Qt::RightDockWidgetArea); + } + // Center widgets if (!mapWidget) { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index ecac1fec86dea2dad19f9918c2bce56cd79663f1..1bacebc985a2f5559c3106e6af7a099923985246 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -75,7 +75,7 @@ This file is part of the QGROUNDCONTROL project #include "SlugsPadCameraControl.h" #include "UASControlParameters.h" -#include "QGCFlightGearLink.h" +#include "QGCMAVLinkInspector.h" class QGCMapTool; @@ -254,6 +254,7 @@ protected: MENU_MAVLINK_LOG_PLAYER, MENU_VIDEO_STREAM_1, MENU_VIDEO_STREAM_2, + MENU_MAVLINK_INSPECTOR, CENTRAL_SEPARATOR= 255, // do not change CENTRAL_LINECHART, CENTRAL_PROTOCOL, @@ -424,6 +425,8 @@ protected: QPointer toolBar; + QPointer mavlinkInspectorWidget; + // Popup widgets JoystickWidget* joystickWidget; diff --git a/src/ui/QGCMAVLinkInspector.cc b/src/ui/QGCMAVLinkInspector.cc new file mode 100644 index 0000000000000000000000000000000000000000..9de38ab4190b8c09845d2c7b6b3713304e5ad68c --- /dev/null +++ b/src/ui/QGCMAVLinkInspector.cc @@ -0,0 +1,72 @@ +#include + +#include "QGCMAVLinkInspector.h" +#include "ui_QGCMAVLinkInspector.h" + +#include + +QGCMAVLinkInspector::QGCMAVLinkInspector(MAVLinkProtocol* protocol, QWidget *parent) : + QWidget(parent), + ui(new Ui::QGCMAVLinkInspector) +{ + ui->setupUi(this); + connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); + ui->treeWidget->setColumnCount(3); + connect(&updateTimer, SIGNAL(timeout()), this, SLOT(refreshView())); + updateTimer.start(1000); +} + +void QGCMAVLinkInspector::refreshView() +{ + foreach (mavlink_message_t msg, receivedMessages.values()) + { + // Update the tree view + if (!treeWidgetItems.contains(msg.msgid)) + { + QString messageName("MSG (#%1)"); + messageName = messageName.arg(msg.msgid); + QStringList fields; + fields << messageName; + fields << ""; + fields << ""; + QTreeWidgetItem* widget = new QTreeWidgetItem(fields); + treeWidgetItems.insert(msg.msgid, widget); + ui->treeWidget->addTopLevelItem(widget); + } + } + +// // List all available MAVLink messages +// QList items; +// for (int i = 0; i < 256; ++i) +// { +// QStringList stringList; +// stringList << QString("message: %1").arg(i) << QString("") << QString("Not received yet."); +// items.append(new QTreeWidgetItem((QTreeWidget*)0, stringList)); +// } +// ui->treeWidget->insertTopLevelItems(0, items); +} + +void QGCMAVLinkInspector::receiveMessage(LinkInterface* link,mavlink_message_t message) +{ + Q_UNUSED(link); + receivedMessages.insert(message.msgid, message); +// Q_UNUSED(link); +// qDebug() << __FILE__ << __LINE__ << "GOT MAVLINK MESSAGE"; +// // Check if children exist +// const QObjectList& fields = ui->treeWidget->children().at(message.msgid)->children(); + +// if (fields.length() == 0) +// { +// // Create children +// } + +// for (int i = 0; i < fields.length(); ++i) +// { +// // Fill in field data +// } +} + +QGCMAVLinkInspector::~QGCMAVLinkInspector() +{ + delete ui; +} diff --git a/src/ui/QGCMAVLinkInspector.h b/src/ui/QGCMAVLinkInspector.h new file mode 100644 index 0000000000000000000000000000000000000000..e9ba9fb1541e9da9b6e66f81544a3c6477201304 --- /dev/null +++ b/src/ui/QGCMAVLinkInspector.h @@ -0,0 +1,38 @@ +#ifndef QGCMAVLINKINSPECTOR_H +#define QGCMAVLINKINSPECTOR_H + +#include +#include +#include + +#include "MAVLinkProtocol.h" + +namespace Ui { + class QGCMAVLinkInspector; +} + +class QTreeWidgetItem; + +class QGCMAVLinkInspector : public QWidget +{ + Q_OBJECT + +public: + explicit QGCMAVLinkInspector(MAVLinkProtocol* protocol, QWidget *parent = 0); + ~QGCMAVLinkInspector(); + +public slots: + void receiveMessage(LinkInterface* link,mavlink_message_t message); + void refreshView(); + +protected: + QMap lastFieldUpdate; ///< Used to switch between highlight and non-highlighting color + QMap receivedMessages; ///< Available / known messages + QMap treeWidgetItems; ///< Available tree widget items + QTimer updateTimer; ///< Only update at 1 Hz to not overload the GUI + +private: + Ui::QGCMAVLinkInspector *ui; +}; + +#endif // QGCMAVLINKINSPECTOR_H diff --git a/src/ui/QGCMAVLinkInspector.ui b/src/ui/QGCMAVLinkInspector.ui new file mode 100644 index 0000000000000000000000000000000000000000..0414339eb0e1bcf8799956d475a079e2d9a0ad1d --- /dev/null +++ b/src/ui/QGCMAVLinkInspector.ui @@ -0,0 +1,33 @@ + + + QGCMAVLinkInspector + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 6 + + + + + + 1 + + + + + + + + +