QGCMAVLinkInspector.cc 2.14 KB
Newer Older
lm's avatar
lm committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#include <QList>

#include "QGCMAVLinkInspector.h"
#include "ui_QGCMAVLinkInspector.h"

#include <QDebug>

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<QTreeWidgetItem *> 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;
}