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/MainWindow.cc b/src/ui/MainWindow.cc index 0c178194e5141d839c6f9a6c5038a8cc6d9e16cd..1f70763d84afec6cfbf3613304545a7811318781 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -1725,43 +1725,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); @@ -1773,25 +1747,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/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()