1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -05:00

AFC: fixes. Implement devices apply and reset channels feedbac

This commit is contained in:
f4exb 2020-10-26 21:39:34 +01:00
parent d0081b2af4
commit b5162dfc5f
4 changed files with 29 additions and 31 deletions

View File

@ -47,7 +47,8 @@ AFC::AFC(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface), Feature(m_featureIdURI, webAPIAdapterInterface),
m_trackerDeviceSet(nullptr), m_trackerDeviceSet(nullptr),
m_trackedDeviceSet(nullptr), m_trackedDeviceSet(nullptr),
m_trackerIndexInDeviceSet(-1) m_trackerIndexInDeviceSet(-1),
m_trackerChannelAPI(nullptr)
{ {
setObjectName(m_featureId); setObjectName(m_featureId);
m_worker = new AFCWorker(webAPIAdapterInterface); m_worker = new AFCWorker(webAPIAdapterInterface);
@ -62,7 +63,7 @@ AFC::~AFC()
} }
delete m_worker; delete m_worker;
removeTrackerFeatureReferences(); removeTrackerFeatureReference();
removeTrackedFeatureReferences(); removeTrackedFeatureReferences();
} }
@ -141,6 +142,11 @@ bool AFC::handleMessage(const Message& cmd)
} }
else if (MsgDevicesApply::match(cmd)) else if (MsgDevicesApply::match(cmd))
{ {
removeTrackerFeatureReference();
trackerDeviceChange(m_settings.m_trackerDeviceSetIndex);
removeTrackedFeatureReferences();
trackedDeviceChange(m_settings.m_trackedDeviceSetIndex);
if (m_worker->isRunning()) if (m_worker->isRunning())
{ {
AFCWorker::MsgDevicesApply *msg = AFCWorker::MsgDevicesApply::create(); AFCWorker::MsgDevicesApply *msg = AFCWorker::MsgDevicesApply::create();
@ -221,11 +227,13 @@ void AFC::applySettings(const AFCSettings& settings, bool force)
if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force) if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force)
{ {
removeTrackerFeatureReference();
trackerDeviceChange(settings.m_trackerDeviceSetIndex); trackerDeviceChange(settings.m_trackerDeviceSetIndex);
} }
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force) if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force)
{ {
removeTrackedFeatureReferences();
trackedDeviceChange(settings.m_trackedDeviceSetIndex); trackedDeviceChange(settings.m_trackedDeviceSetIndex);
} }
@ -524,6 +532,7 @@ void AFC::trackerDeviceChange(int deviceIndex)
if (channel->getURI() == "sdrangel.channel.freqtracker") if (channel->getURI() == "sdrangel.channel.freqtracker")
{ {
channel->addFeatureSettingsFeedback(this); channel->addFeatureSettingsFeedback(this);
m_trackerChannelAPI = channel;
break; break;
} }
} }
@ -546,41 +555,26 @@ void AFC::trackedDeviceChange(int deviceIndex)
} }
} }
void AFC::removeTrackerFeatureReferences() void AFC::removeTrackerFeatureReference()
{ {
MainCore *mainCore = MainCore::instance(); if (m_trackerChannelAPI)
m_trackerIndexInDeviceSet = -1;
if ((m_settings.m_trackerDeviceSetIndex >= 0) && (m_settings.m_trackerDeviceSetIndex < mainCore->getDeviceSets().size()))
{ {
DeviceSet *trackerDeviceSet = mainCore->getDeviceSets()[m_settings.m_trackerDeviceSetIndex]; if (MainCore::instance()->existsChannel(m_trackerChannelAPI)) {
m_trackerChannelAPI->removeFeatureSettingsFeedback(this);
if (trackerDeviceSet == m_trackerDeviceSet)
{
for (int i = 0; i < m_trackerDeviceSet->getNumberOfChannels(); i++)
{
ChannelAPI *channel = m_trackerDeviceSet->getChannelAt(i);
channel->removeFeatureSettingsFeedback(this);
}
} }
} }
} }
void AFC::removeTrackedFeatureReferences() void AFC::removeTrackedFeatureReferences()
{ {
MainCore *mainCore = MainCore::instance(); for (QList<ChannelAPI*>::iterator it = m_trackedChannelAPIs.begin(); it != m_trackedChannelAPIs.end(); ++it)
if ((m_settings.m_trackedDeviceSetIndex >= 0) && (m_settings.m_trackedDeviceSetIndex < mainCore->getDeviceSets().size()))
{ {
DeviceSet *trackerDeviceSet = mainCore->getDeviceSets()[m_settings.m_trackedDeviceSetIndex]; ChannelAPI *channel = *it;
if (trackerDeviceSet == m_trackedDeviceSet) if (MainCore::instance()->existsChannel(channel)) {
{ channel->removeFeatureSettingsFeedback(this);
for (int i = 0; i < m_trackedDeviceSet->getNumberOfChannels(); i++)
{
ChannelAPI *channel = m_trackedDeviceSet->getChannelAt(i);
channel->removeFeatureSettingsFeedback(this);
}
} }
} }
m_trackedChannelAPIs.clear();
} }

View File

@ -161,6 +161,8 @@ private:
DeviceSet *m_trackerDeviceSet; DeviceSet *m_trackerDeviceSet;
DeviceSet *m_trackedDeviceSet; DeviceSet *m_trackedDeviceSet;
int m_trackerIndexInDeviceSet; int m_trackerIndexInDeviceSet;
ChannelAPI *m_trackerChannelAPI;
QList<ChannelAPI*> m_trackedChannelAPIs;
QNetworkAccessManager *m_networkManager; QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest; QNetworkRequest m_networkRequest;
@ -172,7 +174,7 @@ private:
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AFCSettings& settings, bool force); void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AFCSettings& settings, bool force);
void trackerDeviceChange(int deviceIndex); void trackerDeviceChange(int deviceIndex);
void trackedDeviceChange(int deviceIndex); void trackedDeviceChange(int deviceIndex);
void removeTrackerFeatureReferences(); void removeTrackerFeatureReference();
void removeTrackedFeatureReferences(); void removeTrackedFeatureReferences();
private slots: private slots:

View File

@ -362,7 +362,8 @@ void AFCGUI::on_trackedDevice_currentIndexChanged(int index)
void AFCGUI::on_devicesApply_clicked() void AFCGUI::on_devicesApply_clicked()
{ {
AFC::MsgDevicesApply *msg = AFC::MsgDevicesApply::create();
m_afc->getInputMessageQueue()->push(msg);
} }
void AFCGUI::on_targetPeriod_valueChanged(int value) void AFCGUI::on_targetPeriod_valueChanged(int value)

View File

@ -119,12 +119,14 @@ bool AFCWorker::handleMessage(const Message& cmd)
} }
else if (MsgDeviceTrack::match(cmd)) else if (MsgDeviceTrack::match(cmd))
{ {
qDebug() << "AFCWorker::handleMessage: MsgDeviceTrack";
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
updateTarget(); updateTarget();
return true; return true;
} }
else if (MsgDevicesApply::match(cmd)) else if (MsgDevicesApply::match(cmd))
{ {
qDebug() << "AFCWorker::handleMessage: MsgDevicesApply";
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
initTrackerDeviceSet(m_settings.m_trackerDeviceSetIndex); initTrackerDeviceSet(m_settings.m_trackerDeviceSetIndex);
initTrackedDeviceSet(m_settings.m_trackedDeviceSetIndex); initTrackedDeviceSet(m_settings.m_trackedDeviceSetIndex);
@ -294,6 +296,7 @@ void AFCWorker::processChannelSettings(
if (trackerChannelOffset != m_trackerChannelOffset) if (trackerChannelOffset != m_trackerChannelOffset)
{ {
qDebug("AFCWorker::processChannelSettings: FreqTracker offset change: %d", trackerChannelOffset); qDebug("AFCWorker::processChannelSettings: FreqTracker offset change: %d", trackerChannelOffset);
m_trackerChannelOffset = trackerChannelOffset;
QMap<ChannelAPI*, ChannelTracking>::iterator it = m_channelsMap.begin(); QMap<ChannelAPI*, ChannelTracking>::iterator it = m_channelsMap.begin();
for (; it != m_channelsMap.end(); ++it) for (; it != m_channelsMap.end(); ++it)
@ -308,8 +311,6 @@ void AFCWorker::processChannelSettings(
m_channelsMap.erase(it); m_channelsMap.erase(it);
} }
} }
m_trackerChannelOffset = trackerChannelOffset;
} }
} }
else if (m_channelsMap.contains(const_cast<ChannelAPI*>(channelAPI))) else if (m_channelsMap.contains(const_cast<ChannelAPI*>(channelAPI)))