MAVLinkInspectorController.h 5.39 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 92 93

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

Gus Grubba's avatar
Gus Grubba committed
94 95
    quint8              id              () { return _id; }
    QmlObjectListModel* messages        () { return &_messages; }
96

Gus Grubba's avatar
Gus Grubba committed
97 98
    QGCMAVLinkMessage*  findMessage     (uint32_t id, uint8_t cid);
    void                append          (QGCMAVLinkMessage* message);
99 100

signals:
Gus Grubba's avatar
Gus Grubba committed
101
    void messagesChanged                ();
102 103 104 105 106 107 108

private:
    quint8              _id;
    QmlObjectListModel  _messages;  //-- List of QGCMAVLinkMessage
};

//-----------------------------------------------------------------------------
109 110 111 112 113 114 115
class MAVLinkInspectorController : public QObject
{
    Q_OBJECT
public:
    MAVLinkInspectorController();
    ~MAVLinkInspectorController();

116 117
    Q_PROPERTY(QStringList          vehicleNames    READ vehicleNames   NOTIFY vehiclesChanged)
    Q_PROPERTY(QmlObjectListModel*  vehicles        READ vehicles       NOTIFY vehiclesChanged)
Gus Grubba's avatar
Gus Grubba committed
118
    Q_PROPERTY(QGCMAVLinkVehicle*   activeVehicle   READ activeVehicle  NOTIFY activeVehiclesChanged)
119

Gus Grubba's avatar
Gus Grubba committed
120 121 122
    QmlObjectListModel*  vehicles       () { return &_vehicles;     }
    QGCMAVLinkVehicle*   activeVehicle  () { return _activeVehicle; }
    QStringList          vehicleNames   () { return _vehicleNames;  }
123 124 125

signals:
    void vehiclesChanged                ();
Gus Grubba's avatar
Gus Grubba committed
126
    void activeVehiclesChanged          ();
127

128
private slots:
129 130 131
    void _receiveMessage                (LinkInterface* link, mavlink_message_t message);
    void _vehicleAdded                  (Vehicle* vehicle);
    void _vehicleRemoved                (Vehicle* vehicle);
Gus Grubba's avatar
Gus Grubba committed
132 133
    void _setActiveVehicle              (Vehicle* vehicle);
    void _refreshFrequency              ();
134 135

private:
136 137 138
    void _reset                         ();

    QGCMAVLinkVehicle*  _findVehicle    (uint8_t id);
139 140 141 142

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

Gus Grubba's avatar
Gus Grubba committed
144 145
    QGCMAVLinkVehicle*  _activeVehicle = nullptr;
    QTimer              _updateTimer;
146 147
    QStringList         _vehicleNames;
    QmlObjectListModel  _vehicles;  //-- List of QGCMAVLinkVehicle
148
};