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.
soapysdroutput.h
Go to the documentation of this file.
1 // Copyright (C) 2018 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_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_
19 #define PLUGINS_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_
20 
21 #include <stdint.h>
22 
23 #include <QString>
24 #include <QByteArray>
25 #include <QNetworkRequest>
26 
27 #include "dsp/devicesamplesink.h"
29 
30 #include "soapysdroutputsettings.h"
31 
32 class QNetworkAccessManager;
33 class QNetworkReply;
34 class DeviceAPI;
36 
37 namespace SoapySDR
38 {
39  class Device;
40  class ArgInfo;
41 }
42 
43 namespace SWGSDRangel
44 {
45  class SWGArgValue;
46  class SWGArgInfo;
47 }
48 
50  Q_OBJECT
51 public:
54 
55  public:
56  const SoapySDROutputSettings& getSettings() const { return m_settings; }
57  bool getForce() const { return m_force; }
58 
59  static MsgConfigureSoapySDROutput* create(const SoapySDROutputSettings& settings, bool force)
60  {
61  return new MsgConfigureSoapySDROutput(settings, force);
62  }
63 
64  private:
66  bool m_force;
67 
68  MsgConfigureSoapySDROutput(const SoapySDROutputSettings& settings, bool force) :
69  Message(),
70  m_settings(settings),
71  m_force(force)
72  { }
73  };
74 
75  class MsgReportGainChange : public Message {
77 
78  public:
79  const SoapySDROutputSettings& getSettings() const { return m_settings; }
80  bool getGlobalGain() const { return m_globalGain; }
81  bool getIndividualGains() const { return m_individualGains; }
82 
83  static MsgReportGainChange* create(const SoapySDROutputSettings& settings, bool globalGain, bool individualGains)
84  {
85  return new MsgReportGainChange(settings, globalGain, individualGains);
86  }
87 
88  private:
92 
93  MsgReportGainChange(const SoapySDROutputSettings& settings, bool globalGain, bool individualGains) :
94  Message(),
95  m_settings(settings),
96  m_globalGain(globalGain),
97  m_individualGains(individualGains)
98  { }
99  };
100 
101  class MsgStartStop : public Message {
103 
104  public:
105  bool getStartStop() const { return m_startStop; }
106 
107  static MsgStartStop* create(bool startStop) {
108  return new MsgStartStop(startStop);
109  }
110 
111  protected:
113 
114  MsgStartStop(bool startStop) :
115  Message(),
116  m_startStop(startStop)
117  { }
118  };
119 
120  SoapySDROutput(DeviceAPI *deviceAPI);
121  virtual ~SoapySDROutput();
122  virtual void destroy();
123 
124  virtual void init();
125  virtual bool start();
126  virtual void stop();
127  SoapySDROutputThread *getThread() { return m_thread; }
128  void setThread(SoapySDROutputThread *thread) { m_thread = thread; }
129 
130  virtual QByteArray serialize() const;
131  virtual bool deserialize(const QByteArray& data);
132 
133  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
134  virtual const QString& getDeviceDescription() const;
135  virtual int getSampleRate() const;
136  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
137  virtual quint64 getCenterFrequency() const;
138  virtual void setCenterFrequency(qint64 centerFrequency);
139 
140  virtual bool handleMessage(const Message& message);
141 
142  void getFrequencyRange(uint64_t& min, uint64_t& max);
143  void getGlobalGainRange(int& min, int& max);
144  bool isAGCSupported();
145  const SoapySDR::RangeList& getRateRanges();
146  const std::vector<std::string>& getAntennas();
147  const SoapySDR::RangeList& getBandwidthRanges();
148  const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements();
149  const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges();
150  const SoapySDR::ArgInfoList& getStreamArgInfoList();
151  const SoapySDR::ArgInfoList& getDeviceArgInfoList();
152  void initGainSettings(SoapySDROutputSettings& settings);
153  void initTunableElementsSettings(SoapySDROutputSettings& settings);
154  void initStreamArgSettings(SoapySDROutputSettings& settings);
155  void initDeviceArgSettings(SoapySDROutputSettings& settings);
156  bool hasDCAutoCorrection();
157  bool hasDCCorrectionValue();
158  bool hasIQAutoCorrection() { return false; } // not in SoapySDR interface
159  bool hasIQCorrectionValue();
160 
161  virtual int webapiSettingsGet(
163  QString& errorMessage);
164 
165  virtual int webapiSettingsPutPatch(
166  bool force,
167  const QStringList& deviceSettingsKeys,
168  SWGSDRangel::SWGDeviceSettings& response, // query + response
169  QString& errorMessage);
170 
171  virtual int webapiReportGet(
173  QString& errorMessage);
174 
175  virtual int webapiRunGet(
176  SWGSDRangel::SWGDeviceState& response,
177  QString& errorMessage);
178 
179  virtual int webapiRun(
180  bool run,
181  SWGSDRangel::SWGDeviceState& response,
182  QString& errorMessage);
183 
184 private:
186  QMutex m_mutex;
189  bool m_running;
192  QNetworkAccessManager *m_networkManager;
193  QNetworkRequest m_networkRequest;
194 
195  bool openDevice();
196  void closeDevice();
197  SoapySDROutputThread *findThread();
198  void moveThreadToBuddy();
199  bool applySettings(const SoapySDROutputSettings& settings, bool force = false);
200  bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
201  void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings);
202  void updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings);
203  void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SoapySDROutputSettings& settings);
204  void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
205  QVariant webapiVariantFromArgValue(SWGSDRangel::SWGArgValue *argValue);
206  void webapiFormatArgValue(const QVariant& v, SWGSDRangel::SWGArgValue *argValue);
207  void webapiFormatArgInfo(const SoapySDR::ArgInfo& arg, SWGSDRangel::SWGArgInfo *argInfo);
208  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SoapySDROutputSettings& settings, bool force);
209  void webapiReverseSendStartStop(bool start);
210 
211 private slots:
212  void networkManagerFinished(QNetworkReply *reply);
213 };
214 
215 
216 #endif /* PLUGINS_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_ */
static MsgConfigureSoapySDROutput * create(const SoapySDROutputSettings &settings, bool force)
virtual void setMessageQueueToGUI(MessageQueue *queue)
bool hasIQAutoCorrection()
SoapySDROutputThread * getThread()
QNetworkRequest m_networkRequest
MsgReportGainChange(const SoapySDROutputSettings &settings, bool globalGain, bool individualGains)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
QString m_deviceDescription
const SoapySDROutputSettings & getSettings() const
SoapySDROutputSettings m_settings
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual void setSampleRate(int sampleRate)
For when the sink sample rate is set externally.
const SoapySDROutputSettings & getSettings() const
SoapySDROutputSettings m_settings
DeviceSoapySDRShared m_deviceShared
static MsgStartStop * create(bool startStop)
DeviceAPI * m_deviceAPI
MsgConfigureSoapySDROutput(const SoapySDROutputSettings &settings, bool force)
QNetworkAccessManager * m_networkManager
void setThread(SoapySDROutputThread *thread)
static MsgReportGainChange * create(const SoapySDROutputSettings &settings, bool globalGain, bool individualGains)
T max(const T &x, const T &y)
Definition: framework.h:446
SoapySDROutputThread * m_thread
T min(const T &x, const T &y)
Definition: framework.h:440
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48