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.
localsource.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_LOCALSOURCE_H_
19 #define INCLUDE_LOCALSOURCE_H_
20 
21 #include <QObject>
22 #include <QMutex>
23 #include <QNetworkRequest>
24 
26 #include "util/message.h"
27 #include "channel/channelapi.h"
28 #include "localsourcesettings.h"
29 
30 class DeviceAPI;
31 class DeviceSampleSink;
33 class UpChannelizer;
34 class LocalSourceThread;
35 class QNetworkAccessManager;
36 class QNetworkReply;
37 
39  Q_OBJECT
40 public:
43 
44  public:
45  const LocalSourceSettings& getSettings() const { return m_settings; }
46  bool getForce() const { return m_force; }
47 
48  static MsgConfigureLocalSource* create(const LocalSourceSettings& settings, bool force)
49  {
50  return new MsgConfigureLocalSource(settings, force);
51  }
52 
53  private:
55  bool m_force;
56 
57  MsgConfigureLocalSource(const LocalSourceSettings& settings, bool force) :
58  Message(),
59  m_settings(settings),
60  m_force(force)
61  { }
62  };
63 
66 
67  public:
68  static MsgSampleRateNotification* create(int sampleRate) {
69  return new MsgSampleRateNotification(sampleRate);
70  }
71 
72  int getSampleRate() const { return m_sampleRate; }
73 
74  private:
75 
76  MsgSampleRateNotification(int sampleRate) :
77  Message(),
78  m_sampleRate(sampleRate)
79  { }
80 
82  };
83 
86 
87  public:
88  int getLog2Interp() const { return m_log2Interp; }
89  int getFilterChainHash() const { return m_filterChainHash; }
90 
91  static MsgConfigureChannelizer* create(unsigned int m_log2Interp, unsigned int m_filterChainHash) {
92  return new MsgConfigureChannelizer(m_log2Interp, m_filterChainHash);
93  }
94 
95  private:
96  unsigned int m_log2Interp;
97  unsigned int m_filterChainHash;
98 
99  MsgConfigureChannelizer(unsigned int log2Interp, unsigned int filterChainHash) :
100  Message(),
101  m_log2Interp(log2Interp),
102  m_filterChainHash(filterChainHash)
103  { }
104  };
105 
106  LocalSource(DeviceAPI *deviceAPI);
107  virtual ~LocalSource();
108  virtual void destroy() { delete this; }
109 
110  virtual void pull(Sample& sample);
111  virtual void pullAudio(int nbSamples);
112  virtual void start();
113  virtual void stop();
114  virtual bool handleMessage(const Message& cmd);
115 
116  virtual void getIdentifier(QString& id) { id = objectName(); }
117  virtual void getTitle(QString& title) { title = "Local Sink"; }
118  virtual qint64 getCenterFrequency() const { return m_frequencyOffset; }
119 
120  virtual QByteArray serialize() const;
121  virtual bool deserialize(const QByteArray& data);
122 
123  virtual int getNbSinkStreams() const { return 0; }
124  virtual int getNbSourceStreams() const { return 1; }
125 
126  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
127  {
128  (void) streamIndex;
129  (void) sinkElseSource;
130  return m_frequencyOffset;
131  }
132 
133  virtual int webapiSettingsGet(
135  QString& errorMessage);
136 
137  virtual int webapiSettingsPutPatch(
138  bool force,
139  const QStringList& channelSettingsKeys,
141  QString& errorMessage);
142 
144  void setCenterFrequency(uint64_t centerFrequency) { m_centerFrequency = centerFrequency; }
145 
147  void setSampleRate(uint32_t sampleRate) { m_sampleRate = sampleRate; }
148 
149  void setChannelizer(unsigned int log2Interp, unsigned int filterChainHash);
150  void getLocalDevices(std::vector<uint32_t>& indexes);
151 
152  static const QString m_channelIdURI;
153  static const QString m_channelId;
154 
155 signals:
156  void pullSamples(unsigned int count);
157 
158 private:
162  bool m_running;
163 
171 
176 
177  QNetworkAccessManager *m_networkManager;
178  QNetworkRequest m_networkRequest;
179 
181 
182  void applySettings(const LocalSourceSettings& settings, bool force = false);
188  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const LocalSourceSettings& settings, bool force);
189 
190 private slots:
191  void networkManagerFinished(QNetworkReply *reply);
192  void processSamples(int offset);
193 };
194 
195 #endif /* INCLUDE_LOCALSOURCE_H_ */
void pullSamples(unsigned int count)
void processSamples(int offset)
virtual void start()
std::vector< Sample > SampleVector
Definition: dsptypes.h:96
static MsgConfigureChannelizer * create(unsigned int m_log2Interp, unsigned int m_filterChainHash)
Definition: localsource.h:91
static const QString m_channelId
Definition: localsource.h:153
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: localsource.h:160
SampleSourceFifo * m_localSampleSourceFifo
Definition: localsource.h:166
uint64_t m_centerFrequency
Definition: localsource.h:172
const LocalSourceSettings & getSettings() const
Definition: localsource.h:45
MsgConfigureLocalSource(const LocalSourceSettings &settings, bool force)
Definition: localsource.h:57
virtual bool deserialize(const QByteArray &data)
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
static MsgConfigureLocalSource * create(const LocalSourceSettings &settings, bool force)
Definition: localsource.h:48
void networkManagerFinished(QNetworkReply *reply)
QNetworkAccessManager * m_networkManager
Definition: localsource.h:177
void setSampleRate(uint32_t sampleRate)
Definition: localsource.h:147
static const QString m_channelIdURI
Definition: localsource.h:152
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
QNetworkRequest m_networkRequest
Definition: localsource.h:178
void getLocalDevices(std::vector< uint32_t > &indexes)
int m_localSamplesIndex
Definition: localsource.h:169
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: localsource.h:126
LocalSource(DeviceAPI *deviceAPI)
Definition: localsource.cpp:48
void calculateFrequencyOffset()
static MsgSampleRateNotification * create(int sampleRate)
Definition: localsource.h:68
__int64 int64_t
Definition: rtptypes_win.h:47
unsigned int uint32_t
Definition: rtptypes_win.h:46
MsgConfigureChannelizer(unsigned int log2Interp, unsigned int filterChainHash)
Definition: localsource.h:99
virtual QByteArray serialize() const
virtual void pull(Sample &sample)
Definition: localsource.cpp:84
int64_t m_frequencyOffset
Definition: localsource.h:173
void setChannelizer(unsigned int log2Interp, unsigned int filterChainHash)
virtual void destroy()
Definition: localsource.h:108
void validateFilterChainHash(LocalSourceSettings &settings)
uint32_t m_deviceSampleRate
Definition: localsource.h:175
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: localsource.h:118
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
DeviceSampleSink * getLocalDevice(uint32_t index)
virtual void pullAudio(int nbSamples)
virtual int getNbSourceStreams() const
Definition: localsource.h:124
UpChannelizer * m_channelizer
Definition: localsource.h:161
DeviceAPI * m_deviceAPI
Definition: localsource.h:159
QMutex m_settingsMutex
Definition: localsource.h:180
virtual void getIdentifier(QString &id)
Definition: localsource.h:116
void propagateSampleRateAndFrequency(uint32_t index)
void setCenterFrequency(uint64_t centerFrequency)
Definition: localsource.h:144
virtual void getTitle(QString &title)
Definition: localsource.h:117
bool m_running
Definition: localsource.h:162
void applySettings(const LocalSourceSettings &settings, bool force=false)
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
LocalSourceThread * m_sinkThread
Definition: localsource.h:165
int m_localSamplesIndexOffset
Definition: localsource.h:170
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const LocalSourceSettings &settings, bool force)
virtual void stop()
SampleVector m_localSamples
Definition: localsource.h:168
virtual ~LocalSource()
Definition: localsource.cpp:74
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const LocalSourceSettings &settings)
LocalSourceSettings m_settings
Definition: localsource.h:164
uint32_t m_sampleRate
Definition: localsource.h:174
virtual int getNbSinkStreams() const
Definition: localsource.h:123
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48