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

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