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.
sdrplayinput.h
Go to the documentation of this file.
1 // Copyright (C) 2016 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 PLUGINS_SAMPLESOURCE_SDRPLAY_SDRPLAYINPUT_H_
19 #define PLUGINS_SAMPLESOURCE_SDRPLAY_SDRPLAYINPUT_H_
20 
21 #include <stdint.h>
22 
23 #include <QString>
24 #include <QByteArray>
25 #include <QNetworkRequest>
26 
27 #include <mirisdr.h>
28 #include "dsp/devicesamplesource.h"
29 #include "sdrplaysettings.h"
30 
31 class QNetworkAccessManager;
32 class QNetworkReply;
33 class DeviceAPI;
34 class SDRPlayThread;
35 class FileRecord;
36 
38  Q_OBJECT
39 public:
41  {
46  };
47 
48  class MsgConfigureSDRPlay : public Message {
50 
51  public:
52  const SDRPlaySettings& getSettings() const { return m_settings; }
53  bool getForce() const { return m_force; }
54 
55  static MsgConfigureSDRPlay* create(const SDRPlaySettings& settings, bool force)
56  {
57  return new MsgConfigureSDRPlay(settings, force);
58  }
59 
60  private:
62  bool m_force;
63 
64  MsgConfigureSDRPlay(const SDRPlaySettings& settings, bool force) :
65  Message(),
66  m_settings(settings),
67  m_force(force)
68  { }
69  };
70 
71  class MsgReportSDRPlayGains : public Message {
73 
74  public:
75  static MsgReportSDRPlayGains* create(int lnaGain, int mixerGain, int basebandGain, int tunerGain)
76  {
77  return new MsgReportSDRPlayGains(lnaGain, mixerGain, basebandGain, tunerGain);
78  }
79 
80  int getLNAGain() const { return m_lnaGain; }
81  int getMixerGain() const { return m_mixerGain; }
82  int getBasebandGain() const { return m_basebandGain; }
83  int getTunerGain() const { return m_tunerGain; }
84 
85  protected:
86  int m_lnaGain;
90 
91  MsgReportSDRPlayGains(int lnaGain, int mixerGain, int basebandGain, int tunerGain) :
92  Message(),
93  m_lnaGain(lnaGain),
94  m_mixerGain(mixerGain),
95  m_basebandGain(basebandGain),
96  m_tunerGain(tunerGain)
97  { }
98  };
99 
100  class MsgFileRecord : public Message {
102 
103  public:
104  bool getStartStop() const { return m_startStop; }
105 
106  static MsgFileRecord* create(bool startStop) {
107  return new MsgFileRecord(startStop);
108  }
109 
110  protected:
112 
113  MsgFileRecord(bool startStop) :
114  Message(),
115  m_startStop(startStop)
116  { }
117  };
118 
119  class MsgStartStop : public Message {
121 
122  public:
123  bool getStartStop() const { return m_startStop; }
124 
125  static MsgStartStop* create(bool startStop) {
126  return new MsgStartStop(startStop);
127  }
128 
129  protected:
131 
132  MsgStartStop(bool startStop) :
133  Message(),
134  m_startStop(startStop)
135  { }
136  };
137 
138  SDRPlayInput(DeviceAPI *deviceAPI);
139  virtual ~SDRPlayInput();
140  virtual void destroy();
141 
142  virtual void init();
143  virtual bool start();
144  virtual void stop();
145 
146  virtual QByteArray serialize() const;
147  virtual bool deserialize(const QByteArray& data);
148 
149  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
150  virtual const QString& getDeviceDescription() const;
151  virtual int getSampleRate() const;
152  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
153  virtual quint64 getCenterFrequency() const;
154  virtual void setCenterFrequency(qint64 centerFrequency);
155 
156  virtual bool handleMessage(const Message& message);
157 
158  virtual int webapiSettingsGet(
160  QString& errorMessage);
161 
162  virtual int webapiSettingsPutPatch(
163  bool force,
164  const QStringList& deviceSettingsKeys,
165  SWGSDRangel::SWGDeviceSettings& response, // query + response
166  QString& errorMessage);
167 
168  virtual int webapiReportGet(
170  QString& errorMessage);
171 
172  virtual int webapiRunGet(
173  SWGSDRangel::SWGDeviceState& response,
174  QString& errorMessage);
175 
176  virtual int webapiRun(
177  bool run,
178  SWGSDRangel::SWGDeviceState& response,
179  QString& errorMessage);
180 
181  SDRPlayVariant getVariant() const { return m_variant; }
182 
183 private:
185  QMutex m_mutex;
188  mirisdr_dev_t* m_dev;
192  bool m_running;
194  QNetworkAccessManager *m_networkManager;
195  QNetworkRequest m_networkRequest;
196 
197  bool openDevice();
198  void closeDevice();
199  bool applySettings(const SDRPlaySettings& settings, bool forwardChange, bool force);
200  bool setDeviceCenterFrequency(quint64 freq);
203  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SDRPlaySettings& settings, bool force);
204  void webapiReverseSendStartStop(bool start);
205 
206 private slots:
207  void networkManagerFinished(QNetworkReply *reply);
208 };
209 
210 // ====================================================================
211 
213 public:
214  static unsigned int getRate(unsigned int rate_index);
215  static unsigned int getRateIndex(unsigned int rate);
216  static unsigned int getNbRates();
217 private:
218  static const unsigned int m_nb_rates = 18;
219  static unsigned int m_rates[m_nb_rates];
220 };
221 
223 public:
224  static unsigned int getBandwidth(unsigned int bandwidth_index);
225  static unsigned int getBandwidthIndex(unsigned int bandwidth);
226  static unsigned int getNbBandwidths();
227 private:
228  static const unsigned int m_nb_bw = 8;
229  static unsigned int m_bw[m_nb_bw];
230 };
231 
232 class SDRPlayIF {
233 public:
234  static unsigned int getIF(unsigned int if_index);
235  static unsigned int getIFIndex(unsigned int iff);
236  static unsigned int getNbIFs();
237 private:
238  static const unsigned int m_nb_if = 4;
239  static unsigned int m_if[m_nb_if];
240 };
241 
243 public:
244  static QString getBandName(unsigned int band_index);
245  static unsigned int getBandLow(unsigned int band_index);
246  static unsigned int getBandHigh(unsigned int band_index);
247  static unsigned int getNbBands();
248 private:
249  static const unsigned int m_nb_bands = 8;
250  static unsigned int m_bandLow[m_nb_bands];
251  static unsigned int m_bandHigh[m_nb_bands];
252  static const char* m_bandName[m_nb_bands];
253 };
254 
255 #endif /* PLUGINS_SAMPLESOURCE_SDRPLAY_SDRPLAYINPUT_H_ */
QMutex m_mutex
Definition: sdrplayinput.h:185
virtual bool handleMessage(const Message &message)
MsgConfigureSDRPlay(const SDRPlaySettings &settings, bool force)
Definition: sdrplayinput.h:64
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const SDRPlaySettings &settings, bool force)
virtual bool deserialize(const QByteArray &data)
SDRPlayThread * m_sdrPlayThread
Definition: sdrplayinput.h:189
bool setDeviceCenterFrequency(quint64 freq)
virtual void destroy()
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: sdrplayinput.h:152
static MsgStartStop * create(bool startStop)
Definition: sdrplayinput.h:125
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual void stop()
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
QString m_deviceDescription
Definition: sdrplayinput.h:190
virtual QByteArray serialize() const
static MsgFileRecord * create(bool startStop)
Definition: sdrplayinput.h:106
const SDRPlaySettings & getSettings() const
Definition: sdrplayinput.h:52
virtual void setCenterFrequency(qint64 centerFrequency)
MsgFileRecord(bool startStop)
Definition: sdrplayinput.h:113
static MsgReportSDRPlayGains * create(int lnaGain, int mixerGain, int basebandGain, int tunerGain)
Definition: sdrplayinput.h:75
void networkManagerFinished(QNetworkReply *reply)
bool applySettings(const SDRPlaySettings &settings, bool forwardChange, bool force)
QNetworkRequest m_networkRequest
Definition: sdrplayinput.h:195
void webapiReverseSendStartStop(bool start)
FileRecord * m_fileSink
File sink to record device I/Q output.
Definition: sdrplayinput.h:193
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: sdrplayinput.h:149
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
static MsgConfigureSDRPlay * create(const SDRPlaySettings &settings, bool force)
Definition: sdrplayinput.h:55
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
SDRPlayInput(DeviceAPI *deviceAPI)
virtual ~SDRPlayInput()
SDRPlayVariant m_variant
Definition: sdrplayinput.h:186
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
MsgStartStop(bool startStop)
Definition: sdrplayinput.h:132
virtual bool start()
DeviceAPI * m_deviceAPI
Definition: sdrplayinput.h:184
virtual const QString & getDeviceDescription() const
QNetworkAccessManager * m_networkManager
Definition: sdrplayinput.h:194
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const SDRPlaySettings &settings)
SDRPlayVariant getVariant() const
Definition: sdrplayinput.h:181
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
bool openDevice()
SDRPlaySettings m_settings
Definition: sdrplayinput.h:187
virtual int getSampleRate() const
Sample rate exposed by the source.
MsgReportSDRPlayGains(int lnaGain, int mixerGain, int basebandGain, int tunerGain)
Definition: sdrplayinput.h:91
void closeDevice()
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
mirisdr_dev_t * m_dev
Definition: sdrplayinput.h:188
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)