[AFV] Allow to log. input receiver

This commit is contained in:
Klaus Basan
2020-04-26 00:53:48 +02:00
committed by Mat Sutcliffe
parent 2c6794a009
commit 9e6716e515
8 changed files with 70 additions and 18 deletions

View File

@@ -18,6 +18,8 @@
#include <QtMath> #include <QtMath>
#include <QDebug> #include <QDebug>
#include <QStringLiteral>
#include <QStringBuilder>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackSound::SampleProvider; using namespace BlackSound::SampleProvider;
@@ -105,7 +107,7 @@ namespace BlackCore
{ {
m_callsign = callsign; m_callsign = callsign;
CallsignDelayCache::instance().initialise(callsign); CallsignDelayCache::instance().initialise(callsign);
m_type = aircraftType; m_aircraftType = aircraftType;
m_decoder.resetState(); m_decoder.resetState();
m_inUse = true; m_inUse = true;
setEffects(); setEffects();
@@ -125,7 +127,7 @@ namespace BlackCore
{ {
m_callsign = callsign; m_callsign = callsign;
CallsignDelayCache::instance().initialise(callsign); CallsignDelayCache::instance().initialise(callsign);
m_type = aircraftType; m_aircraftType = aircraftType;
m_decoder.resetState(); m_decoder.resetState();
m_inUse = true; m_inUse = true;
setEffects(true); setEffects(true);
@@ -169,7 +171,7 @@ namespace BlackCore
m_inUse = false; m_inUse = false;
setEffects(); setEffects();
m_callsign.clear(); m_callsign.clear();
m_type.clear(); m_aircraftType.clear();
} }
QVector<qint16> CCallsignSampleProvider::decodeOpus(const QByteArray &opusData) QVector<qint16> CCallsignSampleProvider::decodeOpus(const QByteArray &opusData)
@@ -230,6 +232,13 @@ namespace BlackCore
setEffects(); setEffects();
} }
QString CCallsignSampleProvider::toQString() const
{
return QStringLiteral("In use: ") % boolToYesNo(m_inUse) %
QStringLiteral(" cs: ") % m_callsign %
QStringLiteral(" type: ") % m_aircraftType;
}
} // ns } // ns
} // ns } // ns
} // ns } // ns

View File

@@ -51,7 +51,7 @@ namespace BlackCore
const QString &callsign() const { return m_callsign; } const QString &callsign() const { return m_callsign; }
//! Type //! Type
const QString &type() const { return m_type; } const QString &type() const { return m_aircraftType; }
//! Is active? //! Is active?
//! @{ //! @{
@@ -73,6 +73,9 @@ namespace BlackCore
//! Bypass effects //! Bypass effects
void setBypassEffects(bool bypassEffects); void setBypassEffects(bool bypassEffects);
//! Info
QString toQString() const;
private: private:
void timerElapsed(); void timerElapsed();
void idle(); void idle();
@@ -88,7 +91,7 @@ namespace BlackCore
const int m_idleTimeoutMs = 500; const int m_idleTimeoutMs = 500;
QString m_callsign; QString m_callsign;
QString m_type; QString m_aircraftType;
bool m_inUse = false; bool m_inUse = false;
bool m_bypassEffects = false; bool m_bypassEffects = false;

View File

@@ -15,6 +15,7 @@
#include "blacksound/sampleprovider/samples.h" #include "blacksound/sampleprovider/samples.h"
#include <QDebug> #include <QDebug>
#include <QStringBuilder>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
@@ -115,13 +116,14 @@ namespace BlackCore
// CLogMessage(this).debug(u"AFV Click..."); // CLogMessage(this).debug(u"AFV Click...");
} }
//! \todo KB 2020-04 not entirely correct, as it can be the number is the same, but changed callsign
if (numberOfInUseInputs != m_lastNumberOfInUseInputs) if (numberOfInUseInputs != m_lastNumberOfInUseInputs)
{ {
QStringList receivingCallsigns; QStringList receivingCallsigns;
for (const CCallsignSampleProvider *voiceInput : m_voiceInputs) for (const CCallsignSampleProvider *voiceInput : m_voiceInputs)
{ {
const QString callsign = voiceInput->callsign(); const QString callsign = voiceInput->callsign();
if (! callsign.isEmpty()) if (!callsign.isEmpty())
{ {
receivingCallsigns.push_back(callsign); receivingCallsigns.push_back(callsign);
} }
@@ -151,7 +153,7 @@ namespace BlackCore
voiceInput = *it; voiceInput = *it;
} }
if (! voiceInput) if (!voiceInput)
{ {
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == false; }); it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == false; });
if (it != m_voiceInputs.end()) if (it != m_voiceInputs.end())
@@ -208,6 +210,29 @@ namespace BlackCore
return m_frequencyHz; return m_frequencyHz;
} }
void CReceiverSampleProvider::logVoiceInputs(const QString &prefix, qint64 timeCheckOffsetMs)
{
if (timeCheckOffsetMs > 100)
{
const qint64 now = QDateTime::currentMSecsSinceEpoch();
if (m_lastLogMessage + timeCheckOffsetMs > now) { return; }
m_lastLogMessage = now;
}
QString l;
int no = 0;
for (const CCallsignSampleProvider *sp : m_voiceInputs)
{
if (!sp || !sp->inUse()) { continue; } // only log the ones in use
l += (l.isEmpty() ? QStringLiteral("") : QStringLiteral("\n")) %
prefix %
QString::number(no++) % QStringLiteral(": ") % sp->toQString();
}
if (l.isEmpty()) { return; }
CLogMessage(this).debug(l);
}
} // ns } // ns
} // ns } // ns
} // ns } // ns

View File

@@ -87,6 +87,10 @@ namespace BlackCore
//! Get frequency in Hz //! Get frequency in Hz
uint getFrequencyHz() const; uint getFrequencyHz() const;
//! Log all inputs
//! \private DEBUG only
void logVoiceInputs(const QString &prefix = {}, qint64 timeCheckOffsetMs = -1);
signals: signals:
//! Receving callsigns have changed //! Receving callsigns have changed
void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args); void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args);
@@ -104,6 +108,7 @@ namespace BlackCore
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr; BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr;
QVector<CCallsignSampleProvider *> m_voiceInputs; QVector<CCallsignSampleProvider *> m_voiceInputs;
qint64 m_lastLogMessage = -1;
QString m_receivingCallsignsString; QString m_receivingCallsignsString;
BlackMisc::Aviation::CCallsignSet m_receivingCallsigns; BlackMisc::Aviation::CCallsignSet m_receivingCallsigns;

View File

@@ -8,7 +8,9 @@
#include "soundcardsampleprovider.h" #include "soundcardsampleprovider.h"
#include "blackmisc/metadatautils.h" #include "blackmisc/metadatautils.h"
#include "blackconfig/buildconfig.h"
using namespace BlackConfig;
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackSound::SampleProvider; using namespace BlackSound::SampleProvider;
@@ -143,9 +145,15 @@ namespace BlackCore
{ {
receiverInput->addSilentSamples(audioDto, rxTransceiver.frequency, rxTransceiver.distanceRatio); receiverInput->addSilentSamples(audioDto, rxTransceiver.frequency, rxTransceiver.distanceRatio);
} }
// debug ONLY
if (CBuildConfig::isLocalDeveloperDebugBuild())
{
receiverInput->logVoiceInputs(QStringLiteral("Transceiver %1 ").arg(rxTransceiver.id), 1500);
} }
} }
} } // each transceiver
} // filtered rx transceivers
} }
void CSoundcardSampleProvider::updateRadioTransceivers(const QVector<TransceiverDto> &radioTransceivers) void CSoundcardSampleProvider::updateRadioTransceivers(const QVector<TransceiverDto> &radioTransceivers)

View File

@@ -62,7 +62,7 @@ namespace BlackCore
m_output(new COutput(this)), m_output(new COutput(this)),
m_voiceServerTimer(new QTimer(this)) m_voiceServerTimer(new QTimer(this))
{ {
this->setObjectName("AFV client"); this->setObjectName("AFV client: " + apiServer );
m_connection->setReceiveAudio(false); m_connection->setReceiveAudio(false);
connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable); connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable);
@@ -169,14 +169,16 @@ namespace BlackCore
// thread safe connect // thread safe connect
{ {
QPointer<CAfvClient> myself(this);
QMutexLocker lock(&m_mutexConnection); QMutexLocker lock(&m_mutexConnection);
// async connection // async connection
m_connection->connectTo(cid, password, callsign, client, m_connection->connectTo(cid, password, callsign, client,
{ {
// this is the callback when the connection has been established
this, [ = ](bool authenticated) this, [ = ](bool authenticated)
{ {
// this is the callback when the connection has been established if (!myself) { return; }
// HF stations aliased // HF stations aliased
const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations(); const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations();
@@ -388,7 +390,7 @@ namespace BlackCore
}); });
} }
/* /* disabled because NOT used
double CAfvClient::getDeviceInputVolume() const double CAfvClient::getDeviceInputVolume() const
{ {
if (m_input) { return m_input->getDeviceInputVolume(); } if (m_input) { return m_input->getDeviceInputVolume(); }

View File

@@ -51,8 +51,8 @@ namespace BlackCore
m_username = username; m_username = username;
m_password = password; m_password = password;
m_networkVersion = networkVersion;
m_client = client; m_client = client;
m_networkVersion = networkVersion;
m_isAuthenticated = false; m_isAuthenticated = false;
QUrl url(m_addressUrl); QUrl url(m_addressUrl);
@@ -254,7 +254,7 @@ namespace BlackCore
// posted in QAM thread, reply is nullptr if called from another thread // posted in QAM thread, reply is nullptr if called from another thread
sApp->postToNetwork(request, CApplication::NoLogRequestId, json.toJson(), sApp->postToNetwork(request, CApplication::NoLogRequestId, json.toJson(),
{ {
this, [ = ](QNetworkReply * nwReply) this, [ = ](QNetworkReply *nwReply)
{ {
// called in "this" thread // called in "this" thread
const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply); const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply);

View File

@@ -10,7 +10,7 @@ namespace BlackSound
CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) : CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) :
ISampleProvider(parent) ISampleProvider(parent)
{ {
const QString on = QStringLiteral("%1 format: ").arg(this->metaObject()->className(), BlackSound::toQString(format)); const QString on = QStringLiteral("%1 format: '%2'").arg(this->metaObject()->className(), BlackSound::toQString(format));
this->setObjectName(on); this->setObjectName(on);
// Set buffer size to 10 secs // Set buffer size to 10 secs