mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
Ref T730, directly use context from sApp
* using sApp->getIContextOwnAircraft() * no need to pass context, avoid issues when shutting down * minor style changes
This commit is contained in:
committed by
Mat Sutcliffe
parent
99edc9cb13
commit
66b02e61c5
@@ -7,13 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "afvclient.h"
|
#include "afvclient.h"
|
||||||
|
#include "blackcore/context/contextownaircraft.h"
|
||||||
|
#include "blackcore/application.h"
|
||||||
#include "blacksound/audioutilities.h"
|
#include "blacksound/audioutilities.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
|
||||||
using namespace BlackCore::Context;
|
using namespace BlackCore::Context;
|
||||||
using namespace BlackCore::Afv::Audio;
|
using namespace BlackCore::Afv::Audio;
|
||||||
using namespace BlackCore::Afv::Connection;
|
using namespace BlackCore::Afv::Connection;
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
using namespace BlackSound::SampleProvider;
|
using namespace BlackSound::SampleProvider;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
@@ -28,7 +32,7 @@ namespace BlackCore
|
|||||||
m_connection = new CClientConnection(apiServer, this);
|
m_connection = new CClientConnection(apiServer, this);
|
||||||
m_connection->setReceiveAudio(false);
|
m_connection->setReceiveAudio(false);
|
||||||
|
|
||||||
m_input = new CInput(c_sampleRate, this);
|
m_input = new CInput(SampleRate, this);
|
||||||
connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable);
|
connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable);
|
||||||
connect(m_input, &CInput::inputVolumeStream, this, &CAfvClient::inputVolumeStream);
|
connect(m_input, &CInput::inputVolumeStream, this, &CAfvClient::inputVolumeStream);
|
||||||
|
|
||||||
@@ -45,34 +49,26 @@ namespace BlackCore
|
|||||||
{ 1, 122800000, 48.5, 11.5, 1000.0, 1000.0 }
|
{ 1, 122800000, 48.5, 11.5, 1000.0, 1000.0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
m_enabledTransceivers =
|
m_enabledTransceivers = { 0, 1 };
|
||||||
{
|
m_transmittingTransceivers = { { 0 } }; // TxTransceiverDto
|
||||||
{ 0 },
|
|
||||||
{ 1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
m_transmittingTransceivers =
|
|
||||||
{
|
|
||||||
{ 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
qDebug() << "UserClient instantiated";
|
qDebug() << "UserClient instantiated";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::setContextOwnAircraft(const IContextOwnAircraft *contextOwnAircraft)
|
void CAfvClient::initWithContext()
|
||||||
{
|
{
|
||||||
m_contextOwnAircraft = contextOwnAircraft;
|
if (!hasContext()) { return; }
|
||||||
if (m_contextOwnAircraft)
|
this->disconnect(sApp->getIContextOwnAircraft());
|
||||||
{
|
sApp->getIContextOwnAircraft()->disconnect(this);
|
||||||
connect(m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit, this, &CAfvClient::updateTransceiversFromContext);
|
connect(sApp->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CAfvClient::updateTransceiversFromContext);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign)
|
void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign)
|
||||||
{
|
{
|
||||||
|
this->initWithContext();
|
||||||
m_callsign = callsign;
|
m_callsign = callsign;
|
||||||
m_connection->connectTo(cid, password, callsign);
|
m_connection->connectTo(cid, password, callsign);
|
||||||
updateTransceivers();
|
this->updateTransceivers();
|
||||||
|
|
||||||
if (m_connection->isConnected()) { emit connectionStatusChanged(Connected); }
|
if (m_connection->isConnected()) { emit connectionStatusChanged(Connected); }
|
||||||
else { emit connectionStatusChanged(Disconnected); }
|
else { emit connectionStatusChanged(Disconnected); }
|
||||||
@@ -126,7 +122,7 @@ namespace BlackCore
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundcardSampleProvider = new CSoundcardSampleProvider(c_sampleRate, transceiverIDs, this);
|
soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, transceiverIDs, this);
|
||||||
connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged);
|
connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged);
|
||||||
outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this);
|
outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this);
|
||||||
outputSampleProvider->setVolume(m_outputVolume);
|
outputSampleProvider->setVolume(m_outputVolume);
|
||||||
@@ -145,7 +141,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_isStarted) { return; }
|
if (m_isStarted) { return; }
|
||||||
|
|
||||||
soundcardSampleProvider = new CSoundcardSampleProvider(c_sampleRate, { 0, 1 }, this);
|
soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, { 0, 1 }, this);
|
||||||
connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged);
|
connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged);
|
||||||
outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this);
|
outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this);
|
||||||
outputSampleProvider->setVolume(m_outputVolume);
|
outputSampleProvider->setVolume(m_outputVolume);
|
||||||
@@ -205,46 +201,48 @@ namespace BlackCore
|
|||||||
updateTransceivers();
|
updateTransceivers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::updateComFrequency(quint16 id, quint32 frequency)
|
void CAfvClient::updateComFrequency(quint16 id, quint32 frequencyHz)
|
||||||
{
|
{
|
||||||
if (id != 0 && id != 1) { return; }
|
if (id != 0 && id != 1) { return; }
|
||||||
|
|
||||||
// Fix rounding issues like 128074999 Hz -> 128075000 Hz
|
// Fix rounding issues like 128074999 Hz -> 128075000 Hz
|
||||||
quint32 roundedFrequency = qRound(frequency / 1000.0) * 1000;
|
quint32 roundedFrequencyHz = static_cast<quint32>(qRound(frequencyHz / 1000.0)) * 1000;
|
||||||
|
|
||||||
if (m_transceivers.size() >= id + 1)
|
if (m_transceivers.size() >= id + 1)
|
||||||
{
|
{
|
||||||
if (m_transceivers[id].frequency != roundedFrequency)
|
if (m_transceivers[id].frequency != roundedFrequencyHz)
|
||||||
{
|
{
|
||||||
m_transceivers[id].frequency = roundedFrequency;
|
m_transceivers[id].frequency = roundedFrequencyHz;
|
||||||
updateTransceivers();
|
updateTransceivers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::updatePosition(double latitude, double longitude, double height)
|
void CAfvClient::updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters)
|
||||||
{
|
{
|
||||||
for (TransceiverDto &transceiver : m_transceivers)
|
for (TransceiverDto &transceiver : m_transceivers)
|
||||||
{
|
{
|
||||||
transceiver.LatDeg = latitude;
|
transceiver.LatDeg = latitudeDeg;
|
||||||
transceiver.LonDeg = longitude;
|
transceiver.LonDeg = longitudeDeg;
|
||||||
transceiver.HeightAglM = height;
|
transceiver.HeightAglM = heightMeters;
|
||||||
transceiver.HeightMslM = height;
|
transceiver.HeightMslM = heightMeters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::updateTransceivers()
|
void CAfvClient::updateTransceivers()
|
||||||
{
|
{
|
||||||
if (! m_connection->isConnected()) { return; }
|
if (!m_connection->isConnected()) { return; }
|
||||||
|
if (hasContext())
|
||||||
if (m_contextOwnAircraft)
|
|
||||||
{
|
{
|
||||||
BlackMisc::Simulation::CSimulatedAircraft ownAircraft = m_contextOwnAircraft->getOwnAircraft();
|
const CSimulatedAircraft ownAircraft = sApp->getIContextOwnAircraft()->getOwnAircraft();
|
||||||
updatePosition(ownAircraft.latitude().value(CAngleUnit::deg()),
|
updatePosition(ownAircraft.latitude().value(CAngleUnit::deg()),
|
||||||
ownAircraft.longitude().value(CAngleUnit::deg()),
|
ownAircraft.longitude().value(CAngleUnit::deg()),
|
||||||
ownAircraft.getAltitude().value(CLengthUnit::ft()));
|
ownAircraft.getAltitude().value(CLengthUnit::ft()));
|
||||||
updateComFrequency(0, ownAircraft.getCom1System().getFrequencyActive().value(CFrequencyUnit::Hz()));
|
|
||||||
updateComFrequency(1, ownAircraft.getCom2System().getFrequencyActive().value(CFrequencyUnit::Hz()));
|
const quint16 com1Hz = static_cast<quint16>(ownAircraft.getCom1System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
||||||
|
const quint16 com2Hz = static_cast<quint16>(ownAircraft.getCom2System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
||||||
|
updateComFrequency(0, com1Hz);
|
||||||
|
updateComFrequency(1, com2Hz);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<TransceiverDto> enabledTransceivers;
|
QVector<TransceiverDto> enabledTransceivers;
|
||||||
@@ -401,17 +399,26 @@ namespace BlackCore
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator)
|
void CAfvClient::updateTransceiversFromContext(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
|
||||||
{
|
{
|
||||||
Q_UNUSED(originator);
|
Q_UNUSED(originator)
|
||||||
updatePosition(aircraft.latitude().value(CAngleUnit::deg()),
|
updatePosition(aircraft.latitude().value(CAngleUnit::deg()),
|
||||||
aircraft.longitude().value(CAngleUnit::deg()),
|
aircraft.longitude().value(CAngleUnit::deg()),
|
||||||
aircraft.getAltitude().value(CLengthUnit::ft()));
|
aircraft.getAltitude().value(CLengthUnit::ft()));
|
||||||
updateComFrequency(0, aircraft.getCom1System().getFrequencyActive().value(CFrequencyUnit::Hz()));
|
|
||||||
updateComFrequency(1, aircraft.getCom2System().getFrequencyActive().value(CFrequencyUnit::Hz()));
|
const quint16 com1Hz = static_cast<quint16>(aircraft.getCom1System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
||||||
|
const quint16 com2Hz = static_cast<quint16>(aircraft.getCom2System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
||||||
|
|
||||||
|
updateComFrequency(0, com1Hz);
|
||||||
|
updateComFrequency(1, com2Hz);
|
||||||
updateTransceivers();
|
updateTransceivers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAfvClient::hasContext()
|
||||||
|
{
|
||||||
|
return sApp && !sApp->isShuttingDown() && sApp->getIContextOwnAircraft();
|
||||||
|
}
|
||||||
|
|
||||||
double CAfvClient::getOutputVolumeDb() const
|
double CAfvClient::getOutputVolumeDb() const
|
||||||
{
|
{
|
||||||
return m_outputVolume;
|
return m_outputVolume;
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ namespace BlackCore
|
|||||||
class BLACKCORE_EXPORT CAfvClient final : public QObject
|
class BLACKCORE_EXPORT CAfvClient final : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(float inputVolumePeakVU READ getInputVolumePeakVU NOTIFY inputVolumePeakVU)
|
Q_PROPERTY(double inputVolumePeakVU READ getInputVolumePeakVU NOTIFY inputVolumePeakVU)
|
||||||
Q_PROPERTY(float outputVolumePeakVU READ getOutputVolumePeakVU NOTIFY outputVolumePeakVU)
|
Q_PROPERTY(double outputVolumePeakVU READ getOutputVolumePeakVU NOTIFY outputVolumePeakVU)
|
||||||
Q_PROPERTY(ConnectionStatus connectionStatus READ getConnectionStatus NOTIFY connectionStatusChanged)
|
Q_PROPERTY(ConnectionStatus connectionStatus READ getConnectionStatus NOTIFY connectionStatusChanged)
|
||||||
Q_PROPERTY(QString receivingCallsignsCom1 READ getReceivingCallsignsCom1 NOTIFY receivingCallsignsChanged)
|
Q_PROPERTY(QString receivingCallsignsCom1 READ getReceivingCallsignsCom1 NOTIFY receivingCallsignsChanged)
|
||||||
Q_PROPERTY(QString receivingCallsignsCom2 READ getReceivingCallsignsCom2 NOTIFY receivingCallsignsChanged)
|
Q_PROPERTY(QString receivingCallsignsCom2 READ getReceivingCallsignsCom2 NOTIFY receivingCallsignsChanged)
|
||||||
@@ -55,14 +55,15 @@ namespace BlackCore
|
|||||||
//! Dtor
|
//! Dtor
|
||||||
virtual ~CAfvClient() override
|
virtual ~CAfvClient() override
|
||||||
{
|
{
|
||||||
stop();
|
this->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setContextOwnAircraft(const BlackCore::Context::IContextOwnAircraft *contextOwnAircraft);
|
// void setContextOwnAircraft(const BlackCore::Context::IContextOwnAircraft *contextOwnAircraft);
|
||||||
|
|
||||||
QString callsign() const { return m_callsign; }
|
QString callsign() const { return m_callsign; }
|
||||||
|
|
||||||
bool isConnected() const { return m_connection->isConnected(); }
|
bool isConnected() const { return m_connection->isConnected(); }
|
||||||
|
ConnectionStatus getConnectionStatus() const;
|
||||||
|
|
||||||
Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &callsign);
|
Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &callsign);
|
||||||
Q_INVOKABLE void disconnectFrom();
|
Q_INVOKABLE void disconnectFrom();
|
||||||
@@ -80,8 +81,8 @@ namespace BlackCore
|
|||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
Q_INVOKABLE void enableTransceiver(quint16 id, bool enable);
|
Q_INVOKABLE void enableTransceiver(quint16 id, bool enable);
|
||||||
Q_INVOKABLE void updateComFrequency(quint16 id, quint32 frequency);
|
Q_INVOKABLE void updateComFrequency(quint16 id, quint32 frequencyHz);
|
||||||
Q_INVOKABLE void updatePosition(double latitude, double longitude, double height);
|
Q_INVOKABLE void updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters);
|
||||||
|
|
||||||
void setTransmittingTransceivers(quint16 transceiverID);
|
void setTransmittingTransceivers(quint16 transceiverID);
|
||||||
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
||||||
@@ -90,25 +91,25 @@ namespace BlackCore
|
|||||||
|
|
||||||
Q_INVOKABLE void setLoopBack(bool on) { m_loopbackOn = on; }
|
Q_INVOKABLE void setLoopBack(bool on) { m_loopbackOn = on; }
|
||||||
|
|
||||||
double inputVolumeDb() const
|
//! Input volume in DB, +-18DB @{
|
||||||
{
|
double getInputVolumeDb() const { return m_inputVolumeDb; }
|
||||||
return m_inputVolumeDb;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_INVOKABLE void setInputVolumeDb(double value);
|
Q_INVOKABLE void setInputVolumeDb(double value);
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Output volume in DB, +-18DB @{
|
||||||
double getOutputVolumeDb() const;
|
double getOutputVolumeDb() const;
|
||||||
Q_INVOKABLE void setOutputVolumeDb(double outputVolume);
|
Q_INVOKABLE void setOutputVolumeDb(double outputVolume);
|
||||||
|
//! @}
|
||||||
|
|
||||||
float getInputVolumePeakVU() const { return m_inputVolumeStream.PeakVU; }
|
//! VU values, 0..1 @{
|
||||||
float getOutputVolumePeakVU() const { return m_outputVolumeStream.PeakVU; }
|
double getInputVolumePeakVU() const { return m_inputVolumeStream.PeakVU; }
|
||||||
|
double getOutputVolumePeakVU() const { return m_outputVolumeStream.PeakVU; }
|
||||||
ConnectionStatus getConnectionStatus() const;
|
//! @}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void receivingCallsignsChanged(const Audio::TransceiverReceivingCallsignsChangedArgs &args);
|
void receivingCallsignsChanged(const Audio::TransceiverReceivingCallsignsChangedArgs &args);
|
||||||
void inputVolumePeakVU(float value);
|
void inputVolumePeakVU(double value);
|
||||||
void outputVolumePeakVU(float value);
|
void outputVolumePeakVU(double value);
|
||||||
void connectionStatusChanged(ConnectionStatus status);
|
void connectionStatusChanged(ConnectionStatus status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -124,8 +125,8 @@ namespace BlackCore
|
|||||||
void updateTransceivers();
|
void updateTransceivers();
|
||||||
void updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator);
|
void updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
static constexpr int c_sampleRate = 48000;
|
static constexpr int SampleRate = 48000;
|
||||||
static constexpr int frameSize = 960; // 20ms
|
static constexpr int FrameSize = 960; // 20ms
|
||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
Connection::CClientConnection *m_connection = nullptr;
|
Connection::CClientConnection *m_connection = nullptr;
|
||||||
@@ -133,7 +134,7 @@ namespace BlackCore
|
|||||||
// Properties
|
// Properties
|
||||||
QString m_callsign;
|
QString m_callsign;
|
||||||
|
|
||||||
Audio::CInput *m_input = nullptr;
|
Audio::CInput *m_input = nullptr;
|
||||||
Audio::Output *m_output = nullptr;
|
Audio::Output *m_output = nullptr;
|
||||||
|
|
||||||
Audio::CSoundcardSampleProvider *soundcardSampleProvider = nullptr;
|
Audio::CSoundcardSampleProvider *soundcardSampleProvider = nullptr;
|
||||||
@@ -160,7 +161,9 @@ namespace BlackCore
|
|||||||
Audio::InputVolumeStreamArgs m_inputVolumeStream;
|
Audio::InputVolumeStreamArgs m_inputVolumeStream;
|
||||||
Audio::OutputVolumeStreamArgs m_outputVolumeStream;
|
Audio::OutputVolumeStreamArgs m_outputVolumeStream;
|
||||||
|
|
||||||
BlackCore::Context::IContextOwnAircraft const *m_contextOwnAircraft = nullptr;
|
void initWithContext();
|
||||||
|
static bool hasContext();
|
||||||
|
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -778,12 +778,11 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CContextAudio::xCtxNetworkConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
|
void CContextAudio::xCtxNetworkConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
|
||||||
{
|
{
|
||||||
Q_UNUSED(from);
|
Q_UNUSED(from)
|
||||||
BLACK_VERIFY_X(this->getIContextNetwork(), Q_FUNC_INFO, "Missing network context");
|
BLACK_VERIFY_X(this->getIContextNetwork(), Q_FUNC_INFO, "Missing network context");
|
||||||
if (to.isConnected() && this->getIContextNetwork())
|
if (to.isConnected() && this->getIContextNetwork())
|
||||||
{
|
{
|
||||||
CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser();
|
const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser();
|
||||||
m_voiceClient.setContextOwnAircraft(getIContextOwnAircraft());
|
|
||||||
m_voiceClient.connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString());
|
m_voiceClient.connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString());
|
||||||
m_voiceClient.start(QAudioDeviceInfo::defaultInputDevice(), QAudioDeviceInfo::defaultOutputDevice(), {0, 1});
|
m_voiceClient.start(QAudioDeviceInfo::defaultInputDevice(), QAudioDeviceInfo::defaultOutputDevice(), {0, 1});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user