From ea8198d26ec5cac955184ac14ad0bb152cea8931 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 12 Apr 2020 16:32:20 +0200 Subject: [PATCH] [AFV] Allow to set the tx/rx values for the AFV client Simplified function --- src/blackcore/afv/clients/afvclient.cpp | 135 +++++++++++++++++------- src/blackcore/afv/clients/afvclient.h | 7 ++ src/blackcore/context/contextaudio.cpp | 16 +++ src/blackcore/context/contextaudio.h | 5 + 4 files changed, 127 insertions(+), 36 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 98b6cdfc6..3a784cb3e 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -581,6 +581,60 @@ namespace BlackCore return this->isTransmittingTransceiver(comUnitToTransceiverId(comUnit)); } + void CAfvClient::setRxTx(bool rx1, bool tx1, bool rx2, bool tx2) + { + QVector txs; + if (tx1) + { + const TxTransceiverDto tx = { comUnitToTransceiverId(CComSystem::Com1) }; + txs.push_back(tx); + } + if (tx2) + { + const TxTransceiverDto tx = { comUnitToTransceiverId(CComSystem::Com2) }; + txs.push_back(tx); + } + this->setTransmittingTransceivers(txs); + + QSet enabledTransceivers; + if (rx1 || tx1) + { + enabledTransceivers.insert(comUnitToTransceiverId(CComSystem::Com1)); + } + + if (rx2 || tx2) + { + enabledTransceivers.insert(comUnitToTransceiverId(CComSystem::Com2)); + } + + { + QMutexLocker lock(&m_mutexTransceivers); + m_enabledTransceivers = enabledTransceivers; + } + + // force update + this->onTimerUpdate(); + } + + void CAfvClient::getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const + { + rx1 = false; + rx2 = false; + tx1 = false; + tx2 = false; + + const QSet enabled = getEnabledTransceivers(); + rx1 = enabled.contains(comUnitToTransceiverId(CComSystem::Com1)); + rx2 = enabled.contains(comUnitToTransceiverId(CComSystem::Com2)); + + const QVector transmits = getTransmittingTransceivers(); + for (const TxTransceiverDto &dto : transmits) + { + if (dto.id == comUnitToTransceiverId(CComSystem::Com1)) { tx1 = true; } + if (dto.id == comUnitToTransceiverId(CComSystem::Com2)) { tx2 = true; } + } + } + QVector CAfvClient::getTransceivers() const { QMutexLocker lock(&m_mutexTransceivers); @@ -873,7 +927,7 @@ namespace BlackCore { QStringList coms; QMutexLocker lock(&m_mutexSampleProviders); - if (!m_soundcardSampleProvider) { return {{ QString(), QString()}}; } + if (!m_soundcardSampleProvider) { return {{ QString(), QString() }}; } coms << m_soundcardSampleProvider->getReceivingCallsignsString(comUnitToTransceiverId(CComSystem::Com1)); coms << m_soundcardSampleProvider->getReceivingCallsignsString(comUnitToTransceiverId(CComSystem::Com2)); return coms; @@ -1000,43 +1054,52 @@ namespace BlackCore transceiverCom1.frequencyHz = this->getAliasFrequencyHz(f1); transceiverCom2.frequencyHz = this->getAliasFrequencyHz(f2); - bool tx1 = true; - bool rx1 = true; - bool tx2 = false; - bool rx2 = true; - + QVector newEnabledTransceivers; if (m_integratedComUnit) { - tx1 = com1.isTransmitEnabled(); - rx1 = com1.isReceiveEnabled(); - tx2 = com2.isTransmitEnabled(); // we only allow one (1) transmit - rx2 = com2.isReceiveEnabled(); + const bool tx1 = com1.isTransmitEnabled(); + const bool rx1 = com1.isReceiveEnabled(); + const bool tx2 = com2.isTransmitEnabled(); // we only allow one (1) transmit + const bool rx2 = com2.isReceiveEnabled(); + + // enable, we currently treat receive as enable + // flight sim cockpits normally use rx and tx + // AFV uses tx and enable + const bool e1 = rx1; + const bool e2 = rx2; + + // transceivers + const QVector newTransceivers { transceiverCom1, transceiverCom2 }; + QSet newEnabledTransceiverIds; + QVector newTransmittingTransceivers; + if (e1) { newEnabledTransceivers.push_back(transceiverCom1); newEnabledTransceiverIds.insert(transceiverCom1.id); } + if (e2) { newEnabledTransceivers.push_back(transceiverCom2); newEnabledTransceiverIds.insert(transceiverCom2.id); } + + // Transmitting transceivers, currently ALLOW ONLY ONE + if (tx1 && e1) { newTransmittingTransceivers.push_back(transceiverCom1); } + else if (tx2 && e2) { newTransmittingTransceivers.push_back(transceiverCom2); } + + // lock and update + { + QMutexLocker lock(&m_mutexTransceivers); + m_transceivers = newTransceivers; + m_enabledTransceivers = newEnabledTransceiverIds; + m_transmittingTransceivers = newTransmittingTransceivers; + } } - - // enable, we currently treat receive as enable - // flight sim cockpits normally use rx and tx - // AFV uses tx and enable - const bool e1 = rx1; - const bool e2 = rx2; - - // transceivers - QSet newEnabledTransceiverIds; - QVector newTransceivers { transceiverCom1, transceiverCom2 }; - QVector newEnabledTransceivers; - QVector newTransmittingTransceivers; - if (e1) { newEnabledTransceivers.push_back(transceiverCom1); newEnabledTransceiverIds.insert(transceiverCom1.id); } - if (e2) { newEnabledTransceivers.push_back(transceiverCom2); newEnabledTransceiverIds.insert(transceiverCom2.id); } - - // Transmitting transceivers, currently ALLOW ONLY ONE - if (tx1 && e1) { newTransmittingTransceivers.push_back(transceiverCom1); } - else if (tx2 && e2) { newTransmittingTransceivers.push_back(transceiverCom2); } - - // lock and update + else { - QMutexLocker lock(&m_mutexTransceivers); - m_transceivers = newTransceivers; - m_enabledTransceivers = newEnabledTransceiverIds; - m_transmittingTransceivers = newTransmittingTransceivers; + // update position and frequencies, but keep enabled as it was + const QSet ids = getEnabledTransceivers(); + if (ids.contains(comUnitToTransceiverId(CComSystem::Com1))) + { + newEnabledTransceivers.push_back(transceiverCom1); + } + + if (ids.contains(comUnitToTransceiverId(CComSystem::Com2))) + { + newEnabledTransceivers.push_back(transceiverCom2); + } } // in connection and soundcard only use the enabled tarnsceivers @@ -1112,12 +1175,12 @@ namespace BlackCore // change to aliased frequency if needed { QMutexLocker lock(&m_mutex); - auto it = std::find_if(m_aliasedStations.begin(), m_aliasedStations.end(), [roundedFrequencyHz](const StationDto & d) + const auto it = std::find_if(m_aliasedStations.constBegin(), m_aliasedStations.constEnd(), [roundedFrequencyHz](const StationDto & d) { return d.frequencyAliasHz == roundedFrequencyHz; }); - if (it != m_aliasedStations.end()) + if (it != m_aliasedStations.constEnd()) { if (sApp && sApp->getIContextNetwork()) { diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 838e79b8a..44b69c1ad 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -168,6 +168,13 @@ namespace BlackCore bool isTransmittingdComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const; //! @} + //! Simplified enable/disable + //! \threadsafe + //! @{ + void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2); + void getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const; + //! @} + //! Get transceivers //! \threadsafe //! @{ diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 1cbd03d23..72dbe42f0 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -252,6 +252,22 @@ namespace BlackCore } } + void CContextAudioBase::setRxTx(bool rx1, bool tx1, bool rx2, bool tx2) + { + if (m_voiceClient) + { + m_voiceClient->setRxTx(rx1, tx1, rx2, tx2); + } + } + + void CContextAudioBase::getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const + { + if (m_voiceClient) + { + m_voiceClient->setRxTx(rx1, tx1, rx2, tx2); + } + } + const CIdentifier &CContextAudioBase::audioRunsWhere() const { static const CIdentifier i("CContextAudioBaseImpl"); diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index 45b000c86..6f549b222 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -148,6 +148,11 @@ namespace BlackCore void disableVoiceClient() { this->terminateVoiceClient(); } //! @} + //! Receive/transmit @{ + void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2); + void getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const; + //! @} + // -------- parts which can run in core and GUI, referring to local voice client ------------ //! Audio devices