From f6d078de34583ce93b14246374afa597a00c6492 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 16 Jun 2019 20:23:04 +0200 Subject: [PATCH] Ref T684, better detection of callsign type for ATC stations * detection in "CCallsign::unifyCallsign" * force ATC callsign in nAtisReplyReceived --- src/blackcore/vatsim/networkvatlib.cpp | 7 +++-- src/blackmisc/aviation/callsign.cpp | 39 ++++++++++++++++++++------ src/blackmisc/aviation/callsign.h | 6 ++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/blackcore/vatsim/networkvatlib.cpp b/src/blackcore/vatsim/networkvatlib.cpp index 6bc54f37d..9ffc9fc77 100644 --- a/src/blackcore/vatsim/networkvatlib.cpp +++ b/src/blackcore/vatsim/networkvatlib.cpp @@ -1389,8 +1389,9 @@ namespace BlackCore void CNetworkVatlib::onAtisReplyReceived(VatFsdClient *, const char *callsign, const VatControllerAtis *atis, void *cbvar) { auto *self = cbvar_cast(cbvar); - emit self->atisVoiceRoomReplyReceived(self->fromFSD(callsign), self->fromFSD(atis->voiceRoom)); - emit self->atisLogoffTimeReplyReceived(self->fromFSD(callsign), self->fromFSD(atis->zuluLogoff)); + const CCallsign cs(self->fromFSD(callsign), CCallsign::Atc); + emit self->atisVoiceRoomReplyReceived(cs, self->fromFSD(atis->voiceRoom)); + emit self->atisLogoffTimeReplyReceived(cs, self->fromFSD(atis->zuluLogoff)); CInformationMessage atisMessage; atisMessage.setType(CInformationMessage::ATIS); @@ -1413,7 +1414,7 @@ namespace BlackCore } } - emit self->atisReplyReceived(CCallsign(self->fromFSD(callsign), CCallsign::Atc), atisMessage); + emit self->atisReplyReceived(cs, atisMessage); } void CNetworkVatlib::onFlightPlanReceived(VatFsdClient *, const char *callsignChar, const VatFlightPlan *fp, void *cbvar) diff --git a/src/blackmisc/aviation/callsign.cpp b/src/blackmisc/aviation/callsign.cpp index 2e6cff670..601679248 100644 --- a/src/blackmisc/aviation/callsign.cpp +++ b/src/blackmisc/aviation/callsign.cpp @@ -73,23 +73,29 @@ namespace BlackMisc // Ref T664, allow ATC with hyphen, such as Ml-SNO_CTR switch (hint) { - case Atc: return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_' && c != '-'; }); + // ATC allows "-", aircraft not + case Atc: return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_' && c != '-'; }); + case Aircraft: return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_'; }); default: break; } + + // no hint + if (CCallsign::looksLikeAtcCallsign(callsign)) + { + return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_' && c != '-'; }); + } + + // strict check return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_'; }); } const CIcon &CCallsign::convertToIcon(const CCallsign &callsign) { if (callsign.m_callsign.startsWith(QStringView(u"VATGOV"))) { return CIcon::iconByIndex(CIcons::NetworkRolePilot); } - if (callsign.getTypeHint() == CCallsign::Aircraft || !callsign.hasSuffix()) - { - return CIcon::iconByIndex(CIcons::NetworkRolePilot); - } - else - { - return atcSuffixToIcon(callsign.getSuffix()); - } + const bool pilot = callsign.getTypeHint() == CCallsign::Aircraft || !callsign.hasSuffix(); + return pilot ? + CIcon::iconByIndex(CIcons::NetworkRolePilot) : + CCallsign::atcSuffixToIcon(callsign.getSuffix()); } const CIcon &CCallsign::atcSuffixToIcon(const QString &suffix) @@ -133,6 +139,11 @@ namespace BlackMisc m_callsign.at(m_callsign.size() - 1) >= 'A' && m_callsign.at(m_callsign.size() - 1) <= 'Z'; } + bool CCallsign::isSameAsSet() const + { + return m_callsign == m_callsignAsSet; + } + QString CCallsign::getIcaoCode() const { if (this->isAtcCallsign()) @@ -333,5 +344,15 @@ namespace BlackMisc static const QStringList a({ "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS", "INS" }); return a; } + + bool CCallsign::looksLikeAtcCallsign(const QString &callsign) + { + if (!callsign.contains("_")) { return false; } + for (const QString &r : CCallsign::atcAlikeCallsignSuffixes()) + { + if (callsign.endsWith(r)) { return true; } + } + return false; + } } // namespace } // namespace diff --git a/src/blackmisc/aviation/callsign.h b/src/blackmisc/aviation/callsign.h index 8e1034493..a0bd314a7 100644 --- a/src/blackmisc/aviation/callsign.h +++ b/src/blackmisc/aviation/callsign.h @@ -89,6 +89,9 @@ namespace BlackMisc //! Get callsign. const QString &getStringAsSet() const { return m_callsignAsSet; } + //! Same as set callsign? + bool isSameAsSet() const; + //! Get callsign telephony designator (how callsign is pronounced) const QString &getTelephonyDesignator() const { return m_telephonyDesignator; } @@ -175,6 +178,9 @@ namespace BlackMisc //! List of real ("TWR") and treated like ATC suffixes (e.g. OBS); static const QStringList &atcAlikeCallsignSuffixes(); + //! Does this look like an ATC callsign + static bool looksLikeAtcCallsign(const QString &callsign); + //! Suffix to icon static const CIcon &atcSuffixToIcon(const QString &suffix);