From a41fb7cf7446135dcec3b394a45c6f7550c73163 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 6 Sep 2015 13:15:07 -0700 Subject: [PATCH] Fix UT only shutdown ordering crash --- src/GAudioOutput.cc | 21 +-------------------- src/GAudioOutput.h | 6 +----- src/uas/UAS.cc | 26 ++++++++++++++++++-------- src/uas/UAS.h | 3 +++ 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index 9725a54c4..82d996e22 100644 --- a/src/GAudioOutput.cc +++ b/src/GAudioOutput.cc @@ -55,7 +55,6 @@ GAudioOutput::GAudioOutput(QObject *parent) : worker->moveToThread(thread); connect(this, &GAudioOutput::textToSpeak, worker, &QGCAudioWorker::say); - connect(this, &GAudioOutput::beepOnce, worker, &QGCAudioWorker::beep); connect(thread, &QThread::finished, thread, &QObject::deleteLater); connect(thread, &QThread::finished, worker, &QObject::deleteLater); thread->start(); @@ -82,28 +81,10 @@ bool GAudioOutput::isMuted() return muted; } -bool GAudioOutput::say(QString text, int severity) +bool GAudioOutput::say(const QString& text, int severity) { if (!muted) { emit textToSpeak(text, severity); } return true; } - -/** - * @param text This message will be played after the alert beep - */ -bool GAudioOutput::alert(QString text) -{ - if (!muted) { - emit textToSpeak(text, 1); - } - return true; -} - -void GAudioOutput::beep() -{ - if (!muted) { - emit beepOnce(); - } -} diff --git a/src/GAudioOutput.h b/src/GAudioOutput.h index ffbd49dbf..5297a079d 100644 --- a/src/GAudioOutput.h +++ b/src/GAudioOutput.h @@ -77,11 +77,7 @@ public: public slots: /** @brief Say this text if current output priority matches */ - bool say(QString text, int severity = 6); - /** @brief Play alert sound and say notification message */ - bool alert(QString text); - /** @brief Play emergency sound once */ - void beep(); + bool say(const QString& text, int severity = 6); /** @brief Mute/unmute sound */ void mute(bool mute); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 75bb69abb..c4e4616f6 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -348,7 +348,7 @@ void UAS::updateState() connectionLost = true; receivedMode = false; QString audiostring = QString("Link lost to system %1").arg(this->getUASID()); - GAudioOutput::instance()->say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_ALERT); + _say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_ALERT); } // Update connection loss time on each iteration @@ -362,7 +362,7 @@ void UAS::updateState() if (connectionLost && (heartbeatInterval < timeoutIntervalHeartbeat)) { QString audiostring = QString("Link regained to system %1").arg(this->getUASID()); - GAudioOutput::instance()->say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_NOTICE); + _say(audiostring.toLower(), GAudioOutput::AUDIO_SEVERITY_NOTICE); connectionLost = false; connectionLossTime = 0; emit heartbeatTimeout(false, 0); @@ -553,12 +553,12 @@ void UAS::receiveMessage(mavlink_message_t message) if (statechanged && ((int)state.system_status == (int)MAV_STATE_CRITICAL || state.system_status == (int)MAV_STATE_EMERGENCY)) { - GAudioOutput::instance()->say(QString("Emergency for system %1").arg(this->getUASID()), GAudioOutput::AUDIO_SEVERITY_EMERGENCY); + _say(QString("Emergency for system %1").arg(this->getUASID()), GAudioOutput::AUDIO_SEVERITY_EMERGENCY); QTimer::singleShot(3000, GAudioOutput::instance(), SLOT(startEmergency())); } else if (modechanged || statechanged) { - GAudioOutput::instance()->say(audiostring.toLower()); + _say(audiostring.toLower()); } } @@ -621,7 +621,7 @@ void UAS::receiveMessage(mavlink_message_t message) /* warn only every 12 seconds */ && (QGC::groundTimeUsecs() - lastVoltageWarning) > 12000000) { - GAudioOutput::instance()->say(QString("Voltage warning for system %1: %2 volts").arg(getUASID()).arg(lpVoltage, 0, 'f', 1, QChar(' '))); + _say(QString("Voltage warning for system %1: %2 volts").arg(getUASID()).arg(lpVoltage, 0, 'f', 1, QChar(' '))); lastVoltageWarning = QGC::groundTimeUsecs(); lastTickVoltageValue = tickLowpassVoltage; } @@ -1198,7 +1198,7 @@ void UAS::receiveMessage(mavlink_message_t message) mavlink_msg_mission_item_reached_decode(&message, &wpr); waypointManager.handleWaypointReached(message.sysid, message.compid, &wpr); QString text = QString("System %1 reached waypoint %2").arg(getUASID()).arg(wpr.seq); - GAudioOutput::instance()->say(text); + _say(text); emit textMessageReceived(message.sysid, message.compid, MAV_SEVERITY_INFO, text); } break; @@ -1247,7 +1247,7 @@ void UAS::receiveMessage(mavlink_message_t message) { text.remove("#"); emit textMessageReceived(uasId, message.compid, severity, text); - GAudioOutput::instance()->say(text.toLower(), severity); + _say(text.toLower(), severity); } else { @@ -3393,7 +3393,7 @@ void UAS::startLowBattAlarm() { if (!lowBattAlarm) { - GAudioOutput::instance()->alert(tr("System %1 has low battery").arg(getUASID())); + _say(tr("System %1 has low battery").arg(getUASID())); lowBattAlarm = true; } } @@ -3465,3 +3465,13 @@ void UAS::unsetRCToParameterMap() _vehicle->sendMessage(message); } } + +void UAS::_say(const QString& text, int severity) +{ +#ifndef UNITTEST_BUILD + GAudioOutput::instance()->say(text, severity); +#else + Q_UNUSED(text) + Q_UNUSED(severity) +#endif +} diff --git a/src/uas/UAS.h b/src/uas/UAS.h index e6abf766a..39862eb34 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -981,6 +981,9 @@ protected slots: /** @brief Read settings from disk */ void readSettings(); +private: + void _say(const QString& text, int severity = 6); + private: Vehicle* _vehicle; }; -- 2.22.0