mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T730, swift style functions in AFC client
* COM unit related functions * signal to indicate changed COM values
This commit is contained in:
committed by
Mat Sutcliffe
parent
afd7881a90
commit
088ef74392
@@ -20,6 +20,7 @@ using namespace BlackMisc;
|
|||||||
using namespace BlackMisc::Audio;
|
using namespace BlackMisc::Audio;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackSound;
|
using namespace BlackSound;
|
||||||
using namespace BlackSound::SampleProvider;
|
using namespace BlackSound::SampleProvider;
|
||||||
|
|
||||||
@@ -52,8 +53,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
m_transceivers =
|
m_transceivers =
|
||||||
{
|
{
|
||||||
{ 0, 122800000, 48.5, 11.5, 1000.0, 1000.0 },
|
{ 0, UniCom, 48.5, 11.5, 1000.0, 1000.0 },
|
||||||
{ 1, 122800000, 48.5, 11.5, 1000.0, 1000.0 }
|
{ 1, UniCom, 48.5, 11.5, 1000.0, 1000.0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
m_enabledTransceivers = { 0, 1 };
|
m_enabledTransceivers = { 0, 1 };
|
||||||
@@ -184,6 +185,27 @@ namespace BlackCore
|
|||||||
updateTransceivers();
|
updateTransceivers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAfvClient::enableComUnit(CComSystem::ComUnit comUnit, bool enable)
|
||||||
|
{
|
||||||
|
this->enableTransceiver(comUnitToTransceiverId(comUnit), enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CAfvClient::isEnabledTransceiver(quint16 id) const
|
||||||
|
{
|
||||||
|
// we double check, enabled and exist!
|
||||||
|
if (!m_enabledTransceivers.contains(id)) { return false; }
|
||||||
|
for (const TransceiverDto &dto : m_transceivers)
|
||||||
|
{
|
||||||
|
if (dto.id == id) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CAfvClient::isEnabledComUnit(CComSystem::ComUnit comUnit) const
|
||||||
|
{
|
||||||
|
return this->isEnabledTransceiver(comUnitToTransceiverId(comUnit));
|
||||||
|
}
|
||||||
|
|
||||||
void CAfvClient::updateComFrequency(quint16 id, quint32 frequencyHz)
|
void CAfvClient::updateComFrequency(quint16 id, quint32 frequencyHz)
|
||||||
{
|
{
|
||||||
if (id != 0 && id != 1) { return; }
|
if (id != 0 && id != 1) { return; }
|
||||||
@@ -201,6 +223,17 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAfvClient::updateComFrequency(CComSystem::ComUnit comUnit, const CFrequency &comFrequency)
|
||||||
|
{
|
||||||
|
const quint16 freqHz = static_cast<quint16>(comFrequency.valueInteger(CFrequencyUnit::Hz()));
|
||||||
|
this->updateComFrequency(comUnitToTransceiverId(comUnit), freqHz);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAfvClient::updateComFrequency(CComSystem::ComUnit comUnit, const CComSystem &comSystem)
|
||||||
|
{
|
||||||
|
this->updateComFrequency(comUnit, comSystem.getFrequencyActive());
|
||||||
|
}
|
||||||
|
|
||||||
void CAfvClient::updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters)
|
void CAfvClient::updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters)
|
||||||
{
|
{
|
||||||
for (TransceiverDto &transceiver : m_transceivers)
|
for (TransceiverDto &transceiver : m_transceivers)
|
||||||
@@ -221,11 +254,8 @@ namespace BlackCore
|
|||||||
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()));
|
||||||
|
this->updateComFrequency(CComSystem::Com1, ownAircraft.getCom1System());
|
||||||
const quint16 com1Hz = static_cast<quint16>(ownAircraft.getCom1System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
this->updateComFrequency(CComSystem::Com2, ownAircraft.getCom2System());
|
||||||
const quint16 com2Hz = static_cast<quint16>(ownAircraft.getCom2System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
|
||||||
updateComFrequency(0, com1Hz);
|
|
||||||
updateComFrequency(1, com2Hz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<TransceiverDto> enabledTransceivers;
|
QVector<TransceiverDto> enabledTransceivers;
|
||||||
@@ -244,17 +274,36 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::setTransmittingTransceivers(quint16 transceiverID)
|
void CAfvClient::setTransmittingTransceiver(quint16 transceiverID)
|
||||||
{
|
{
|
||||||
TxTransceiverDto tx = { transceiverID };
|
TxTransceiverDto tx = { transceiverID };
|
||||||
setTransmittingTransceivers({ tx });
|
setTransmittingTransceivers({ tx });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAfvClient::setTransmittingComUnit(CComSystem::ComUnit comUnit)
|
||||||
|
{
|
||||||
|
this->setTransmittingTransceiver(comUnitToTransceiverId(comUnit));
|
||||||
|
}
|
||||||
|
|
||||||
void CAfvClient::setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers)
|
void CAfvClient::setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers)
|
||||||
{
|
{
|
||||||
m_transmittingTransceivers = transceivers;
|
m_transmittingTransceivers = transceivers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAfvClient::isTransmittingTransceiver(quint16 id) const
|
||||||
|
{
|
||||||
|
for (const TxTransceiverDto &dto : m_transmittingTransceivers)
|
||||||
|
{
|
||||||
|
if (dto.id == id) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CAfvClient::isTransmittingdComUnit(CComSystem::ComUnit comUnit) const
|
||||||
|
{
|
||||||
|
return this->isTransmittingTransceiver(comUnitToTransceiverId(comUnit));
|
||||||
|
}
|
||||||
|
|
||||||
void CAfvClient::setPtt(bool active)
|
void CAfvClient::setPtt(bool active)
|
||||||
{
|
{
|
||||||
this->setPttForCom(active, COMUnspecified);
|
this->setPttForCom(active, COMUnspecified);
|
||||||
@@ -266,12 +315,11 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (!m_isStarted)
|
if (!m_isStarted)
|
||||||
{
|
{
|
||||||
qDebug() << "Client not started";
|
CLogMessage(this).info(u"Voice client not started");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_transmit == active) { return; }
|
if (m_transmit == active) { return; }
|
||||||
|
|
||||||
m_transmit = active;
|
m_transmit = active;
|
||||||
|
|
||||||
if (soundcardSampleProvider)
|
if (soundcardSampleProvider)
|
||||||
@@ -290,7 +338,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit this->ptt(active, com, this->identifier());
|
emit this->ptt(active, com, this->identifier());
|
||||||
qDebug() << "PTT:" << active;
|
// qDebug() << "PTT:" << active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAfvClient::setInputVolumeDb(double value)
|
void CAfvClient::setInputVolumeDb(double value)
|
||||||
@@ -436,16 +484,46 @@ namespace BlackCore
|
|||||||
void CAfvClient::updateTransceiversFromContext(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
|
void CAfvClient::updateTransceiversFromContext(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
|
||||||
{
|
{
|
||||||
Q_UNUSED(originator)
|
Q_UNUSED(originator)
|
||||||
updatePosition(aircraft.latitude().value(CAngleUnit::deg()),
|
this->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()));
|
||||||
|
|
||||||
const quint16 com1Hz = static_cast<quint16>(aircraft.getCom1System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
const CComSystem com1 = aircraft.getCom1System();
|
||||||
const quint16 com2Hz = static_cast<quint16>(aircraft.getCom2System().getFrequencyActive().valueInteger(CFrequencyUnit::Hz()));
|
const CComSystem com2 = aircraft.getCom2System();
|
||||||
|
this->updateComFrequency(CComSystem::Com1, com1);
|
||||||
|
this->updateComFrequency(CComSystem::Com2, com2);
|
||||||
|
|
||||||
updateComFrequency(0, com1Hz);
|
const bool tx1 = com1.isTransmitEnabled();
|
||||||
updateComFrequency(1, com2Hz);
|
const bool rec1 = com1.isReceiveEnabled();
|
||||||
updateTransceivers();
|
const bool tx2 = com2.isTransmitEnabled();
|
||||||
|
const bool rec2 = com2.isReceiveEnabled();
|
||||||
|
|
||||||
|
this->enableComUnit(CComSystem::Com1, tx1 || rec1);
|
||||||
|
this->enableComUnit(CComSystem::Com2, tx2 || rec2);
|
||||||
|
this->setTransmittingComUnit(CComSystem::Com1);
|
||||||
|
this->setTransmittingComUnit(CComSystem::Com2);
|
||||||
|
|
||||||
|
this->updateTransceivers();
|
||||||
|
emit this->updatedFromOwnAircraftCockpit();
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 CAfvClient::comUnitToTransceiverId(CComSystem::ComUnit comUnit)
|
||||||
|
{
|
||||||
|
switch (comUnit)
|
||||||
|
{
|
||||||
|
case CComSystem::Com1: return 0;
|
||||||
|
case CComSystem::Com2: return 1;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CComSystem::ComUnit CAfvClient::transceiverIdToComUnit(quint16 id)
|
||||||
|
{
|
||||||
|
if (comUnitToTransceiverId(CComSystem::Com1) == id) { return CComSystem::Com1; }
|
||||||
|
if (comUnitToTransceiverId(CComSystem::Com2) == id) { return CComSystem::Com2; }
|
||||||
|
return CComSystem::Com1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAfvClient::hasContext()
|
bool CAfvClient::hasContext()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "blackcore/blackcoreexport.h"
|
#include "blackcore/blackcoreexport.h"
|
||||||
|
|
||||||
#include "blacksound/sampleprovider/volumesampleprovider.h"
|
#include "blacksound/sampleprovider/volumesampleprovider.h"
|
||||||
|
#include "blackmisc/aviation/comsystem.h"
|
||||||
#include "blackmisc/audio/audiosettings.h"
|
#include "blackmisc/audio/audiosettings.h"
|
||||||
#include "blackmisc/audio/ptt.h"
|
#include "blackmisc/audio/ptt.h"
|
||||||
#include "blackmisc/logcategorylist.h"
|
#include "blackmisc/logcategorylist.h"
|
||||||
@@ -94,12 +95,32 @@ namespace BlackCore
|
|||||||
Q_INVOKABLE void start(const QString &inputDeviceName, const QString &outputDeviceName);
|
Q_INVOKABLE void start(const QString &inputDeviceName, const QString &outputDeviceName);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
//! Enable COM unit/transceiver @{
|
||||||
Q_INVOKABLE void enableTransceiver(quint16 id, bool enable);
|
Q_INVOKABLE void enableTransceiver(quint16 id, bool enable);
|
||||||
Q_INVOKABLE void updateComFrequency(quint16 id, quint32 frequencyHz);
|
void enableComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit, bool enable);
|
||||||
Q_INVOKABLE void updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters);
|
bool isEnabledTransceiver(quint16 id) const;
|
||||||
|
bool isEnabledComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
|
||||||
|
//! @}
|
||||||
|
|
||||||
void setTransmittingTransceivers(quint16 transceiverID);
|
//! Set transmitting transceivers @{
|
||||||
|
void setTransmittingTransceiver(quint16 transceiverID);
|
||||||
|
void setTransmittingComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit);
|
||||||
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
void setTransmittingTransceivers(const QVector<TxTransceiverDto> &transceivers);
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Transmitting transceiver/COM unit
|
||||||
|
bool isTransmittingTransceiver(quint16 id) const;
|
||||||
|
bool isTransmittingdComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Update frequency @{
|
||||||
|
Q_INVOKABLE void updateComFrequency(quint16 id, quint32 frequencyHz);
|
||||||
|
void updateComFrequency(BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::PhysicalQuantities::CFrequency &comFrequency);
|
||||||
|
void updateComFrequency(BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::Aviation::CComSystem &comSystem);
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Update own aircraft position
|
||||||
|
Q_INVOKABLE void updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters);
|
||||||
|
|
||||||
//! Push to talk @{
|
//! Push to talk @{
|
||||||
Q_INVOKABLE void setPtt(bool active);
|
Q_INVOKABLE void setPtt(bool active);
|
||||||
@@ -146,6 +167,9 @@ namespace BlackCore
|
|||||||
//! Connection status has been changed
|
//! Connection status has been changed
|
||||||
void connectionStatusChanged(ConnectionStatus status);
|
void connectionStatusChanged(ConnectionStatus status);
|
||||||
|
|
||||||
|
//! Client updated from own aicraft data
|
||||||
|
void updatedFromOwnAircraftCockpit();
|
||||||
|
|
||||||
//! PTT status in this particular AFV client
|
//! PTT status in this particular AFV client
|
||||||
void ptt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier);
|
void ptt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier);
|
||||||
|
|
||||||
@@ -174,6 +198,9 @@ namespace BlackCore
|
|||||||
static constexpr double MaxDb = 18.0;
|
static constexpr double MaxDb = 18.0;
|
||||||
static constexpr quint32 UniCom = 122800000;
|
static constexpr quint32 UniCom = 122800000;
|
||||||
|
|
||||||
|
static quint16 comUnitToTransceiverId(BlackMisc::Aviation::CComSystem::ComUnit comUnit);
|
||||||
|
static BlackMisc::Aviation::CComSystem::ComUnit transceiverIdToComUnit(quint16 id);
|
||||||
|
|
||||||
Connection::CClientConnection *m_connection = nullptr;
|
Connection::CClientConnection *m_connection = nullptr;
|
||||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAfvClient::onSettingsChanged };
|
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAfvClient::onSettingsChanged };
|
||||||
QString m_callsign;
|
QString m_callsign;
|
||||||
|
|||||||
Reference in New Issue
Block a user