| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 06:28:24 +01:00
										 |  |  | // Copyright (C) 2018-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>          //
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Kacper Michajłow <kasper93@gmail.com>                      //
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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_INTERFEROMETER_H
 | 
					
						
							|  |  |  | #define INCLUDE_INTERFEROMETER_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <QNetworkRequest>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/mimochannel.h"
 | 
					
						
							|  |  |  | #include "dsp/spectrumvis.h"
 | 
					
						
							| 
									
										
										
										
											2021-05-30 13:12:00 +02:00
										 |  |  | #include "dsp/scopevis.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | #include "channel/channelapi.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							|  |  |  | #include "util/message.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "interferometersettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QThread; | 
					
						
							|  |  |  | class DeviceAPI; | 
					
						
							|  |  |  | class InterferometerBaseband; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							|  |  |  | class QNetworkAccessManager; | 
					
						
							| 
									
										
										
										
											2022-03-02 23:07:15 +01:00
										 |  |  | class ObjectPipe; | 
					
						
							| 
									
										
										
										
											2024-05-12 21:53:09 +02:00
										 |  |  | class DevieSampleSource; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | class Interferometer: public MIMOChannel, public ChannelAPI | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     class MsgConfigureInterferometer : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const InterferometerSettings& getSettings() const { return m_settings; } | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         const QList<QString>& getSettingsKeys() const { return m_settingsKeys; } | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         static MsgConfigureInterferometer* create(const InterferometerSettings& settings, const QList<QString>& settingsKeys, bool force) | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |             return new MsgConfigureInterferometer(settings, settingsKeys, force); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         InterferometerSettings m_settings; | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         QList<QString> m_settingsKeys; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         MsgConfigureInterferometer(const InterferometerSettings& settings, const QList<QString>& settingsKeys, bool force) : | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |             m_settingsKeys(settingsKeys), | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |             m_force(force) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class MsgBasebandNotification : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         static MsgBasebandNotification* create(int sampleRate, qint64 centerFrequency) { | 
					
						
							|  |  |  |             return new MsgBasebandNotification(sampleRate, centerFrequency); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int getSampleRate() const { return m_sampleRate; } | 
					
						
							|  |  |  |         qint64 getCenterFrequency() const { return m_centerFrequency; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgBasebandNotification(int sampleRate, qint64 centerFrequency) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_sampleRate(sampleRate), | 
					
						
							|  |  |  |             m_centerFrequency(centerFrequency) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int m_sampleRate; | 
					
						
							|  |  |  |         qint64 m_centerFrequency; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     class MsgReportDevices : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         QList<int>& getDeviceSetIndexes() { return m_deviceSetIndexes; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgReportDevices* create() { | 
					
						
							|  |  |  |             return new MsgReportDevices(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         QList<int> m_deviceSetIndexes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgReportDevices() : | 
					
						
							|  |  |  |             Message() | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     explicit Interferometer(DeviceAPI *deviceAPI); | 
					
						
							|  |  |  | 	~Interferometer() final; | 
					
						
							|  |  |  | 	void destroy() final { delete this; } | 
					
						
							|  |  |  |     void setDeviceAPI(DeviceAPI *deviceAPI) final; | 
					
						
							|  |  |  |     DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void startSinks() final; //!< thread start()
 | 
					
						
							|  |  |  | 	void stopSinks() final;  //!< thread exit() and wait()
 | 
					
						
							|  |  |  |     void startSources() final { /* not for MIMMO*/ } | 
					
						
							|  |  |  |     void stopSources() final { /* not for MIMMO*/ } | 
					
						
							|  |  |  | 	void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex) final; | 
					
						
							|  |  |  |     void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex) final; | 
					
						
							|  |  |  |     void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } | 
					
						
							|  |  |  |     QString getMIMOName() final { return objectName(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void getIdentifier(QString& id) final { id = objectName(); } | 
					
						
							|  |  |  |     QString getIdentifier() const final { return objectName(); } | 
					
						
							|  |  |  |     void getTitle(QString& title) final { title = "Interferometer"; } | 
					
						
							|  |  |  |     qint64 getCenterFrequency() const final { return m_frequencyOffset; } | 
					
						
							|  |  |  |     void setCenterFrequency(qint64) final { /* not for MIMMO*/ } | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     uint32_t getDeviceSampleRate() const { return m_deviceSampleRate; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     QByteArray serialize() const final; | 
					
						
							|  |  |  |     bool deserialize(const QByteArray& data) final; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     int getNbSinkStreams() const final { return 2; } | 
					
						
							|  |  |  |     int getNbSourceStreams() const final { return 0; } | 
					
						
							|  |  |  |     int getStreamIndex() const final { return -1; } | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         (void) streamIndex; | 
					
						
							|  |  |  |         (void) sinkElseSource; | 
					
						
							|  |  |  |         return m_frequencyOffset; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } | 
					
						
							| 
									
										
										
										
											2021-05-30 13:12:00 +02:00
										 |  |  |     ScopeVis *getScopeVis() { return &m_scopeSink; } | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     void applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash); | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     const QList<int>& getDeviceSetList() { return m_localInputDeviceIndexes; } | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     int webapiSettingsGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |         QString& errorMessage) final; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     int webapiSettingsPutPatch( | 
					
						
							|  |  |  |         bool force, | 
					
						
							|  |  |  |         const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |         QString& errorMessage) final; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     int webapiWorkspaceGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& query, | 
					
						
							|  |  |  |         QString& errorMessage) final; | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     static void webapiFormatChannelSettings( | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |         const InterferometerSettings& settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static void webapiUpdateChannelSettings( | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |         InterferometerSettings& settings, | 
					
						
							|  |  |  |         const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 20:24:18 +01:00
										 |  |  |     static const char* const m_channelIdURI; | 
					
						
							|  |  |  |     static const char* const m_channelId; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     static const int m_fftSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     DeviceAPI *m_deviceAPI; | 
					
						
							|  |  |  |     SpectrumVis m_spectrumVis; | 
					
						
							| 
									
										
										
										
											2021-05-30 13:12:00 +02:00
										 |  |  |     ScopeVis m_scopeSink; | 
					
						
							| 
									
										
										
										
											2022-10-10 23:15:49 +02:00
										 |  |  |     QThread *m_thread; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     InterferometerBaseband* m_basebandSink; | 
					
						
							| 
									
										
										
										
											2024-07-06 22:43:46 +02:00
										 |  |  |     QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2022-10-10 23:15:49 +02:00
										 |  |  |     bool m_running; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     InterferometerSettings m_settings; | 
					
						
							|  |  |  |     MessageQueue *m_guiMessageQueue;  //!< Input message queue to the GUI
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 21:53:09 +02:00
										 |  |  |     uint64_t m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     int64_t m_frequencyOffset; | 
					
						
							|  |  |  |     uint32_t m_deviceSampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     QList<int> m_localInputDeviceIndexes; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  | 	bool handleMessage(const Message& cmd) final; //!< Processing of a message. Returns true if message has actually been processed
 | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     void applySettings(const InterferometerSettings& settings, const QList<QString>& settingsKeys, bool force = false); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     static void validateFilterChainHash(InterferometerSettings& settings); | 
					
						
							| 
									
										
										
										
											2024-05-12 21:53:09 +02:00
										 |  |  |     void calculateFrequencyOffset(uint32_t log2Decim, uint32_t filterChainHash); | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     void updateDeviceSetList(); | 
					
						
							| 
									
										
										
										
											2024-05-12 21:53:09 +02:00
										 |  |  |     DeviceSampleSource *getLocalDevice(int deviceSetIndex); | 
					
						
							|  |  |  |     void propagateSampleRateAndFrequency(int index, uint32_t log2Decim); | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |     void webapiReverseSendSettings(const QList<QString>& channelSettingsKeys, const InterferometerSettings& settings, bool force); | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |     void sendChannelSettings( | 
					
						
							| 
									
										
										
										
											2022-03-02 23:07:15 +01:00
										 |  |  |         const QList<ObjectPipe*>& pipes, | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         const QList<QString>& channelSettingsKeys, | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |         const InterferometerSettings& settings, | 
					
						
							|  |  |  |         bool force | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     ) const; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |     void webapiFormatChannelSettings( | 
					
						
							| 
									
										
										
										
											2024-05-12 03:52:19 +02:00
										 |  |  |         const QList<QString>& channelSettingsKeys, | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  |         SWGSDRangel::SWGChannelSettings *swgChannelSettings, | 
					
						
							|  |  |  |         const InterferometerSettings& settings, | 
					
						
							|  |  |  |         bool force | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     ) const; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void handleInputMessages(); | 
					
						
							| 
									
										
										
										
											2024-08-25 23:36:46 +02:00
										 |  |  |     void networkManagerFinished(QNetworkReply *reply) const; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:38:12 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_INTERFEROMETER_H
 |