Commit ad0fb3da authored by lm's avatar lm

Merged

parents 6e00bdcc 6f8998fa
...@@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project
#include <QList> #include <QList>
#include <QApplication> #include <QApplication>
#include "LinkManager.h" #include "LinkManager.h"
#include <iostream>
#include <QDebug> #include <QDebug>
...@@ -65,6 +66,7 @@ LinkManager::~LinkManager() ...@@ -65,6 +66,7 @@ LinkManager::~LinkManager()
void LinkManager::add(LinkInterface* link) void LinkManager::add(LinkInterface* link)
{ {
if(!link) return;
links.append(link); links.append(link);
emit newLink(link); emit newLink(link);
} }
...@@ -73,6 +75,7 @@ void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol) ...@@ -73,6 +75,7 @@ void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol)
{ {
// Connect link to protocol // Connect link to protocol
// the protocol will receive new bytes from the link // the protocol will receive new bytes from the link
if(!link || !protocol) return;
connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray))); connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray)));
// Store the connection information in the protocol links map // Store the connection information in the protocol links map
protocolLinks.insertMulti(protocol, link); protocolLinks.insertMulti(protocol, link);
...@@ -91,7 +94,8 @@ bool LinkManager::connectAll() ...@@ -91,7 +94,8 @@ bool LinkManager::connectAll()
foreach (LinkInterface* link, links) foreach (LinkInterface* link, links)
{ {
if(! link->connect()) allConnected = false; if(!link) {}
else if(!link->connect()) allConnected = false;
} }
return allConnected; return allConnected;
...@@ -103,7 +107,9 @@ bool LinkManager::disconnectAll() ...@@ -103,7 +107,9 @@ bool LinkManager::disconnectAll()
foreach (LinkInterface* link, links) foreach (LinkInterface* link, links)
{ {
if(! link->disconnect()) allDisconnected = false; //static int i=0;
if(!link){}
else if(!link->disconnect()) allDisconnected = false;
} }
return allDisconnected; return allDisconnected;
...@@ -111,14 +117,32 @@ bool LinkManager::disconnectAll() ...@@ -111,14 +117,32 @@ bool LinkManager::disconnectAll()
bool LinkManager::connectLink(LinkInterface* link) bool LinkManager::connectLink(LinkInterface* link)
{ {
if(!link) return false;
return link->connect(); return link->connect();
} }
bool LinkManager::disconnectLink(LinkInterface* link) bool LinkManager::disconnectLink(LinkInterface* link)
{ {
if(!link) return false;
return link->disconnect(); return link->disconnect();
} }
bool LinkManager::removeLink(LinkInterface* link)
{
if(link)
{
for (int i=0; i < QList<LinkInterface*>(links).size(); i++)
{
if(link==links.at(i))
{
links.removeAt(i); //remove from link list
}
}
return true;
}
return false;
}
/** /**
* The access time is linear in the number of links. * The access time is linear in the number of links.
* *
......
...@@ -67,6 +67,8 @@ public slots: ...@@ -67,6 +67,8 @@ public slots:
void add(LinkInterface* link); void add(LinkInterface* link);
void addProtocol(LinkInterface* link, ProtocolInterface* protocol); void addProtocol(LinkInterface* link, ProtocolInterface* protocol);
bool removeLink(LinkInterface* link);
bool connectAll(); bool connectAll();
bool connectLink(LinkInterface* link); bool connectLink(LinkInterface* link);
......
...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include "LinkManager.h" #include "LinkManager.h"
#include "QGC.h" #include "QGC.h"
#include <MG.h> #include <MG.h>
#include <iostream>
#ifdef _WIN32 #ifdef _WIN32
#include "windows.h" #include "windows.h"
#endif #endif
...@@ -122,7 +123,7 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P ...@@ -122,7 +123,7 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P
SerialLink::~SerialLink() SerialLink::~SerialLink()
{ {
disconnect(); disconnect();
delete port; if(port) delete port;
port = NULL; port = NULL;
} }
...@@ -255,6 +256,8 @@ bool SerialLink::disconnect() ...@@ -255,6 +256,8 @@ bool SerialLink::disconnect()
port->close(); port->close();
dataMutex.unlock(); dataMutex.unlock();
if(this->isRunning()) this->terminate(); //stop running the thread, restart it upon connect
bool closed = true; bool closed = true;
//port->isOpen(); //port->isOpen();
...@@ -541,7 +544,7 @@ bool SerialLink::setPortName(QString portName) ...@@ -541,7 +544,7 @@ bool SerialLink::setPortName(QString portName)
this->porthandle = "\\\\.\\" + this->porthandle; this->porthandle = "\\\\.\\" + this->porthandle;
} }
#endif #endif
delete port; if(port) delete port;
port = new QextSerialPort(porthandle, QextSerialPort::Polling); port = new QextSerialPort(porthandle, QextSerialPort::Polling);
port->setBaudRate(baudrate); port->setBaudRate(baudrate);
......
...@@ -95,6 +95,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), ...@@ -95,6 +95,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
UAS::~UAS() UAS::~UAS()
{ {
delete links; delete links;
links=NULL;
} }
int UAS::getUASID() const int UAS::getUASID() const
...@@ -126,6 +127,7 @@ void UAS::setSelected() ...@@ -126,6 +127,7 @@ void UAS::setSelected()
void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
{ {
if (!link) return;
if (!links->contains(link)) if (!links->contains(link))
{ {
addLink(link); addLink(link);
...@@ -371,12 +373,6 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -371,12 +373,6 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
GAudioOutput::instance()->notifyPositive(); GAudioOutput::instance()->notifyPositive();
} }
positionLock = true; positionLock = true;
// Send to patch antenna
// FIXME Message re-routing should be implemented differently
//mavlink_message_t msg;
//mavlink_msg_global_position_pack(MG::SYSTEM::ID, MG::SYSTEM::COMPID, &msg, pos.usec, pos.lat, pos.lon, pos.alt, pos.vx, pos.vy, pos.vz);
//sendMessage(msg);
} }
break; break;
case MAVLINK_MSG_ID_GPS_RAW: case MAVLINK_MSG_ID_GPS_RAW:
...@@ -840,6 +836,7 @@ void UAS::sendMessage(mavlink_message_t message) ...@@ -840,6 +836,7 @@ void UAS::sendMessage(mavlink_message_t message)
void UAS::sendMessage(LinkInterface* link, mavlink_message_t message) void UAS::sendMessage(LinkInterface* link, mavlink_message_t message)
{ {
if(!link) return;
// Create buffer // Create buffer
uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
// Write message into buffer, prepending start sign // Write message into buffer, prepending start sign
......
...@@ -47,6 +47,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -47,6 +47,7 @@ This file is part of the QGROUNDCONTROL project
#endif #endif
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MAVLinkSettingsWidget.h" #include "MAVLinkSettingsWidget.h"
#include "LinkManager.h"
CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags)
{ {
...@@ -58,6 +59,10 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -58,6 +59,10 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
// add link types // add link types
ui.linkType->addItem("Serial",QGC_LINK_SERIAL); ui.linkType->addItem("Serial",QGC_LINK_SERIAL);
ui.linkType->addItem("UDP",QGC_LINK_UDP); ui.linkType->addItem("UDP",QGC_LINK_UDP);
ui.linkType->addItem("Simulation",QGC_LINK_SIMULATION);
ui.linkType->addItem("Serial Forwarding",QGC_LINK_FORWARDING);
ui.connectionType->addItem("MAVLink", QGC_PROTOCOL_MAVLINK);
// Create action to open this menu // Create action to open this menu
// Create configuration action for this link // Create configuration action for this link
...@@ -195,11 +200,20 @@ void CommConfigurationWindow::setLinkName(QString name) ...@@ -195,11 +200,20 @@ void CommConfigurationWindow::setLinkName(QString name)
void CommConfigurationWindow::remove() void CommConfigurationWindow::remove()
{ {
link->disconnect(); if(action) delete action; //delete action first since it has a pointer to link
//delete link; action=NULL;
//delete action;
if(link)
{
LinkManager::instance()->removeLink(link); //remove link from LinkManager list
link->disconnect(); //disconnect port, and also calls terminate() to stop the thread
if (link->isRunning()) link->terminate(); // terminate() the serial thread just in case it is still running
link->wait(); // wait() until thread is stoped before deleting
delete link;
}
link=NULL;
this->window()->close(); this->window()->close();
qDebug() << "TODO: Link cannot be deleted: CommConfigurationWindow::remove() NOT IMPLEMENTED!";
} }
void CommConfigurationWindow::connectionState(bool connect) void CommConfigurationWindow::connectionState(bool connect)
......
...@@ -42,7 +42,14 @@ This file is part of the QGROUNDCONTROL project ...@@ -42,7 +42,14 @@ This file is part of the QGROUNDCONTROL project
enum qgc_link_t enum qgc_link_t
{ {
QGC_LINK_SERIAL, QGC_LINK_SERIAL,
QGC_LINK_UDP QGC_LINK_UDP,
QGC_LINK_SIMULATION,
QGC_LINK_FORWARDING
};
enum qgc_protocol_t
{
QGC_PROTOCOL_MAVLINK
}; };
#ifdef OPAL_RT #ifdef OPAL_RT
......
...@@ -43,23 +43,7 @@ ...@@ -43,23 +43,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="linkType"> <widget class="QComboBox" name="linkType"/>
<item>
<property name="text">
<string>Serial Link</string>
</property>
</item>
<item>
<property name="text">
<string>UDP</string>
</property>
</item>
<item>
<property name="text">
<string>Simulation</string>
</property>
</item>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
...@@ -71,13 +55,8 @@ ...@@ -71,13 +55,8 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="connectionType"> <widget class="QComboBox" name="connectionType">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>-1</number>
</property> </property>
<item>
<property name="text">
<string>MAVLink</string>
</property>
</item>
</widget> </widget>
</item> </item>
</layout> </layout>
......
...@@ -510,12 +510,3 @@ void SerialConfigurationWindow::setLinkName(QString name) ...@@ -510,12 +510,3 @@ void SerialConfigurationWindow::setLinkName(QString name)
setWindowTitle(tr("Configuration of ") + link->getName()); setWindowTitle(tr("Configuration of ") + link->getName());
} }
void SerialConfigurationWindow::remove()
{
link->disconnect();
//delete link;
//delete action;
this->window()->close();
qDebug() << "TODO: Link cannot be deleted: SerialConfigurationWindow::remove() NOT IMPLEMENTED!";
}
...@@ -60,12 +60,6 @@ public slots: ...@@ -60,12 +60,6 @@ public slots:
void setParityEven(); void setParityEven();
void setPortName(QString port); void setPortName(QString port);
void setLinkName(QString name); void setLinkName(QString name);
/**
* @brief Remove this link
*
* Disconnects the associated link, removes it from all menus and closes the window.
*/
void remove();
void setupPortList(); void setupPortList();
protected slots: protected slots:
......
...@@ -38,6 +38,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -38,6 +38,7 @@ This file is part of the QGROUNDCONTROL project
QMap3D::QMap3D(QWidget * parent, const char * name, WindowFlags f) : QMap3D::QMap3D(QWidget * parent, const char * name, WindowFlags f) :
QWidget(parent,f) QWidget(parent,f)
{ {
Q_UNUSED(name);
setupUi(this); setupUi(this);
#if ((OPENSCENEGRAPH_MAJOR_VERSION == 2) & (OPENSCENEGRAPH_MINOR_VERSION > 8)) | (OPENSCENEGRAPH_MAJOR_VERSION > 2) #if ((OPENSCENEGRAPH_MAJOR_VERSION == 2) & (OPENSCENEGRAPH_MINOR_VERSION > 8)) | (OPENSCENEGRAPH_MAJOR_VERSION > 2)
graphicsView->setCameraManipulator(new osgEarth::Util::EarthManipulator); graphicsView->setCameraManipulator(new osgEarth::Util::EarthManipulator);
......
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