From 781db93355c95758f666e07ee1068d7448e50dbf Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 15 Nov 2018 20:45:33 +0100 Subject: [PATCH] Ref T432, find ATC station for frequency utility functions --- src/blackmisc/aviation/atcstation.cpp | 64 ++++++++++++++--------- src/blackmisc/aviation/atcstation.h | 14 +++-- src/blackmisc/aviation/atcstationlist.cpp | 9 ++++ src/blackmisc/aviation/atcstationlist.h | 11 ++-- src/blackmisc/aviation/comsystem.cpp | 16 ++++-- src/blackmisc/aviation/comsystem.h | 6 +++ 6 files changed, 83 insertions(+), 37 deletions(-) diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index 0569cb4ac..547e5286d 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -76,6 +76,13 @@ namespace BlackMisc m_controller.setCallsign(callsign); } + QString CAtcStation::getCallsignAndControllerRealName() const + { + if (m_callsign.isEmpty()) { return this->getControllerRealName(); } + if (!m_controller.hasRealName()) { return m_callsign.asString(); } + return m_callsign.asString() % QStringLiteral(" ") % this->getControllerRealName(); + } + void CAtcStation::setController(const CUser &controller) { m_controller = controller; @@ -269,6 +276,11 @@ namespace BlackMisc return comUnit.isActiveFrequencyWithin25kHzChannel(this->getFrequency()); } + bool CAtcStation::isFrequencyWithinChannelSpacing(const CFrequency &frequency, CComSystem::ChannelSpacing spacing) const + { + return CComSystem::isWithinChannelSpacing(frequency, this->getFrequency(), spacing); + } + CTime CAtcStation::bookedWhen() const { if (!this->hasValidBookingTimes()) { return CTime(0, nullptr); } @@ -346,20 +358,20 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexBookedFrom: return CVariant::from(m_bookedFromUtc); + case IndexBookedFrom: return CVariant::from(m_bookedFromUtc); case IndexBookedUntil: return CVariant::from(m_bookedUntilUtc); - case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved()); - case IndexController: return m_controller.propertyByIndex(index.copyFrontRemoved()); - case IndexFrequency: return m_frequency.propertyByIndex(index.copyFrontRemoved()); - case IndexIsOnline: return CVariant::from(m_isOnline); - case IndexLatitude: return this->latitude().propertyByIndex(index.copyFrontRemoved()); - case IndexLongitude: return this->longitude().propertyByIndex(index.copyFrontRemoved()); - case IndexPosition: return m_position.propertyByIndex(index.copyFrontRemoved()); - case IndexRange: return m_range.propertyByIndex(index.copyFrontRemoved()); - case IndexIsInRange: return CVariant::fromValue(isInRange()); - case IndexAtis: return m_atis.propertyByIndex(index.copyFrontRemoved()); - case IndexMetar: return m_metar.propertyByIndex(index.copyFrontRemoved()); - case IndexVoiceRoom: return m_voiceRoom.propertyByIndex(index.copyFrontRemoved()); + case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved()); + case IndexController: return m_controller.propertyByIndex(index.copyFrontRemoved()); + case IndexFrequency: return m_frequency.propertyByIndex(index.copyFrontRemoved()); + case IndexIsOnline: return CVariant::from(m_isOnline); + case IndexLatitude: return this->latitude().propertyByIndex(index.copyFrontRemoved()); + case IndexLongitude: return this->longitude().propertyByIndex(index.copyFrontRemoved()); + case IndexPosition: return m_position.propertyByIndex(index.copyFrontRemoved()); + case IndexRange: return m_range.propertyByIndex(index.copyFrontRemoved()); + case IndexIsInRange: return CVariant::fromValue(isInRange()); + case IndexAtis: return m_atis.propertyByIndex(index.copyFrontRemoved()); + case IndexMetar: return m_metar.propertyByIndex(index.copyFrontRemoved()); + case IndexVoiceRoom: return m_voiceRoom.propertyByIndex(index.copyFrontRemoved()); default: return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? ICoordinateWithRelativePosition::propertyByIndex(index) : @@ -403,20 +415,20 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexBookedFrom: return Compare::compare(this->getBookedFromUtc(), compareValue.getBookedFromUtc()); + case IndexBookedFrom: return Compare::compare(this->getBookedFromUtc(), compareValue.getBookedFromUtc()); case IndexBookedUntil: return Compare::compare(this->getBookedUntilUtc(), compareValue.getBookedUntilUtc()); - case IndexCallsign: return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); - case IndexController: return m_controller.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getController()); - case IndexFrequency: return m_frequency.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFrequency()); - case IndexIsOnline: return Compare::compare(this->isOnline(), compareValue.isOnline()); - case IndexLatitude: return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); - case IndexLongitude: return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); - case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); - case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); - case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange()); - case IndexAtis: return m_atis.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAtis()); - case IndexMetar: return m_metar.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getMetar()); - case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); + case IndexCallsign: return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); + case IndexController: return m_controller.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getController()); + case IndexFrequency: return m_frequency.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFrequency()); + case IndexIsOnline: return Compare::compare(this->isOnline(), compareValue.isOnline()); + case IndexLatitude: return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); + case IndexLongitude: return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); + case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); + case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); + case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange()); + case IndexAtis: return m_atis.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAtis()); + case IndexMetar: return m_metar.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getMetar()); + case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); default: if (ICoordinateWithRelativePosition::canHandleIndex(index)) { diff --git a/src/blackmisc/aviation/atcstation.h b/src/blackmisc/aviation/atcstation.h index fd90009a6..a4a22ff98 100644 --- a/src/blackmisc/aviation/atcstation.h +++ b/src/blackmisc/aviation/atcstation.h @@ -71,9 +71,9 @@ namespace BlackMisc CAtcStation(const QString &callsign); //! ATC station constructor - CAtcStation(const CCallsign &callsign, const BlackMisc::Network::CUser &controller, - const BlackMisc::PhysicalQuantities::CFrequency &frequency, - const BlackMisc::Geo::CCoordinateGeodetic &pos, const BlackMisc::PhysicalQuantities::CLength &range, + CAtcStation(const CCallsign &callsign, const Network::CUser &controller, + const PhysicalQuantities::CFrequency &frequency, + const Geo::CCoordinateGeodetic &pos, const PhysicalQuantities::CLength &range, bool isOnline = false, const QDateTime &bookedFromUtc = QDateTime(), const QDateTime &bookedUntilUtc = QDateTime(), const CInformationMessage &atis = CInformationMessage(CInformationMessage::ATIS), const CInformationMessage &metar = CInformationMessage(CInformationMessage::METAR)); @@ -104,6 +104,9 @@ namespace BlackMisc //! Get controller name. QString getControllerRealName() const { return m_controller.getRealName(); } + //! Callsign and controller's name if available + QString getCallsignAndControllerRealName() const; + //! Get controller name. QString getControllerId() const { return m_controller.getId(); } @@ -194,7 +197,10 @@ namespace BlackMisc bool isBookedNow() const; //! Tuned in within 25KHz channel spacing - bool isComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const; + bool isComUnitTunedIn25KHz(const Aviation::CComSystem &comUnit) const; + + //! Is frequency within channel spacing + bool isFrequencyWithinChannelSpacing(const PhysicalQuantities::CFrequency &frequency, CComSystem::ChannelSpacing spacing) const; //! When booked, 0 means now, //! negative values mean booking in past, diff --git a/src/blackmisc/aviation/atcstationlist.cpp b/src/blackmisc/aviation/atcstationlist.cpp index d98fc6ae9..99114cfb5 100644 --- a/src/blackmisc/aviation/atcstationlist.cpp +++ b/src/blackmisc/aviation/atcstationlist.cpp @@ -40,6 +40,15 @@ namespace BlackMisc }); } + CAtcStationList CAtcStationList::findIfFrequencyIsWithinSpacing(const CFrequency &frequency, CComSystem::ChannelSpacing spacing) + { + if (frequency.isNull()) { return CAtcStationList(); } + return this->findBy([&](const CAtcStation & atcStation) + { + return atcStation.isFrequencyWithinChannelSpacing(frequency, spacing); + }); + } + bool CAtcStationList::updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer) { const CInformationMessage::InformationType t = im.getType(); diff --git a/src/blackmisc/aviation/atcstationlist.h b/src/blackmisc/aviation/atcstationlist.h index 12ce1aabf..23b27f9e8 100644 --- a/src/blackmisc/aviation/atcstationlist.h +++ b/src/blackmisc/aviation/atcstationlist.h @@ -13,11 +13,13 @@ #define BLACKMISC_AVIATION_ATCSTATIONLIST_H #include "blackmisc/aviation/atcstation.h" +#include "blackmisc/aviation/comsystem.h" #include "blackmisc/aviation/callsignobjectlist.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/collection.h" +#include "blackmisc/pq/frequency.h" #include "blackmisc/geo/geoobjectlist.h" #include "blackmisc/network/userlist.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/collection.h" #include "blackmisc/sequence.h" #include "blackmisc/variant.h" @@ -27,8 +29,6 @@ namespace BlackMisc { namespace Aviation { - class CComSystem; - //! Value object for a list of ATC stations. class BLACKMISC_EXPORT CAtcStationList : public CSequence, @@ -48,6 +48,9 @@ namespace BlackMisc //! Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing CAtcStationList findIfComUnitTunedIn25KHz(const CComSystem &comUnit) const; + //! Find 0..n stations within channel spacing + CAtcStationList findIfFrequencyIsWithinSpacing(const PhysicalQuantities::CFrequency &frequency, CComSystem::ChannelSpacing spacing); + //! Update if message changed bool updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer); diff --git a/src/blackmisc/aviation/comsystem.cpp b/src/blackmisc/aviation/comsystem.cpp index 9622b35b1..5ca15eca0 100644 --- a/src/blackmisc/aviation/comsystem.cpp +++ b/src/blackmisc/aviation/comsystem.cpp @@ -67,6 +67,16 @@ namespace BlackMisc return isWithinChannelSpacing(this->getFrequencyActive(), comFrequency, ChannelSpacing25KHz); } + bool CComSystem::isActiveFrequencyWithin50kHzChannel(const CFrequency &comFrequency) const + { + return isWithinChannelSpacing(this->getFrequencyActive(), comFrequency, ChannelSpacing50KHz); + } + + bool CComSystem::isActiveFrequencyWithinChannelSpacing(const CFrequency &comFrequency, CComSystem::ChannelSpacing channelSpacing) const + { + return isWithinChannelSpacing(this->getFrequencyActive(), comFrequency, channelSpacing); + } + void CComSystem::setActiveUnicom() { this->toggleActiveStandby(); @@ -139,9 +149,9 @@ namespace BlackMisc { if (setFrequency.isNull() || compareFrequency.isNull()) { return false; } if (setFrequency == compareFrequency) return true; // shortcut for many of such comparisons - double channelSpacingKHz = 0.5 * CComSystem::channelSpacingToFrequencyKHz(channelSpacing); - double compareFrequencyKHz = compareFrequency.value(CFrequencyUnit::kHz()); - double setFrequencyKHz = setFrequency.value(CFrequencyUnit::kHz()); + const double channelSpacingKHz = 0.5 * CComSystem::channelSpacingToFrequencyKHz(channelSpacing); + const double compareFrequencyKHz = compareFrequency.value(CFrequencyUnit::kHz()); + const double setFrequencyKHz = setFrequency.value(CFrequencyUnit::kHz()); return (setFrequencyKHz - channelSpacingKHz < compareFrequencyKHz) && (setFrequencyKHz + channelSpacingKHz > compareFrequencyKHz); } diff --git a/src/blackmisc/aviation/comsystem.h b/src/blackmisc/aviation/comsystem.h index 483eeb713..06e0ddad4 100644 --- a/src/blackmisc/aviation/comsystem.h +++ b/src/blackmisc/aviation/comsystem.h @@ -94,6 +94,12 @@ namespace BlackMisc //! Is active frequency within 25kHz channel? bool isActiveFrequencyWithin25kHzChannel(const PhysicalQuantities::CFrequency &comFrequency) const; + //! Is active frequency within 25kHz channel? + bool isActiveFrequencyWithin50kHzChannel(const PhysicalQuantities::CFrequency &comFrequency) const; + + //! Is active frequency within 25kHz channel? + bool isActiveFrequencyWithinChannelSpacing(const PhysicalQuantities::CFrequency &comFrequency, CComSystem::ChannelSpacing channelSpacing) const; + //! Set UNICOM frequency as active void setActiveUnicom();