AFC: process tracker frequency change only if its offset actually chages

This commit is contained in:
f4exb 2020-10-24 13:05:28 +02:00
parent b69ab47e90
commit bee032833e
3 changed files with 28 additions and 22 deletions

View File

@ -124,7 +124,7 @@ AFCGUI::AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);
ui->targetFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->targetFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->targetFrequency->setValueRange(11, 0, 99999999999L); ui->targetFrequency->setValueRange(10, 0, 9999999999L);
ui->toleranceFrequency->setColorMapper(ColorMapper(ColorMapper::GrayYellow)); ui->toleranceFrequency->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
ui->toleranceFrequency->setValueRange(5, 0, 99999L); ui->toleranceFrequency->setValueRange(5, 0, 99999L);

View File

@ -115,7 +115,7 @@ bool AFCWorker::handleMessage(const Message& cmd)
else if (MsgDeviceTrack::match(cmd)) else if (MsgDeviceTrack::match(cmd))
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
updateTarget(); updateTarget(m_trackerChannelOffset);
return true; return true;
} }
else if (MsgDevicesApply::match(cmd)) else if (MsgDevicesApply::match(cmd))
@ -267,24 +267,30 @@ void AFCWorker::processChannelSettings(
if (*swgChannelSettings->getChannelType() == "FreqTracker") if (*swgChannelSettings->getChannelType() == "FreqTracker")
{ {
m_trackerChannelOffset = swgChannelSettings->getFreqTrackerSettings()->getInputFrequencyOffset(); int trackerChannelOffset = swgChannelSettings->getFreqTrackerSettings()->getInputFrequencyOffset();
QMap<ChannelAPI*, ChannelTracking>::iterator it = m_channelsMap.begin();
for (; it != m_channelsMap.end(); ++it) if (trackerChannelOffset != m_trackerChannelOffset)
{ {
if (mainCore->existsChannel(it.key())) QMap<ChannelAPI*, ChannelTracking>::iterator it = m_channelsMap.begin();
{
int channelOffset = it.value().m_channelOffset + m_trackerChannelOffset - it.value().m_trackerOffset;
updateChannelOffset(it.key(), it.value().m_channelDirection, channelOffset);
}
else
{
m_channelsMap.erase(it);
}
}
if (m_settings.m_hasTargetFrequency) { for (; it != m_channelsMap.end(); ++it)
updateTarget(); {
if (mainCore->existsChannel(it.key()))
{
int channelOffset = it.value().m_channelOffset + trackerChannelOffset - it.value().m_trackerOffset;
updateChannelOffset(it.key(), it.value().m_channelDirection, channelOffset);
}
else
{
m_channelsMap.erase(it);
}
}
if (m_settings.m_hasTargetFrequency) {
updateTarget(trackerChannelOffset);
}
m_trackerChannelOffset = trackerChannelOffset;
} }
} }
else if (m_channelsMap.contains(const_cast<ChannelAPI*>(channelAPI))) else if (m_channelsMap.contains(const_cast<ChannelAPI*>(channelAPI)))
@ -340,7 +346,7 @@ bool AFCWorker::updateChannelOffset(ChannelAPI *channelAPI, int direction, int o
return true; return true;
} }
void AFCWorker::updateTarget() void AFCWorker::updateTarget(int& trackerChannelOffset)
{ {
SWGSDRangel::SWGDeviceSettings resDevice; SWGSDRangel::SWGDeviceSettings resDevice;
SWGSDRangel::SWGChannelSettings resChannel; SWGSDRangel::SWGChannelSettings resChannel;
@ -370,7 +376,7 @@ void AFCWorker::updateTarget()
return; return;
} }
int64_t trackerFrequency = m_trackerDeviceFrequency + m_trackerChannelOffset; int64_t trackerFrequency = m_trackerDeviceFrequency + trackerChannelOffset;
int64_t correction = m_settings.m_targetFrequency - trackerFrequency; int64_t correction = m_settings.m_targetFrequency - trackerFrequency;
int64_t tolerance = m_settings.m_freqTolerance; int64_t tolerance = m_settings.m_freqTolerance;
qDebug() << "AFCWorker::updateTarget: correction:" << correction << "tolerance:" << tolerance; qDebug() << "AFCWorker::updateTarget: correction:" << correction << "tolerance:" << tolerance;
@ -397,8 +403,8 @@ void AFCWorker::updateTarget()
} }
// adjust tracker offset // adjust tracker offset
if (updateChannelOffset(m_freqTracker, 0, m_trackerChannelOffset + correction, 1)) { if (updateChannelOffset(m_freqTracker, 0, trackerChannelOffset + correction, 1)) {
m_trackerChannelOffset += correction; trackerChannelOffset += correction;
} }
} }
else // act on device else // act on device

View File

@ -163,7 +163,7 @@ private:
SWGSDRangel::SWGChannelSettings *swgChannelSettings SWGSDRangel::SWGChannelSettings *swgChannelSettings
); );
bool updateChannelOffset(ChannelAPI *channelAPI, int direction, int offset, unsigned int blockCount = 0); bool updateChannelOffset(ChannelAPI *channelAPI, int direction, int offset, unsigned int blockCount = 0);
void updateTarget(); void updateTarget(int& trackerChannelOffset);
bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency); bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency);
int getDeviceDirection(DeviceAPI *deviceAPI); int getDeviceDirection(DeviceAPI *deviceAPI);
void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey); void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey);