MAVLinkInspectorController.h 5.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include "MAVLinkProtocol.h"
#include "Vehicle.h"

#include <QObject>
#include <QString>
#include <QDebug>
18
#include <QAbstractListModel>
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
Q_DECLARE_LOGGING_CATEGORY(MAVLinkInspectorLog)

//-----------------------------------------------------------------------------
class QGCMAVLinkMessageField : public QObject {
    Q_OBJECT
    Q_PROPERTY(QString      name        READ name       CONSTANT)
    Q_PROPERTY(QString      type        READ type       CONSTANT)
    Q_PROPERTY(QString      value       READ value      NOTIFY valueChanged)

public:
    QGCMAVLinkMessageField(QObject* parent, QString name, QString type);

    QString     name            () { return _name;  }
    QString     type            () { return _type;  }
    QString     value           () { return _value; }

    void        updateValue     (QString newValue) { _value = newValue; emit valueChanged(); }

signals:
    void        valueChanged    ();

private:
    QString     _type;
    QString     _name;
    QString     _value;
};

//-----------------------------------------------------------------------------
class QGCMAVLinkMessage : public QObject {
    Q_OBJECT
Gus Grubba's avatar
Gus Grubba committed
50 51 52 53
    Q_PROPERTY(quint32              id          READ id         NOTIFY indexChanged)
    Q_PROPERTY(quint32              cid         READ cid        NOTIFY indexChanged)
    Q_PROPERTY(QString              name        READ name       NOTIFY indexChanged)
    Q_PROPERTY(qreal                messageHz   READ messageHz  NOTIFY freqChanged)
54
    Q_PROPERTY(quint64              count       READ count      NOTIFY messageChanged)
Gus Grubba's avatar
Gus Grubba committed
55
    Q_PROPERTY(QmlObjectListModel*  fields      READ fields     NOTIFY indexChanged)
56 57 58 59

public:
    QGCMAVLinkMessage(QObject* parent, mavlink_message_t* message);

Gus Grubba's avatar
Gus Grubba committed
60 61
    quint32             id          () { return _message.msgid;  }
    quint8              cid         () { return _message.compid; }
62
    QString             name        () { return _name;  }
Gus Grubba's avatar
Gus Grubba committed
63
    qreal               messageHz   () { return _messageHz; }
64
    quint64             count       () { return _count; }
Gus Grubba's avatar
Gus Grubba committed
65
    quint64             lastCount   () { return _lastCount; }
66 67 68
    QmlObjectListModel* fields      () { return &_fields; }

    void                update      (mavlink_message_t* message);
Gus Grubba's avatar
Gus Grubba committed
69
    void                updateFreq  ();
70 71 72

signals:
    void messageChanged             ();
Gus Grubba's avatar
Gus Grubba committed
73 74
    void freqChanged                ();
    void indexChanged               ();
75 76 77 78

private:
    QmlObjectListModel  _fields;
    QString             _name;
Gus Grubba's avatar
Gus Grubba committed
79
    qreal               _messageHz  = 0.0;
80
    uint64_t            _count      = 0;
Gus Grubba's avatar
Gus Grubba committed
81
    uint64_t            _lastCount  = 0;
82 83 84 85 86 87
    mavlink_message_t   _message;   //-- List of QGCMAVLinkMessageField
};

//-----------------------------------------------------------------------------
class QGCMAVLinkVehicle : public QObject {
    Q_OBJECT
Gus Grubba's avatar
Gus Grubba committed
88 89
    Q_PROPERTY(quint8               id              READ id             CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  messages        READ messages       NOTIFY messagesChanged)
90 91
    Q_PROPERTY(QList<int>           compIDs         READ compIDs        NOTIFY compIDsChanged)
    Q_PROPERTY(QStringList          compIDsStr      READ compIDsStr     NOTIFY compIDsChanged)
92 93 94 95

public:
    QGCMAVLinkVehicle(QObject* parent, quint8 id);

Gus Grubba's avatar
Gus Grubba committed
96 97
    quint8              id              () { return _id; }
    QmlObjectListModel* messages        () { return &_messages; }
98 99
    QList<int>          compIDs         () { return _compIDs; }
    QStringList         compIDsStr      () { return _compIDsStr; }
100

Gus Grubba's avatar
Gus Grubba committed
101 102
    QGCMAVLinkMessage*  findMessage     (uint32_t id, uint8_t cid);
    void                append          (QGCMAVLinkMessage* message);
103 104

signals:
Gus Grubba's avatar
Gus Grubba committed
105
    void messagesChanged                ();
106 107 108 109
    void compIDsChanged                 ();

private:
    void _checkCompID                   (QGCMAVLinkMessage *message);
110 111 112

private:
    quint8              _id;
113 114 115
    QList<int>          _compIDs;
    QStringList         _compIDsStr;
    QmlObjectListModel  _messages;      //-- List of QGCMAVLinkMessage
116 117 118
};

//-----------------------------------------------------------------------------
119 120 121 122 123 124 125
class MAVLinkInspectorController : public QObject
{
    Q_OBJECT
public:
    MAVLinkInspectorController();
    ~MAVLinkInspectorController();

126 127
    Q_PROPERTY(QStringList          vehicleNames    READ vehicleNames   NOTIFY vehiclesChanged)
    Q_PROPERTY(QmlObjectListModel*  vehicles        READ vehicles       NOTIFY vehiclesChanged)
Gus Grubba's avatar
Gus Grubba committed
128
    Q_PROPERTY(QGCMAVLinkVehicle*   activeVehicle   READ activeVehicle  NOTIFY activeVehiclesChanged)
129

Gus Grubba's avatar
Gus Grubba committed
130 131 132
    QmlObjectListModel*  vehicles       () { return &_vehicles;     }
    QGCMAVLinkVehicle*   activeVehicle  () { return _activeVehicle; }
    QStringList          vehicleNames   () { return _vehicleNames;  }
133 134 135

signals:
    void vehiclesChanged                ();
Gus Grubba's avatar
Gus Grubba committed
136
    void activeVehiclesChanged          ();
137

138
private slots:
139 140 141
    void _receiveMessage                (LinkInterface* link, mavlink_message_t message);
    void _vehicleAdded                  (Vehicle* vehicle);
    void _vehicleRemoved                (Vehicle* vehicle);
Gus Grubba's avatar
Gus Grubba committed
142 143
    void _setActiveVehicle              (Vehicle* vehicle);
    void _refreshFrequency              ();
144 145

private:
146 147 148
    void _reset                         ();

    QGCMAVLinkVehicle*  _findVehicle    (uint8_t id);
149 150 151 152

private:
    int         _selectedSystemID       = 0;                    ///< Currently selected system
    int         _selectedComponentID    = 0;                    ///< Currently selected component
153

Gus Grubba's avatar
Gus Grubba committed
154 155
    QGCMAVLinkVehicle*  _activeVehicle = nullptr;
    QTimer              _updateTimer;
156 157
    QStringList         _vehicleNames;
    QmlObjectListModel  _vehicles;  //-- List of QGCMAVLinkVehicle
158
};