Commit 42351ee0 authored by Don Gagne's avatar Don Gagne

Restructure LinkManager/MAVLinkProtocol

parent e7d85710
...@@ -281,11 +281,11 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -281,11 +281,11 @@ bool QGCApplication::_initForNormalAppBoot(void)
// to make sure that all components are initialized when the // to make sure that all components are initialized when the
// first messages arrive // first messages arrive
udpLink = new UDPLink(QHostAddress::Any, 14550); udpLink = new UDPLink(QHostAddress::Any, 14550);
LinkManager::instance()->add(udpLink); LinkManager::instance()->addLink(udpLink);
} else { } else {
// We want to have a default serial link available for "quick" connecting. // We want to have a default serial link available for "quick" connecting.
SerialLink *slink = new SerialLink(); SerialLink *slink = new SerialLink();
LinkManager::instance()->add(slink); LinkManager::instance()->addLink(slink);
} }
#ifdef QGC_RTLAB_ENABLED #ifdef QGC_RTLAB_ENABLED
......
...@@ -186,11 +186,6 @@ signals: ...@@ -186,11 +186,6 @@ signals:
**/ **/
void disconnected(); void disconnected();
/**
* @brief This signal is emitted instantly when the link status changes
**/
void connected(bool connected);
/** /**
* @brief This signal is emitted if the human readable name of this link changes * @brief This signal is emitted if the human readable name of this link changes
*/ */
......
...@@ -43,7 +43,7 @@ LinkManager* LinkManager::_instance = NULL; ...@@ -43,7 +43,7 @@ LinkManager* LinkManager::_instance = NULL;
LinkManager* LinkManager::instance(void) LinkManager* LinkManager::instance(void)
{ {
if(_instance == 0) { if(_instance == 0) {
_instance = new LinkManager(qgcApp()); new LinkManager(qgcApp());
Q_CHECK_PTR(_instance); Q_CHECK_PTR(_instance);
} }
...@@ -65,10 +65,14 @@ void LinkManager::deleteInstance(void) ...@@ -65,10 +65,14 @@ void LinkManager::deleteInstance(void)
**/ **/
LinkManager::LinkManager(QObject* parent, bool registerSingleton) : LinkManager::LinkManager(QObject* parent, bool registerSingleton) :
QGCSingleton(parent, registerSingleton), QGCSingleton(parent, registerSingleton),
_connectionsSuspended(false) _connectionsSuspended(false),
_mavlink(NULL)
{ {
_links = QList<LinkInterface*>(); Q_ASSERT(_instance == NULL);
_protocolLinks = QMap<ProtocolInterface*, LinkInterface*>(); _instance = this;
_mavlink = new MAVLinkProtocol;
Q_CHECK_PTR(_mavlink);
} }
LinkManager::~LinkManager() LinkManager::~LinkManager()
...@@ -80,69 +84,39 @@ LinkManager::~LinkManager() ...@@ -80,69 +84,39 @@ LinkManager::~LinkManager()
deleteLink(link); deleteLink(link);
} }
_links.clear(); _links.clear();
// Clear out the queue so disconnects make it all the way through threads
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
delete _mavlink;
} }
void LinkManager::add(LinkInterface* link) void LinkManager::addLink(LinkInterface* link)
{ {
Q_ASSERT(link); Q_ASSERT(link);
// Take ownership for delete // Take ownership for delete
link->_ownedByLinkManager = true; link->_ownedByLinkManager = true;
_dataMutex.lock(); _linkListMutex.lock();
if (!_links.contains(link)) { if (!_links.contains(link)) {
_links.append(link); _links.append(link);
_dataMutex.unlock(); _linkListMutex.unlock();
emit newLink(link); emit newLink(link);
} else { } else {
_dataMutex.unlock(); _linkListMutex.unlock();
} }
}
void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol)
{
Q_ASSERT(link);
Q_ASSERT(protocol);
// Connect link to protocol // MainWindow may be around when doing things like running unit tests
// the protocol will receive new bytes from the link if (MainWindow::instance()) {
_dataMutex.lock(); connect(link, SIGNAL(communicationError(QString,QString)), MainWindow::instance(), SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection);
QList<LinkInterface*> linkList = _protocolLinks.values(protocol);
// If protocol has not been added before (list length == 0)
// OR if link has not been added to protocol, add
if (!linkList.contains(link))
{
// Protocol is new, add
connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray)));
// Add status
connect(link, SIGNAL(connected(bool)), protocol, SLOT(linkStatusChanged(bool)));
// Store the connection information in the protocol links map
_protocolLinks.insertMulti(protocol, link);
_dataMutex.unlock();
// Make sure the protocol clears its metadata for this link.
protocol->resetMetadataForLink(link);
} else {
_dataMutex.unlock();
} }
//qDebug() << __FILE__ << __LINE__ << "ADDED LINK TO PROTOCOL" << link->getName() << protocol->getName() << "NEW SIZE OF LINK LIST:" << _protocolLinks.size();
} connect(link, &LinkInterface::bytesReceived, _mavlink, &MAVLinkProtocol::receiveBytes);
connect(link, &LinkInterface::connected, _mavlink, &MAVLinkProtocol::linkConnected);
QList<LinkInterface*> LinkManager::getLinksForProtocol(ProtocolInterface* protocol) connect(link, &LinkInterface::disconnected, _mavlink, &MAVLinkProtocol::linkDisconnected);
{ _mavlink->resetMetadataForLink(link);
_dataMutex.lock();
QList<LinkInterface*> links = _protocolLinks.values(protocol);
_dataMutex.unlock();
return links;
}
ProtocolInterface* LinkManager::getProtocolForLink(LinkInterface* link)
{
_dataMutex.lock();
ProtocolInterface* protocol = _protocolLinks.key(link);
_dataMutex.unlock();
return protocol;
} }
bool LinkManager::connectAll() bool LinkManager::connectAll()
...@@ -153,14 +127,14 @@ bool LinkManager::connectAll() ...@@ -153,14 +127,14 @@ bool LinkManager::connectAll()
bool allConnected = true; bool allConnected = true;
_dataMutex.lock(); _linkListMutex.lock();
foreach (LinkInterface* link, _links) { foreach (LinkInterface* link, _links) {
Q_ASSERT(link); Q_ASSERT(link);
if (!link->_connect()) { if (!link->_connect()) {
allConnected = false; allConnected = false;
} }
} }
_dataMutex.unlock(); _linkListMutex.unlock();
return allConnected; return allConnected;
} }
...@@ -169,7 +143,7 @@ bool LinkManager::disconnectAll() ...@@ -169,7 +143,7 @@ bool LinkManager::disconnectAll()
{ {
bool allDisconnected = true; bool allDisconnected = true;
_dataMutex.lock(); _linkListMutex.lock();
foreach (LinkInterface* link, _links) foreach (LinkInterface* link, _links)
{ {
Q_ASSERT(link); Q_ASSERT(link);
...@@ -177,7 +151,7 @@ bool LinkManager::disconnectAll() ...@@ -177,7 +151,7 @@ bool LinkManager::disconnectAll()
allDisconnected = false; allDisconnected = false;
} }
} }
_dataMutex.unlock(); _linkListMutex.unlock();
return allDisconnected; return allDisconnected;
} }
...@@ -203,19 +177,13 @@ void LinkManager::deleteLink(LinkInterface* link) ...@@ -203,19 +177,13 @@ void LinkManager::deleteLink(LinkInterface* link)
{ {
Q_ASSERT(link); Q_ASSERT(link);
_dataMutex.lock(); _linkListMutex.lock();
Q_ASSERT(_links.contains(link)); Q_ASSERT(_links.contains(link));
_links.removeOne(link); _links.removeOne(link);
Q_ASSERT(!_links.contains(link)); Q_ASSERT(!_links.contains(link));
// Remove link from protocol map _linkListMutex.unlock();
QList<ProtocolInterface* > protocols = _protocolLinks.keys(link);
foreach (ProtocolInterface* proto, protocols) {
_protocolLinks.remove(proto, link);
}
_dataMutex.unlock();
// Emit removal of link // Emit removal of link
emit linkDeleted(link); emit linkDeleted(link);
...@@ -230,15 +198,15 @@ void LinkManager::deleteLink(LinkInterface* link) ...@@ -230,15 +198,15 @@ void LinkManager::deleteLink(LinkInterface* link)
*/ */
const QList<LinkInterface*> LinkManager::getLinks() const QList<LinkInterface*> LinkManager::getLinks()
{ {
_dataMutex.lock(); _linkListMutex.lock();
QList<LinkInterface*> ret(_links); QList<LinkInterface*> ret(_links);
_dataMutex.unlock(); _linkListMutex.unlock();
return ret; return ret;
} }
const QList<SerialLink*> LinkManager::getSerialLinks() const QList<SerialLink*> LinkManager::getSerialLinks()
{ {
_dataMutex.lock(); _linkListMutex.lock();
QList<SerialLink*> s; QList<SerialLink*> s;
foreach (LinkInterface* link, _links) foreach (LinkInterface* link, _links)
...@@ -250,7 +218,7 @@ const QList<SerialLink*> LinkManager::getSerialLinks() ...@@ -250,7 +218,7 @@ const QList<SerialLink*> LinkManager::getSerialLinks()
if (serialLink) if (serialLink)
s.append(serialLink); s.append(serialLink);
} }
_dataMutex.unlock(); _linkListMutex.unlock();
return s; return s;
} }
......
...@@ -21,13 +21,8 @@ This file is part of the PIXHAWK project ...@@ -21,13 +21,8 @@ This file is part of the PIXHAWK project
======================================================================*/ ======================================================================*/
/** /// @file
* @file /// @author Lorenz Meier <mavteam@student.ethz.ch>
* @brief Manage communication links
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef _LINKMANAGER_H_ #ifndef _LINKMANAGER_H_
#define _LINKMANAGER_H_ #define _LINKMANAGER_H_
...@@ -41,15 +36,16 @@ This file is part of the PIXHAWK project ...@@ -41,15 +36,16 @@ This file is part of the PIXHAWK project
#include "SerialLink.h" #include "SerialLink.h"
#include "ProtocolInterface.h" #include "ProtocolInterface.h"
#include "QGCSingleton.h" #include "QGCSingleton.h"
#include "MAVLinkProtocol.h"
class LinkManagerTest; class LinkManagerTest;
/** /// Manage communication links
* The Link Manager organizes the physical Links. It can manage arbitrary ///
* links and takes care of connecting them as well assigning the correct /// The Link Manager organizes the physical Links. It can manage arbitrary
* protocol instance to transport the link data into the application. /// links and takes care of connecting them as well assigning the correct
* /// protocol instance to transport the link data into the application.
**/
class LinkManager : public QGCSingleton class LinkManager : public QGCSingleton
{ {
Q_OBJECT Q_OBJECT
...@@ -62,65 +58,64 @@ public: ...@@ -62,65 +58,64 @@ public:
~LinkManager(); ~LinkManager();
QList<LinkInterface*> getLinksForProtocol(ProtocolInterface* protocol); /// Returns list of all links
ProtocolInterface* getProtocolForLink(LinkInterface* link);
/** @brief Get a list of all links */
const QList<LinkInterface*> getLinks(); const QList<LinkInterface*> getLinks();
/** @brief Get a list of all serial links */ // Returns list of all serial links
const QList<SerialLink*> getSerialLinks(); const QList<SerialLink*> getSerialLinks();
/** @brief Get a list of all protocols */ /// Sets the flag to suspend the all new connections
const QList<ProtocolInterface*> getProtocols() {
return _protocolLinks.uniqueKeys();
}
/// @brief Sets the lag to suspend the all new connections
/// @param reason User visible reason to suspend connections /// @param reason User visible reason to suspend connections
void setConnectionsSuspended(QString reason); void setConnectionsSuspended(QString reason);
/// @brief Sets the flag to allow new connections to be made /// Sets the flag to allow new connections to be made
void setConnectionsAllowed(void) { _connectionsSuspended = false; } void setConnectionsAllowed(void) { _connectionsSuspended = false; }
/// @brief Deletes the specified link. Will disconnect if connected. /// Adds the link to the LinkManager. LinkManager takes ownership of this object. To delete
/// it, call LinkManager::deleteLink.
void addLink(LinkInterface* link);
/// Deletes the specified link. Will disconnect if connected.
void deleteLink(LinkInterface* link); void deleteLink(LinkInterface* link);
public slots:
/// @brief Adds the link to the LinkManager. LinkManager takes ownership of this object. To delete
// it, call LinkManager::deleteLink.
void add(LinkInterface* link);
void addProtocol(LinkInterface* link, ProtocolInterface* protocol); /// Re-connects all existing links
bool connectAll(); bool connectAll();
bool connectLink(LinkInterface* link);
/// Disconnects all existing links
bool disconnectAll(); bool disconnectAll();
/// Connect the specified link
bool connectLink(LinkInterface* link);
/// Disconnect the specified link
bool disconnectLink(LinkInterface* link); bool disconnectLink(LinkInterface* link);
/// Returns the one mavlink protocol object in the system
MAVLinkProtocol* mavlink(void) { return _mavlink; }
signals: signals:
void newLink(LinkInterface* link); void newLink(LinkInterface* link);
void linkDeleted(LinkInterface* link); void linkDeleted(LinkInterface* link);
private: private:
/// @brief All access to LinkManager is through LinkManager::instance /// All access to LinkManager is through LinkManager::instance
LinkManager(QObject* parent = NULL, bool registerSingleton = true); LinkManager(QObject* parent = NULL, bool registerSingleton = true);
// LinkManager unit test is allowed to new LinkManager objects /// LinkManager unit test is allowed to new LinkManager objects
friend class LinkManagerTest; friend class LinkManagerTest;
static LinkManager* _instance; bool _connectionsSuspendedMsg(void);
QList<LinkInterface*> _links; static LinkManager* _instance; /// LinkManager singleton
QMultiMap<ProtocolInterface*,LinkInterface*> _protocolLinks;
QMutex _dataMutex;
bool _connectionsSuspendedMsg(void); QList<LinkInterface*> _links; ///< List of available links
QMutex _linkListMutex; ///< Mutex for thread safe access to _links list
bool _connectionsSuspended; ///< true: all new connections should not be allowed
QString _connectionsSuspendedReason; ///< User visible reason for suspension
bool _connectionsSuspended; ///< true: all new connections should not be allowed MAVLinkProtocol* _mavlink; ///< The one and only mavlink protocol
QString _connectionsSuspendedReason; ///< User visible reason for suspension
}; };
#endif #endif
...@@ -179,14 +179,25 @@ void MAVLinkProtocol::resetMetadataForLink(const LinkInterface *link) ...@@ -179,14 +179,25 @@ void MAVLinkProtocol::resetMetadataForLink(const LinkInterface *link)
currLossCounter[linkId] = 0; currLossCounter[linkId] = 0;
} }
void MAVLinkProtocol::linkStatusChanged(bool connected) void MAVLinkProtocol::linkConnected(void)
{ {
LinkInterface* link = qobject_cast<LinkInterface*>(QObject::sender()); LinkInterface* link = qobject_cast<LinkInterface*>(QObject::sender());
Q_ASSERT(link);
if (link == NULL) { _linkStatusChanged(link, true);
Q_ASSERT(false); }
return;
} void MAVLinkProtocol::linkDisconnected(void)
{
LinkInterface* link = qobject_cast<LinkInterface*>(QObject::sender());
Q_ASSERT(link);
_linkStatusChanged(link, false);
}
void MAVLinkProtocol::_linkStatusChanged(LinkInterface* link, bool connected)
{
Q_ASSERT(link);
if (connected) { if (connected) {
Q_ASSERT(!_connectedLinks.contains(link)); Q_ASSERT(!_connectedLinks.contains(link));
...@@ -441,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) ...@@ -441,7 +452,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
if (m_multiplexingEnabled) if (m_multiplexingEnabled)
{ {
// Get all links connected to this unit // Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinksForProtocol(this); QList<LinkInterface*> links = LinkManager::instance()->getLinks();
// Emit message on all links that are currently connected // Emit message on all links that are currently connected
foreach (LinkInterface* currLink, links) foreach (LinkInterface* currLink, links)
...@@ -486,7 +497,7 @@ int MAVLinkProtocol::getComponentId() ...@@ -486,7 +497,7 @@ int MAVLinkProtocol::getComponentId()
void MAVLinkProtocol::sendMessage(mavlink_message_t message) void MAVLinkProtocol::sendMessage(mavlink_message_t message)
{ {
// Get all links connected to this unit // Get all links connected to this unit
QList<LinkInterface*> links = LinkManager::instance()->getLinksForProtocol(this); QList<LinkInterface*> links = LinkManager::instance()->getLinks();
// Emit message on all links that are currently connected // Emit message on all links that are currently connected
QList<LinkInterface*>::iterator i; QList<LinkInterface*>::iterator i;
......
...@@ -38,7 +38,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -38,7 +38,6 @@ This file is part of the QGROUNDCONTROL project
#include <QMap> #include <QMap>
#include <QByteArray> #include <QByteArray>
#include "ProtocolInterface.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGC.h" #include "QGC.h"
...@@ -51,10 +50,10 @@ This file is part of the QGROUNDCONTROL project ...@@ -51,10 +50,10 @@ This file is part of the QGROUNDCONTROL project
* for more information, please see the official website. * for more information, please see the official website.
* @ref http://pixhawk.ethz.ch/software/mavlink/ * @ref http://pixhawk.ethz.ch/software/mavlink/
**/ **/
class MAVLinkProtocol : public ProtocolInterface class MAVLinkProtocol : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
MAVLinkProtocol(); MAVLinkProtocol();
~MAVLinkProtocol(); ~MAVLinkProtocol();
...@@ -143,7 +142,10 @@ public: ...@@ -143,7 +142,10 @@ public:
public slots: public slots:
/** @brief Receive bytes from a communication interface */ /** @brief Receive bytes from a communication interface */
void receiveBytes(LinkInterface* link, QByteArray b); void receiveBytes(LinkInterface* link, QByteArray b);
void linkStatusChanged(bool connected);
void linkConnected(void);
void linkDisconnected(void);
/** @brief Send MAVLink message through serial interface */ /** @brief Send MAVLink message through serial interface */
void sendMessage(mavlink_message_t message); void sendMessage(mavlink_message_t message);
/** @brief Send MAVLink message */ /** @brief Send MAVLink message */
...@@ -257,6 +259,9 @@ signals: ...@@ -257,6 +259,9 @@ signals:
void actionGuardChanged(bool enabled); void actionGuardChanged(bool enabled);
/** @brief Emitted if actiion request timeout changed */ /** @brief Emitted if actiion request timeout changed */
void actionRetransmissionTimeoutChanged(int ms); void actionRetransmissionTimeoutChanged(int ms);
/** @brief Update the packet loss from one system */
void receiveLossChanged(int uasId, float loss);
/** /**
* @brief Emitted if a new radio status packet received * @brief Emitted if a new radio status packet received
* *
...@@ -275,6 +280,7 @@ signals: ...@@ -275,6 +280,7 @@ signals:
void saveTempFlightDataLog(QString tempLogfile); void saveTempFlightDataLog(QString tempLogfile);
private: private:
void _linkStatusChanged(LinkInterface* link, bool connected);
bool _closeLogFile(void); bool _closeLogFile(void);
void _startLogging(void); void _startLogging(void);
void _stopLogging(void); void _stopLogging(void);
......
...@@ -106,7 +106,7 @@ MAVLinkSimulationLink::MAVLinkSimulationLink(QString readFile, QString writeFile ...@@ -106,7 +106,7 @@ MAVLinkSimulationLink::MAVLinkSimulationLink(QString readFile, QString writeFile
srand(QTime::currentTime().msec()); srand(QTime::currentTime().msec());
maxTimeNoise = 0; maxTimeNoise = 0;
this->id = getNextLinkId(); this->id = getNextLinkId();
LinkManager::instance()->add(this); LinkManager::instance()->addLink(this);
} }
MAVLinkSimulationLink::~MAVLinkSimulationLink() MAVLinkSimulationLink::~MAVLinkSimulationLink()
...@@ -802,7 +802,6 @@ bool MAVLinkSimulationLink::_disconnect(void) ...@@ -802,7 +802,6 @@ bool MAVLinkSimulationLink::_disconnect(void)
_isConnected = false; _isConnected = false;
emit disconnected(); emit disconnected();
emit connected(false);
//exit(); //exit();
} }
...@@ -820,7 +819,6 @@ bool MAVLinkSimulationLink::_connect(void) ...@@ -820,7 +819,6 @@ bool MAVLinkSimulationLink::_connect(void)
{ {
_isConnected = true; _isConnected = true;
emit connected(); emit connected();
emit connected(true);
start(LowPriority); start(LowPriority);
MAVLinkSimulationMAV* mav1 = new MAVLinkSimulationMAV(this, 1, 37.480391, -122.282883); MAVLinkSimulationMAV* mav1 = new MAVLinkSimulationMAV(this, 1, 37.480391, -122.282883);
......
...@@ -240,7 +240,6 @@ void SerialLink::run() ...@@ -240,7 +240,6 @@ void SerialLink::run()
m_port = NULL; m_port = NULL;
emit disconnected(); emit disconnected();
emit connected(false);
} }
QGC::SLEEP::msleep(500); QGC::SLEEP::msleep(500);
...@@ -340,7 +339,6 @@ void SerialLink::run() ...@@ -340,7 +339,6 @@ void SerialLink::run()
m_port = NULL; m_port = NULL;
emit disconnected(); emit disconnected();
emit connected(false);
} }
} }
...@@ -503,7 +501,6 @@ bool SerialLink::hardwareConnect(QString &type) ...@@ -503,7 +501,6 @@ bool SerialLink::hardwareConnect(QString &type)
emit communicationUpdate(getName(),"Opened port!"); emit communicationUpdate(getName(),"Opened port!");
emit connected(); emit connected();
emit connected(true);
qDebug() << "CONNECTING LINK: " << __FILE__ << __LINE__ << "type:" << type << "with settings" << m_port->portName() qDebug() << "CONNECTING LINK: " << __FILE__ << __LINE__ << "type:" << type << "with settings" << m_port->portName()
<< getBaudRate() << getDataBits() << getParityType() << getStopBits(); << getBaudRate() << getDataBits() << getParityType() << getStopBits();
......
...@@ -191,7 +191,6 @@ bool TCPLink::_disconnect(void) ...@@ -191,7 +191,6 @@ bool TCPLink::_disconnect(void)
_socket = NULL; _socket = NULL;
emit disconnected(); emit disconnected();
emit connected(false);
} }
return true; return true;
...@@ -241,7 +240,6 @@ bool TCPLink::_hardwareConnect(void) ...@@ -241,7 +240,6 @@ bool TCPLink::_hardwareConnect(void)
} }
_socketIsConnected = true; _socketIsConnected = true;
emit connected(true);
emit connected(); emit connected();
return true; return true;
......
...@@ -287,7 +287,6 @@ bool UDPLink::_disconnect(void) ...@@ -287,7 +287,6 @@ bool UDPLink::_disconnect(void)
connectState = false; connectState = false;
emit disconnected(); emit disconnected();
emit connected(false);
return !connectState; return !connectState;
} }
...@@ -352,7 +351,6 @@ bool UDPLink::hardwareConnect(void) ...@@ -352,7 +351,6 @@ bool UDPLink::hardwareConnect(void)
//QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); //QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
emit connected(connectState);
if (connectState) { if (connectState) {
emit connected(); emit connected();
} }
......
...@@ -85,7 +85,7 @@ void LinkManagerTest::_add_test(void) ...@@ -85,7 +85,7 @@ void LinkManagerTest::_add_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink(); MockLink* link = new MockLink();
_linkMgr->add(link); _linkMgr->addLink(link);
QList<LinkInterface*> links = _linkMgr->getLinks(); QList<LinkInterface*> links = _linkMgr->getLinks();
QCOMPARE(links.count(), 1); QCOMPARE(links.count(), 1);
...@@ -98,7 +98,7 @@ void LinkManagerTest::_delete_test(void) ...@@ -98,7 +98,7 @@ void LinkManagerTest::_delete_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink(); MockLink* link = new MockLink();
_linkMgr->add(link); _linkMgr->addLink(link);
_linkMgr->deleteLink(link); _linkMgr->deleteLink(link);
QCOMPARE(_linkMgr->getLinks().count(), 0); QCOMPARE(_linkMgr->getLinks().count(), 0);
...@@ -111,7 +111,7 @@ void LinkManagerTest::_addSignals_test(void) ...@@ -111,7 +111,7 @@ void LinkManagerTest::_addSignals_test(void)
Q_ASSERT(_multiSpy->checkNoSignals() == true); Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink(); MockLink* link = new MockLink();
_linkMgr->add(link); _linkMgr->addLink(link);
QCOMPARE(_multiSpy->checkOnlySignalByMask(newLinkSignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(newLinkSignalMask), true);
QSignalSpy* spy = _multiSpy->getSpyByIndex(newLinkSignalIndex); QSignalSpy* spy = _multiSpy->getSpyByIndex(newLinkSignalIndex);
...@@ -132,7 +132,7 @@ void LinkManagerTest::_deleteSignals_test(void) ...@@ -132,7 +132,7 @@ void LinkManagerTest::_deleteSignals_test(void)
Q_ASSERT(_multiSpy->checkNoSignals() == true); Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink(); MockLink* link = new MockLink();
_linkMgr->add(link); _linkMgr->addLink(link);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
_linkMgr->deleteLink(link); _linkMgr->deleteLink(link);
......
...@@ -76,8 +76,7 @@ void MainWindowTest::_connectWindowClose_test(void) ...@@ -76,8 +76,7 @@ void MainWindowTest::_connectWindowClose_test(void)
MockLink* link = new MockLink(); MockLink* link = new MockLink();
Q_CHECK_PTR(link); Q_CHECK_PTR(link);
// FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work LinkManager::instance()->addLink(link);
_mainWindow->addLink(link);
linkMgr->connectLink(link); linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
......
...@@ -147,8 +147,7 @@ void MavlinkLogTest::_connectLog_test(void) ...@@ -147,8 +147,7 @@ void MavlinkLogTest::_connectLog_test(void)
MockLink* link = new MockLink(); MockLink* link = new MockLink();
Q_CHECK_PTR(link); Q_CHECK_PTR(link);
// FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work LinkManager::instance()->addLink(link);
mainWindow->addLink(link);
linkMgr->connectLink(link); linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
......
...@@ -104,7 +104,6 @@ bool MockLink::_connect(void) ...@@ -104,7 +104,6 @@ bool MockLink::_connect(void)
_connected = true; _connected = true;
start(); start();
emit connected(); emit connected();
emit connected(true);
} }
return true; return true;
...@@ -116,7 +115,6 @@ bool MockLink::_disconnect(void) ...@@ -116,7 +115,6 @@ bool MockLink::_disconnect(void)
_connected = false; _connected = false;
exit(); exit();
emit disconnected(); emit disconnected();
emit connected(false);
} }
return true; return true;
......
...@@ -56,7 +56,6 @@ void TCPLinkUnitTest::init(void) ...@@ -56,7 +56,6 @@ void TCPLinkUnitTest::init(void)
_rgSignals[bytesReceivedSignalIndex] = SIGNAL(bytesReceived(LinkInterface*, QByteArray)); _rgSignals[bytesReceivedSignalIndex] = SIGNAL(bytesReceived(LinkInterface*, QByteArray));
_rgSignals[connectedSignalIndex] = SIGNAL(connected(void)); _rgSignals[connectedSignalIndex] = SIGNAL(connected(void));
_rgSignals[disconnectedSignalIndex] = SIGNAL(disconnected(void)); _rgSignals[disconnectedSignalIndex] = SIGNAL(disconnected(void));
_rgSignals[connected2SignalIndex] = SIGNAL(connected(bool));
_rgSignals[nameChangedSignalIndex] = SIGNAL(nameChanged(QString)); _rgSignals[nameChangedSignalIndex] = SIGNAL(nameChanged(QString));
_rgSignals[communicationErrorSignalIndex] = SIGNAL(communicationError(const QString&, const QString&)); _rgSignals[communicationErrorSignalIndex] = SIGNAL(communicationError(const QString&, const QString&));
_rgSignals[communicationUpdateSignalIndex] = SIGNAL(communicationUpdate(const QString&, const QString&)); _rgSignals[communicationUpdateSignalIndex] = SIGNAL(communicationUpdate(const QString&, const QString&));
...@@ -157,11 +156,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void) ...@@ -157,11 +156,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void)
// Connect to the server // Connect to the server
QCOMPARE(_link->_connect(), true); QCOMPARE(_link->_connect(), true);
// Make sure we get the two different connected signals // Make sure we get the connected signals
QCOMPARE(_multiSpy->waitForSignalByIndex(connectedSignalIndex, 10000), true); QCOMPARE(_multiSpy->waitForSignalByIndex(connectedSignalIndex, 10000), true);
QCOMPARE(_multiSpy->checkOnlySignalByMask(connectedSignalMask | connected2SignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(connectedSignalMask), true);
QList<QVariant> arguments = _multiSpy->getSpyByIndex(connected2SignalIndex)->takeFirst();
QCOMPARE(arguments.at(0).toBool(), true);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
// Test link->server data path // Test link->server data path
...@@ -186,7 +183,7 @@ void TCPLinkUnitTest::_connectSucceed_test(void) ...@@ -186,7 +183,7 @@ void TCPLinkUnitTest::_connectSucceed_test(void)
QCOMPARE(_multiSpy->checkOnlySignalByMask(bytesReceivedSignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(bytesReceivedSignalMask), true);
// Read the data and make sure it matches // Read the data and make sure it matches
arguments = _multiSpy->getSpyByIndex(bytesReceivedSignalIndex)->takeFirst(); QList<QVariant> arguments = _multiSpy->getSpyByIndex(bytesReceivedSignalIndex)->takeFirst();
QVERIFY(arguments.at(1).toByteArray() == bytesOut); QVERIFY(arguments.at(1).toByteArray() == bytesOut);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
...@@ -194,11 +191,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void) ...@@ -194,11 +191,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void)
// Disconnect the link // Disconnect the link
_link->_disconnect(); _link->_disconnect();
// Make sure we get the disconnected signals on link side // Make sure we get the disconnected signal on link side
QCOMPARE(_multiSpy->waitForSignalByIndex(disconnectedSignalIndex, 1000), true); QCOMPARE(_multiSpy->waitForSignalByIndex(disconnectedSignalIndex, 1000), true);
QCOMPARE(_multiSpy->checkOnlySignalByMask(disconnectedSignalMask | connected2SignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(disconnectedSignalMask), true);
arguments = _multiSpy->getSpyByIndex(connected2SignalIndex)->takeFirst();
QCOMPARE(arguments.at(0).toBool(), false);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
// Try to connect again to make sure everything was cleaned up correctly from previous connection // Try to connect again to make sure everything was cleaned up correctly from previous connection
...@@ -206,11 +201,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void) ...@@ -206,11 +201,9 @@ void TCPLinkUnitTest::_connectSucceed_test(void)
// Connect to the server // Connect to the server
QCOMPARE(_link->_connect(), true); QCOMPARE(_link->_connect(), true);
// Make sure we get the two different connected signals // Make sure we get the connected signal
QCOMPARE(_multiSpy->waitForSignalByIndex(connectedSignalIndex, 1000), true); QCOMPARE(_multiSpy->waitForSignalByIndex(connectedSignalIndex, 1000), true);
QCOMPARE(_multiSpy->checkOnlySignalByMask(connectedSignalMask | connected2SignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(connectedSignalMask), true);
arguments = _multiSpy->getSpyByIndex(connected2SignalIndex)->takeFirst();
QCOMPARE(arguments.at(0).toBool(), true);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
server->quit(); server->quit();
......
...@@ -58,7 +58,6 @@ private: ...@@ -58,7 +58,6 @@ private:
bytesReceivedSignalIndex = 0, bytesReceivedSignalIndex = 0,
connectedSignalIndex, connectedSignalIndex,
disconnectedSignalIndex, disconnectedSignalIndex,
connected2SignalIndex,
nameChangedSignalIndex, nameChangedSignalIndex,
communicationErrorSignalIndex, communicationErrorSignalIndex,
communicationUpdateSignalIndex, communicationUpdateSignalIndex,
...@@ -70,7 +69,6 @@ private: ...@@ -70,7 +69,6 @@ private:
bytesReceivedSignalMask = 1 << bytesReceivedSignalIndex, bytesReceivedSignalMask = 1 << bytesReceivedSignalIndex,
connectedSignalMask = 1 << connectedSignalIndex, connectedSignalMask = 1 << connectedSignalIndex,
disconnectedSignalMask = 1 << disconnectedSignalIndex, disconnectedSignalMask = 1 << disconnectedSignalIndex,
connected2SignalMask = 1 << connected2SignalIndex,
nameChangedSignalMask = 1 << nameChangedSignalIndex, nameChangedSignalMask = 1 << nameChangedSignalIndex,
communicationErrorSignalMask = 1 << communicationErrorSignalIndex, communicationErrorSignalMask = 1 << communicationErrorSignalIndex,
communicationUpdateSignalMask = 1 << communicationUpdateSignalIndex, communicationUpdateSignalMask = 1 << communicationUpdateSignalIndex,
......
...@@ -135,6 +135,8 @@ void UnitTest::cleanup(void) ...@@ -135,6 +135,8 @@ void UnitTest::cleanup(void)
QEXPECT_FAIL("", "Expecting failure due internal testing", Continue); QEXPECT_FAIL("", "Expecting failure due internal testing", Continue);
} }
QCOMPARE(_missedFileDialogCount, 0); QCOMPARE(_missedFileDialogCount, 0);
qgcApp()->destroySingletonsForUnitTest();
} }
void UnitTest::setExpectedMessageBox(QMessageBox::StandardButton response) void UnitTest::setExpectedMessageBox(QMessageBox::StandardButton response)
......
...@@ -481,7 +481,7 @@ void QGCUASFileManager::_sendRequest(Request* request) ...@@ -481,7 +481,7 @@ void QGCUASFileManager::_sendRequest(Request* request)
request->hdr.seqNumber = _lastOutgoingSeqNumber; request->hdr.seqNumber = _lastOutgoingSeqNumber;
if (_systemIdQGC == 0) { if (_systemIdQGC == 0) {
_systemIdQGC = MainWindow::instance()->getMAVLink()->getSystemId(); _systemIdQGC = LinkManager::instance()->mavlink()->getSystemId();
} }
Q_ASSERT(_mav); Q_ASSERT(_mav);
......
...@@ -1765,7 +1765,7 @@ void UAS::sendMessage(mavlink_message_t message) ...@@ -1765,7 +1765,7 @@ void UAS::sendMessage(mavlink_message_t message)
void UAS::forwardMessage(mavlink_message_t message) void UAS::forwardMessage(mavlink_message_t message)
{ {
// Emit message on all links that are currently connected // Emit message on all links that are currently connected
QList<LinkInterface*>link_list = LinkManager::instance()->getLinksForProtocol(mavlink); QList<LinkInterface*>link_list = LinkManager::instance()->getLinks();
foreach(LinkInterface* link, link_list) foreach(LinkInterface* link, link_list)
{ {
......
...@@ -71,7 +71,7 @@ void UASParameterCommsMgr::loadParamCommsSettings() ...@@ -71,7 +71,7 @@ void UASParameterCommsMgr::loadParamCommsSettings()
void UASParameterCommsMgr::_sendParamRequestListMsg(void) void UASParameterCommsMgr::_sendParamRequestListMsg(void)
{ {
MAVLinkProtocol* mavlink = MainWindow::instance()->getMAVLink(); MAVLinkProtocol* mavlink = LinkManager::instance()->mavlink();
Q_ASSERT(mavlink); Q_ASSERT(mavlink);
mavlink_message_t msg; mavlink_message_t msg;
......
...@@ -60,7 +60,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -60,7 +60,7 @@ This file is part of the QGROUNDCONTROL project
#include "LinkManager.h" #include "LinkManager.h"
#include "MainWindow.h" #include "MainWindow.h"
CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent) : QDialog(parent) CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, QWidget *parent) : QDialog(parent)
{ {
this->link = link; this->link = link;
...@@ -112,7 +112,6 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -112,7 +112,6 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
// Create configuration action for this link // Create configuration action for this link
// Connect the current UAS // Connect the current UAS
action = new QAction(QIcon(":/files/images/devices/network-wireless.svg"), "", this); action = new QAction(QIcon(":/files/images/devices/network-wireless.svg"), "", this);
LinkManager::instance()->add(link);
action->setData(link->getId()); action->setData(link->getId());
action->setEnabled(true); action->setEnabled(true);
action->setVisible(true); action->setVisible(true);
...@@ -127,12 +126,11 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -127,12 +126,11 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
connect(ui.closeButton, SIGNAL(clicked()), this->window(), SLOT(close())); connect(ui.closeButton, SIGNAL(clicked()), this->window(), SLOT(close()));
connect(ui.deleteButton, SIGNAL(clicked()), this, SLOT(remove())); connect(ui.deleteButton, SIGNAL(clicked()), this, SLOT(remove()));
connect(this->link, SIGNAL(connected(bool)), this, SLOT(connectionState(bool))); connect(link, &LinkInterface::connected, this, &CommConfigurationWindow::_linkConnected);
connect(link, &LinkInterface::disconnected, this, &CommConfigurationWindow::_linkDisconnected);
// Fill in the current data // Fill in the current data
if(this->link->isConnected()) ui.connectButton->setChecked(true); if(this->link->isConnected()) ui.connectButton->setChecked(true);
//connect(this->link, SIGNAL(connected(bool)), ui.connectButton, SLOT(setChecked(bool)));
if(this->link->isConnected()) { if(this->link->isConnected()) {
ui.connectionStatusLabel->setText(tr("Connected")); ui.connectionStatusLabel->setText(tr("Connected"));
...@@ -226,14 +224,10 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -226,14 +224,10 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(linkCurrentIndexChanged(int))); connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(linkCurrentIndexChanged(int)));
// Open details pane for MAVLink if necessary // Open details pane for MAVLink if necessary
MAVLinkProtocol* mavlink = dynamic_cast<MAVLinkProtocol*>(protocol); MAVLinkProtocol* mavlink = LinkManager::instance()->mavlink();
if (mavlink != 0) { QWidget* conf = new MAVLinkSettingsWidget(mavlink, this);
QWidget* conf = new MAVLinkSettingsWidget(mavlink, this); ui.protocolScrollArea->setWidget(conf);
ui.protocolScrollArea->setWidget(conf); ui.protocolGroupBox->setTitle(mavlink->getName()+" (Global Settings)");
ui.protocolGroupBox->setTitle(protocol->getName()+" (Global Settings)");
} else {
qDebug() << "Protocol is NOT MAVLink, can't open configuration window";
}
// Open details for UDP link if necessary // Open details for UDP link if necessary
// TODO // TODO
...@@ -288,7 +282,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype) ...@@ -288,7 +282,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
UDPLink *udp = new UDPLink(); UDPLink *udp = new UDPLink();
tmpLink = udp; tmpLink = udp;
MainWindow::instance()->addLink(tmpLink);
break; break;
} }
...@@ -296,7 +289,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype) ...@@ -296,7 +289,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
TCPLink *tcp = new TCPLink(); TCPLink *tcp = new TCPLink();
tmpLink = tcp; tmpLink = tcp;
MainWindow::instance()->addLink(tmpLink);
break; break;
} }
...@@ -305,7 +297,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype) ...@@ -305,7 +297,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
OpalLink* opal = new OpalLink(); OpalLink* opal = new OpalLink();
tmpLink = opal; tmpLink = opal;
MainWindow::instance()->addLink(tmpLink);
break; break;
} }
#endif // QGC_RTLAB_ENABLED #endif // QGC_RTLAB_ENABLED
...@@ -315,7 +306,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype) ...@@ -315,7 +306,6 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
MockLink* mock = new MockLink; MockLink* mock = new MockLink;
tmpLink = mock; tmpLink = mock;
MainWindow::instance()->addLink(tmpLink);
break; break;
} }
#endif #endif
...@@ -325,10 +315,13 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype) ...@@ -325,10 +315,13 @@ void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
SerialLink *serial = new SerialLink(); SerialLink *serial = new SerialLink();
tmpLink = serial; tmpLink = serial;
MainWindow::instance()->addLink(tmpLink);
break; break;
} }
} }
if (tmpLink) {
LinkManager::instance()->addLink(tmpLink);
}
// trigger new window // trigger new window
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(tmpLink)); const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(tmpLink));
...@@ -385,7 +378,15 @@ void CommConfigurationWindow::remove() ...@@ -385,7 +378,15 @@ void CommConfigurationWindow::remove()
this->deleteLater(); this->deleteLater();
} }
void CommConfigurationWindow::connectionState(bool connect) void CommConfigurationWindow::_linkConnected(void) {
_connectionState(true);
}
void CommConfigurationWindow::_linkDisconnected(void) {
_connectionState(false);
}
void CommConfigurationWindow::_connectionState(bool connect)
{ {
ui.connectButton->setChecked(connect); ui.connectButton->setChecked(connect);
if(connect) { if(connect) {
......
...@@ -73,7 +73,7 @@ class CommConfigurationWindow : public QDialog ...@@ -73,7 +73,7 @@ class CommConfigurationWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent = 0); CommConfigurationWindow(LinkInterface* link, QWidget *parent = 0);
~CommConfigurationWindow(); ~CommConfigurationWindow();
QAction* getAction(); QAction* getAction();
...@@ -86,12 +86,16 @@ public slots: ...@@ -86,12 +86,16 @@ public slots:
/** @brief Set the protocol for this link */ /** @brief Set the protocol for this link */
void setProtocol(int protocol); void setProtocol(int protocol);
void setConnection(); void setConnection();
void connectionState(bool connect);
void setLinkName(QString name); void setLinkName(QString name);
/** @brief Disconnects the associated link, removes it from all menus and closes the window. */ /** @brief Disconnects the associated link, removes it from all menus and closes the window. */
void remove(); void remove();
private slots:
void _linkConnected(void);
void _linkDisconnected(void);
private: private:
void _connectionState(bool connect);
Ui::commSettings ui; Ui::commSettings ui;
LinkInterface* link; LinkInterface* link;
......
...@@ -217,7 +217,7 @@ void DebugConsole::linkSelected(int linkId) ...@@ -217,7 +217,7 @@ void DebugConsole::linkSelected(int linkId)
if (currLink) if (currLink)
{ {
disconnect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray))); disconnect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray)));
disconnect(currLink, SIGNAL(connected(bool)), this, SLOT(setConnectionState(bool))); disconnect(currLink, &LinkInterface::connected, this, &DebugConsole::_linkConnected);
disconnect(currLink,SIGNAL(communicationUpdate(QString,QString)),this,SLOT(linkStatusUpdate(QString,QString))); disconnect(currLink,SIGNAL(communicationUpdate(QString,QString)),this,SLOT(linkStatusUpdate(QString,QString)));
snapShotTimer.stop(); snapShotTimer.stop();
} }
...@@ -229,9 +229,9 @@ void DebugConsole::linkSelected(int linkId) ...@@ -229,9 +229,9 @@ void DebugConsole::linkSelected(int linkId)
if (linkId != -1) { if (linkId != -1) {
currLink = links[linkId]; currLink = links[linkId];
connect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray))); connect(currLink, SIGNAL(bytesReceived(LinkInterface*,QByteArray)), this, SLOT(receiveBytes(LinkInterface*, QByteArray)));
connect(currLink, SIGNAL(connected(bool)), this, SLOT(setConnectionState(bool))); disconnect(currLink, &LinkInterface::connected, this, &DebugConsole::_linkConnected);
connect(currLink,SIGNAL(communicationUpdate(QString,QString)),this,SLOT(linkStatusUpdate(QString,QString))); connect(currLink,SIGNAL(communicationUpdate(QString,QString)),this,SLOT(linkStatusUpdate(QString,QString)));
setConnectionState(currLink->isConnected()); _setConnectionState(currLink->isConnected());
snapShotTimer.start(); snapShotTimer.start();
} }
} }
...@@ -761,10 +761,20 @@ void DebugConsole::hold(bool hold) ...@@ -761,10 +761,20 @@ void DebugConsole::hold(bool hold)
} }
} }
void DebugConsole::_linkConnected(void)
{
_setConnectionState(true);
}
void DebugConsole::_linkDisconnected(void)
{
_setConnectionState(false);
}
/** /**
* Sets the connection state the widget shows to this state * Sets the connection state the widget shows to this state
*/ */
void DebugConsole::setConnectionState(bool connected) void DebugConsole::_setConnectionState(bool connected)
{ {
if(connected) { if(connected) {
m_ui->connectButton->setText(tr("Disconn.")); m_ui->connectButton->setText(tr("Disconn."));
......
...@@ -81,8 +81,6 @@ public slots: ...@@ -81,8 +81,6 @@ public slots:
void MAVLINKfilterEnabled(bool filter); void MAVLINKfilterEnabled(bool filter);
/** @brief Freeze input, do not store new incoming data */ /** @brief Freeze input, do not store new incoming data */
void hold(bool hold); void hold(bool hold);
/** @brief Set connection state of the current link */
void setConnectionState(bool);
/** @brief Handle the connect button */ /** @brief Handle the connect button */
void handleConnectButton(); void handleConnectButton();
/** @brief Enable auto-freeze mode if traffic intensity is too high to display */ /** @brief Enable auto-freeze mode if traffic intensity is too high to display */
...@@ -144,8 +142,15 @@ protected: ...@@ -144,8 +142,15 @@ protected:
QStringList commandHistory; QStringList commandHistory;
QString currCommand; QString currCommand;
int commandIndex; int commandIndex;
private slots:
void _linkConnected(void);
void _linkDisconnected(void);
private: private:
/** @brief Set connection state of the current link */
void _setConnectionState(bool);
Ui::DebugConsole *m_ui; Ui::DebugConsole *m_ui;
}; };
......
...@@ -142,7 +142,7 @@ void MAVLinkSettingsWidget::enableDroneOS(bool enable) ...@@ -142,7 +142,7 @@ void MAVLinkSettingsWidget::enableDroneOS(bool enable)
// Delete from all lists first // Delete from all lists first
UDPLink* firstUdp = NULL; UDPLink* firstUdp = NULL;
QList<LinkInterface*> links = LinkManager::instance()->getLinksForProtocol(protocol); QList<LinkInterface*> links = LinkManager::instance()->getLinks();
foreach (LinkInterface* link, links) foreach (LinkInterface* link, links)
{ {
UDPLink* udp = dynamic_cast<UDPLink*>(link); UDPLink* udp = dynamic_cast<UDPLink*>(link);
......
...@@ -112,7 +112,6 @@ void MainWindow::deleteInstance(void) ...@@ -112,7 +112,6 @@ void MainWindow::deleteInstance(void)
MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode) : MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode) :
currentView(VIEW_FLIGHT), currentView(VIEW_FLIGHT),
currentStyle(QGC_MAINWINDOW_STYLE_DARK), currentStyle(QGC_MAINWINDOW_STYLE_DARK),
mavlink(new MAVLinkProtocol()),
centerStackActionGroup(new QActionGroup(this)), centerStackActionGroup(new QActionGroup(this)),
autoReconnect(false), autoReconnect(false),
simulationLink(NULL), simulationLink(NULL),
...@@ -131,8 +130,8 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE ...@@ -131,8 +130,8 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE
this->setAttribute(Qt::WA_DeleteOnClose); this->setAttribute(Qt::WA_DeleteOnClose);
connect(menuActionHelper, SIGNAL(needToShowDockWidget(QString,bool)),SLOT(showDockWidget(QString,bool))); connect(menuActionHelper, SIGNAL(needToShowDockWidget(QString,bool)),SLOT(showDockWidget(QString,bool)));
connect(mavlink, SIGNAL(protocolStatusMessage(const QString&, const QString&)), this, SLOT(showCriticalMessage(const QString&, const QString&))); connect(LinkManager::instance()->mavlink(), SIGNAL(protocolStatusMessage(const QString&, const QString&)), this, SLOT(showCriticalMessage(const QString&, const QString&)));
connect(mavlink, SIGNAL(saveTempFlightDataLog(QString)), this, SLOT(_saveTempFlightDataLog(QString))); connect(LinkManager::instance()->mavlink(), SIGNAL(saveTempFlightDataLog(QString)), this, SLOT(_saveTempFlightDataLog(QString)));
loadSettings(); loadSettings();
...@@ -242,11 +241,11 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE ...@@ -242,11 +241,11 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE
QList<LinkInterface*> links = LinkManager::instance()->getLinks(); QList<LinkInterface*> links = LinkManager::instance()->getLinks();
foreach(LinkInterface* link, links) foreach(LinkInterface* link, links)
{ {
this->addLink(link); _addLinkMenu(link);
} }
connect(LinkManager::instance(), SIGNAL(newLink(LinkInterface*)), this, SLOT(addLink(LinkInterface*))); connect(LinkManager::instance(), &LinkManager::newLink, this, &MainWindow::_addLinkMenu);
// Connect user interface devices // Connect user interface devices
emit initStatusChanged(tr("Initializing joystick interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); emit initStatusChanged(tr("Initializing joystick interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
joystick = new JoystickInput(); joystick = new JoystickInput();
...@@ -274,8 +273,7 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE ...@@ -274,8 +273,7 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE
SerialLink* link = new SerialLink(); SerialLink* link = new SerialLink();
// Add to registry // Add to registry
linkMgr->add(link); linkMgr->addLink(link);
linkMgr->addProtocol(link, mavlink);
linkMgr->connectLink(link); linkMgr->connectLink(link);
} }
...@@ -365,11 +363,6 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE ...@@ -365,11 +363,6 @@ MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
if (mavlink)
{
delete mavlink;
mavlink = NULL;
}
if (simulationLink) if (simulationLink)
{ {
delete simulationLink; delete simulationLink;
...@@ -496,12 +489,12 @@ void MainWindow::buildCustomWidget() ...@@ -496,12 +489,12 @@ void MainWindow::buildCustomWidget()
void MainWindow::buildCommonWidgets() void MainWindow::buildCommonWidgets()
{ {
// Add generic MAVLink decoder // Add generic MAVLink decoder
mavlinkDecoder = new MAVLinkDecoder(mavlink, this); mavlinkDecoder = new MAVLinkDecoder(LinkManager::instance()->mavlink(), this);
connect(mavlinkDecoder, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), connect(mavlinkDecoder, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),
this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64))); this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)));
// Log player // Log player
logPlayer = new QGCMAVLinkLogPlayer(mavlink, statusBar()); logPlayer = new QGCMAVLinkLogPlayer(LinkManager::instance()->mavlink(), statusBar());
statusBar()->addPermanentWidget(logPlayer); statusBar()->addPermanentWidget(logPlayer);
// Initialize all of the views, if they haven't been already, and add their central widgets // Initialize all of the views, if they haven't been already, and add their central widgets
...@@ -588,7 +581,7 @@ void MainWindow::buildCommonWidgets() ...@@ -588,7 +581,7 @@ void MainWindow::buildCommonWidgets()
createDockWidget(simView, new PrimaryFlightDisplay(this), tr("Primary Flight Display"), "PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET", VIEW_SIMULATION, Qt::RightDockWidgetArea); createDockWidget(simView, new PrimaryFlightDisplay(this), tr("Primary Flight Display"), "PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET", VIEW_SIMULATION, Qt::RightDockWidgetArea);
// Add dock widgets for the engineering view // Add dock widgets for the engineering view
createDockWidget(engineeringView, new QGCMAVLinkInspector(mavlink, this), tr("MAVLink Inspector"), "MAVLINK_INSPECTOR_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea); createDockWidget(engineeringView, new QGCMAVLinkInspector(LinkManager::instance()->mavlink(), this), tr("MAVLink Inspector"), "MAVLINK_INSPECTOR_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea);
createDockWidget(engineeringView, new ParameterInterface(this), tr("Onboard Parameters"), "PARAMETER_INTERFACE_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea); createDockWidget(engineeringView, new ParameterInterface(this), tr("Onboard Parameters"), "PARAMETER_INTERFACE_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea);
createDockWidget(engineeringView, new QGCUASFileViewMulti(this), tr("Onboard Files"), "FILE_VIEW_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea); createDockWidget(engineeringView, new QGCUASFileViewMulti(this), tr("Onboard Files"), "FILE_VIEW_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea);
createDockWidget(engineeringView, new HUD(320, 240, this), tr("Video Downlink"), "HEAD_UP_DISPLAY_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea); createDockWidget(engineeringView, new HUD(320, 240, this), tr("Video Downlink"), "HEAD_UP_DISPLAY_DOCKWIDGET", VIEW_ENGINEER, Qt::RightDockWidgetArea);
...@@ -669,7 +662,7 @@ void MainWindow::loadDockWidget(const QString& name) ...@@ -669,7 +662,7 @@ void MainWindow::loadDockWidget(const QString& name)
} }
else if (name == "MAVLINK_INSPECTOR_DOCKWIDGET") else if (name == "MAVLINK_INSPECTOR_DOCKWIDGET")
{ {
createDockWidget(centerStack->currentWidget(),new QGCMAVLinkInspector(mavlink,this),tr("MAVLink Inspector"),"MAVLINK_INSPECTOR_DOCKWIDGET",currentView,Qt::RightDockWidgetArea); createDockWidget(centerStack->currentWidget(),new QGCMAVLinkInspector(LinkManager::instance()->mavlink(),this),tr("MAVLink Inspector"),"MAVLINK_INSPECTOR_DOCKWIDGET",currentView,Qt::RightDockWidgetArea);
} }
else if (name == "PARAMETER_INTERFACE_DOCKWIDGET") else if (name == "PARAMETER_INTERFACE_DOCKWIDGET")
{ {
...@@ -800,7 +793,6 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -800,7 +793,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
storeViewState(); storeViewState();
storeSettings(); storeSettings();
mavlink->storeSettings();
UASManager::instance()->storeSettings(); UASManager::instance()->storeSettings();
event->accept(); event->accept();
} }
...@@ -812,7 +804,7 @@ void MainWindow::connectCommonWidgets() ...@@ -812,7 +804,7 @@ void MainWindow::connectCommonWidgets()
{ {
if (infoDockWidget && infoDockWidget->widget()) if (infoDockWidget && infoDockWidget->widget())
{ {
connect(mavlink, SIGNAL(receiveLossChanged(int, float)), connect(LinkManager::instance()->mavlink(), SIGNAL(receiveLossChanged(int, float)),
infoDockWidget->widget(), SLOT(updateSendLoss(int, float))); infoDockWidget->widget(), SLOT(updateSendLoss(int, float)));
} }
} }
...@@ -1290,13 +1282,13 @@ void MainWindow::showSettings() ...@@ -1290,13 +1282,13 @@ void MainWindow::showSettings()
settings.exec(); settings.exec();
} }
// FIXME: Where is this called from
LinkInterface* MainWindow::addLink() LinkInterface* MainWindow::addLink()
{ {
SerialLink* link = new SerialLink(); SerialLink* link = new SerialLink();
// TODO This should be only done in the dialog itself // TODO This should be only done in the dialog itself
LinkManager::instance()->add(link); LinkManager::instance()->addLink(link);
LinkManager::instance()->addProtocol(link, mavlink);
// Go fishing for this link's configuration window // Go fishing for this link's configuration window
QList<QAction*> actions = ui.menuNetwork->actions(); QList<QAction*> actions = ui.menuNetwork->actions();
...@@ -1339,41 +1331,29 @@ bool MainWindow::configLink(LinkInterface *link) ...@@ -1339,41 +1331,29 @@ bool MainWindow::configLink(LinkInterface *link)
return found; return found;
} }
void MainWindow::addLink(LinkInterface *link) void MainWindow::_addLinkMenu(LinkInterface *link)
{ {
// IMPORTANT! KEEP THESE TWO LINES
// THEY MAKE SURE THE LINK IS PROPERLY REGISTERED
// BEFORE LINKING THE UI AGAINST IT
// Register (does nothing if already registered)
LinkManager::instance()->add(link);
LinkManager::instance()->addProtocol(link, mavlink);
// Go fishing for this link's configuration window // Go fishing for this link's configuration window
QList<QAction*> actions = ui.menuNetwork->actions(); QList<QAction*> actions = ui.menuNetwork->actions();
bool found(false); bool alreadyAdded = false;
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link)); const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link));
const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId()); const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId());
foreach (QAction* act, actions) foreach (QAction* act, actions) {
{ if (act->data().toInt() == linkID) {
if (act->data().toInt() == linkID) alreadyAdded = true;
{ break;
found = true;
} }
} }
if (!found) if (!alreadyAdded) {
{ CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, this);
CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
commsWidgetList.append(commWidget); commsWidgetList.append(commWidget);
connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*))); connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*)));
QAction* action = commWidget->getAction(); QAction* action = commWidget->getAction();
ui.menuNetwork->addAction(action); ui.menuNetwork->addAction(action);
// Error handling
connect(link, SIGNAL(communicationError(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection);
} }
} }
...@@ -1750,6 +1730,7 @@ bool MainWindow::dockWidgetTitleBarsEnabled() const ...@@ -1750,6 +1730,7 @@ bool MainWindow::dockWidgetTitleBarsEnabled() const
return menuActionHelper->dockWidgetTitleBarsEnabled(); return menuActionHelper->dockWidgetTitleBarsEnabled();
} }
/// @brief Save the specified Flight Data Log
void MainWindow::_saveTempFlightDataLog(QString tempLogfile) void MainWindow::_saveTempFlightDataLog(QString tempLogfile)
{ {
QString saveFilename = QGCFileDialog::getSaveFileName(this, QString saveFilename = QGCFileDialog::getSaveFileName(this,
......
...@@ -46,7 +46,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -46,7 +46,6 @@ This file is part of the QGROUNDCONTROL project
#include "WaypointList.h" #include "WaypointList.h"
#include "CameraView.h" #include "CameraView.h"
#include "UASListWidget.h" #include "UASListWidget.h"
#include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h" #include "MAVLinkSimulationLink.h"
#include "submainwindow.h" #include "submainwindow.h"
#include "input/JoystickInput.h" #include "input/JoystickInput.h"
...@@ -175,7 +174,6 @@ public slots: ...@@ -175,7 +174,6 @@ public slots:
void showSettings(); void showSettings();
/** @brief Add a communication link */ /** @brief Add a communication link */
LinkInterface* addLink(); LinkInterface* addLink();
void addLink(LinkInterface* link);
bool configLink(LinkInterface *link); bool configLink(LinkInterface *link);
/** @brief Simulate a link */ /** @brief Simulate a link */
void simulateLink(bool simulate); void simulateLink(bool simulate);
...@@ -293,11 +291,6 @@ public: ...@@ -293,11 +291,6 @@ public:
return logPlayer; return logPlayer;
} }
MAVLinkProtocol* getMAVLink()
{
return mavlink;
}
protected: protected:
typedef enum _VIEW_SECTIONS typedef enum _VIEW_SECTIONS
...@@ -360,8 +353,6 @@ protected: ...@@ -360,8 +353,6 @@ protected:
void loadSettings(); void loadSettings();
void storeSettings(); void storeSettings();
// TODO Should be moved elsewhere, as the protocol does not belong to the UI
QPointer<MAVLinkProtocol> mavlink;
LinkInterface* udpLink; LinkInterface* udpLink;
...@@ -461,8 +452,8 @@ protected: ...@@ -461,8 +452,8 @@ protected:
CUSTOM_MODE customMode; CUSTOM_MODE customMode;
private slots: private slots:
/// @brief Save the specified Flight Data Log
void _saveTempFlightDataLog(QString tempLogfile); void _saveTempFlightDataLog(QString tempLogfile);
void _addLinkMenu(LinkInterface* link);
private: private:
/// Constructor is private since all creation should be through MainWindow::_create /// Constructor is private since all creation should be through MainWindow::_create
......
...@@ -14,11 +14,22 @@ OpalLinkConfigurationWindow::OpalLinkConfigurationWindow(OpalLink* link, ...@@ -14,11 +14,22 @@ OpalLinkConfigurationWindow::OpalLinkConfigurationWindow(OpalLink* link,
ui.opalInstIDSpinBox->setValue(this->link->getOpalInstID()); ui.opalInstIDSpinBox->setValue(this->link->getOpalInstID());
connect(ui.opalInstIDSpinBox, SIGNAL(valueChanged(int)), link, SLOT(setOpalInstID(int))); connect(ui.opalInstIDSpinBox, SIGNAL(valueChanged(int)), link, SLOT(setOpalInstID(int)));
connect(link, SIGNAL(connected(bool)), this, SLOT(allowSettingsAccess(bool))); connect(link, &LinkInterface::connected, this, OpalLinkConfigurationWindow::_linkConnected);
connect(link, &LinkInterface::disconnected, this, OpalLinkConfigurationWindow::_linkDisConnected);
this->show(); this->show();
} }
void OpalLinkConfigurationWindow::allowSettingsAccess(bool enabled) void OpalLinkConfigurationWindow::_linkConnected(void)
{
_allowSettingsAccess(true);
}
void OpalLinkConfigurationWindow::_linkConnected(void)
{
_allowSettingsAccess(false);
}
void OpalLinkConfigurationWindow::_allowSettingsAccess(bool enabled)
{ {
ui.paramFileButton->setEnabled(enabled); ui.paramFileButton->setEnabled(enabled);
ui.servoConfigFileButton->setEnabled(enabled); ui.servoConfigFileButton->setEnabled(enabled);
......
...@@ -15,11 +15,13 @@ public: ...@@ -15,11 +15,13 @@ public:
explicit OpalLinkConfigurationWindow(OpalLink* link, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet); explicit OpalLinkConfigurationWindow(OpalLink* link, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet);
signals: signals:
public slots: private slots:
void _linkConnected(void);
void allowSettingsAccess(bool enabled); void _linkDisconnected(void);
private: private:
void _allowSettingsAccess(bool enabled);
Ui::OpalLinkSettings ui; Ui::OpalLinkSettings ui;
OpalLink* link; OpalLink* link;
}; };
......
...@@ -661,8 +661,8 @@ void QGCToolBar::addLink(LinkInterface* link) ...@@ -661,8 +661,8 @@ void QGCToolBar::addLink(LinkInterface* link)
toolBarBaudAction->setVisible(true); toolBarBaudAction->setVisible(true);
currentLink = link; currentLink = link;
connect(currentLink, SIGNAL(connected(bool)), this, SLOT(updateLinkState(bool))); connect(currentLink, &LinkInterface::connected, this, &QGCToolBar::_linkConnected);
updateLinkState(link->isConnected()); _updateLinkState(link->isConnected());
qDebug() << "ADD LINK"; qDebug() << "ADD LINK";
...@@ -683,7 +683,7 @@ void QGCToolBar::removeLink(LinkInterface* link) ...@@ -683,7 +683,7 @@ void QGCToolBar::removeLink(LinkInterface* link)
// Update GUI according to scan result // Update GUI according to scan result
if (currentLink) { if (currentLink) {
updateLinkState(currentLink->isConnected()); _updateLinkState(currentLink->isConnected());
} else { } else {
connectButton->setText(tr("New Serial Link")); connectButton->setText(tr("New Serial Link"));
portComboBox->hide(); portComboBox->hide();
...@@ -740,7 +740,17 @@ void QGCToolBar::updateComboBox() ...@@ -740,7 +740,17 @@ void QGCToolBar::updateComboBox()
} }
} }
void QGCToolBar::updateLinkState(bool connected) void QGCToolBar::_linkConnected(void)
{
_updateLinkState(true);
}
void QGCToolBar::_linkDisconnected(void)
{
_updateLinkState(false);
}
void QGCToolBar::_updateLinkState(bool connected)
{ {
Q_UNUSED(connected); Q_UNUSED(connected);
if (currentLink && currentLink->isConnected() && portComboBox->isVisible()) if (currentLink && currentLink->isConnected() && portComboBox->isVisible())
...@@ -767,32 +777,32 @@ void QGCToolBar::updateLinkState(bool connected) ...@@ -767,32 +777,32 @@ void QGCToolBar::updateLinkState(bool connected)
} }
} }
void QGCToolBar::connectLink(bool connect) void QGCToolBar::connectLink(bool connectLink)
{ {
LinkManager* linkMgr = LinkManager::instance(); LinkManager* linkMgr = LinkManager::instance();
Q_ASSERT(linkMgr); Q_ASSERT(linkMgr);
// No serial port yet present // No serial port yet present
if (connect && linkMgr->getSerialLinks().count() == 0) { if (connectLink && linkMgr->getSerialLinks().count() == 0) {
MainWindow::instance()->addLink(); MainWindow::instance()->addLink();
currentLink = linkMgr->getLinks().last(); currentLink = linkMgr->getLinks().last();
} else if (connect) { } else if (connectLink) {
SerialLink *link = qobject_cast<SerialLink*>(currentLink); SerialLink *link = qobject_cast<SerialLink*>(currentLink);
if (link) { if (link) {
link->setPortName(portComboBox->itemData(portComboBox->currentIndex()).toString().trimmed()); link->setPortName(portComboBox->itemData(portComboBox->currentIndex()).toString().trimmed());
int baud = baudcomboBox->currentText().toInt(); int baud = baudcomboBox->currentText().toInt();
link->setBaudRate(baud); link->setBaudRate(baud);
QObject::connect(link, SIGNAL(connected(bool)), this, SLOT(updateLinkState(bool))); connect(link, &LinkInterface::connected, this, &QGCToolBar::_linkConnected);
linkMgr->connectLink(link); linkMgr->connectLink(link);
} }
} else if (!connect && currentLink) { } else if (!connectLink && currentLink) {
linkMgr->disconnectLink(currentLink); linkMgr->disconnectLink(currentLink);
QObject::disconnect(currentLink, SIGNAL(connected(bool)), this, SLOT(updateLinkState(bool))); disconnect(currentLink, &LinkInterface::connected, this, &QGCToolBar::_linkConnected);
} }
if (currentLink) { if (currentLink) {
updateLinkState(currentLink->isConnected()); _updateLinkState(currentLink->isConnected());
} }
} }
......
...@@ -52,8 +52,6 @@ public slots: ...@@ -52,8 +52,6 @@ public slots:
void addLink(LinkInterface* link); void addLink(LinkInterface* link);
/** @brief Remove link which is currently handled */ /** @brief Remove link which is currently handled */
void removeLink(LinkInterface* link); void removeLink(LinkInterface* link);
/** @brief Update the link state */
void updateLinkState(bool connected);
/** @brief Set the system state */ /** @brief Set the system state */
void updateState(UASInterface* system, QString name, QString description); void updateState(UASInterface* system, QString name, QString description);
/** @brief Set the system mode */ /** @brief Set the system mode */
...@@ -146,6 +144,14 @@ protected: ...@@ -146,6 +144,14 @@ protected:
QAction* firstAction; QAction* firstAction;
QToolButton *advancedButton; QToolButton *advancedButton;
QButtonGroup *group; QButtonGroup *group;
private slots:
void _linkConnected(void);
void _linkDisconnected(void);
private:
/** @brief Update the link state */
void _updateLinkState(bool connected);
}; };
#endif // QGCTOOLBAR_H #endif // QGCTOOLBAR_H
...@@ -137,10 +137,6 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge ...@@ -137,10 +137,6 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
ui.advCheckBox->setChecked(false); ui.advCheckBox->setChecked(false);
ui.advGroupBox->setVisible(false); ui.advGroupBox->setVisible(false);
//connect(this->link, SIGNAL(connected(bool)), this, SLOT());
//ui.portName->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
//ui.baudRate->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
switch(this->link->getParityType()) { switch(this->link->getParityType()) {
case 0: case 0:
ui.parNone->setChecked(true); ui.parNone->setChecked(true);
......
...@@ -52,15 +52,8 @@ _ui(new Ui::SettingsDialog) ...@@ -52,15 +52,8 @@ _ui(new Ui::SettingsDialog)
// Add the joystick settings pane // Add the joystick settings pane
_ui->tabWidget->addTab(new JoystickWidget(joystick, this), "Controllers"); _ui->tabWidget->addTab(new JoystickWidget(joystick, this), "Controllers");
// Add all protocols MAVLinkSettingsWidget* msettings = new MAVLinkSettingsWidget(LinkManager::instance()->mavlink(), this);
QList<ProtocolInterface*> protocols = LinkManager::instance()->getProtocols(); _ui->tabWidget->addTab(msettings, "MAVLink");
foreach (ProtocolInterface* protocol, protocols) {
MAVLinkProtocol* mavlink = dynamic_cast<MAVLinkProtocol*>(protocol);
if (mavlink) {
MAVLinkSettingsWidget* msettings = new MAVLinkSettingsWidget(mavlink, this);
_ui->tabWidget->addTab(msettings, "MAVLink");
}
}
this->window()->setWindowTitle(tr("QGroundControl Settings")); this->window()->setWindowTitle(tr("QGroundControl Settings"));
......
...@@ -124,20 +124,20 @@ void UASListWidget::updateStatus() ...@@ -124,20 +124,20 @@ void UASListWidget::updateStatus()
if (!link) if (!link)
continue; continue;
ProtocolInterface* p = LinkManager::instance()->getProtocolForLink(link); MAVLinkProtocol* mavlink = LinkManager::instance()->mavlink();
// Build the tooltip out of the protocol parsing data: received, dropped, and parsing errors. // Build the tooltip out of the protocol parsing data: received, dropped, and parsing errors.
QString displayString(""); QString displayString("");
int c; int c;
if ((c = p->getReceivedPacketCount(link)) != -1) if ((c = mavlink->getReceivedPacketCount(link)) != -1)
{ {
displayString += QString(tr("<br/>Received: %2")).arg(QString::number(c)); displayString += QString(tr("<br/>Received: %2")).arg(QString::number(c));
} }
if ((c = p->getDroppedPacketCount(link)) != -1) if ((c = mavlink->getDroppedPacketCount(link)) != -1)
{ {
displayString += QString(tr("<br/>Dropped: %2")).arg(QString::number(c)); displayString += QString(tr("<br/>Dropped: %2")).arg(QString::number(c));
} }
if ((c = p->getParsingErrorCount(link)) != -1) if ((c = mavlink->getParsingErrorCount(link)) != -1)
{ {
displayString += QString(tr("<br/>Errors: %2")).arg(QString::number(c)); displayString += QString(tr("<br/>Errors: %2")).arg(QString::number(c));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment