From 5724d286d0a2612364bf18d6c57caf3a7c6e750e Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sun, 5 Feb 2023 11:26:15 +0100 Subject: [PATCH] Add 8.33 kHz spacing helper methods Related to #186 --- src/blackmisc/aviation/comsystem.cpp | 13 +++++++++++++ src/blackmisc/aviation/comsystem.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/blackmisc/aviation/comsystem.cpp b/src/blackmisc/aviation/comsystem.cpp index c056ca5f6..5c5d78613 100644 --- a/src/blackmisc/aviation/comsystem.cpp +++ b/src/blackmisc/aviation/comsystem.cpp @@ -181,6 +181,19 @@ namespace BlackMisc::Aviation } } + bool CComSystem::isExclusiveWithin8_33kHzChannel(const PhysicalQuantities::CFrequency &freq) + { + const int freqKHz = freq.value(CFrequencyUnit::kHz()); + if (freqKHz < 118000 || freqKHz >= 137000 || !isValid8_33kHzChannel(freqKHz)) { return false; } + return !isWithin25kHzChannel(freq); + } + + bool CComSystem::isWithin25kHzChannel(const PhysicalQuantities::CFrequency &freq) + { + const int end = static_cast(freq.value(CFrequencyUnit::kHz())) % 100; + return end == 0 || end == 25 || end == 50 || end == 75; + } + bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing) { if (setFrequency.isNull() || compareFrequency.isNull()) { return false; } diff --git a/src/blackmisc/aviation/comsystem.h b/src/blackmisc/aviation/comsystem.h index e10542ba0..586c8f7ef 100644 --- a/src/blackmisc/aviation/comsystem.h +++ b/src/blackmisc/aviation/comsystem.h @@ -148,6 +148,13 @@ namespace BlackMisc::Aviation //! Round passed frequency in kHz to 8.33 frequency spacing static int round8_33kHzChannel(int fKHz); + //! Is frequency a "new" 8.33 kHz frequency and not within 25 kHz spacing + //! E.g. returns false for 122.825 but true for 118.305 + static bool isExclusiveWithin8_33kHzChannel(const PhysicalQuantities::CFrequency &freq); + + //! Is frequency within 25 kHz frequency spacing + static bool isWithin25kHzChannel(const PhysicalQuantities::CFrequency &freq); + //! Parses almost any shitty string to a valid COM frequency static PhysicalQuantities::CFrequency parseComFrequency(const QString &input, PhysicalQuantities::CPqString::SeparatorMode sep);