diff --git a/src/host/setup/ChannelConfigSetWnd.h b/src/host/setup/ChannelConfigSetWnd.h index 574f646d..e4a4af03 100644 --- a/src/host/setup/ChannelConfigSetWnd.h +++ b/src/host/setup/ChannelConfigSetWnd.h @@ -149,6 +149,9 @@ private: m_channelNo.setRange(0, 4095); m_channelNo.setShadow(false); m_channelNo.addCallback("changed", [&]() { + if (!m_radioChNo.isChecked()) + return; + m_setup->m_conf["system"]["config"]["channelNo"] = __INT_HEX_STR(m_channelNo.getValue()); m_setup->calculateRxTxFreq(); m_channelFreq.setValue(m_setup->m_txFrequency); @@ -167,34 +170,17 @@ private: m_channelFreq.setValue(m_setup->m_txFrequency); m_channelFreq.setShadow(false); m_channelFreq.addCallback("changed", [&]() { - entry = m_setup->m_idenTable->find(m_setup->m_channelId); - - uint32_t txFrequency = m_channelFreq.getValue(); - - uint32_t prevTxFrequency = m_setup->m_txFrequency; - m_setup->m_txFrequency = txFrequency; - uint32_t prevRxFrequency = m_setup->m_rxFrequency; - m_setup->m_rxFrequency = m_setup->m_txFrequency + (uint32_t)(entry.txOffsetMhz() * 1000000); - - float spaceHz = entry.chSpaceKhz() * 1000; + if (!m_radioChFreq.isChecked()) + return; - uint32_t rootFreq = m_setup->m_txFrequency - entry.baseFrequency(); - uint8_t prevChannelNo = m_setup->m_channelNo; - m_setup->m_channelNo = (uint32_t)(rootFreq / spaceHz); - - if (m_setup->m_channelNo < 0 || m_setup->m_channelNo > 4096) { - m_setup->m_channelNo = prevChannelNo; - m_setup->m_txFrequency = prevTxFrequency; - m_setup->m_rxFrequency = prevRxFrequency; - } - - m_setup->m_conf["system"]["config"]["channelNo"] = __INT_HEX_STR(m_setup->m_channelNo); - m_setup->calculateRxTxFreq(); + uint32_t txFrequency = (uint32_t)(m_channelFreq.getValue()); + m_setup->calculateRxTxFreq(false, txFrequency); m_channelNo.setValue(m_setup->m_channelNo); if (m_setup->m_isConnected) { m_setup->writeRFParams(); } }); + m_hzLabel.setGeometry(FPoint(40, 12), FSize(5, 1)); } diff --git a/src/host/setup/HostSetup.cpp b/src/host/setup/HostSetup.cpp index 28112b1d..4a084026 100644 --- a/src/host/setup/HostSetup.cpp +++ b/src/host/setup/HostSetup.cpp @@ -598,7 +598,7 @@ void HostSetup::saveConfig() /* Helper to calculate the Rx/Tx frequencies. */ -bool HostSetup::calculateRxTxFreq(bool consoleDisplay) +bool HostSetup::calculateRxTxFreq(bool consoleDisplay, uint32_t txFrequency) { IdenTable entry = m_idenTable->find(m_channelId); if (entry.baseFrequency() == 0U) { @@ -610,37 +610,57 @@ bool HostSetup::calculateRxTxFreq(bool consoleDisplay) return false; } - yaml::Node systemConf = m_conf["system"]; - yaml::Node rfssConfig = systemConf["config"]; - m_channelNo = (uint32_t)::strtoul(rfssConfig["channelNo"].as("1").c_str(), NULL, 16); - if (m_channelNo == 0U) { // clamp to 1 - m_channelNo = 1U; - } - if (m_channelNo > 4095U) { // clamp to 4095 - m_channelNo = 4095U; - } + if (txFrequency > 0U) { + uint32_t prevTxFrequency = m_txFrequency; + m_txFrequency = txFrequency; + uint32_t prevRxFrequency = m_rxFrequency; + m_rxFrequency = m_txFrequency + (uint32_t)(entry.txOffsetMhz() * 1000000); - if (m_startupDuplex) { - if (entry.txOffsetMhz() == 0U) { - if (consoleDisplay) { - g_logDisplayLevel = 1U; - } + float spaceHz = entry.chSpaceKhz() * 1000.0; - ::LogError(LOG_HOST, "Channel Id %u has an invalid Tx offset.", m_channelId); - return false; - } - - uint32_t calcSpace = (uint32_t)(entry.chSpaceKhz() / 0.125); - float calcTxOffset = entry.txOffsetMhz() * 1000000.0; + uint32_t rootFreq = m_txFrequency - entry.baseFrequency(); + uint8_t prevChannelNo = m_channelNo; + m_channelNo = (uint32_t)(rootFreq / spaceHz); - m_rxFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo)) + (int32_t)calcTxOffset); - m_txFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo))); + if (m_channelNo < 0 || m_channelNo > 4096) { + m_channelNo = prevChannelNo; + m_txFrequency = prevTxFrequency; + m_rxFrequency = prevRxFrequency; + } } else { - uint32_t calcSpace = (uint32_t)(entry.chSpaceKhz() / 0.125); + yaml::Node systemConf = m_conf["system"]; + yaml::Node rfssConfig = systemConf["config"]; + m_channelNo = (uint32_t)::strtoul(rfssConfig["channelNo"].as("1").c_str(), NULL, 16); + if (m_channelNo == 0U) { // clamp to 1 + m_channelNo = 1U; + } + if (m_channelNo > 4095U) { // clamp to 4095 + m_channelNo = 4095U; + } + + if (m_startupDuplex) { + if (entry.txOffsetMhz() == 0U) { + if (consoleDisplay) { + g_logDisplayLevel = 1U; + } + + ::LogError(LOG_HOST, "Channel Id %u has an invalid Tx offset.", m_channelId); + return false; + } - m_rxFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo))); - m_txFrequency = m_rxFrequency; + uint32_t calcSpace = (uint32_t)(entry.chSpaceKhz() / 0.125); + float calcTxOffset = entry.txOffsetMhz() * 1000000.0; + + m_rxFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo)) + (int32_t)calcTxOffset); + m_txFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo))); + } + else { + uint32_t calcSpace = (uint32_t)(entry.chSpaceKhz() / 0.125); + + m_rxFrequency = (uint32_t)((entry.baseFrequency() + ((calcSpace * 125) * m_channelNo))); + m_txFrequency = m_rxFrequency; + } } if (m_isHotspot) { diff --git a/src/host/setup/HostSetup.h b/src/host/setup/HostSetup.h index 2c0d36c1..8d7c6545 100644 --- a/src/host/setup/HostSetup.h +++ b/src/host/setup/HostSetup.h @@ -218,9 +218,10 @@ protected: /** * @brief Helper to calculate the Rx/Tx frequencies. * @param consoleDisplay Flag indicating output should goto the console log. + * @param txFrequency Transmit frequency to use (this will auto calculate the Rx frequency from Tx frequency). * @returns bool True, if Rx/Tx frequencies are calculated, otherwise false. */ - bool calculateRxTxFreq(bool consoleDisplay = false); + bool calculateRxTxFreq(bool consoleDisplay = false, uint32_t txFrequency = 0U); /** * @brief Helper to log the system configuration parameters. */