UASMessageHandler.h 4.25 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23


/*!
 * @file
 *   @brief Message Handler
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#ifndef QGCMESSAGEHANDLER_H
#define QGCMESSAGEHANDLER_H

#include <QObject>
#include <QVector>
#include <QMutex>

24
#include "Vehicle.h"
25
#include "QGCToolbox.h"
26

dogmaphobic's avatar
dogmaphobic committed
27
class Vehicle;
28
class UASInterface;
29
class UASMessageHandler;
30
class QGCApplication;
31 32

/*!
33
 * @class UASMessage
34 35
 * @brief Message element
 */
36
class UASMessage
37
{
38
    friend class UASMessageHandler;
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
public:
    /**
     * @brief Get message source component ID
     */
    int getComponentID()        { return _compId; }
    /**
     * @brief Get message severity (from MAV_SEVERITY_XXX enum)
     */
    int getSeverity()           { return _severity; }
    /**
     * @brief Get message text (e.g. "[pm] sending list")
     */
    QString getText()           { return _text; }
    /**
     * @brief Get (html) formatted text (in the form: "[11:44:21.137 - COMP:50] Info: [pm] sending list")
     */
    QString getFormatedText()   { return _formatedText; }
56 57 58 59
    /**
     * @return true: This message is a of a severity which is considered an error
     */
    bool severityIsError();
60

61
private:
62
    UASMessage(int componentid, int severity, QString text);
63 64 65 66 67 68 69
    void _setFormatedText(const QString formatedText) { _formatedText = formatedText; }
    int _compId;
    int _severity;
    QString _text;
    QString _formatedText;
};

70
class UASMessageHandler : public QGCTool
71 72
{
    Q_OBJECT
dogmaphobic's avatar
dogmaphobic committed
73

74
public:
75
    explicit UASMessageHandler(QGCApplication* app, QGCToolbox* toolbox);
76
    ~UASMessageHandler();
77

78 79 80 81 82 83 84 85 86 87 88
    /**
     * @brief Locks access to the message list
     */
    void lockAccess()   {_mutex.lock(); }
    /**
     * @brief Unlocks access to the message list
     */
    void unlockAccess() {_mutex.unlock(); }
    /**
     * @brief Access to the message list
     */
89
    const QVector<UASMessage*>& messages() { return _messages; }
90 91 92 93
    /**
     * @brief Clear messages
     */
    void clearMessages();
dogmaphobic's avatar
dogmaphobic committed
94 95 96 97
    /**
     * @brief Get error message count (Resets count once read)
     */
    int getErrorCount();
98 99 100 101
    /**
     * @brief Get error message count (never reset)
     */
    int getErrorCountTotal();
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107 108 109
    /**
     * @brief Get warning message count (Resets count once read)
     */
    int getWarningCount();
    /**
     * @brief Get normal message count (Resets count once read)
     */
    int getNormalCount();
110 111 112 113
    /**
     * @brief Get latest error message
     */
    QString getLatestError()   { return _latestError; }
dogmaphobic's avatar
dogmaphobic committed
114

115 116
    /// Begin to show message which are errors in the toolbar
    void showErrorsInToolbar(void) { _showErrorsInToolbar = true; }
dogmaphobic's avatar
dogmaphobic committed
117

118 119 120
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

121 122 123 124 125 126 127 128 129
public slots:
    /**
     * @brief Handle text message from current active UAS
     * @param uasid UAS Id
     * @param componentid Component Id
     * @param severity Message severity
     * @param text Message Text
     */
    void handleTextMessage(int uasid, int componentid, int severity, QString text);
dogmaphobic's avatar
dogmaphobic committed
130

131 132 133 134 135
signals:
    /**
     * @brief Sent out when new message arrives
     * @param message A pointer to the message. NULL if resetting (new UAS assigned)
     */
136
    void textMessageReceived(UASMessage* message);
dogmaphobic's avatar
dogmaphobic committed
137 138 139 140 141
    /**
     * @brief Sent out when the message count changes
     * @param count The new message count
     */
    void textMessageCountChanged(int count);
dogmaphobic's avatar
dogmaphobic committed
142

143 144
private slots:
    void _activeVehicleChanged(Vehicle* vehicle);
dogmaphobic's avatar
dogmaphobic committed
145

146
private:
147
    Vehicle*                _activeVehicle;
Lorenz Meier's avatar
Lorenz Meier committed
148 149
    int                     _activeComponent;
    bool                    _multiComp;
150 151 152 153 154 155 156 157 158
    QVector<UASMessage*>    _messages;
    QMutex                  _mutex;
    int                     _errorCount;
    int                     _errorCountTotal;
    int                     _warningCount;
    int                     _normalCount;
    QString                 _latestError;
    bool                    _showErrorsInToolbar;
    MultiVehicleManager*    _multiVehicleManager;
159 160 161
};

#endif // QGCMESSAGEHANDLER_H