| 
									
										
										
										
											2020-10-16 19:20:55 +02: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 08:38:43 +02:00
										 |  |  | #include <QMap>
 | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | #include <QTimer>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "util/message.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "afcsettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebAPIAdapterInterface; | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  | class DeviceSet; | 
					
						
							|  |  |  | class ChannelAPI; | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class AFCWorker : public QObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     class MsgConfigureAFCWorker : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const AFCSettings& getSettings() const { return m_settings; } | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |         const QList<QString>& getSettingsKeys() const { return m_settingsKeys; } | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |         static MsgConfigureAFCWorker* create(const AFCSettings& settings, const QList<QString>& settingsKeys, bool force) | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |             return new MsgConfigureAFCWorker(settings, settingsKeys, force); | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         AFCSettings m_settings; | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |         QList<QString> m_settingsKeys; | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |         MsgConfigureAFCWorker(const AFCSettings& settings, const QList<QString>& settingsKeys, bool force) : | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |             m_settingsKeys(settingsKeys), | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |             m_force(force) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |     class MsgTrackedDeviceChange : public Message { | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |         int getDeviceIndex() const { return m_deviceIndex; } | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |         static MsgTrackedDeviceChange* create(int deviceIndex) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgTrackedDeviceChange(deviceIndex); | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |         int m_deviceIndex; | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |         MsgTrackedDeviceChange(int deviceIndex) : | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |             Message(), | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |             m_deviceIndex(deviceIndex) | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-24 10:35:07 +02: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 19:20:55 +02:00
										 |  |  |     AFCWorker(WebAPIAdapterInterface *webAPIAdapterInterface); | 
					
						
							|  |  |  |     ~AFCWorker(); | 
					
						
							|  |  |  |     void reset(); | 
					
						
							| 
									
										
										
										
											2022-09-21 06:01:45 +02:00
										 |  |  |     void startWork(); | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |     void stopWork(); | 
					
						
							|  |  |  |     MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } | 
					
						
							|  |  |  |     void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; } | 
					
						
							| 
									
										
										
										
											2020-10-26 13:48:19 +01:00
										 |  |  |     uint64_t getTrackerDeviceFrequency() const { return m_trackerDeviceFrequency; } | 
					
						
							|  |  |  |     int getTrackerChannelOffset() const { return m_trackerChannelOffset; } | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02: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), | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |             m_channelDirection(channelDirection) | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |         {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ChannelTracking(const ChannelTracking& other) : | 
					
						
							|  |  |  |             m_channelOffset(other.m_channelOffset), | 
					
						
							|  |  |  |             m_trackerOffset(other.m_trackerOffset), | 
					
						
							|  |  |  |             m_channelDirection(other.m_channelDirection) | 
					
						
							|  |  |  |         {} | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |     WebAPIAdapterInterface *m_webAPIAdapterInterface; | 
					
						
							|  |  |  | 	MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
 | 
					
						
							|  |  |  |     MessageQueue *m_msgQueueToGUI; //!< Queue to report state to GUI
 | 
					
						
							|  |  |  |     AFCSettings m_settings; | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02: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 19:20:55 +02:00
										 |  |  | 	QTimer m_updateTimer; | 
					
						
							| 
									
										
										
										
											2022-09-15 21:59:42 +02:00
										 |  |  |     QRecursiveMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool handleMessage(const Message& cmd); | 
					
						
							| 
									
										
										
										
											2022-11-19 23:30:49 +01:00
										 |  |  |     void applySettings(const AFCSettings& settings, const QList<QString>& settingsKeys, bool force = false); | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |     void initTrackerDeviceSet(int deviceSetIndex); | 
					
						
							|  |  |  |     void initTrackedDeviceSet(int deviceSetIndex); | 
					
						
							|  |  |  |     void processChannelSettings( | 
					
						
							|  |  |  |         const ChannelAPI *channelAPI, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings *swgChannelSettings | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     bool updateChannelOffset(ChannelAPI *channelAPI, int direction, int offset); | 
					
						
							| 
									
										
										
										
											2020-10-22 08:38:43 +02:00
										 |  |  |     bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency); | 
					
						
							|  |  |  |     int getDeviceDirection(DeviceAPI *deviceAPI); | 
					
						
							|  |  |  |     void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey); | 
					
						
							| 
									
										
										
										
											2020-10-26 13:48:19 +01:00
										 |  |  |     void reportUpdateTarget(int correction, bool done); | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2020-10-25 11:34:47 +01:00
										 |  |  |     void updateTarget(); | 
					
						
							| 
									
										
										
										
											2020-10-16 19:20:55 +02:00
										 |  |  |     void handleInputMessages(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 11:00:03 +00:00
										 |  |  | #endif // INCLUDE_FEATURE_AFCWORKER_H_
 |