From 64178c82a94ad7a139abe860d2f1ca25b5b2715b Mon Sep 17 00:00:00 2001 From: Bryant Date: Mon, 5 Nov 2012 09:12:43 -0800 Subject: [PATCH] Fixed the Clear button in the MAVLink inspector window to actually clear previous messages. --- src/ui/QGCMAVLinkInspector.cc | 28 +++++++++++++++++++--------- src/ui/QGCMAVLinkInspector.h | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ui/QGCMAVLinkInspector.cc b/src/ui/QGCMAVLinkInspector.cc index c21ffa9fc..9c0de1a38 100644 --- a/src/ui/QGCMAVLinkInspector.cc +++ b/src/ui/QGCMAVLinkInspector.cc @@ -18,32 +18,35 @@ QGCMAVLinkInspector::QGCMAVLinkInspector(MAVLinkProtocol* protocol, QWidget *par { ui->setupUi(this); - /* Insert system */ + // Make sure "All" is an option for both the system and components ui->systemComboBox->addItem(tr("All"), 0); ui->componentComboBox->addItem(tr("All"), 0); - mavlink_message_info_t msg[256] = MAVLINK_MESSAGE_INFO; - memcpy(messageInfo, msg, sizeof(mavlink_message_info_t)*256); + // Store metadata for all MAVLink messages. + mavlink_message_info_t msg_infos[256] = MAVLINK_MESSAGE_INFO; + memcpy(messageInfo, msg_infos, sizeof(mavlink_message_info_t)*256); + + // Initialize the received data for all messages to invalid (0xFF) memset(receivedMessages, 0xFF, sizeof(mavlink_message_t)*256); - connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); + // Set up the column headers for the message listing QStringList header; header << tr("Name"); header << tr("Value"); header << tr("Type"); ui->treeWidget->setHeaderLabels(header); - connect(&updateTimer, SIGNAL(timeout()), this, SLOT(refreshView())); - - // ARM UI + // Connect the UI connect(ui->systemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuSystem(int))); connect(ui->componentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuComponent(int))); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearView())); - // ARM external connections + // Connect external connections connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addSystem(UASInterface*))); + connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); - // Start + // Attach the UI's refresh rate to a timer. + connect(&updateTimer, SIGNAL(timeout()), this, SLOT(refreshView())); updateTimer.start(updateInterval); } @@ -90,8 +93,15 @@ void QGCMAVLinkInspector::addComponent(int uas, int component, const QString& na rebuildComponentList(); } +/** + * Reset the view. This entails clearing all data structures and resetting data from already- + * received messages. + */ void QGCMAVLinkInspector::clearView() { + memset(receivedMessages, 0xFF, sizeof(mavlink_message_t)*256); + lastMessageUpdate.clear(); + messagesHz.clear(); treeWidgetItems.clear(); ui->treeWidget->clear(); } diff --git a/src/ui/QGCMAVLinkInspector.h b/src/ui/QGCMAVLinkInspector.h index 1052cfd2e..300c88ceb 100644 --- a/src/ui/QGCMAVLinkInspector.h +++ b/src/ui/QGCMAVLinkInspector.h @@ -44,7 +44,7 @@ protected: mavlink_message_t receivedMessages[256]; ///< Available / known messages QMap treeWidgetItems; ///< Available tree widget items QTimer updateTimer; ///< Only update at 1 Hz to not overload the GUI - mavlink_message_info_t messageInfo[256]; + mavlink_message_info_t messageInfo[256]; // Store the metadata for all available MAVLink messages. // Update one message field void updateField(int msgid, int fieldid, QTreeWidgetItem* item); -- 2.22.0