SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
freqtracker.h
Go to the documentation of this file.
1 // Copyright (C) 2019 Edouard Griffiths, F4EXB. //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef INCLUDE_FREQTRACKER_H
19 #define INCLUDE_FREQTRACKER_H
20 
21 #include <vector>
22 
23 #include <QNetworkRequest>
24 #include <QMutex>
25 
26 #include "dsp/basebandsamplesink.h"
27 #include "channel/channelapi.h"
28 #include "dsp/ncof.h"
29 #include "dsp/interpolator.h"
30 #include "util/movingaverage.h"
31 #include "dsp/agc.h"
32 #include "dsp/bandpass.h"
33 #include "dsp/lowpass.h"
34 #include "dsp/phaselockcomplex.h"
35 #include "dsp/freqlockcomplex.h"
36 #include "util/message.h"
37 #include "util/doublebufferfifo.h"
38 
39 #include "freqtrackersettings.h"
40 
41 class QNetworkAccessManager;
42 class QNetworkReply;
43 class DeviceAPI;
44 class DownChannelizer;
46 class QTimer;
47 class fftfilt;
48 
49 class FreqTracker : public BasebandSampleSink, public ChannelAPI {
50  Q_OBJECT
51 public:
54 
55  public:
56  const FreqTrackerSettings& getSettings() const { return m_settings; }
57  bool getForce() const { return m_force; }
58 
59  static MsgConfigureFreqTracker* create(const FreqTrackerSettings& settings, bool force)
60  {
61  return new MsgConfigureFreqTracker(settings, force);
62  }
63 
64  private:
66  bool m_force;
67 
68  MsgConfigureFreqTracker(const FreqTrackerSettings& settings, bool force) :
69  Message(),
70  m_settings(settings),
71  m_force(force)
72  { }
73  };
74 
77 
78  public:
79  int getSampleRate() const { return m_sampleRate; }
80  int getCenterFrequency() const { return m_centerFrequency; }
81 
82  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
83  {
84  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
85  }
86 
87  private:
90 
91  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
92  Message(),
93  m_sampleRate(sampleRate),
94  m_centerFrequency(centerFrequency)
95  { }
96  };
97 
100 
101  public:
102  static MsgSampleRateNotification* create(int sampleRate, int frequencyOffset) {
103  return new MsgSampleRateNotification(sampleRate, frequencyOffset);
104  }
105 
106  int getSampleRate() const { return m_sampleRate; }
107  int getFrequencyOffset() const { return m_frequencyOffset; }
108 
109  private:
110  MsgSampleRateNotification(int sampleRate, int frequencyOffset) :
111  Message(),
112  m_sampleRate(sampleRate),
113  m_frequencyOffset(frequencyOffset)
114  { }
115 
118  };
119 
120  FreqTracker(DeviceAPI *deviceAPI);
121  ~FreqTracker();
122  virtual void destroy() { delete this; }
123 
124  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
125  virtual void start();
126  virtual void stop();
127  virtual bool handleMessage(const Message& cmd);
128 
129  virtual void getIdentifier(QString& id) { id = objectName(); }
130  virtual void getTitle(QString& title) { title = m_settings.m_title; }
131  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
132 
133  virtual QByteArray serialize() const;
134  virtual bool deserialize(const QByteArray& data);
135 
136  virtual int getNbSinkStreams() const { return 1; }
137  virtual int getNbSourceStreams() const { return 0; }
138 
139  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
140  {
141  (void) streamIndex;
142  (void) sinkElseSource;
144  }
145 
146  virtual int webapiSettingsGet(
148  QString& errorMessage);
149 
150  virtual int webapiSettingsPutPatch(
151  bool force,
152  const QStringList& channelSettingsKeys,
154  QString& errorMessage);
155 
156  virtual int webapiReportGet(
158  QString& errorMessage);
159 
161  double getMagSq() const { return m_magsq; }
162  bool getSquelchOpen() const { return m_squelchOpen; }
164  Real getFrequency() const;
165  Real getAvgDeltaFreq() const { return m_avgDeltaFreq; }
166 
167  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
168  {
169  if (m_magsqCount > 0)
170  {
174  }
175 
178  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
179 
180  m_magsqSum = 0.0f;
181  m_magsqPeak = 0.0f;
182  m_magsqCount = 0;
183  }
184 
185  static const QString m_channelIdURI;
186  static const QString m_channelId;
187 
188 private:
190  {
192  m_magsq(1e-12),
193  m_magsqPeak(1e-12)
194  {}
195  double m_magsq;
196  double m_magsqPeak;
197  };
198 
199  enum RateState {
202  };
203 
208 
213  bool m_running;
214 
221 
223 
228  double m_magsq;
229  double m_magsqSum;
230  double m_magsqPeak;
233 
235 
236  static const int m_udpBlockSize;
237  QNetworkAccessManager *m_networkManager;
238  QNetworkRequest m_networkRequest;
239 
240  const QTimer *m_timer;
246 
247  void applySettings(const FreqTrackerSettings& settings, bool force = false);
248  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
249  void setInterpolator();
250  void configureChannelizer();
251  void connectTimer();
252  void disconnectTimer();
255  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const FreqTrackerSettings& settings, bool force);
256 
257  void processOneSample(Complex &ci);
258 
259 private slots:
260  void networkManagerFinished(QNetworkReply *reply);
261  void tick();
262 };
263 
264 #endif // INCLUDE_FREQTRACKER_H
uint32_t m_squelchCount
Definition: freqtracker.h:225
fftfilt * m_rrcFilter
Definition: freqtracker.h:222
void applySettings(const FreqTrackerSettings &settings, bool force=false)
virtual void getIdentifier(QString &id)
Definition: freqtracker.h:129
double getMagSq() const
Definition: freqtracker.h:161
FreqTracker(DeviceAPI *deviceAPI)
Definition: freqtracker.cpp:53
virtual void getTitle(QString &title)
Definition: freqtracker.h:130
FreqLockComplex m_fll
Definition: freqtracker.h:217
double m_magsqSum
Definition: freqtracker.h:229
bool m_timerConnected
Definition: freqtracker.h:241
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: freqtracker.h:131
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: freqtracker.h:205
Definition: ncof.h:24
MsgSampleRateNotification(int sampleRate, int frequencyOffset)
Definition: freqtracker.h:110
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const FreqTrackerSettings &settings)
virtual void start()
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
void setInterpolator()
static MsgSampleRateNotification * create(int sampleRate, int frequencyOffset)
Definition: freqtracker.h:102
virtual void destroy()
Definition: freqtracker.h:122
QMutex m_settingsMutex
Definition: freqtracker.h:245
uint32_t m_deviceSampleRate
Definition: freqtracker.h:209
unsigned int uint32_t
Definition: rtptypes_win.h:46
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: freqtracker.h:167
bool getPllLocked() const
Definition: freqtracker.h:163
uint32_t m_squelchGate
Squelch gate in samples.
Definition: freqtracker.h:227
static const QString m_channelIdURI
Definition: freqtracker.h:185
MovingAverageUtil< Real, double, 16 > m_movingAverage
Definition: freqtracker.h:234
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Real m_interpolatorDistance
Definition: freqtracker.h:219
virtual int getNbSourceStreams() const
Definition: freqtracker.h:137
static const QString m_channelId
Definition: freqtracker.h:186
int m_magsqCount
Definition: freqtracker.h:231
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
double m_magsqPeak
Definition: freqtracker.h:230
int m_lastCorrAbs
Definition: freqtracker.h:243
int m_inputSampleRate
Definition: freqtracker.h:210
MsgConfigureFreqTracker(const FreqTrackerSettings &settings, bool force)
Definition: freqtracker.h:68
uint32_t m_tickCount
Definition: freqtracker.h:242
bool getSquelchOpen() const
Definition: freqtracker.h:162
uint32_t getSampleRate() const
Definition: freqtracker.h:160
void processOneSample(Complex &ci)
Real m_squelchLevel
Definition: freqtracker.h:224
int m_inputFrequencyOffset
Definition: freqtracker.h:211
PhaseLockComplex m_pll
Definition: freqtracker.h:216
const QTimer * m_timer
Definition: freqtracker.h:240
virtual QByteArray serialize() const
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
bool m_running
Definition: freqtracker.h:213
Interpolator m_interpolator
Definition: freqtracker.h:218
FreqTrackerSettings m_settings
Definition: freqtracker.h:207
virtual void stop()
static const int m_udpBlockSize
Definition: freqtracker.h:236
const FreqTrackerSettings & getSettings() const
Definition: freqtracker.h:56
virtual bool deserialize(const QByteArray &data)
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: freqtracker.h:139
Real m_avgDeltaFreq
Definition: freqtracker.h:244
void networkManagerFinished(QNetworkReply *reply)
bool m_squelchOpen
Definition: freqtracker.h:226
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const FreqTrackerSettings &settings, bool force)
MagSqLevelsStore m_magSqLevelStore
Definition: freqtracker.h:232
Real m_interpolatorDistanceRemain
Definition: freqtracker.h:220
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: freqtracker.h:91
virtual int getNbSinkStreams() const
Definition: freqtracker.h:136
double m_magsq
Definition: freqtracker.h:228
void configureChannelizer()
bool locked() const
uint32_t m_channelSampleRate
Definition: freqtracker.h:212
Real getFrequency() const
DeviceAPI * m_deviceAPI
Definition: freqtracker.h:204
std::complex< Real > Complex
Definition: dsptypes.h:43
DownChannelizer * m_channelizer
Definition: freqtracker.h:206
static MsgConfigureFreqTracker * create(const FreqTrackerSettings &settings, bool force)
Definition: freqtracker.h:59
float Real
Definition: dsptypes.h:42
Real getAvgDeltaFreq() const
Definition: freqtracker.h:165
QNetworkAccessManager * m_networkManager
Definition: freqtracker.h:237
void disconnectTimer()
QNetworkRequest m_networkRequest
Definition: freqtracker.h:238
void connectTimer()
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: freqtracker.h:82
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)