2020-04-28 12:44:03 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2015-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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
#ifndef INCLUDE_SPECTRUMVIS_H
|
|
|
|
#define INCLUDE_SPECTRUMVIS_H
|
|
|
|
|
2022-02-12 18:57:33 -05:00
|
|
|
#include <QObject>
|
2022-09-15 15:59:42 -04:00
|
|
|
#include <QRecursiveMutex>
|
2020-04-29 11:41:17 -04:00
|
|
|
|
|
|
|
#include "dsp/basebandsamplesink.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "dsp/fftengine.h"
|
2017-10-22 13:12:43 -04:00
|
|
|
#include "dsp/fftwindow.h"
|
2021-04-20 04:32:21 -04:00
|
|
|
#include "dsp/spectrumsettings.h"
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2015-08-17 20:47:14 -04:00
|
|
|
#include "util/message.h"
|
2022-02-12 18:57:33 -05:00
|
|
|
#include "util/messagequeue.h"
|
2018-06-28 17:47:15 -04:00
|
|
|
#include "util/movingaverage2d.h"
|
2018-06-30 20:16:59 -04:00
|
|
|
#include "util/fixedaverage2d.h"
|
2018-10-12 02:47:14 -04:00
|
|
|
#include "util/max2d.h"
|
2020-04-29 11:41:17 -04:00
|
|
|
#include "websockets/wsspectrum.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2020-04-28 12:44:03 -04:00
|
|
|
class GLSpectrumInterface;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2020-05-05 12:58:18 -04:00
|
|
|
namespace SWGSDRangel {
|
|
|
|
class SWGGLSpectrum;
|
|
|
|
class SWGSpectrumServer;
|
2020-05-05 19:38:23 -04:00
|
|
|
class SWGSuccessResponse;
|
2020-05-05 12:58:18 -04:00
|
|
|
};
|
|
|
|
|
2022-02-12 18:57:33 -05:00
|
|
|
class SDRBASE_API SpectrumVis : public QObject, public BasebandSampleSink {
|
|
|
|
Q_OBJECT
|
2014-05-18 11:52:39 -04:00
|
|
|
public:
|
2020-05-14 16:14:11 -04:00
|
|
|
class SDRBASE_API MsgConfigureSpectrumVis : public Message {
|
2020-04-30 20:12:30 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2021-04-20 04:32:21 -04:00
|
|
|
const SpectrumSettings& getSettings() const { return m_settings; }
|
2020-04-30 20:12:30 -04:00
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
2021-04-20 04:32:21 -04:00
|
|
|
static MsgConfigureSpectrumVis* create(const SpectrumSettings& settings, bool force) {
|
2020-04-30 20:12:30 -04:00
|
|
|
return new MsgConfigureSpectrumVis(settings, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-04-20 04:32:21 -04:00
|
|
|
SpectrumSettings m_settings;
|
2020-04-30 20:12:30 -04:00
|
|
|
bool m_force;
|
|
|
|
|
2021-04-20 04:32:21 -04:00
|
|
|
MsgConfigureSpectrumVis(const SpectrumSettings& settings, bool force) :
|
2020-04-30 20:12:30 -04:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
m_force(force)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-07-05 05:04:20 -04:00
|
|
|
class SDRBASE_API MsgStartStop : public Message {
|
2020-07-05 04:03:41 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getStartStop() const { return m_startStop; }
|
|
|
|
|
|
|
|
static MsgStartStop* create(bool startStop) {
|
|
|
|
return new MsgStartStop(startStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_startStop;
|
|
|
|
|
|
|
|
MsgStartStop(bool startStop) :
|
|
|
|
Message(),
|
|
|
|
m_startStop(startStop)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-11-11 13:34:28 -05:00
|
|
|
class SDRBASE_API MsgConfigureWSpectrumOpenClose : public Message
|
2020-05-01 18:35:47 -04:00
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
Real getOpenClose() const { return m_openClose; }
|
|
|
|
|
|
|
|
static MsgConfigureWSpectrumOpenClose* create(bool openClose) {
|
|
|
|
return new MsgConfigureWSpectrumOpenClose(openClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_openClose;
|
|
|
|
|
|
|
|
MsgConfigureWSpectrumOpenClose(bool openClose) :
|
|
|
|
Message(),
|
|
|
|
m_openClose(openClose)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2021-02-17 04:15:34 -05:00
|
|
|
class SDRBASE_API MsgFrequencyZooming : public Message {
|
2021-02-15 07:49:51 -05:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
float getFrequencyZoomFactor() const { return m_frequencyZoomFactor; }
|
|
|
|
float getFrequencyZoomPos() const { return m_frequencyZoomPos; }
|
|
|
|
|
|
|
|
static MsgFrequencyZooming* create(float frequencyZoomFactor, float frequencyZoomPos) {
|
|
|
|
return new MsgFrequencyZooming(frequencyZoomFactor, frequencyZoomPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float m_frequencyZoomFactor;
|
|
|
|
float m_frequencyZoomPos;
|
|
|
|
|
|
|
|
MsgFrequencyZooming(float frequencyZoomFactor, float frequencyZoomPos) :
|
|
|
|
Message(),
|
|
|
|
m_frequencyZoomFactor(frequencyZoomFactor),
|
|
|
|
m_frequencyZoomPos(frequencyZoomPos)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2018-10-12 02:47:14 -04:00
|
|
|
enum AvgMode
|
2018-06-30 20:16:59 -04:00
|
|
|
{
|
2018-07-01 16:36:36 -04:00
|
|
|
AvgModeNone,
|
2018-10-12 02:47:14 -04:00
|
|
|
AvgModeMovingAvg,
|
|
|
|
AvgModeFixedAvg,
|
|
|
|
AvgModeMax
|
2018-06-30 20:16:59 -04:00
|
|
|
};
|
|
|
|
|
2020-04-30 03:57:05 -04:00
|
|
|
SpectrumVis(Real scalef);
|
|
|
|
virtual ~SpectrumVis();
|
|
|
|
|
|
|
|
void setGLSpectrum(GLSpectrumInterface* glSpectrum) { m_glSpectrum = glSpectrum; }
|
2022-05-13 16:24:48 -04:00
|
|
|
void setWorkspaceIndex(int index) { m_workspaceIndex = index; }
|
|
|
|
int getWorkspaceIndex() const { return m_workspaceIndex; }
|
2020-04-30 03:57:05 -04:00
|
|
|
|
|
|
|
void setScalef(Real scalef);
|
|
|
|
void configureWSSpectrum(const QString& address, uint16_t port);
|
2021-04-20 04:32:21 -04:00
|
|
|
const SpectrumSettings& getSettings() const { return m_settings; }
|
2020-07-16 10:58:45 -04:00
|
|
|
Real getSpecMax() const { return m_specMax / m_powFFTDiv; }
|
2021-02-10 02:34:42 -05:00
|
|
|
void getPowerSpectrumCopy(std::vector<Real>& copy) { copy.assign(m_powerSpectrum.begin(), m_powerSpectrum.end()); }
|
2021-02-18 00:23:12 -05:00
|
|
|
void getPSDCopy(std::vector<Real>& copy) const { copy.assign(m_psd.begin(), m_psd.begin() + m_settings.m_fftSize); }
|
|
|
|
void getZoomedPSDCopy(std::vector<Real>& copy) const;
|
2020-04-30 03:57:05 -04:00
|
|
|
|
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
2021-06-24 15:09:11 -04:00
|
|
|
void feed(const ComplexVector::const_iterator& begin, const ComplexVector::const_iterator& end, bool positiveOnly);
|
2020-04-30 03:57:05 -04:00
|
|
|
virtual void feed(const Complex *begin, unsigned int length); //!< direct FFT feed
|
|
|
|
void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
2022-02-12 18:57:33 -05:00
|
|
|
virtual void pushMessage(Message *msg);
|
|
|
|
virtual QString getSinkName();
|
|
|
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
2020-04-30 03:57:05 -04:00
|
|
|
|
2021-02-08 15:52:47 -05:00
|
|
|
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
|
|
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
|
|
|
|
2020-05-05 12:58:18 -04:00
|
|
|
int webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const;
|
2020-05-05 19:38:23 -04:00
|
|
|
int webapiSpectrumSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& spectrumSettingsKeys,
|
|
|
|
SWGSDRangel::SWGGLSpectrum& response, // query + response
|
|
|
|
QString& errorMessage);
|
2020-05-05 12:58:18 -04:00
|
|
|
int webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const;
|
2020-05-05 19:38:23 -04:00
|
|
|
int webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
|
|
|
|
int webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
|
2020-05-05 12:58:18 -04:00
|
|
|
|
2020-04-30 03:57:05 -04:00
|
|
|
private:
|
2019-10-26 16:30:53 -04:00
|
|
|
class MsgConfigureScalingFactor : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgConfigureScalingFactor(Real scalef) :
|
|
|
|
Message(),
|
|
|
|
m_scalef(scalef)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Real getScalef() const { return m_scalef; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Real m_scalef;
|
|
|
|
};
|
|
|
|
|
2020-04-30 03:57:05 -04:00
|
|
|
class MsgConfigureWSpectrum : public Message
|
|
|
|
{
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgConfigureWSpectrum(const QString& address, uint16_t port) :
|
|
|
|
Message(),
|
|
|
|
m_address(address),
|
|
|
|
m_port(port)
|
|
|
|
{}
|
|
|
|
|
|
|
|
const QString& getAddress() const { return m_address; }
|
|
|
|
uint16_t getPort() const { return m_port; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_address;
|
|
|
|
uint16_t m_port;
|
|
|
|
};
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2020-07-05 04:03:41 -04:00
|
|
|
bool m_running;
|
2014-05-18 11:52:39 -04:00
|
|
|
FFTEngine* m_fft;
|
|
|
|
FFTWindow m_window;
|
2020-03-12 01:27:38 -04:00
|
|
|
unsigned int m_fftEngineSequence;
|
2022-05-13 16:24:48 -04:00
|
|
|
int m_workspaceIndex;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
std::vector<Complex> m_fftBuffer;
|
2021-02-10 02:34:42 -05:00
|
|
|
std::vector<Real> m_powerSpectrum; //!< displayable power spectrum
|
|
|
|
std::vector<Real> m_psd; //!< real PSD
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2021-04-20 04:32:21 -04:00
|
|
|
SpectrumSettings m_settings;
|
2021-02-08 17:40:28 -05:00
|
|
|
int m_overlapSize;
|
|
|
|
int m_refillSize;
|
|
|
|
int m_fftBufferFill;
|
2015-07-14 19:19:39 -04:00
|
|
|
bool m_needMoreSamples;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2021-02-15 07:49:51 -05:00
|
|
|
float m_frequencyZoomFactor;
|
|
|
|
float m_frequencyZoomPos;
|
|
|
|
|
2018-01-22 08:07:24 -05:00
|
|
|
Real m_scalef;
|
2020-04-28 12:44:03 -04:00
|
|
|
GLSpectrumInterface* m_glSpectrum;
|
2020-04-29 11:41:17 -04:00
|
|
|
WSSpectrum m_wsSpectrum;
|
2018-06-30 20:16:59 -04:00
|
|
|
MovingAverage2D<double> m_movingAverage;
|
|
|
|
FixedAverage2D<double> m_fixedAverage;
|
2018-10-12 02:47:14 -04:00
|
|
|
Max2D<double> m_max;
|
2020-07-16 10:58:45 -04:00
|
|
|
Real m_specMax;
|
2018-06-28 17:47:15 -04:00
|
|
|
|
2020-04-29 11:41:17 -04:00
|
|
|
uint64_t m_centerFrequency;
|
|
|
|
int m_sampleRate;
|
|
|
|
|
2018-06-28 17:47:15 -04:00
|
|
|
Real m_ofs;
|
2018-07-05 19:34:05 -04:00
|
|
|
Real m_powFFTDiv;
|
2018-06-28 17:47:15 -04:00
|
|
|
static const Real m_mult;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2022-02-12 18:57:33 -05:00
|
|
|
MessageQueue m_inputMessageQueue;
|
2021-02-08 15:52:47 -05:00
|
|
|
MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI
|
|
|
|
|
2022-09-15 15:59:42 -04:00
|
|
|
QRecursiveMutex m_mutex;
|
2015-10-21 20:27:56 -04:00
|
|
|
|
2021-06-24 15:09:11 -04:00
|
|
|
void processFFT(bool positiveOnly);
|
2020-07-09 18:08:42 -04:00
|
|
|
void setRunning(bool running) { m_running = running; }
|
2021-04-20 04:32:21 -04:00
|
|
|
void applySettings(const SpectrumSettings& settings, bool force = false);
|
2022-02-12 18:57:33 -05:00
|
|
|
bool handleMessage(const Message& message);
|
2020-04-30 20:16:20 -04:00
|
|
|
void handleConfigureDSP(uint64_t centerFrequency, int sampleRate);
|
2019-10-26 16:30:53 -04:00
|
|
|
void handleScalef(Real scalef);
|
2020-04-30 20:16:20 -04:00
|
|
|
void handleWSOpenClose(bool openClose);
|
2020-04-30 03:57:05 -04:00
|
|
|
void handleConfigureWSSpectrum(const QString& address, uint16_t port);
|
2020-05-05 12:58:18 -04:00
|
|
|
|
2021-04-20 04:32:21 -04:00
|
|
|
static void webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& response, const SpectrumSettings& settings);
|
2020-05-05 19:38:23 -04:00
|
|
|
static void webapiUpdateSpectrumSettings(
|
2021-04-20 04:32:21 -04:00
|
|
|
SpectrumSettings& settings,
|
2020-05-05 19:38:23 -04:00
|
|
|
const QStringList& spectrumSettingsKeys,
|
|
|
|
SWGSDRangel::SWGGLSpectrum& response);
|
2022-02-12 18:57:33 -05:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleInputMessages();
|
2014-05-18 11:52:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_SPECTRUMVIS_H
|