QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LinkInterface.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QElapsedTimer>
4#include <QtQmlIntegration/QtQmlIntegration>
5
6#include <memory>
7
8#include "LinkConfiguration.h"
10
11class LinkManager;
12class QLoggingCategory;
13class QThread;
15
18class LinkInterface : public QObject
19{
20 Q_OBJECT
21 QML_ELEMENT
22 QML_UNCREATABLE("")
23 friend class LinkManager;
24
25public:
26 virtual ~LinkInterface();
27
28 Q_INVOKABLE virtual void disconnect() = 0; // Implementations should guard against multiple calls
29
30 virtual bool isConnected() const = 0;
31 virtual bool isLogReplay() const { return false; }
32 virtual bool isSecureConnection() const { return false; }
35 virtual bool isRadioLink() const { return _radioStatusSeen; }
37
40 uint8_t mavlinkChannel() const;
41 bool mavlinkChannelIsSet() const;
42 bool decodedFirstMavlinkPacket() const { return _decodedFirstMavlinkPacket; }
44 void writeBytesThreadSafe(const char *bytes, int length);
48 void addVehicleReference() { ++_vehicleReferenceCount; }
54 void reportMavlinkV2Traffic() { _mavlinkV2TrafficSeen = true; }
55 bool mavlinkV1TrafficReported() const { return _mavlinkV1TrafficReported; }
56
59 static constexpr int kMavlinkV1TrafficGraceMsecsDefault = 10000;
60 static void setMavlinkV1TrafficGraceMsecs(int msecs) { _mavlinkV1TrafficGraceMsecs = msecs; }
61
63 SigningController* signing() { return _signingController.get(); }
64 const SigningController* signing() const { return _signingController.get(); }
65
66signals:
67 void bytesReceived(LinkInterface *link, const QByteArray &data);
68 void bytesSent(LinkInterface *link, const QByteArray &data);
69 void connected();
71 void communicationError(const QString &title, const QString &error);
72
73protected:
75 explicit LinkInterface(SharedLinkConfigurationPtr &config, QObject *parent = nullptr);
76
79 virtual bool _allocateMavlinkChannel();
80
81 virtual void _freeMavlinkChannel();
82
83 void _connectionRemoved();
84
92 void _shutdownWorkerThread(QThread *thread, const QLoggingCategory &category, bool allowTerminate = true);
93
95
96private slots:
98 virtual void _writeBytes(const QByteArray &bytes) = 0;
99
100private:
102 virtual bool _connect() = 0;
103
104 void _orphanWorkerThread(QThread *thread);
105
106 uint8_t _mavlinkChannel = std::numeric_limits<uint8_t>::max();
107 bool _decodedFirstMavlinkPacket = false;
108 int _vehicleReferenceCount = 0;
109 bool _mavlinkV1TrafficReported = false;
110 bool _mavlinkV2TrafficSeen = false;
111 bool _radioStatusSeen = false;
112 QElapsedTimer _mavlinkV1FirstSeenTimer;
113 static inline int _mavlinkV1TrafficGraceMsecs = kMavlinkV1TrafficGraceMsecsDefault;
116 std::unique_ptr<SigningController> _signingController;
117};
118
119typedef std::shared_ptr<LinkInterface> SharedLinkInterfacePtr;
120typedef std::weak_ptr<LinkInterface> WeakLinkInterfacePtr;
Config config
std::shared_ptr< LinkConfiguration > SharedLinkConfigurationPtr
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
std::weak_ptr< LinkInterface > WeakLinkInterfacePtr
Error error
struct __mavlink_message mavlink_message_t
The link interface defines the interface for all links used to communicate with the ground station ap...
void bytesReceived(LinkInterface *link, const QByteArray &data)
void disconnected()
void setDecodedFirstMavlinkPacket(bool decodedFirstMavlinkPacket)
uint8_t mavlinkChannel() const
void _shutdownWorkerThread(QThread *thread, const QLoggingCategory &category, bool allowTerminate=true)
void addVehicleReference()
virtual void _freeMavlinkChannel()
virtual bool isLogReplay() const
bool decodedFirstMavlinkPacket() const
virtual Q_INVOKABLE void disconnect()=0
void sendMessageThreadSafe(mavlink_message_t &message)
void reportMavlinkV1Traffic()
virtual bool isRadioLink() const
const SharedLinkConfigurationPtr linkConfiguration() const
void reportMavlinkV2Traffic()
Called when a v2 message is received: permanently suppresses the v1-only warning for this link.
void _connectionRemoved()
bool mavlinkChannelIsSet() const
virtual bool isConnected() const =0
virtual bool _allocateMavlinkChannel()
SigningController * signing()
Per-link signing state and confirmation state machine. Non-null after channel allocation.
bool mavlinkV1TrafficReported() const
void removeVehicleReference()
virtual bool isSecureConnection() const
void communicationError(const QString &title, const QString &error)
const SigningController * signing() const
static void setMavlinkV1TrafficGraceMsecs(int msecs)
void bytesSent(LinkInterface *link, const QByteArray &data)
void writeBytesThreadSafe(const char *bytes, int length)
static constexpr int kMavlinkV1TrafficGraceMsecsDefault
void connected()
SharedLinkConfigurationPtr linkConfiguration()
SharedLinkConfigurationPtr _config
void reportRadioStatusReceived()
Manage communication links The Link Manager organizes the physical Links. It can manage arbitrary lin...
Definition LinkManager.h:30
Owns MAVLink signing state and the deferred-confirmation state machine for one LinkInterface.