-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathLinkManager.h
More file actions
144 lines (116 loc) · 4.8 KB
/
Copy pathLinkManager.h
File metadata and controls
144 lines (116 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*===================================================================
APM_PLANNER Open Source Ground Control Station
(c) 2014 APM_PLANNER PROJECT <http://www.diydrones.com>
This file is part of the APM_PLANNER project
APM_PLANNER is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
APM_PLANNER is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief LinkManager
*
* @author Michael Carpenter <malcom2073@gmail.com>
* @author QGROUNDCONTROL PROJECT - This code has GPLv3+ snippets from QGROUNDCONTROL, (c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
*/
#ifndef LINKMANAGER_H
#define LINKMANAGER_H
#include <QObject>
/**
* @brief The ConnectionManager class
* This class handles all connections between the GCS and the actual hardware.
* It will create (on request) serial or UDP links, connect the links to the associated mavlink parsers,
* and emit signals upwards when mavlink messages come in.
* This class lives in the UI thread
* The Serial Link lives in the UI Thread
* The mavlink decoder lives in its own thread
* the UAS Class lives in the UI thread
*/
#include "MAVLinkDecoder.h"
#include "MAVLinkProtocol.h"
#include <QMap>
#include <QStringList>
#include "UASInterface.h"
#include "UAS.h"
#include "UASObject.h"
class LinkManager : public QObject
{
Q_OBJECT
public:
explicit LinkManager(QObject *parent = nullptr);
static LinkManager* instance();
~LinkManager();
void shutdown(); // Called when appplication exits
void disableTimeouts(int index);
void enableTimeouts(int index);
void disableAllTimeouts();
void enableAllTimeouts();
MAVLinkProtocol* getProtocol() const;
bool connectLink(int index);
void disconnectLink(int index);
UASInterface* getUas(int id);
UASInterface* createUAS(MAVLinkProtocol* mavlink, LinkInterface* link, int sysid, mavlink_heartbeat_t* heartbeat, QObject* parent = nullptr);
void addLink(LinkInterface *link);
QList<int> getLinks() const;
LinkInterface* getLink(int linkId) const;
// Remove a link based on instance
void removeLink(LinkInterface *link);
// Remove a link based on unique id
void removeLink(int linkId);
LinkInterface::LinkType getLinkType(int linkid);
bool getLinkConnected(int linkid);
QString getSerialLinkPort(int linkid); // [TODO] remove
QString getLinkName(int linkid); // [TODO] remove
QString getLinkShortName(int linkid); // [TODO] remove
QString getLinkDetail(int linkid); // [TODO] remove
int getSerialLinkBaud(int linkid); // [TODO] remove
QStringList getCurrentPorts();
void stopLogging();
void startLogging();
void setLogSubDirectory(const QString& dir);
bool loggingEnabled() const;
UASObject *getUasObject(int uasid);
QMap<int,UASObject*> m_uasObjectMap; // [TODO] make private
void addSimObject(uint8_t sysid,UASObject *obj); // [TODO] remove
void removeSimObject(uint8_t sysid); // [TODO] remove
signals:
//void newLink(LinkInterface* link);
void newLink(int linkid);
void protocolStatusMessage(QString title,QString text);
void linkChanged(int linkid);
/** @brief aggregated signal for when link status changes */
void linkChanged(LinkInterface *link);
void linkError(int linkid, QString message);
void messageReceived(LinkInterface* link,mavlink_message_t message);
public slots:
void receiveMessage(LinkInterface* link,mavlink_message_t message);
void protocolStatusMessageRec(QString title,QString text);
void enableLogging(bool enabled);
void reloadSettings();
void linkUpdated(LinkInterface* link);
private slots:
void linkConnected(LinkInterface* link);
void linkDisonnected(LinkInterface* link);
void linkErrorRec(LinkInterface* link,QString error);
void linkTimeoutTriggered(LinkInterface*);
private:
void loadSettings();
void saveSettings();
private:
QMap<int,LinkInterface*> m_connectionMap;
QMap<int,UASInterface*> m_uasMap;
QMap<QString,int> m_portToBaudMap;
QScopedPointer<MAVLinkDecoder, QScopedPointerDeleteLater> m_mavlinkDecoder;
QScopedPointer<MAVLinkProtocol, QScopedPointerDeleteLater> m_mavlinkProtocol;
QString m_logSubDir;
bool m_mavlinkLoggingEnabled;
};
#endif // LINKMANAGER_H