2020-10-16 17:20:55 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef INCLUDE_FEATURE_AFCWORKER_H_
|
|
|
|
#define INCLUDE_FEATURE_AFCWORKER_H_
|
|
|
|
|
|
|
|
#include <QObject>
|
2020-10-22 06:38:43 +00:00
|
|
|
#include <QMap>
|
2020-10-16 17:20:55 +00:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "util/message.h"
|
|
|
|
#include "util/messagequeue.h"
|
|
|
|
|
|
|
|
#include "afcsettings.h"
|
|
|
|
|
|
|
|
class WebAPIAdapterInterface;
|
2020-10-22 06:38:43 +00:00
|
|
|
class DeviceSet;
|
|
|
|
class ChannelAPI;
|
2020-10-16 17:20:55 +00:00
|
|
|
|
|
|
|
class AFCWorker : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
class MsgConfigureAFCWorker : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const AFCSettings& getSettings() const { return m_settings; }
|
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
|
|
|
static MsgConfigureAFCWorker* create(const AFCSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
return new MsgConfigureAFCWorker(settings, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AFCSettings m_settings;
|
|
|
|
bool m_force;
|
|
|
|
|
|
|
|
MsgConfigureAFCWorker(const AFCSettings& settings, bool force) :
|
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
m_force(force)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-10-22 06:38:43 +00:00
|
|
|
class MsgTrackedDeviceChange : public Message {
|
2020-10-16 17:20:55 +00:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2020-10-22 06:38:43 +00:00
|
|
|
int getDeviceIndex() const { return m_deviceIndex; }
|
2020-10-16 17:20:55 +00:00
|
|
|
|
2020-10-22 06:38:43 +00:00
|
|
|
static MsgTrackedDeviceChange* create(int deviceIndex)
|
|
|
|
{
|
|
|
|
return new MsgTrackedDeviceChange(deviceIndex);
|
2020-10-16 17:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-10-22 06:38:43 +00:00
|
|
|
int m_deviceIndex;
|
2020-10-16 17:20:55 +00:00
|
|
|
|
2020-10-22 06:38:43 +00:00
|
|
|
MsgTrackedDeviceChange(int deviceIndex) :
|
2020-10-16 17:20:55 +00:00
|
|
|
Message(),
|
2020-10-22 06:38:43 +00:00
|
|
|
m_deviceIndex(deviceIndex)
|
2020-10-16 17:20:55 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-10-24 08:35:07 +00:00
|
|
|
class MsgDeviceTrack : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgDeviceTrack* create() {
|
|
|
|
return new MsgDeviceTrack();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
MsgDeviceTrack() :
|
|
|
|
Message()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgDevicesApply : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgDevicesApply* create() {
|
|
|
|
return new MsgDevicesApply();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
MsgDevicesApply() :
|
|
|
|
Message()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-10-16 17:20:55 +00:00
|
|
|
AFCWorker(WebAPIAdapterInterface *webAPIAdapterInterface);
|
|
|
|
~AFCWorker();
|
|
|
|
void reset();
|
|
|
|
bool startWork();
|
|
|
|
void stopWork();
|
|
|
|
bool isRunning() const { return m_running; }
|
|
|
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
|
|
|
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
|
|
|
|
|
|
|
|
private:
|
2020-10-22 06:38:43 +00:00
|
|
|
struct ChannelTracking
|
|
|
|
{
|
|
|
|
int m_channelOffset;
|
|
|
|
int m_trackerOffset;
|
|
|
|
int m_channelDirection;
|
|
|
|
|
|
|
|
ChannelTracking() :
|
|
|
|
m_channelOffset(0),
|
|
|
|
m_trackerOffset(0),
|
|
|
|
m_channelDirection(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ChannelTracking(int channelOffset, int trackerOffset, int channelDirection) :
|
|
|
|
m_channelOffset(channelOffset),
|
|
|
|
m_trackerOffset(trackerOffset),
|
|
|
|
m_channelDirection(m_channelDirection)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ChannelTracking(const ChannelTracking& other) :
|
|
|
|
m_channelOffset(other.m_channelOffset),
|
|
|
|
m_trackerOffset(other.m_trackerOffset),
|
|
|
|
m_channelDirection(other.m_channelDirection)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2020-10-16 17:20:55 +00:00
|
|
|
WebAPIAdapterInterface *m_webAPIAdapterInterface;
|
|
|
|
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
|
|
|
MessageQueue *m_msgQueueToGUI; //!< Queue to report state to GUI
|
|
|
|
AFCSettings m_settings;
|
|
|
|
bool m_running;
|
2020-10-22 06:38:43 +00:00
|
|
|
DeviceSet *m_trackerDeviceSet;
|
|
|
|
DeviceSet *m_trackedDeviceSet;
|
|
|
|
ChannelAPI *m_freqTracker;
|
|
|
|
uint64_t m_trackerDeviceFrequency;
|
|
|
|
int m_trackerChannelOffset;
|
|
|
|
QMap<ChannelAPI*, ChannelTracking> m_channelsMap;
|
2020-10-16 17:20:55 +00:00
|
|
|
QTimer m_updateTimer;
|
|
|
|
QMutex m_mutex;
|
|
|
|
|
|
|
|
bool handleMessage(const Message& cmd);
|
|
|
|
void applySettings(const AFCSettings& settings, bool force = false);
|
2020-10-22 06:38:43 +00:00
|
|
|
void initTrackerDeviceSet(int deviceSetIndex);
|
|
|
|
void initTrackedDeviceSet(int deviceSetIndex);
|
|
|
|
void processChannelSettings(
|
|
|
|
const ChannelAPI *channelAPI,
|
|
|
|
const QList<QString> &channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings
|
|
|
|
);
|
2020-10-24 08:35:07 +00:00
|
|
|
bool updateChannelOffset(ChannelAPI *channelAPI, int direction, int offset, unsigned int blockCount = 0);
|
2020-10-24 11:05:28 +00:00
|
|
|
void updateTarget(int& trackerChannelOffset);
|
2020-10-22 06:38:43 +00:00
|
|
|
bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency);
|
|
|
|
int getDeviceDirection(DeviceAPI *deviceAPI);
|
|
|
|
void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey);
|
2020-10-16 17:20:55 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleInputMessages();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_FEATURE_SIMPLEPTTWORKER_H_
|