diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index 76c4fde4c142de7e24b6655c863b4fd70b5106f2..91b92bfdd2654e5f35a761f5da0a6614d000c249 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -32,6 +32,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include "LinkManager.h" +#include #include @@ -65,6 +66,7 @@ LinkManager::~LinkManager() void LinkManager::add(LinkInterface* link) { + if(!link) return; links.append(link); emit newLink(link); } @@ -73,6 +75,7 @@ void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol) { // Connect link to protocol // the protocol will receive new bytes from the link + if(!link || !protocol) return; connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray))); // Store the connection information in the protocol links map protocolLinks.insertMulti(protocol, link); @@ -91,7 +94,8 @@ bool LinkManager::connectAll() foreach (LinkInterface* link, links) { - if(! link->connect()) allConnected = false; + if(!link) {} + else if(!link->connect()) allConnected = false; } return allConnected; @@ -103,7 +107,9 @@ bool LinkManager::disconnectAll() foreach (LinkInterface* link, links) { - if(! link->disconnect()) allDisconnected = false; + static int i=0; + if(!link){} + else if(!link->disconnect()) allDisconnected = false; } return allDisconnected; @@ -111,14 +117,30 @@ bool LinkManager::disconnectAll() bool LinkManager::connectLink(LinkInterface* link) { + if(!link) return false; return link->connect(); } bool LinkManager::disconnectLink(LinkInterface* link) { + if(!link) return false; return link->disconnect(); } +bool LinkManager::removeLink(LinkInterface* link) +{ + if(link) + { + for (int i=0; i < QList(links).size(); i++) + { + if(link==links.at(i)) + { + links.removeAt(i); //remove from link list + } + } + } +} + /** * The access time is linear in the number of links. * diff --git a/src/comm/LinkManager.h b/src/comm/LinkManager.h index b1768758b2a356362c37d93ed85ca5c22c1ca3e9..8d283c3de0d3f1273bf41afdabdccd8724812d7a 100644 --- a/src/comm/LinkManager.h +++ b/src/comm/LinkManager.h @@ -67,6 +67,8 @@ public slots: void add(LinkInterface* link); void addProtocol(LinkInterface* link, ProtocolInterface* protocol); + bool removeLink(LinkInterface* link); + bool connectAll(); bool connectLink(LinkInterface* link); diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index d4b48cdc1143beda514fabbeb9dcd5e77eb693de..9bf345b44b8156f0d413645588d270f7abe51d31 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -34,6 +34,7 @@ This file is part of the QGROUNDCONTROL project #include "SerialLink.h" #include "LinkManager.h" #include +#include #ifdef _WIN32 #include "windows.h" #endif @@ -106,7 +107,7 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P SerialLink::~SerialLink() { disconnect(); - delete port; + if(port) delete port; port = NULL; } @@ -239,6 +240,8 @@ bool SerialLink::disconnect() port->close(); dataMutex.unlock(); + if(this->isRunning()) this->terminate(); //stop running the thread, restart it upon connect + bool closed = true; //port->isOpen(); @@ -516,7 +519,7 @@ bool SerialLink::setPortName(QString portName) this->porthandle = "\\\\.\\" + this->porthandle; } #endif - delete port; + if(port) delete port; port = new QextSerialPort(porthandle, QextSerialPort::Polling); port->setBaudRate(baudrate); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 69af7a9d1b56ef76563d197614f603b6e21837fa..263102ee3b796d979c20a2241070f9b4a464ea0e 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -93,6 +93,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), UAS::~UAS() { delete links; + links=NULL; } int UAS::getUASID() const @@ -124,6 +125,7 @@ void UAS::setSelected() void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) { + if (!link) return; if (!links->contains(link)) { addLink(link); @@ -365,9 +367,9 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) positionLock = true; // Send to patch antenna - 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); +// 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; case MAVLINK_MSG_ID_GPS_RAW: @@ -831,6 +833,7 @@ void UAS::sendMessage(mavlink_message_t message) void UAS::sendMessage(LinkInterface* link, mavlink_message_t message) { + if(!link) return; // Create buffer uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; // Write message into buffer, prepending start sign diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 0708aeef9f3b0e32e42db0b216e323a058cac989..33e57ba2514c5bc6138ac22f3b9a228362158e88 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -47,6 +47,7 @@ This file is part of the QGROUNDCONTROL project #endif #include "MAVLinkProtocol.h" #include "MAVLinkSettingsWidget.h" +#include "LinkManager.h" CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) { @@ -58,6 +59,10 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn // add link types ui.linkType->addItem("Serial",QGC_LINK_SERIAL); 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 configuration action for this link @@ -195,11 +200,20 @@ void CommConfigurationWindow::setLinkName(QString name) void CommConfigurationWindow::remove() { - link->disconnect(); - //delete link; - //delete action; + if(action) delete action; //delete action first since it has a pointer to link + action=NULL; + + 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(); - qDebug() << "TODO: Link cannot be deleted: CommConfigurationWindow::remove() NOT IMPLEMENTED!"; } void CommConfigurationWindow::connectionState(bool connect) diff --git a/src/ui/CommConfigurationWindow.h b/src/ui/CommConfigurationWindow.h index fce37dbbe380be280ff7f347bfb78d4b2b0a99c7..93f1566aeceb26a15d5f080291402eaa40f470bc 100644 --- a/src/ui/CommConfigurationWindow.h +++ b/src/ui/CommConfigurationWindow.h @@ -42,7 +42,14 @@ This file is part of the QGROUNDCONTROL project enum qgc_link_t { 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 diff --git a/src/ui/CommSettings.ui b/src/ui/CommSettings.ui index 8aec750ea97e720f99ae659f9a5c723cae78563f..71a4c30cd881d5eda30099d868921d2cd96e4d38 100644 --- a/src/ui/CommSettings.ui +++ b/src/ui/CommSettings.ui @@ -43,23 +43,7 @@ - - - - Serial Link - - - - - UDP - - - - - Simulation - - - + @@ -71,13 +55,8 @@ - 0 + -1 - - - MAVLink - - diff --git a/src/ui/SerialConfigurationWindow.cc b/src/ui/SerialConfigurationWindow.cc index 5542bc93bd382ec0971c464a00c644c7e3303c9b..e070fca798e6aba69fb58f7a33e1fc86a1353d46 100644 --- a/src/ui/SerialConfigurationWindow.cc +++ b/src/ui/SerialConfigurationWindow.cc @@ -509,12 +509,3 @@ void SerialConfigurationWindow::setLinkName(QString name) 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!"; -} - diff --git a/src/ui/SerialConfigurationWindow.h b/src/ui/SerialConfigurationWindow.h index d71fb95e2aa5f415f1033c93cab511fa66e07805..abfa5c138c0ea3ba8ffb5e7c118ff26ab2ce86c5 100644 --- a/src/ui/SerialConfigurationWindow.h +++ b/src/ui/SerialConfigurationWindow.h @@ -60,12 +60,6 @@ public slots: void setParityEven(); void setPortName(QString port); 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(); protected slots: diff --git a/src/ui/map3D/GCManipulator.cc b/src/ui/map3D/GCManipulator.cc index 6f2fb0e7f80bf0496ccf72707de2c132f7793bf4..05c9b246c9328055016a96095541e1251b17892c 100644 --- a/src/ui/map3D/GCManipulator.cc +++ b/src/ui/map3D/GCManipulator.cc @@ -254,10 +254,10 @@ GCManipulator::calcMovement(void) if (buttonMask == GUIEventAdapter::LEFT_MOUSE_BUTTON) { // rotate camera -#ifdef __APPLE__ - osg::Vec3d axis; -#else +#ifdef __WIN32__ osg::Vec3 axis; +#else + osg::Vec3d axis; #endif float angle; diff --git a/src/ui/map3D/QMap3D.cc b/src/ui/map3D/QMap3D.cc index ab4c98b915d22351867f28a6a43e06f1c5ea8b0d..83ff90179ab0be7bfda1b1eb7c49616a897892e3 100644 --- a/src/ui/map3D/QMap3D.cc +++ b/src/ui/map3D/QMap3D.cc @@ -39,7 +39,7 @@ QMap3D::QMap3D(QWidget * parent, const char * name, WindowFlags f) : QWidget(parent,f) { setupUi(this); - graphicsView->setCameraManipulator(new osgEarthUtil::EarthManipulator); + graphicsView->setCameraManipulator(new osgEarth::Util::EarthManipulator); graphicsView->setSceneData(new osg::Group); graphicsView->updateCamera(); show();