MavlinkConsoleController.h 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/****************************************************************************
 *
 *   (c) 2009-2017 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 "QmlObjectListModel.h"
#include "Fact.h"
#include "FactMetaData.h"
#include <QObject>
#include <QString>
#include <QMetaObject>
18
#include <QStringListModel>
19 20 21 22 23

// Fordward decls
class Vehicle;

/// Controller for MavlinkConsole.qml.
24
class MavlinkConsoleController : public QStringListModel
25 26 27 28 29
{
    Q_OBJECT

public:
    MavlinkConsoleController();
30
    virtual ~MavlinkConsoleController();
31

32
    Q_INVOKABLE void sendCommand(QString command);
33

34 35
    Q_INVOKABLE QString historyUp(const QString& current);
    Q_INVOKABLE QString historyDown(const QString& current);
36 37 38 39 40 41

private slots:
    void _setActiveVehicle  (Vehicle* vehicle);
    void _receiveData(uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, QByteArray data);

private:
42
    bool _processANSItext(QByteArray &line);
43
    void _sendSerialData(QByteArray, bool close = false);
44
    void writeLine(int line, const QByteArray &text);
45

46 47 48 49 50 51 52 53 54 55 56 57
    class CommandHistory
    {
    public:
        void append(const QString& command);
        QString up(const QString& current);
        QString down(const QString& current);
    private:
        static constexpr int maxHistoryLength = 100;
        QList<QString> _history;
        int _index = 0;
    };

58 59 60 61 62
    int           _cursor_home_pos;
    int           _cursor;
    QByteArray    _incoming_buffer;
    Vehicle*      _vehicle;
    QList<QMetaObject::Connection> _uas_connections;
63
    CommandHistory _history;
64 65

};