QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MAVLinkConsoleController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QMetaObject>
5#include <QtCore/QObject>
6#include <QtCore/QString>
7#include <QtCore/QStringListModel>
8#include <QtQmlIntegration/QtQmlIntegration>
9
10Q_DECLARE_LOGGING_CATEGORY(MAVLinkConsoleControllerLog)
11
12class QGCPalette;
13class Vehicle;
14
15class MAVLinkConsoleController : public QStringListModel
16{
17 Q_OBJECT
18 QML_ELEMENT
19 Q_MOC_INCLUDE("Vehicle.h")
20 Q_PROPERTY(QString text READ _getText CONSTANT)
21
22 class CommandHistory
23 {
24 public:
25 void append(const QString &command);
26 QString up(const QString &current);
27 QString down(const QString &current);
28
29 private:
30 QList<QString> _history;
31 int _index = 0;
32 static constexpr int kMaxHistoryLength = 100;
33 };
34
35public:
36 explicit MAVLinkConsoleController(QObject *parent = nullptr);
38
39 Q_INVOKABLE void sendCommand(const QString &command);
40 Q_INVOKABLE QString historyUp(const QString &current) { return _history.up(current); }
41 Q_INVOKABLE QString historyDown(const QString &current) { return _history.down(current); }
42
46 Q_INVOKABLE QString handleClipboard(const QString &command_pre);
47
48private slots:
49 void _setActiveVehicle(Vehicle *vehicle);
50 void _receiveData(uint8_t device, uint8_t flags, uint16_t timeout, uint32_t baudrate, const QByteArray &data);
51
52private:
53 bool _processANSItext(QByteArray &line);
54 void _sendSerialData(const QByteArray &data, bool close = false);
55 void _writeLine(int line, const QByteArray &text);
56 QString _transformLineForRichText(const QString &line) const;
57 QString _getText() const;
58
59 QGCPalette *_palette = nullptr;
60 int _cursorHomePos = -1;
61 int _cursorY = 0;
62 int _cursorX = 0;
63 QByteArray _incomingBuffer;
64 QList<QMetaObject::Connection> _connections;
65 CommandHistory _history;
66 Vehicle *_vehicle = nullptr;
67
68 static constexpr int kMaxNumLines = 500;
69};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
void sendCommand(const QString &command)
QString historyUp(const QString &current)
QString handleClipboard(const QString &command_pre)
QString historyDown(const QString &current)