-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLinkManager1.h
129 lines (117 loc) · 4.45 KB
/
LinkManager1.h
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
/*===================================================================
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 <[email protected]>
* @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) 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 mavlink decoder lives in its own thread
* the UAS Class lives in the UI thread
*/
#include "MAVLinkDecoder1.h"
#include "MAVLinkProtocol1.h"
#include <QMap>
#include <QHostAddress>
#include "UASInterface1.h"
#include "UAS1.h"
#include "UASObject.h"
class LinkManager : public QObject
{
Q_OBJECT
public:
explicit LinkManager(QObject *parent = 0);
static LinkManager* instance()
{
static LinkManager* _instance = 0;
if(_instance == 0)
{
_instance = new LinkManager();
}
return _instance;
}
~LinkManager();
void disableTimeouts(int index);
void enableTimeouts(int index);
void disableAllTimeouts();
void enableAllTimeouts();
void loadSettings();
void saveSettings();
int addUdpConnection(QHostAddress addr,int port);
int addTcpConnection(QHostAddress addr,int port,bool asServer);
void modifyTcpConnection(int index,QHostAddress addr,int port,bool asServer);
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=NULL);
void addLink(LinkInterface *link);
QList<int> getLinks();
// 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 getLinkName(int linkid);
int getUdpLinkPort(int linkid);
int getTcpLinkPort(int linkid);
QHostAddress getTcpLinkHost(int linkid);
bool isTcpServer(int linkid);
void setUdpLinkPort(int linkid, int port);
void addUdpHost(int linkid,QString hostname);
QList<QString> getCurrentPorts();
void stopLogging();
void startLogging();
void setLogSubDirectory(QString dir);
bool loggingEnabled();
UASObject *getUasObject(int uasid);
QMap<int,UASObject*> m_uasObjectMap;
private:
QMap<int,LinkInterface*> m_connectionMap;
QMap<int,UASInterface*> m_uasMap;
QMap<QString,int> m_portToBaudMap;
MAVLinkDecoder *m_mavlinkDecoder;
MAVLinkProtocol *m_mavlinkProtocol;
QString m_logSubDir;
bool m_mavlinkLoggingEnabled;
signals:
//void newLink(LinkInterface* link);
void newLink(int linkid);
void protocolStatusMessage(QString title,QString text);
void linkChanged(int linkid);
void linkError(int linkid, QString message);
private slots:
void linkConnected(LinkInterface* link);
void linkDisonnected(LinkInterface* link);
void linkErrorRec(LinkInterface* link,QString error);
void linkTimeoutTriggered(LinkInterface*);
public slots:
void messageReceived(LinkInterface* link,mavlink_message_t message);
void protocolStatusMessageRec(QString title,QString text);
void enableLogging(bool enabled);
};
#endif // LINKMANAGER_H