mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
[AFV] Fix aliased frequency handling
* ONLY use HF frequency if stations match and is closest station * better log messages
This commit is contained in:
committed by
Mat Sutcliffe
parent
ae5ede5667
commit
881ec39043
@@ -14,6 +14,7 @@
|
||||
#include "blacksound/audioutilities.h"
|
||||
#include "blackmisc/audio/audiodeviceinfolist.h"
|
||||
#include "blackmisc/threadutils.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -1039,7 +1040,6 @@ namespace BlackCore
|
||||
|
||||
if (it != m_aliasedStations.end())
|
||||
{
|
||||
roundedFrequencyHz = it->frequencyHz; // we use this frequency
|
||||
if (sApp->getIContextNetwork())
|
||||
{
|
||||
// Get the callsign for this frequency and fuzzy compare with our alias station
|
||||
@@ -1049,29 +1049,33 @@ namespace BlackCore
|
||||
const CAtcStationList matchingAtcStations = sApp->getIContextNetwork()->getOnlineStationsForFrequency(f, spacing);
|
||||
const CAtcStation closest = matchingAtcStations.findClosest(1, sApp->getIContextOwnAircraft()->getOwnAircraftSituation().getPosition()).frontOrDefault();
|
||||
|
||||
if (fuzzyMatchCallSign(it->name, closest.getCallsign().asString()))
|
||||
if (fuzzyMatchCallsign(it->name, closest.getCallsign().asString()))
|
||||
{
|
||||
// this is how it should be
|
||||
CLogMessage(this).debug(u"%1 Aliasing %2Hz [VHF] to %3Hz [HF]") << closest.getCallsign() << frequencyHz << it->frequencyHz;
|
||||
roundedFrequencyHz = it->frequencyHz;
|
||||
CLogMessage(this).debug(u"Aliasing '%1' %2Hz [VHF] to %3Hz [HF]") << closest.getCallsign() << frequencyHz << it->frequencyHz;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ups!
|
||||
CLogMessage(this).debug(u"Aliasing %1Hz [VHF] to %2Hz [HF], BUT station NOT found!") << frequencyHz << it->frequencyHz;
|
||||
CLogMessage(this).debug(u"Station '%1' NOT found! Using original frequency %2Hz") << it->name << roundedFrequencyHz;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// without contexts
|
||||
CLogMessage(this).debug(u"Aliasing %1Hz [VHF] to %2Hz [HF]") << frequencyHz << it->frequencyHz;
|
||||
// without contexts always use HF frequency if found
|
||||
roundedFrequencyHz = it->frequencyHz; // we use this frequency
|
||||
CLogMessage(this).debug(u"Aliasing %1Hz [VHF] to %2Hz [HF] (no context)") << frequencyHz << it->frequencyHz;
|
||||
}
|
||||
}
|
||||
}
|
||||
return roundedFrequencyHz;
|
||||
}
|
||||
|
||||
bool CAfvClient::fuzzyMatchCallSign(const QString &callsign, const QString &compareTo) const
|
||||
bool CAfvClient::fuzzyMatchCallsign(const QString &callsign, const QString &compareTo) const
|
||||
{
|
||||
if (callsign.isEmpty() || compareTo.isEmpty()) { return false; } // empty callsigns should NOT match
|
||||
|
||||
QString prefixA;
|
||||
QString suffixA;
|
||||
QString prefixB;
|
||||
@@ -1083,10 +1087,12 @@ namespace BlackCore
|
||||
|
||||
void CAfvClient::getPrefixSuffix(const QString &callsign, QString &prefix, QString &suffix) const
|
||||
{
|
||||
QRegularExpression separator("[(-|_)]");
|
||||
QStringList parts = callsign.split(separator);
|
||||
prefix = parts.first();
|
||||
suffix = parts.last();
|
||||
thread_local const QRegularExpression separator("[(\\-|_)]");
|
||||
const QStringList parts = callsign.split(separator);
|
||||
|
||||
// avoid issues if there are no parts, or only one
|
||||
prefix = parts.size() > 0 ? parts.first() : QString();
|
||||
suffix = parts.size() > 1 ? parts.last() : QString();
|
||||
}
|
||||
|
||||
quint16 CAfvClient::comUnitToTransceiverId(CComSystem::ComUnit comUnit)
|
||||
|
||||
@@ -312,7 +312,7 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
quint32 getAliasFrequencyHz(quint32 frequencyHz) const;
|
||||
|
||||
bool fuzzyMatchCallSign(const QString &callsign, const QString &compareTo) const;
|
||||
bool fuzzyMatchCallsign(const QString &callsign, const QString &compareTo) const;
|
||||
void getPrefixSuffix(const QString &callsign, QString &prefix, QString &suffix) const;
|
||||
|
||||
static constexpr int PositionUpdatesMs = 20000; //!< position timer
|
||||
|
||||
Reference in New Issue
Block a user