mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
Ref T432, find ATC station for frequency utility functions
This commit is contained in:
@@ -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); }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<CAtcStation>,
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user