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.
soapysdrinput.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_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
19 #define PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
20 
21 #include <stdint.h>
22 
23 #include <QString>
24 #include <QByteArray>
25 #include <QNetworkRequest>
26 
28 #include "dsp/devicesamplesource.h"
29 
30 #include "soapysdrinputsettings.h"
31 
32 class QNetworkAccessManager;
33 class QNetworkReply;
34 class DeviceAPI;
36 class FileRecord;
37 
38 namespace SoapySDR
39 {
40  class Device;
41  class ArgInfo;
42 }
43 
44 namespace SWGSDRangel
45 {
46  class SWGArgValue;
47  class SWGArgInfo;
48 }
49 
51 {
52  Q_OBJECT
53 public:
56 
57  public:
58  const SoapySDRInputSettings& getSettings() const { return m_settings; }
59  bool getForce() const { return m_force; }
60 
61  static MsgConfigureSoapySDRInput* create(const SoapySDRInputSettings& settings, bool force)
62  {
63  return new MsgConfigureSoapySDRInput(settings, force);
64  }
65 
66  private:
68  bool m_force;
69 
70  MsgConfigureSoapySDRInput(const SoapySDRInputSettings& settings, bool force) :
71  Message(),
72  m_settings(settings),
73  m_force(force)
74  { }
75  };
76 
77  class MsgFileRecord : public Message {
79 
80  public:
81  bool getStartStop() const { return m_startStop; }
82 
83  static MsgFileRecord* create(bool startStop) {
84  return new MsgFileRecord(startStop);
85  }
86 
87  protected:
89 
90  MsgFileRecord(bool startStop) :
91  Message(),
92  m_startStop(startStop)
93  { }
94  };
95 
96  class MsgStartStop : public Message {
98 
99  public:
100  bool getStartStop() const { return m_startStop; }
101 
102  static MsgStartStop* create(bool startStop) {
103  return new MsgStartStop(startStop);
104  }
105 
106  protected:
108 
109  MsgStartStop(bool startStop) :
110  Message(),
111  m_startStop(startStop)
112  { }
113  };
114 
115  class MsgReportGainChange : public Message {
117 
118  public:
119  const SoapySDRInputSettings& getSettings() const { return m_settings; }
120  bool getGlobalGain() const { return m_globalGain; }
121  bool getIndividualGains() const { return m_individualGains; }
122 
123  static MsgReportGainChange* create(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains)
124  {
125  return new MsgReportGainChange(settings, globalGain, individualGains);
126  }
127 
128  private:
132 
133  MsgReportGainChange(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains) :
134  Message(),
135  m_settings(settings),
136  m_globalGain(globalGain),
137  m_individualGains(individualGains)
138  { }
139  };
140 
141  SoapySDRInput(DeviceAPI *deviceAPI);
142  virtual ~SoapySDRInput();
143  virtual void destroy();
144 
145  virtual void init();
146  virtual bool start();
147  virtual void stop();
148  SoapySDRInputThread *getThread() { return m_thread; }
149  void setThread(SoapySDRInputThread *thread) { m_thread = thread; }
150 
151  virtual QByteArray serialize() const;
152  virtual bool deserialize(const QByteArray& data);
153 
154  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
155  virtual const QString& getDeviceDescription() const;
156  virtual int getSampleRate() const;
157  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
158  virtual quint64 getCenterFrequency() const;
159  virtual void setCenterFrequency(qint64 centerFrequency);
160 
161  virtual bool handleMessage(const Message& message);
162 
163  void getFrequencyRange(uint64_t& min, uint64_t& max);
164  void getGlobalGainRange(int& min, int& max);
165  bool isAGCSupported();
166  const std::vector<std::string>& getAntennas();
167  const SoapySDR::RangeList& getRateRanges();
168  const SoapySDR::RangeList& getBandwidthRanges();
169  int getAntennaIndex(const std::string& antenna);
170  const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements();
171  const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges();
172  const SoapySDR::ArgInfoList& getStreamArgInfoList();
173  const SoapySDR::ArgInfoList& getDeviceArgInfoList();
174  void initGainSettings(SoapySDRInputSettings& settings);
175  void initTunableElementsSettings(SoapySDRInputSettings& settings);
176  void initStreamArgSettings(SoapySDRInputSettings& settings);
177  void initDeviceArgSettings(SoapySDRInputSettings& settings);
178  bool hasDCAutoCorrection();
179  bool hasDCCorrectionValue();
180  bool hasIQAutoCorrection() { return false; } // not in SoapySDR interface
181  bool hasIQCorrectionValue();
182 
183  virtual int webapiSettingsGet(
185  QString& errorMessage);
186 
187  virtual int webapiSettingsPutPatch(
188  bool force,
189  const QStringList& deviceSettingsKeys,
190  SWGSDRangel::SWGDeviceSettings& response, // query + response
191  QString& errorMessage);
192 
193  virtual int webapiReportGet(
195  QString& errorMessage);
196 
197  virtual int webapiRunGet(
198  SWGSDRangel::SWGDeviceState& response,
199  QString& errorMessage);
200 
201  virtual int webapiRun(
202  bool run,
203  SWGSDRangel::SWGDeviceState& response,
204  QString& errorMessage);
205 
206 private:
208  QMutex m_mutex;
211  bool m_running;
215  QNetworkAccessManager *m_networkManager;
216  QNetworkRequest m_networkRequest;
217 
218  bool openDevice();
219  void closeDevice();
220  SoapySDRInputThread *findThread();
221  void moveThreadToBuddy();
222  bool applySettings(const SoapySDRInputSettings& settings, bool force = false);
223  bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
224  void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings);
225  void updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings);
226  void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SoapySDRInputSettings& settings);
227  void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
228  QVariant webapiVariantFromArgValue(SWGSDRangel::SWGArgValue *argValue);
229  void webapiFormatArgValue(const QVariant& v, SWGSDRangel::SWGArgValue *argValue);
230  void webapiFormatArgInfo(const SoapySDR::ArgInfo& arg, SWGSDRangel::SWGArgInfo *argInfo);
231  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SoapySDRInputSettings& settings, bool force);
232  void webapiReverseSendStartStop(bool start);
233 
234 private slots:
235  void networkManagerFinished(QNetworkReply *reply);
236 };
237 
238 
239 
240 #endif /* PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_ */
void setThread(SoapySDRInputThread *thread)
DeviceAPI * m_deviceAPI
SoapySDRInputThread * m_thread
DeviceSoapySDRShared m_deviceShared
MsgReportGainChange(const SoapySDRInputSettings &settings, bool globalGain, bool individualGains)
QString m_deviceDescription
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
static MsgConfigureSoapySDRInput * create(const SoapySDRInputSettings &settings, bool force)
Definition: soapysdrinput.h:61
QNetworkRequest m_networkRequest
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
static MsgFileRecord * create(bool startStop)
Definition: soapysdrinput.h:83
static MsgReportGainChange * create(const SoapySDRInputSettings &settings, bool globalGain, bool individualGains)
const SoapySDRInputSettings & getSettings() const
Definition: soapysdrinput.h:58
MsgStartStop(bool startStop)
SoapySDRInputSettings m_settings
static MsgStartStop * create(bool startStop)
bool hasIQAutoCorrection()
const SoapySDRInputSettings & getSettings() const
SoapySDRInputSettings m_settings
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
SoapySDRInputThread * getThread()
MsgConfigureSoapySDRInput(const SoapySDRInputSettings &settings, bool force)
Definition: soapysdrinput.h:70
FileRecord * m_fileSink
File sink to record device I/Q output.
T max(const T &x, const T &y)
Definition: framework.h:446
virtual void setMessageQueueToGUI(MessageQueue *queue)
T min(const T &x, const T &y)
Definition: framework.h:440
MsgFileRecord(bool startStop)
Definition: soapysdrinput.h:90
QNetworkAccessManager * m_networkManager
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48