Ref T432, find ATC station for frequency utility functions

This commit is contained in:
Klaus Basan
2018-11-15 20:45:33 +01:00
parent beec69281a
commit 781db93355
6 changed files with 83 additions and 37 deletions

View File

@@ -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<ColumnIndex>();
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<ColumnIndex>();
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))
{

View File

@@ -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,

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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();