diff --git a/src/ui/QGCMAVLinkInspector.cc b/src/ui/QGCMAVLinkInspector.cc index c21ffa9fc12fdb2b3737b7a228631013bb93228c..9c0de1a38320873b294d338f808ad0ee749b41e0 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 1052cfd2e8e6c265d65f71a3d1a4a9b1d6044dc6..300c88ceb56dffa4cfa5f988071b42ce0297a622 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);