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.
dsddemod.h
Go to the documentation of this file.
1 // Copyright (C) 2016 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef INCLUDE_DSDDEMOD_H
20 #define INCLUDE_DSDDEMOD_H
21 
22 #include <vector>
23 
24 #include <QMutex>
25 #include <QNetworkRequest>
26 
27 #include "dsp/basebandsamplesink.h"
28 #include "channel/channelapi.h"
29 #include "dsp/phasediscri.h"
30 #include "dsp/nco.h"
31 #include "dsp/interpolator.h"
32 #include "dsp/lowpass.h"
33 #include "dsp/bandpass.h"
34 #include "dsp/afsquelch.h"
35 #include "util/movingaverage.h"
36 #include "dsp/afsquelch.h"
37 #include "audio/audiofifo.h"
38 #include "util/message.h"
39 #include "util/doublebufferfifo.h"
40 
41 #include "dsddemodsettings.h"
42 #include "dsddecoder.h"
43 
44 class QNetworkAccessManager;
45 class QNetworkReply;
46 class DeviceAPI;
48 class DownChannelizer;
49 
50 class DSDDemod : public BasebandSampleSink, public ChannelAPI {
51  Q_OBJECT
52 public:
53  class MsgConfigureDSDDemod : public Message {
55 
56  public:
57  const DSDDemodSettings& getSettings() const { return m_settings; }
58  bool getForce() const { return m_force; }
59 
60  static MsgConfigureDSDDemod* create(const DSDDemodSettings& settings, bool force)
61  {
62  return new MsgConfigureDSDDemod(settings, force);
63  }
64 
65  private:
67  bool m_force;
68 
69  MsgConfigureDSDDemod(const DSDDemodSettings& settings, bool force) :
70  Message(),
71  m_settings(settings),
72  m_force(force)
73  { }
74  };
75 
78 
79  public:
80  int getSampleRate() const { return m_sampleRate; }
81  int getCenterFrequency() const { return m_centerFrequency; }
82 
83  static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
84  {
85  return new MsgConfigureChannelizer(sampleRate, centerFrequency);
86  }
87 
88  private:
91 
92  MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
93  Message(),
94  m_sampleRate(sampleRate),
95  m_centerFrequency(centerFrequency)
96  { }
97  };
98 
99  DSDDemod(DeviceAPI *deviceAPI);
100  ~DSDDemod();
101  virtual void destroy() { delete this; }
102  void setScopeXYSink(BasebandSampleSink* sampleSink) { m_scopeXY = sampleSink; }
103 
104  void configureMyPosition(MessageQueue* messageQueue, float myLatitude, float myLongitude);
105 
106  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
107  virtual void start();
108  virtual void stop();
109  virtual bool handleMessage(const Message& cmd);
110 
111  virtual void getIdentifier(QString& id) { id = objectName(); }
112  virtual void getTitle(QString& title) { title = m_settings.m_title; }
113  virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
114 
115  virtual QByteArray serialize() const;
116  virtual bool deserialize(const QByteArray& data);
117 
118  virtual int getNbSinkStreams() const { return 1; }
119  virtual int getNbSourceStreams() const { return 0; }
120 
121  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
122  {
123  (void) streamIndex;
124  (void) sinkElseSource;
126  }
127 
128  double getMagSq() { return m_magsq; }
129  bool getSquelchOpen() const { return m_squelchOpen; }
130 
131  const DSDDecoder& getDecoder() const { return m_dsdDecoder; }
132 
133  void getMagSqLevels(double& avg, double& peak, int& nbSamples)
134  {
135  if (m_magsqCount > 0)
136  {
140  }
141 
144  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
145 
146  m_magsqSum = 0.0f;
147  m_magsqPeak = 0.0f;
148  m_magsqCount = 0;
149  }
150 
151  const char *updateAndGetStatusText();
152 
153  virtual int webapiSettingsGet(
155  QString& errorMessage);
156 
157  virtual int webapiSettingsPutPatch(
158  bool force,
159  const QStringList& channelSettingsKeys,
161  QString& errorMessage);
162 
163  virtual int webapiReportGet(
165  QString& errorMessage);
166 
167  static const QString m_channelIdURI;
168  static const QString m_channelId;
169 
170 private:
172  {
174  m_magsq(1e-12),
175  m_magsqPeak(1e-12)
176  {}
177  double m_magsq;
178  double m_magsqPeak;
179  };
180 
181  typedef enum
182  {
189  } SignalFormat;
190 
193 
194  public:
195  float getMyLatitude() const { return m_myLatitude; }
196  float getMyLongitude() const { return m_myLongitude; }
197 
198  static MsgConfigureMyPosition* create(float myLatitude, float myLongitude)
199  {
200  return new MsgConfigureMyPosition(myLatitude, myLongitude);
201  }
202 
203  private:
206 
207  MsgConfigureMyPosition(float myLatitude, float myLongitude) :
208  m_myLatitude(myLatitude),
209  m_myLongitude(myLongitude)
210  {}
211  };
212 
213  enum RateState {
216  };
217 
221 
226 
237 
239  double m_magsq;
240  double m_magsqSum;
241  double m_magsqPeak;
244 
251 
256 
258 
259  char m_formatStatusText[82+1];
260  SignalFormat m_signalFormat;
262 
263  QNetworkAccessManager *m_networkManager;
264  QNetworkRequest m_networkRequest;
265 
267 
268  static const int m_udpBlockSize;
269 
270  void applyAudioSampleRate(int sampleRate);
271  void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
272  void applySettings(const DSDDemodSettings& settings, bool force = false);
273  void formatStatusText();
274 
277  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const DSDDemodSettings& settings, bool force);
278 
279 private slots:
280  void networkManagerFinished(QNetworkReply *reply);
281 
282 };
283 
284 #endif // INCLUDE_DSDDEMOD_H
PhaseDiscriminators m_phaseDiscri
Definition: dsddemod.h:261
MagSqLevelsStore m_magSqLevelStore
Definition: dsddemod.h:243
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
int m_squelchCount
Definition: dsddemod.h:232
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: dsddemod.cpp:830
std::vector< AudioSample > AudioVector
Definition: dsptypes.h:98
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const DSDDemodSettings &settings)
Definition: dsddemod.cpp:968
MsgConfigureDSDDemod(const DSDDemodSettings &settings, bool force)
Definition: dsddemod.h:69
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: dsddemod.h:133
AudioVector m_audioBuffer
Definition: dsddemod.h:246
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: dsddemod.h:219
MovingAverageUtil< Real, double, 16 > m_movingAverage
Definition: dsddemod.h:238
char m_formatStatusText[82+1]
Fixed signal format dependent status text.
Definition: dsddemod.h:259
static const QString m_channelIdURI
Definition: dsddemod.h:167
DeviceAPI * m_deviceAPI
Definition: dsddemod.h:218
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: dsddemod.cpp:841
virtual bool deserialize(const QByteArray &data)
Definition: dsddemod.cpp:624
virtual void getTitle(QString &title)
Definition: dsddemod.h:112
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: dsddemod.h:113
static const int m_udpBlockSize
Definition: dsddemod.h:268
int m_inputFrequencyOffset
Definition: dsddemod.h:223
double m_magsqPeak
Definition: dsddemod.h:241
SampleVector m_scopeSampleBuffer
Definition: dsddemod.h:245
static MsgConfigureMyPosition * create(float myLatitude, float myLongitude)
Definition: dsddemod.h:198
AudioFifo m_audioFifo1
Definition: dsddemod.h:252
virtual void getIdentifier(QString &id)
Definition: dsddemod.h:111
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Definition: dsddemod.cpp:125
double getMagSq()
Definition: dsddemod.h:128
int m_sampleBufferIndex
Definition: dsddemod.h:249
void applySettings(const DSDDemodSettings &settings, bool force=false)
Definition: dsddemod.cpp:472
qint64 m_inputFrequencyOffset
void setScopeXYSink(BasebandSampleSink *sampleSink)
Definition: dsddemod.h:102
quint32 m_audioSampleRate
Definition: dsddemod.h:225
AudioFifo m_audioFifo2
Definition: dsddemod.h:253
int m_magsqCount
Definition: dsddemod.h:242
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const DSDDemodSettings &settings, bool force)
Definition: dsddemod.cpp:1038
int m_squelchGate
Definition: dsddemod.h:233
DSDDemodSettings m_settings
Definition: dsddemod.h:66
virtual int getNbSourceStreams() const
Definition: dsddemod.h:119
Definition: nco.h:25
QMutex m_settingsMutex
Definition: dsddemod.h:266
SignalFormat
Definition: dsddemod.h:181
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: dsddemod.cpp:1017
DownChannelizer * m_channelizer
Definition: dsddemod.h:220
double m_squelchLevel
Definition: dsddemod.h:234
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: dsddemod.cpp:957
void formatStatusText()
Definition: dsddemod.cpp:647
bool getSquelchOpen() const
Definition: dsddemod.h:129
DoubleBufferFIFO< Real > m_squelchDelayLine
Definition: dsddemod.h:236
Interpolator m_interpolator
Definition: dsddemod.h:228
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: dsddemod.cpp:365
NCO m_nco
Definition: dsddemod.h:227
BasebandSampleSink * m_scopeXY
Definition: dsddemod.h:254
DSDDemodSettings m_settings
Definition: dsddemod.h:224
void applyAudioSampleRate(int sampleRate)
Definition: dsddemod.cpp:433
uint m_audioBufferFill
Definition: dsddemod.h:247
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: dsddemod.h:121
DSDDemod(DeviceAPI *deviceAPI)
Definition: dsddemod.cpp:54
void networkManagerFinished(QNetworkReply *reply)
Definition: dsddemod.cpp:1136
bool m_scopeEnabled
Definition: dsddemod.h:255
virtual void stop()
Definition: dsddemod.cpp:361
FixReal * m_sampleBuffer
samples ring buffer
Definition: dsddemod.h:248
int m_sampleCount
Definition: dsddemod.h:231
void configureMyPosition(MessageQueue *messageQueue, float myLatitude, float myLongitude)
Definition: dsddemod.cpp:119
SignalFormat m_signalFormat
Used to keep formatting during successive calls for the same standard type.
Definition: dsddemod.h:260
Real m_interpolatorDistance
Definition: dsddemod.h:229
const DSDDemodSettings & getSettings() const
Definition: dsddemod.h:57
double m_magsqSum
Definition: dsddemod.h:240
Real m_interpolatorDistanceRemain
Definition: dsddemod.h:230
int m_inputSampleRate
Definition: dsddemod.h:222
static const QString m_channelId
Definition: dsddemod.h:168
const char * updateAndGetStatusText()
Definition: dsddemod.cpp:641
virtual QByteArray serialize() const
Definition: dsddemod.cpp:619
QNetworkAccessManager * m_networkManager
Definition: dsddemod.h:263
MsgConfigureChannelizer(int sampleRate, int centerFrequency)
Definition: dsddemod.h:92
int m_scaleFromShort
Definition: dsddemod.h:250
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: dsddemod.h:83
virtual void destroy()
Definition: dsddemod.h:101
DSDDecoder m_dsdDecoder
Definition: dsddemod.h:257
virtual void start()
Definition: dsddemod.cpp:353
const DSDDecoder & getDecoder() const
Definition: dsddemod.h:131
MsgConfigureMyPosition(float myLatitude, float myLongitude)
Definition: dsddemod.h:207
float Real
Definition: dsptypes.h:42
double m_magsq
Definition: dsddemod.h:239
qint16 FixReal
Definition: dsptypes.h:35
bool m_squelchOpen
Definition: dsddemod.h:235
static MsgConfigureDSDDemod * create(const DSDDemodSettings &settings, bool force)
Definition: dsddemod.h:60
QNetworkRequest m_networkRequest
Definition: dsddemod.h:264
virtual int getNbSinkStreams() const
Definition: dsddemod.h:118
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force=false)
Definition: dsddemod.cpp:447