QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleLinkManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QElapsedTimer>
4#include <QtCore/QObject>
5#include <QtCore/QTimer>
6#include <QtQmlIntegration/QtQmlIntegration>
7
8#include "LinkInterface.h"
10
11class Vehicle;
12class VehicleLinkManagerTest;
13
14class VehicleLinkManager : public QObject
15{
16 Q_OBJECT
17 QML_ELEMENT
18 QML_UNCREATABLE("")
19 Q_MOC_INCLUDE("Vehicle.h")
21 Q_PROPERTY(QStringList linkNames READ linkNames NOTIFY linkNamesChanged)
22 Q_PROPERTY(QStringList linkStatuses READ linkStatuses NOTIFY linkStatusesChanged)
25 Q_PROPERTY(bool autoDisconnect MEMBER _autoDisconnect NOTIFY autoDisconnectChanged)
26
27 friend class Vehicle;
28#ifdef QGC_UNITTEST_BUILD
29 friend class VehicleLinkManagerTest;
30#endif
31
32public:
35
36 void mavlinkMessageReceived(LinkInterface *link, const mavlink_message_t &message);
37 bool containsLink(LinkInterface *link);
38 WeakLinkInterfacePtr primaryLink() const { return _primaryLink; }
39 QString primaryLinkName() const;
40 QStringList linkNames() const;
41 QStringList linkStatuses() const;
42 bool communicationLost() const { return _communicationLost; }
43 bool communicationLostEnabled() const { return _communicationLostEnabled; }
44 void setPrimaryLinkByName(const QString &name);
46 void closeVehicle();
47
48signals:
50 void allLinksRemoved(Vehicle *vehicle);
55 void autoDisconnectChanged(bool autoDisconnect);
56
57private slots:
58 void _commLostCheck();
59
60private:
61 int _containsLinkIndex(const LinkInterface *link);
62 void _addLink(LinkInterface *link);
63 void _removeLink(LinkInterface *link);
64 void _linkDisconnected();
65 bool _updatePrimaryLink();
66 SharedLinkInterfacePtr _bestActivePrimaryLink();
67 void _commRegainedOnLink(LinkInterface *link);
68
69 struct LinkInfo_t {
71 bool commLost = false;
72 QElapsedTimer heartbeatElapsedTimer;
73 };
74
75 Vehicle *_vehicle = nullptr;
76 QTimer *_commLostCheckTimer = nullptr;
77 QList<LinkInfo_t> _rgLinkInfo;
78 WeakLinkInterfacePtr _primaryLink;
79 bool _communicationLost = false;
80 bool _communicationLostEnabled = true;
81 bool _autoDisconnect = false;
82 bool _allLinksRemovedSignalledByCloseVehicle = false;
83
84 static constexpr int _commLostCheckTimeoutMSecs = 1000;
85 static constexpr int _heartbeatMaxElpasedMSecs = 3500;
86
87public:
89 static constexpr int kTestHeartbeatTimeoutMs = 500;
90
93 static constexpr int kTestCommLostDetectionTimeoutMs = _commLostCheckTimeoutMSecs + kTestHeartbeatTimeoutMs + 500;
94};
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
std::weak_ptr< LinkInterface > WeakLinkInterfacePtr
struct __mavlink_message mavlink_message_t
The link interface defines the interface for all links used to communicate with the ground station ap...
void communicationLostEnabledChanged(bool communicationLostEnabled)
QStringList linkNames() const
void autoDisconnectChanged(bool autoDisconnect)
WeakLinkInterfacePtr primaryLink() const
void allLinksRemoved(Vehicle *vehicle)
QStringList linkStatuses() const
void setPrimaryLinkByName(const QString &name)
void mavlinkMessageReceived(LinkInterface *link, const mavlink_message_t &message)
static constexpr int kTestCommLostDetectionTimeoutMs
void setCommunicationLostEnabled(bool communicationLostEnabled)
bool containsLink(LinkInterface *link)
void communicationLostChanged(bool communicationLost)
static constexpr int kTestHeartbeatTimeoutMs
Heartbeat timeout used in unit tests (much shorter for faster tests)
void linkStatusesChanged()
bool communicationLostEnabled() const
bool communicationLost() const
QString primaryLinkName() const