From 6bf930650a44022db1bd1c9c1cc8d9774fcd31fa Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 6 Feb 2014 16:07:16 +0100 Subject: [PATCH] fixes #123 by displaying the Audio test in the GUI * added methods to get results in context * added signal to indicate audio test completed * updated GUI to display results * changed test run methods to non-const to be consistent with voice lib * Logic in GUI to avoid parallel / interfering tests * Fixed wrong Q_ASSERT message and QTimer::singleShot in voice_vatlib.cpp --- samples/blackgui/mainwindow.cpp | 2 +- samples/blackgui/mainwindow.h | 8 ++++ samples/blackgui/mainwindow.ui | 22 +++++++---- samples/blackgui/mainwindow_init.cpp | 1 + samples/blackgui/mainwindow_voice.cpp | 41 +++++++++++++++++--- src/blackcore/context_voice.cpp | 28 ++++++++++++-- src/blackcore/context_voice.h | 14 ++++++- src/blackcore/context_voice_interface.cpp | 27 ++++++++++--- src/blackcore/context_voice_interface.h | 19 ++++++++- src/blackcore/voice_vatlib.cpp | 47 +++++++++++------------ 10 files changed, 158 insertions(+), 51 deletions(-) diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 27a163e99..e0b499f82 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -22,7 +22,7 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint) : Qt::Tool), ui(new Ui::MainWindow), m_infoWindow(nullptr), - m_init(false), m_windowMode(windowMode), + m_init(false), m_windowMode(windowMode), m_audioTestRunning(NoAudioTest), // misc m_dBusConnection("dummy"), // table view models diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 6345e406f..318703963 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -95,11 +95,19 @@ protected: MainPageSettings = 7 }; + enum AudioTest + { + NoAudioTest, + SquelchTest, + MicrophoneTest + }; + private: QScopedPointer ui; CInfoWindow *m_infoWindow; bool m_init; GuiModes::WindowMode m_windowMode; + AudioTest m_audioTestRunning; QDBusConnection m_dBusConnection; // the table view models diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index 084caea82..3d5537107 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -1799,7 +1799,7 @@ QStatusBar QLabel { - 2 + 0 @@ -2230,13 +2230,6 @@ QStatusBar QLabel { - - - - true - - - @@ -2244,6 +2237,19 @@ QStatusBar QLabel { + + + + + 16777215 + 40 + + + + true + + + diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 20c1cf5c0..3233b6a39 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -200,6 +200,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); this->connect(this->m_timerCollectedCockpitUpdates, &QTimer::timeout, this, &MainWindow::sendCockpitUpdates); this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &MainWindow::audioTestUpdate); + connect = this->connect(this->m_contextVoice, &IContextVoice::audioTestCompleted, this, &MainWindow::audioTestUpdate); // start timers, update timers will be started when network is connected this->m_timerContextWatchdog->start(2 * 1000); diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp index c3210656e..b3fa15833 100644 --- a/samples/blackgui/mainwindow_voice.cpp +++ b/samples/blackgui/mainwindow_voice.cpp @@ -165,19 +165,24 @@ void MainWindow::startAudioTest() } QObject *sender = QObject::sender(); - this->m_timerAudioTests->start(625); // I let this run for 10*625ms, so there is enough overhead to really complete it + this->m_timerAudioTests->start(600); // I let this run for ms, so there is enough overhead to really complete it this->ui->prb_SettingsAudioTestProgress->setValue(0); + this->ui->pte_SettingsAudioTestActionAndResult->clear(); if (sender == this->ui->pb_SettingsAudioMicrophoneTest) { + this->m_audioTestRunning = MicrophoneTest; this->m_contextVoice->runMicrophoneTest(); - this->ui->le_SettingsAudioTestActionAndResult->setText("Speak normally for 5 seconds"); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Speak normally for 5 seconds"); } else if (sender == this->ui->pb_SettingsAudioSquelchTest) { + this->m_audioTestRunning = SquelchTest; this->m_contextVoice->runSquelchTest(); - this->ui->le_SettingsAudioTestActionAndResult->setText("Silence for 5 seconds"); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Silence for 5 seconds"); } this->ui->prb_SettingsAudioTestProgress->setVisible(true); + this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(false); + this->ui->pb_SettingsAudioSquelchTest->setEnabled(false); } /* @@ -186,15 +191,39 @@ void MainWindow::startAudioTest() void MainWindow::audioTestUpdate() { int v = this->ui->prb_SettingsAudioTestProgress->value(); - if (v < 100) + QObject *sender = this->sender(); + + if (v < 100 && (sender == m_timerAudioTests)) { + // timer update, increasing progress this->ui->prb_SettingsAudioTestProgress->setValue(v + 10); } else { - // fetch results - // TODO this->m_timerAudioTests->stop(); + this->ui->prb_SettingsAudioTestProgress->setValue(100); + if (sender == m_timerAudioTests) return; // just timer update + + // getting here we assume the audio test finished signal + // fetch results + this->ui->pte_SettingsAudioTestActionAndResult->clear(); + if (this->m_contextVoiceAvailable) + { + if (this->m_audioTestRunning == SquelchTest) + { + double s = this->m_contextVoice->getSquelchValue(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(QString::number(s)); + } + else if (this->m_audioTestRunning == MicrophoneTest) + { + QString m = this->m_contextVoice->getMicrophoneTestResult(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(m); + } + } + this->m_audioTestRunning = NoAudioTest; + this->m_timerAudioTests->stop(); + this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(true); + this->ui->pb_SettingsAudioSquelchTest->setEnabled(true); this->ui->prb_SettingsAudioTestProgress->setVisible(false); } } diff --git a/src/blackcore/context_voice.cpp b/src/blackcore/context_voice.cpp index cb6716dc7..07d4faeee 100644 --- a/src/blackcore/context_voice.cpp +++ b/src/blackcore/context_voice.cpp @@ -22,8 +22,12 @@ namespace BlackCore { Q_ASSERT(runtime); - // 1. Init by "network driver" + // 1. Init by "voice driver" this->m_voice = new CVoiceVatlib(this); + + // 2. Signal / slots + connect(this->m_voice, &CVoiceVatlib::micTestFinished, this, &CContextVoice::audioTestCompleted); + connect(this->m_voice, &CVoiceVatlib::squelchTestFinished, this, &CContextVoice::audioTestCompleted); } /* @@ -229,7 +233,7 @@ namespace BlackCore /* * Mic test. */ - void CContextVoice::runMicrophoneTest() const + void CContextVoice::runMicrophoneTest() { Q_ASSERT(this->m_voice); this->m_voice->runMicrophoneTest(); @@ -238,11 +242,29 @@ namespace BlackCore /* * Squelch test. */ - void CContextVoice::runSquelchTest() const + void CContextVoice::runSquelchTest() { Q_ASSERT(this->m_voice); this->m_voice->runSquelchTest(); } + /* + * Microphone test + */ + QString CContextVoice::getMicrophoneTestResult() const + { + Q_ASSERT(this->m_voice); + return this->m_voice->micTestResultAsString(); + } + + /* + * Squelch value + */ + double CContextVoice::getSquelchValue() const + { + Q_ASSERT(this->m_voice); + return static_cast(this->m_voice->inputSquelch()); + } + } // namespace diff --git a/src/blackcore/context_voice.h b/src/blackcore/context_voice.h index ba8980f13..a1b9dd602 100644 --- a/src/blackcore/context_voice.h +++ b/src/blackcore/context_voice.h @@ -159,12 +159,22 @@ namespace BlackCore /*! * \copydoc IContextVoice::runMicrophoneTest() */ - virtual void runMicrophoneTest() const; + virtual void runMicrophoneTest(); /*! * \copydoc IContextVoice::runSquelchTest() */ - virtual void runSquelchTest() const; + virtual void runSquelchTest(); + + /*! + * \copydoc IContextVoice::getMicrophoneTestResult() + */ + virtual QString getMicrophoneTestResult() const; + + /*! + * \copydoc IContextVoice::getSquelchValue() + */ + virtual double getSquelchValue() const; private: CVoiceVatlib *m_voice; //!< underlying voice lib diff --git a/src/blackcore/context_voice_interface.cpp b/src/blackcore/context_voice_interface.cpp index beed1ef55..062920b95 100644 --- a/src/blackcore/context_voice_interface.cpp +++ b/src/blackcore/context_voice_interface.cpp @@ -26,9 +26,10 @@ namespace BlackCore /* * Workaround for signals, not working without, but why? */ - void IContextVoice::relaySignals(const QString & /** serviceName **/, QDBusConnection & /** connection **/) + void IContextVoice::relaySignals(const QString &serviceName, QDBusConnection &connection) { - // void + connection.connect(serviceName, IContextVoice::ServicePath(), IContextVoice::InterfaceName(), + "audioTestCompleted", this, SIGNAL(audioTestCompleted())); } /* @@ -154,19 +155,35 @@ namespace BlackCore /* * MIC test */ - void IContextVoice::runMicrophoneTest() const + void IContextVoice::runMicrophoneTest() { this->m_dBusInterface->callDBus(QLatin1Literal("runMicrophoneTest")); } /* - * MIC test + * Mic test */ - void IContextVoice::runSquelchTest() const + void IContextVoice::runSquelchTest() { this->m_dBusInterface->callDBus(QLatin1Literal("runSquelchTest")); } + /* + * Test result + */ + QString IContextVoice::getMicrophoneTestResult() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getMicrophoneTestResult")); + } + + /* + * Squelch value + */ + double IContextVoice::getSquelchValue() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSquelchValue")); + } + /* * Volumes, by COM systems */ diff --git a/src/blackcore/context_voice_interface.h b/src/blackcore/context_voice_interface.h index 808895143..49b18bbcd 100644 --- a/src/blackcore/context_voice_interface.h +++ b/src/blackcore/context_voice_interface.h @@ -201,13 +201,28 @@ namespace BlackCore /*! * \brief Microphone test */ - virtual void runMicrophoneTest() const; + virtual void runMicrophoneTest(); /*! * \brief Microphone test */ - virtual void runSquelchTest() const; + virtual void runSquelchTest(); + /*! + * \brief Get the microphone test result + */ + virtual QString getMicrophoneTestResult() const; + + /*! + * \brief Get the squelch value + */ + virtual double getSquelchValue() const; + + signals: + /*! + * \brief Audio test has been completed + */ + void audioTestCompleted(); }; } diff --git a/src/blackcore/voice_vatlib.cpp b/src/blackcore/voice_vatlib.cpp index a55e2347f..d9ef10132 100644 --- a/src/blackcore/voice_vatlib.cpp +++ b/src/blackcore/voice_vatlib.cpp @@ -112,7 +112,7 @@ namespace BlackCore */ void CVoiceVatlib::setInputDevice(const BlackMisc::Voice::CAudioDevice &device) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); if (!device.isValid()) { qWarning() << "Cannot set invalid input device!"; @@ -142,7 +142,7 @@ namespace BlackCore */ void CVoiceVatlib::setOutputDevice(const BlackMisc::Voice::CAudioDevice &device) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); if (!device.isValid()) { qWarning() << "Cannot set invalid output device!"; @@ -170,7 +170,7 @@ namespace BlackCore */ BlackMisc::Voice::CVoiceRoomList CVoiceVatlib::getComVoiceRoomsWithAudioStatus() const { - Q_ASSERT_X(m_voiceRooms.size() == 2, "CVoiceClientVatlib", "Wrong numer of COM voice rooms"); + Q_ASSERT_X(m_voiceRooms.size() == 2, "CVoiceVatlib", "Wrong numer of COM voice rooms"); CVoiceRoomList voiceRooms; if (m_voice->IsValid() && m_voice->IsSetup()) { @@ -208,8 +208,8 @@ namespace BlackCore */ void CVoiceVatlib::switchAudioOutput(const ComUnit comUnit, bool enable) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); try { m_voice->SetOutoutState(static_cast(comUnit), 0, enable); @@ -226,7 +226,7 @@ namespace BlackCore */ void CVoiceVatlib::runSquelchTest() { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); try { @@ -246,19 +246,18 @@ namespace BlackCore */ void CVoiceVatlib::runMicrophoneTest() { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); try { m_voice->BeginMicTest(); + // Start the timer only if no exception was thrown before + QTimer::singleShot(5000, this, SLOT(onEndMicTest())); } catch (...) { this->exceptionDispatcher(Q_FUNC_INFO); } - - // Start the timer only if no exception was thrown before - QTimer::singleShot(5000, this, SLOT(onEndMicTest())); } /* @@ -321,8 +320,8 @@ namespace BlackCore */ void CVoiceVatlib::joinVoiceRoom(const ComUnit comUnit, const BlackMisc::Voice::CVoiceRoom &voiceRoom) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); if (!voiceRoom.isValid()) { @@ -354,8 +353,8 @@ namespace BlackCore CVoiceRoom vr = this->voiceRoomForUnit(comUnit); if (!vr.isConnected()) return; - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); try { @@ -383,8 +382,8 @@ namespace BlackCore */ void CVoiceVatlib::setRoomOutputVolume(const ComUnit comUnit, const qint32 volume) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); try { @@ -401,8 +400,8 @@ namespace BlackCore */ void CVoiceVatlib::startTransmitting(const ComUnit comUnit) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); try { @@ -419,8 +418,8 @@ namespace BlackCore */ void CVoiceVatlib::stopTransmitting(const ComUnit comUnit) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); - Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceClientVatlib", "Room index out of bounds!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsRoomValid(static_cast(comUnit)), "CVoiceVatlib", "Room index out of bounds!"); try { m_voice->SetMicState(static_cast(comUnit), false); @@ -486,7 +485,7 @@ namespace BlackCore */ void CVoiceVatlib::timerEvent(QTimerEvent *) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); try { @@ -504,7 +503,7 @@ namespace BlackCore */ void CVoiceVatlib::onEndFindSquelch() { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); try { @@ -520,7 +519,7 @@ namespace BlackCore void CVoiceVatlib::onEndMicTest() { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); try { @@ -538,7 +537,7 @@ namespace BlackCore */ void CVoiceVatlib::onUserJoinedLeft(const ComUnit comUnit) { - Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceClientVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); Q_ASSERT_X(m_temporaryUserRoomIndex == CVoiceVatlib::InvalidRoomIndex, "CVoiceClientVatlib::onUserJoinedLeft", "Cannot list users for two rooms in parallel!"); try {