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
This commit is contained in:
Klaus Basan
2019-09-30 23:52:46 +02:00
committed by Mat Sutcliffe
parent 5c56715c28
commit 91b65fa2b6
2 changed files with 42 additions and 19 deletions

View File

@@ -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<quint16>(comFrequency.valueInteger(CFrequencyUnit::Hz()));
const quint32 freqHz = static_cast<quint32>(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<TransceiverDto> enabledTransceivers;
@@ -477,6 +492,11 @@ namespace BlackCore
return {};
}
void CAfvClient::onPositionUpdateTimer()
{
this->updateTransceivers();
}
void CAfvClient::onSettingsChanged()
{
const CSettings audioSettings = m_audioSettings.get();

View File

@@ -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();
};