diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index cc7172cb8cb640a0a42df42d704eb585e7c53155..739334d6780d61ca22f9d578ceb8e6b74f7fc01f 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1148,13 +1148,12 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) case MAVLINK_MSG_ID_STATUSTEXT: { QByteArray b; - b.resize(MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN); + b.resize(MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN+1); mavlink_msg_statustext_get_text(&message, b.data()); - //b.append('\0'); + // Ensure NUL-termination + b[b.length()-1] = '\0'; QString text = QString(b); int severity = mavlink_msg_statustext_get_severity(&message); - //qDebug() << "RECEIVED STATUS:" << text;false - //emit statusTextReceived(severity, text); if (text.startsWith("#audio:")) { diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index 5468d2c93ae213f9c595dd0e288b0d22f31ef0fb..8e856aa4f15c0d511e19e4fd266a0cc8da73439a 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -93,14 +93,23 @@ DebugConsole::DebugConsole(QWidget *parent) : // Update measurements the first time updateTrafficMeasurements(); + // First connect management slots, then make sure to add all existing objects + // Connect to link manager to get notified about new links + connect(LinkManager::instance(), SIGNAL(newLink(LinkInterface*)), this, SLOT(addLink(LinkInterface*))); + // Connect to UAS manager to get notified about new UAS + connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(uasCreated(UASInterface*))); + // Get a list of all existing links links = QList(); foreach (LinkInterface* link, LinkManager::instance()->getLinks()) { addLink(link); } - // Connect to link manager to get notified about new links - connect(LinkManager::instance(), SIGNAL(newLink(LinkInterface*)), this, SLOT(addLink(LinkInterface*))); + // Get a list of all existing UAS + foreach (UASInterface* uas, UASManager::instance()->getUASList()) { + uasCreated(uas); + } + // Connect link combo box connect(m_ui->linkComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(linkSelected(int))); // Connect send button @@ -169,6 +178,12 @@ void DebugConsole::storeSettings() //qDebug() << "Storing settings!"; } +void DebugConsole::uasCreated(UASInterface* uas) +{ + connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), + this, SLOT(receiveTextMessage(int,int,int,QString)), Qt::UniqueConnection); +} + /** * Add a link to the debug console output */ @@ -183,8 +198,8 @@ void DebugConsole::addLink(LinkInterface* link) linkSelected(m_ui->linkComboBox->currentIndex()); // Register for name changes - connect(link, SIGNAL(nameChanged(QString)), this, SLOT(updateLinkName(QString))); - connect(link, SIGNAL(deleteLink(LinkInterface* const)), this, SLOT(removeLink(LinkInterface* const))); + connect(link, SIGNAL(nameChanged(QString)), this, SLOT(updateLinkName(QString)), Qt::UniqueConnection); + connect(link, SIGNAL(deleteLink(LinkInterface* const)), this, SLOT(removeLink(LinkInterface* const)), Qt::UniqueConnection); } void DebugConsole::removeLink(LinkInterface* const linkInterface) diff --git a/src/ui/DebugConsole.h b/src/ui/DebugConsole.h index fb631845ac26c800c3ef95112876ba56f7dd3dc7..4a7cf6b8debcf54ef2e5320510d981be32013228 100644 --- a/src/ui/DebugConsole.h +++ b/src/ui/DebugConsole.h @@ -45,6 +45,8 @@ namespace Ui class DebugConsole; } +class UASInterface; + /** * @brief Shows a debug console * @@ -61,6 +63,8 @@ public: public slots: /** @brief Add a link to the list of monitored links */ void addLink(LinkInterface* link); + /** @brief Add a UAS to the list of monitored UAS */ + void uasCreated(UASInterface* uas); /** @brief Remove a link from the list */ void removeLink(LinkInterface* const link); /** @brief Update a link name */ diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index cfeaae750851dacc2776134cc0df9464d7fc1e60..f83027efaddd6b5b50757d1ba86d6e4ea4f0363f 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -128,8 +128,8 @@ HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) : if (font.family() != fontFamilyName) qDebug() << "ERROR! Font not loaded: " << fontFamilyName; // Connect with UAS - connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); - //start(); + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)), Qt::UniqueConnection); + setActiveUAS(UASManager::instance()->getActiveUAS()); } HDDisplay::~HDDisplay() @@ -476,6 +476,8 @@ void HDDisplay::renderOverlay() */ void HDDisplay::setActiveUAS(UASInterface* uas) { + if (!uas) + return; // Disconnect any previously connected active UAS if (this->uas != NULL) { removeSource(this->uas); diff --git a/src/ui/HSIDisplay.cc b/src/ui/HSIDisplay.cc index 736b5f27956992208974ab87ee35c994c4388536..624353d1607dafe8fd976a625a7df32451496b71 100644 --- a/src/ui/HSIDisplay.cc +++ b/src/ui/HSIDisplay.cc @@ -178,6 +178,8 @@ HSIDisplay::HSIDisplay(QWidget *parent) : connect(&statusClearTimer, SIGNAL(timeout()), this, SLOT(clearStatusMessage())); statusClearTimer.start(3000); + setActiveUAS(UASManager::instance()->getActiveUAS()); + setFocusPolicy(Qt::StrongFocus); } diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index ae2fccd813f0a21db4db1898cc12c02247b8a777..036779e70031330f3929512ef9d8e72132b21abc 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -1682,43 +1682,17 @@ void MainWindow::UASCreated(UASInterface* uas) break; } + // XXX The multi-UAS selection menu has been disabled for now, + // its redundant with right-clicking the UAS in the list. + // this code piece might be removed later if this is the final + // conclusion (May 2013) // QAction* uasAction = new QAction(icon, tr("Select %1 for control").arg(uas->getUASName()), ui.menuConnected_Systems); // connect(uas, SIGNAL(systemRemoved()), uasAction, SLOT(deleteLater())); // connect(uasAction, SIGNAL(triggered()), uas, SLOT(setSelected())); - connect(uas, SIGNAL(systemSpecsChanged(int)), this, SLOT(UASSpecsChanged(int))); - // ui.menuConnected_Systems->addAction(uasAction); - // FIXME Should be not inside the mainwindow - if (debugConsoleDockWidget) - { - DebugConsole *debugConsole = dynamic_cast(debugConsoleDockWidget->widget()); - if (debugConsole) - { - connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), - debugConsole, SLOT(receiveTextMessage(int,int,int,QString))); - } - } - - // Health / System status indicator - if (infoDockWidget) - { - UASInfoWidget *infoWidget = dynamic_cast(infoDockWidget->widget()); - if (infoWidget) - { - infoWidget->addUAS(uas); - } - } - // UAS List - if (listDockWidget) - { - UASListWidget *listWidget = dynamic_cast(listDockWidget->widget()); - if (listWidget) - { - listWidget->addUAS(uas); - } - } + connect(uas, SIGNAL(systemSpecsChanged(int)), this, SLOT(UASSpecsChanged(int))); // HIL showHILConfigurationWidget(uas); @@ -1730,25 +1704,12 @@ void MainWindow::UASCreated(UASInterface* uas) } - - // Line chart - //if (!linechartWidget) - //{ - - // Center widgets - - //linechartWidget->addSystem(uas); - - linechartWidget->addSource(mavlinkDecoder); - //addCentralWidget(linechartWidget, tr("Realtime Plot")); - if (dataView->centralWidget() != linechartWidget) - { - dataView->setCentralWidget(linechartWidget); - linechartWidget->show(); - } - //dataView->setCentralWidget(linechartWidget); - //linechartWidget->show(); - //} + linechartWidget->addSource(mavlinkDecoder); + if (dataView->centralWidget() != linechartWidget) + { + dataView->setCentralWidget(linechartWidget); + linechartWidget->show(); + } // Load default custom widgets for this autopilot type loadCustomWidgetsFromDefaults(uas->getSystemTypeName(), uas->getAutopilotTypeName()); diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 73f38cea07d5c47b69e55346e5b65c4b75c96042..6fb68338334d1740e754943aa103aa8c9f0f4a91 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -81,6 +81,7 @@ + diff --git a/src/ui/QGCWaypointListMulti.cc b/src/ui/QGCWaypointListMulti.cc index 53a0065dff5491e45e413c9e8fee843996271c52..9cbe050d7449e007e16a0c810cd18445e89a51d7 100644 --- a/src/ui/QGCWaypointListMulti.cc +++ b/src/ui/QGCWaypointListMulti.cc @@ -15,6 +15,12 @@ QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) : WaypointList* list = new WaypointList(ui->stackedWidget, NULL); lists.insert(offline_uas_id, list); ui->stackedWidget->addWidget(list); + + if (UASManager::instance()->getActiveUAS()) { + systemCreated(UASManager::instance()->getActiveUAS()); + systemSetActive(UASManager::instance()->getActiveUAS()->getUASID()); + } + } void QGCWaypointListMulti::systemDeleted(QObject* uas) diff --git a/src/ui/uas/UASInfoWidget.cc b/src/ui/uas/UASInfoWidget.cc index b09bb9d632636ac751e825e919c0c13556997086..8042d88d0c6fe0f578ca27195aa58bc4f2279bce 100644 --- a/src/ui/uas/UASInfoWidget.cc +++ b/src/ui/uas/UASInfoWidget.cc @@ -34,7 +34,7 @@ This file is part of the PIXHAWK project #include #include #include -#include +#include #include #include #include @@ -46,20 +46,12 @@ UASInfoWidget::UASInfoWidget(QWidget *parent, QString name) : QWidget(parent) { ui.setupUi(this); this->name = name; - - connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); - activeUAS = NULL; - //instruments = new QMap(); - - // Set default battery type - // setBattery(0, LIPOLY, 3); - startTime = MG::TIME::getGroundTimeNow(); - // startVoltage = 0.0f; + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); + setActiveUAS(UASManager::instance()->getActiveUAS()); - // lastChargeLevel = 0.5f; - // lastRemainingTime = 1; + startTime = QGC::groundTimeMilliseconds(); // Set default values /** Set two voltage decimals and zero charge level decimals **/ @@ -117,7 +109,8 @@ void UASInfoWidget::addUAS(UASInterface* uas) void UASInfoWidget::setActiveUAS(UASInterface* uas) { - activeUAS = uas; + if (uas) + activeUAS = uas; } void UASInfoWidget::updateBattery(UASInterface* uas, double voltage, double percent, int seconds) diff --git a/src/ui/uas/UASListWidget.cc b/src/ui/uas/UASListWidget.cc index e0b52e43239839300dace1b111a1bea294042332..26f64a949d2ff33fa188cfc721f4d60e3ded08af 100644 --- a/src/ui/uas/UASListWidget.cc +++ b/src/ui/uas/UASListWidget.cc @@ -67,6 +67,11 @@ UASListWidget::UASListWidget(QWidget *parent) : QWidget(parent), m_ui(new Ui::UA this->setVisible(false); connect(UASManager::instance(),SIGNAL(UASCreated(UASInterface*)),this,SLOT(addUAS(UASInterface*))); + + // Get a list of all existing UAS + foreach (UASInterface* uas, UASManager::instance()->getUASList()) { + addUAS(uas); + } } UASListWidget::~UASListWidget()