From 91b65fa2b6f949d9ed5121f29d13ea59c8b1cacb Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 30 Sep 2019 23:52:46 +0200 Subject: [PATCH] Ref T730, AFV client fixes * correct quint32 for frequency * make sure frequencies are not updated twice, only update position * re-init transceivers if stopped and started again --- src/blackcore/afv/clients/afvclient.cpp | 54 +++++++++++++++++-------- src/blackcore/afv/clients/afvclient.h | 7 +++- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 454a7bd34..337981260 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -49,8 +49,19 @@ namespace BlackCore m_output = new Output(this); connect(m_output, &Output::outputVolumeStream, this, &CAfvClient::outputVolumeStream); connect(m_connection, &CClientConnection::audioReceived, this, &CAfvClient::audioOutDataAvailable); - connect(&m_voiceServerPositionTimer, &QTimer::timeout, this, qOverload<>(&CAfvClient::updateTransceivers)); + connect(&m_voiceServerPositionTimer, &QTimer::timeout, this, &CAfvClient::onPositionUpdateTimer); + // transceivers + this->initTransceivers(); + + // init by settings + this->onSettingsChanged(); + + CLogMessage(this).info(u"UserClient instantiated"); + } + + void CAfvClient::initTransceivers() + { m_transceivers = { { 0, UniCom, 48.5, 11.5, 1000.0, 1000.0 }, @@ -60,10 +71,8 @@ namespace BlackCore m_enabledTransceivers = { 0, 1 }; m_transmittingTransceivers = { { 0 } }; // TxTransceiverDto - // init by settings - this->onSettingsChanged(); - - CLogMessage(this).info(u"UserClient instantiated"); + // init with context values + this->initWithContext(); } void CAfvClient::initWithContext() @@ -79,7 +88,7 @@ namespace BlackCore this->initWithContext(); m_callsign = callsign; m_connection->connectTo(cid, password, callsign); - this->updateTransceivers(); + this->updateTransceivers(); // uses context if available if (m_connection->isConnected()) { emit this->connectionStatusChanged(Connected); } else { emit this->connectionStatusChanged(Disconnected); } @@ -136,6 +145,8 @@ namespace BlackCore return; } + this->initTransceivers(); + soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, transceiverIDs, this); connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged); outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this); @@ -171,11 +182,11 @@ namespace BlackCore m_connection->setReceiveAudio(false); m_transceivers.clear(); - updateTransceivers(); + this->updateTransceivers(false); m_input->stop(); m_output->stop(); - CLogMessage(this).info(u"Client NOT stopped"); + CLogMessage(this).info(u"Client stopped"); } void CAfvClient::enableTransceiver(quint16 id, bool enable) @@ -183,7 +194,7 @@ namespace BlackCore if (enable) { m_enabledTransceivers.insert(id); } else { m_enabledTransceivers.remove(id); } - updateTransceivers(); + this->updateTransceivers(); } void CAfvClient::enableComUnit(CComSystem::ComUnit comUnit, bool enable) @@ -219,14 +230,14 @@ namespace BlackCore if (m_transceivers[id].frequencyHz != roundedFrequencyHz) { m_transceivers[id].frequencyHz = roundedFrequencyHz; - updateTransceivers(); + this->updateTransceivers(false); // no frequency update } } } void CAfvClient::updateComFrequency(CComSystem::ComUnit comUnit, const CFrequency &comFrequency) { - const quint16 freqHz = static_cast(comFrequency.valueInteger(CFrequencyUnit::Hz())); + const quint32 freqHz = static_cast(comFrequency.valueInteger(CFrequencyUnit::Hz())); this->updateComFrequency(comUnitToTransceiverId(comUnit), freqHz); } @@ -246,17 +257,21 @@ namespace BlackCore } } - void CAfvClient::updateTransceivers() + void CAfvClient::updateTransceivers(bool updateFrequencies) { if (!m_connection->isConnected()) { return; } if (hasContext()) { const CSimulatedAircraft ownAircraft = sApp->getIContextOwnAircraft()->getOwnAircraft(); - updatePosition(ownAircraft.latitude().value(CAngleUnit::deg()), - ownAircraft.longitude().value(CAngleUnit::deg()), - ownAircraft.getAltitude().value(CLengthUnit::ft())); - this->updateComFrequency(CComSystem::Com1, ownAircraft.getCom1System()); - this->updateComFrequency(CComSystem::Com2, ownAircraft.getCom2System()); + this->updatePosition(ownAircraft.latitude().value(CAngleUnit::deg()), + ownAircraft.longitude().value(CAngleUnit::deg()), + ownAircraft.getAltitude().value(CLengthUnit::ft())); + + if (updateFrequencies) + { + this->updateComFrequency(CComSystem::Com1, ownAircraft.getCom1System()); + this->updateComFrequency(CComSystem::Com2, ownAircraft.getCom2System()); + } } QVector enabledTransceivers; @@ -477,6 +492,11 @@ namespace BlackCore return {}; } + void CAfvClient::onPositionUpdateTimer() + { + this->updateTransceivers(); + } + void CAfvClient::onSettingsChanged() { const CSettings audioSettings = m_audioSettings.get(); diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index e24a188c4..ae84d6434 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -186,10 +186,12 @@ namespace BlackCore QString getReceivingCallsignsCom1(); QString getReceivingCallsignsCom2(); - void input_OpusDataAvailable(); + void inputOpusDataAvailable(); + + void onPositionUpdateTimer(); void onSettingsChanged(); - void updateTransceivers(); + void updateTransceivers(bool updateFrequencies = true); void updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); static constexpr int SampleRate = 48000; @@ -234,6 +236,7 @@ namespace BlackCore Audio::InputVolumeStreamArgs m_inputVolumeStream; Audio::OutputVolumeStreamArgs m_outputVolumeStream; + void initTransceivers(); void initWithContext(); static bool hasContext(); };