Consider Channel Spacing (50, 25, 8.33kHz) for COM frequencies.

Deals with a special topic: While frequencies at VATSIM/flightsim are usually set in 25kHz spacing, some ATC stations (radar) require 8.33kHz tuning.
The now made extension handles this and allows to listen to a voice room even if the corresponding frequency is not exactly tuned in.

Example: EKDK_CTR 135,270 but needs to be tuned in as 135,275
This commit is contained in:
Klaus Basan
2014-01-26 15:51:48 +01:00
parent 14e90a6bc6
commit 0fa421d8a6
9 changed files with 175 additions and 57 deletions

View File

@@ -87,13 +87,10 @@ namespace BlackCore
*/
CVoiceRoomList CContextNetwork::getSelectedVoiceRooms() const
{
CFrequency com1 = this->m_ownAircraft.getCom1System().getFrequencyActive();
CFrequency com2 = this->m_ownAircraft.getCom2System().getFrequencyActive();
CAtcStationList stationsCom1 = this->m_atcStationsOnline.findBy(&CAtcStation::getFrequency, com1);
CAtcStationList stationsCom2 = this->m_atcStationsOnline.findBy(&CAtcStation::getFrequency, com2);
stationsCom1.sortBy(&CAtcStation::getDistanceToPlane);
CAtcStationList stationsCom1 = this->m_atcStationsOnline.findIfComUnitTunedIn25KHz(this->m_ownAircraft.getCom1System());
CAtcStationList stationsCom2 = this->m_atcStationsOnline.findIfComUnitTunedIn25KHz(this->m_ownAircraft.getCom2System());
stationsCom1.sortBy(&CAtcStation::getDistanceToPlane);
stationsCom2.sortBy(&CAtcStation::getDistanceToPlane);
CVoiceRoom vr;
CVoiceRoomList rooms;

View File

@@ -188,6 +188,16 @@ namespace BlackMisc
*/
void setCom2System(const CComSystem &comSystem) { this->m_com2system = comSystem; }
/*!
* \brief Is any (COM1/2) active frequency within 8.3383kHz channel?
*/
bool isActiveFrequencyWithin8_33kHzChannel(const BlackMisc::PhysicalQuantities::CFrequency &comFrequency)
{
return this->m_com1system.isActiveFrequencyWithin8_33kHzChannel(comFrequency) ||
this->m_com2system.isActiveFrequencyWithin8_33kHzChannel(comFrequency);
}
/*!
* \brief Get transponder
*/

View File

@@ -10,15 +10,15 @@
#ifndef BLACKMISC_ATCSTATION_H
#define BLACKMISC_ATCSTATION_H
#include "valuemap.h"
#include "vvoiceroom.h"
#include "aviocomsystem.h"
#include "avinformationmessage.h"
#include "avcallsign.h"
#include "nwuser.h"
#include "coordinategeodetic.h"
#include "pqfrequency.h"
#include "pqlength.h"
#include "pqtime.h"
#include "nwuser.h"
#include "vvoiceroom.h"
#include "coordinategeodetic.h"
#include "avcallsign.h"
#include "avinformationmessage.h"
#include <QDateTime>
#include <QMap>
#include <functional>
@@ -319,6 +319,14 @@ namespace BlackMisc
*/
bool isBookedNow() const;
/*!
* \brief Tuned in within 25KHz channel spacing
*/
bool isComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const
{
return comUnit.isActiveFrequencyWithin25kHzChannel(this->getFrequency());
}
/*!
* When booked, 0 means now,
* negative values mean booking in past,

View File

@@ -55,12 +55,23 @@ namespace BlackMisc
});
}
/*
* Find if on frequency of COM unit
*/
CAtcStationList CAtcStationList::findIfComUnitTunedIn25KHz(const CComSystem &comUnit) const
{
return this->findBy([&](const CAtcStation & atcStation)
{
return atcStation.isComUnitTunedIn25KHz(comUnit);
});
}
/*
* Distances to own plane
*/
void CAtcStationList::calculateDistancesToPlane(const Geo::CCoordinateGeodetic &position)
{
std::for_each(this->begin(), this->end(), [ & ](CAtcStation &station)
std::for_each(this->begin(), this->end(), [ & ](CAtcStation & station)
{
station.calculcateDistanceToPlane(position);
});

View File

@@ -49,22 +49,21 @@ namespace BlackMisc
/*!
* \brief Find 0..n stations by callsign
* \param callsign
* \return
*/
CAtcStationList findByCallsign(const CCallsign &callsign) const;
/*!
* \brief Find 0..n stations within range of given coordinate
* \param coordinate
* \param range
* \return
*/
CAtcStationList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const;
/*!
* \brief Update distances to own plane
* \param position
* \brief Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing
*/
CAtcStationList findIfComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const;
/*!
* \brief Update distances to coordinate, usually own aircraft's position
*/
void calculateDistancesToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);

View File

@@ -79,8 +79,7 @@ namespace BlackMisc
}
/*!
* \brief Stream to DBus <<
* \param argument
* \copydoc CValueObject::marshallToDbus()
*/
virtual void marshallToDbus(QDBusArgument &argument) const
{
@@ -88,8 +87,7 @@ namespace BlackMisc
}
/*!
* \brief Stream from DBus >>
* \param argument
* \copydoc CValueObject::unmarshallFromDbus()
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument)
{

View File

@@ -41,7 +41,7 @@ namespace BlackMisc
{
CFrequency f(frequencyMHz, CFrequencyUnit::MHz());
if (f == this->getFrequencyActive()) return; // save all the comparisons / rounding
CComSystem::roundTo25KHz(f);
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
this->CModulator::setFrequencyActive(f);
this->validate(true);
}
@@ -50,24 +50,74 @@ namespace BlackMisc
{
CFrequency f(frequencyMHz, CFrequencyUnit::MHz());
if (f == this->getFrequencyStandby()) return; // save all the comparisons / rounding
CComSystem::roundTo25KHz(f);
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
this->CModulator::setFrequencyStandby(f);
this->validate(true);
}
/*
* Round to 25KHz
* Round to channel spacing
*/
void CComSystem::roundTo25KHz(PhysicalQuantities::CFrequency &frequency)
void CComSystem::roundToChannelSpacing(PhysicalQuantities::CFrequency &frequency, ChannelSpacing channelSpacing)
{
double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
double f = frequency.valueRounded(CFrequencyUnit::kHz(), 0);
quint32 d = static_cast<quint32>(f / 25.0);
quint32 d = static_cast<quint32>(f / channelSpacingKHz);
frequency.switchUnit(CFrequencyUnit::MHz());
double f0 = frequency.valueRounded(CFrequencyUnit::MHz(), 3);
double f1 = CMath::round(d * (25.0 / 1000.0), 3);
double f2 = CMath::round((d + 1) * (25.0 / 1000.0), 3);
double f1 = CMath::round(d * (channelSpacingKHz / 1000.0), 3);
double f2 = CMath::round((d + 1) * (channelSpacingKHz / 1000.0), 3);
bool down = qAbs(f1 - f0) < qAbs(f2 - f0); // which is the closest value
frequency.setCurrentUnitValue(down ? f1 : f2);
}
/*
* Within channel spacing
*/
bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing)
{
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());
return (setFrequencyKHz - channelSpacingKHz < compareFrequencyKHz) &&
(setFrequencyKHz + channelSpacingKHz > compareFrequencyKHz);
}
/*
* Helper, give me number for channels spacing
*/
double CComSystem::channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing)
{
switch (channelSpacing)
{
case ChannelSpacing50KHz: return 50.0;
case ChannelSpacing25KHz: return 25.0;
case ChannelSpacing8_33KHz: return 25.0 / 3.0;
default: qFatal("Wrong channel spacing"); return 0.0; // return just supressing compiler warning
}
}
/*
* Marshall
*/
void CComSystem::marshallToDbus(QDBusArgument &argument) const
{
CModulator::marshallToDbus(argument);
argument << static_cast<uint>(this->m_channelSpacing);
}
/*
* Unmarshall
*/
void CComSystem::unmarshallFromDbus(const QDBusArgument &argument)
{
CModulator::unmarshallFromDbus(argument);
uint cs;
argument >> cs;
this->m_channelSpacing = static_cast<ChannelSpacing>(cs);
}
} // namespace
}

View File

@@ -18,7 +18,20 @@ namespace BlackMisc
*/
class CComSystem : public CModulator<CComSystem>
{
public:
/*!
* Channel spacing frequency
*/
enum ChannelSpacing
{
ChannelSpacing50KHz,
ChannelSpacing25KHz,
ChannelSpacing8_33KHz
};
private:
ChannelSpacing m_channelSpacing;
/*!
* \brief Constructor
* \param validate
@@ -29,11 +42,17 @@ namespace BlackMisc
*
*/
CComSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3):
CModulator(name, activeFrequency, standbyFrequency, digits)
CModulator(name, activeFrequency, standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz)
{
this->validate(validate);
}
/*!
* \brief Give me channel spacing in KHz
* \remarks Just a helper method, that is why no CFrequency is returned
*/
static double channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing);
protected:
/*!
* \brief Are the set values valid / in range?
@@ -50,16 +69,35 @@ namespace BlackMisc
*/
bool validate(bool strict = true) const;
/*!
* \copydoc CValueObject::marshallFromDbus()
*/
virtual void marshallToDbus(QDBusArgument &argument) const;
/*!
* \copydoc CValueObject::unmarshallFromDbus()
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument);
public:
/*!
* Default constructor
*/
CComSystem() : CModulator() {}
CComSystem() : CModulator(), m_channelSpacing(ChannelSpacing25KHz) {}
/*!
* \brief Constructor
*/
CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3):
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz)
{
this->validate(true);
}
/*!
* \brief Copy constructor
*/
CComSystem(const CComSystem &other) : CModulator(other) {}
CComSystem(const CComSystem &other) : CModulator(other), m_channelSpacing(other.m_channelSpacing) {}
/*!
* \copydoc CValueObject::toQVariant
@@ -78,27 +116,35 @@ namespace BlackMisc
return CModulator::getValueHash();
}
/*!
* \brief Constructor
*/
CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3):
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits)
{
this->validate(true);
}
/*!
* \brief Set active frequency
* \remarks will be rounded to 25KHz
* \remarks will be rounded to channel spacing
* \see ChannelSpacing
*/
void setFrequencyActiveMHz(double frequencyMHz);
/*!
* \brief Set standby frequency
* \remarks will be rounded to 25KHz
* \remarks will be rounded to channel spacing
*/
void setFrequencyStandbyMHz(double frequencyMHz);
/*!
* \brief Is active frequency within 8.3383kHz channel?
*/
bool isActiveFrequencyWithin8_33kHzChannel(const BlackMisc::PhysicalQuantities::CFrequency &comFrequency)
{
return CComSystem::isWithinChannelSpacing(this->getFrequencyActive(), comFrequency, ChannelSpacing8_33KHz);
}
/*!
* \brief Is active frequency within 25kHz channel?
*/
bool isActiveFrequencyWithin25kHzChannel(const BlackMisc::PhysicalQuantities::CFrequency &comFrequency) const
{
return CComSystem::isWithinChannelSpacing(this->getFrequencyActive(), comFrequency, ChannelSpacing25KHz);
}
/*!
* \brief Set UNICOM frequency as active
*/
@@ -119,8 +165,6 @@ namespace BlackMisc
/*!
* \brief operator ==
* \param other
* \return
*/
bool operator ==(const CComSystem &other) const
{
@@ -129,8 +173,6 @@ namespace BlackMisc
/*!
* \brief operator !=
* \param other
* \return
*/
bool operator !=(const CComSystem &other) const
{
@@ -328,9 +370,15 @@ namespace BlackMisc
}
/*!
* \brief Round to 25KHz, set MHz as unit
* \brief Round to channel spacing, set MHz as unit
* \see ChannelSpacing
*/
static void roundTo25KHz(BlackMisc::PhysicalQuantities::CFrequency &frequency);
static void roundToChannelSpacing(BlackMisc::PhysicalQuantities::CFrequency &frequency, ChannelSpacing channelSpacing);
/*!
* \brief Is compareFrequency within channel spacing of setFrequency
*/
static bool isWithinChannelSpacing(const BlackMisc::PhysicalQuantities::CFrequency &setFrequency, const BlackMisc::PhysicalQuantities::CFrequency &compareFrequency, ChannelSpacing channelSpacing);
};

View File

@@ -205,20 +205,17 @@ namespace BlackMisc
}
/*!
* \brief Stream to DBus <<
* \param argument
* \copydoc CValueObject::marshallFromDbus()
*/
virtual void marshallToDbus(QDBusArgument &argument) const;
/*!
* \brief Stream from DBus >>
* \param argument
* \copydoc CValueObject::unmarshallFromDbus()
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument);
/*!
* \brief Value hash
* \return
* \copydoc CValueObject::getValueHash()
*/
virtual uint getValueHash() const;