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.
xtrxinput.h
Go to the documentation of this file.
1 // Copyright (C) 2017, 2018 Edouard Griffiths, F4EXB //
3 // Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
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 PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
20 #define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
21 #include <stdint.h>
22 
23 #include <QString>
24 #include <QByteArray>
25 #include <QNetworkRequest>
26 
27 #include "dsp/devicesamplesource.h"
28 #include "xtrx/devicextrxshared.h"
29 #include "xtrxinputsettings.h"
30 
31 class QNetworkAccessManager;
32 class QNetworkReply;
33 class DeviceAPI;
34 class XTRXInputThread;
35 struct DeviceXTRXParams;
36 class FileRecord;
37 
39 {
40  Q_OBJECT
41 public:
42  class MsgConfigureXTRX : public Message {
44 
45  public:
46  const XTRXInputSettings& getSettings() const { return m_settings; }
47  bool getForce() const { return m_force; }
48 
49  static MsgConfigureXTRX* create(const XTRXInputSettings& settings, bool force)
50  {
51  return new MsgConfigureXTRX(settings, force);
52  }
53 
54  private:
56  bool m_force;
57 
58  MsgConfigureXTRX(const XTRXInputSettings& settings, bool force) :
59  Message(),
60  m_settings(settings),
61  m_force(force)
62  { }
63  };
64 
65  class MsgGetStreamInfo : public Message {
67 
68  public:
70  {
71  return new MsgGetStreamInfo();
72  }
73 
74  private:
76  Message()
77  { }
78  };
79 
80  class MsgGetDeviceInfo : public Message {
82 
83  public:
85  {
86  return new MsgGetDeviceInfo();
87  }
88 
89  private:
91  Message()
92  { }
93  };
94 
97 
98  public:
100  {
101  return new MsgReportClockGenChange();
102  }
103 
104  private:
106  Message()
107  { }
108  };
109 
110  class MsgReportStreamInfo : public Message {
112 
113  public:
114  bool getSuccess() const { return m_success; }
115  bool getActive() const { return m_active; }
116  uint32_t getFifoFilledCount() const { return m_fifoFilledCount; }
117  uint32_t getFifoSize() const { return m_fifoSize; }
118 
120  bool success,
121  bool active,
122  uint32_t fifoFilledCount,
123  uint32_t fifoSize
124  )
125  {
126  return new MsgReportStreamInfo(
127  success,
128  active,
129  fifoFilledCount,
130  fifoSize
131  );
132  }
133 
134  private:
135  bool m_success;
136  // everything from lms_stream_status_t
137  bool m_active;
140 
142  bool success,
143  bool active,
144  uint32_t fifoFilledCount,
145  uint32_t fifoSize
146  ) :
147  Message(),
148  m_success(success),
149  m_active(active),
150  m_fifoFilledCount(fifoFilledCount),
151  m_fifoSize(fifoSize)
152  { }
153  };
154 
155  class MsgStartStop : public Message {
157 
158  public:
159  bool getStartStop() const { return m_startStop; }
160 
161  static MsgStartStop* create(bool startStop) {
162  return new MsgStartStop(startStop);
163  }
164 
165  protected:
167 
168  MsgStartStop(bool startStop) :
169  Message(),
170  m_startStop(startStop)
171  { }
172  };
173 
174  class MsgFileRecord : public Message {
176 
177  public:
178  bool getStartStop() const { return m_startStop; }
179 
180  static MsgFileRecord* create(bool startStop) {
181  return new MsgFileRecord(startStop);
182  }
183 
184  protected:
186 
187  MsgFileRecord(bool startStop) :
188  Message(),
189  m_startStop(startStop)
190  { }
191  };
192 
193  XTRXInput(DeviceAPI *deviceAPI);
194  virtual ~XTRXInput();
195  virtual void destroy();
196 
197  virtual void init();
198  virtual bool start();
199  virtual void stop();
201  void setThread(XTRXInputThread *thread) { m_XTRXInputThread = thread; }
202 
203  virtual QByteArray serialize() const;
204  virtual bool deserialize(const QByteArray& data);
205 
206  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
207  virtual const QString& getDeviceDescription() const;
208  virtual int getSampleRate() const;
209  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
210  uint32_t getDevSampleRate() const;
211  uint32_t getLog2HardDecim() const;
212  double getClockGen() const;
213  virtual quint64 getCenterFrequency() const;
214  virtual void setCenterFrequency(qint64 centerFrequency);
215 
216  virtual bool handleMessage(const Message& message);
217 
218  virtual int webapiSettingsGet(
220  QString& errorMessage);
221 
222  virtual int webapiSettingsPutPatch(
223  bool force,
224  const QStringList& deviceSettingsKeys,
225  SWGSDRangel::SWGDeviceSettings& response, // query + response
226  QString& errorMessage);
227 
228  virtual int webapiReportGet(
230  QString& errorMessage);
231 
232  virtual int webapiRunGet(
233  SWGSDRangel::SWGDeviceState& response,
234  QString& errorMessage);
235 
236  virtual int webapiRun(
237  bool run,
238  SWGSDRangel::SWGDeviceState& response,
239  QString& errorMessage);
240 
241  std::size_t getChannelIndex();
242  void getLORange(float& minF, float& maxF, float& stepF) const;
243  void getSRRange(float& minF, float& maxF, float& stepF) const;
244  void getLPRange(float& minF, float& maxF, float& stepF) const;
245 
246  void apply_gain_auto(uint32_t gain);
247  void apply_gain_lna(double gain);
248  void apply_gain_tia(double gain);
249  void apply_gain_pga(double gain);
250 
251 private:
253  QMutex m_mutex;
257  bool m_running;
259  QNetworkAccessManager *m_networkManager;
260  QNetworkRequest m_networkRequest;
261 
263 
264  bool openDevice();
265  void closeDevice();
267  void moveThreadToBuddy();
268 
269  void suspendTxThread();
270  void resumeTxThread();
271  bool applySettings(const XTRXInputSettings& settings, bool force = false, bool forceNCOFrequency = false);
274  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const XTRXInputSettings& settings, bool force);
275  void webapiReverseSendStartStop(bool start);
276 
277 private slots:
278  void networkManagerFinished(QNetworkReply *reply);
279 };
280 
281 #endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_ */
void moveThreadToBuddy()
Definition: xtrxinput.cpp:232
void webapiReverseSendStartStop(bool start)
Definition: xtrxinput.cpp:1619
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: xtrxinput.cpp:1488
virtual const QString & getDeviceDescription() const
Definition: xtrxinput.cpp:504
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: xtrxinput.cpp:556
bool m_active
Indicates whether the stream is currently active.
Definition: xtrxinput.h:137
MsgFileRecord(bool startStop)
Definition: xtrxinput.h:187
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
Definition: xtrxinput.cpp:551
uint32_t getLog2HardDecim() const
Definition: xtrxinput.cpp:531
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: xtrxinput.cpp:1326
QNetworkAccessManager * m_networkManager
Definition: xtrxinput.h:259
DeviceAPI * m_deviceAPI
Definition: xtrxinput.h:252
void suspendTxThread()
Definition: xtrxinput.cpp:437
void getLORange(float &minF, float &maxF, float &stepF) const
Definition: xtrxinput.cpp:576
bool applySettings(const XTRXInputSettings &settings, bool force=false, bool forceNCOFrequency=false)
Definition: xtrxinput.cpp:848
QNetworkRequest m_networkRequest
Definition: xtrxinput.h:260
uint32_t m_fifoSize
Size of FIFO buffer.
Definition: xtrxinput.h:139
XTRXInput(DeviceAPI *deviceAPI)
Definition: xtrxinput.cpp:50
void getLPRange(float &minF, float &maxF, float &stepF) const
Definition: xtrxinput.cpp:594
static MsgConfigureXTRX * create(const XTRXInputSettings &settings, bool force)
Definition: xtrxinput.h:49
MsgConfigureXTRX(const XTRXInputSettings &settings, bool force)
Definition: xtrxinput.h:58
bool getStartStop() const
Definition: xtrxinput.h:159
bool m_running
Definition: xtrxinput.h:257
static MsgGetStreamInfo * create()
Definition: xtrxinput.h:69
QMutex m_mutex
Definition: xtrxinput.h:253
virtual void destroy()
Definition: xtrxinput.cpp:81
double getClockGen() const
Definition: xtrxinput.cpp:542
unsigned int uint32_t
Definition: rtptypes_win.h:46
virtual QByteArray serialize() const
Definition: xtrxinput.cpp:477
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: xtrxinput.cpp:1479
uint32_t getFifoSize() const
Definition: xtrxinput.h:117
void apply_gain_lna(double gain)
Definition: xtrxinput.cpp:806
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: xtrxinput.cpp:1337
bool getStartStop() const
Definition: xtrxinput.h:178
QString m_deviceDescription
Definition: xtrxinput.h:256
XTRXInputSettings m_settings
Definition: xtrxinput.h:55
MsgStartStop(bool startStop)
Definition: xtrxinput.h:168
virtual bool handleMessage(const Message &message)
Definition: xtrxinput.cpp:603
uint32_t m_fifoFilledCount
Number of samples in FIFO buffer.
Definition: xtrxinput.h:138
virtual bool deserialize(const QByteArray &data)
Definition: xtrxinput.cpp:482
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: xtrxinput.h:209
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
Definition: xtrxinput.cpp:1468
static MsgFileRecord * create(bool startStop)
Definition: xtrxinput.h:180
static MsgGetDeviceInfo * create()
Definition: xtrxinput.h:84
void apply_gain_tia(double gain)
Definition: xtrxinput.cpp:819
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
static MsgReportClockGenChange * create()
Definition: xtrxinput.h:99
virtual int getSampleRate() const
Sample rate exposed by the source.
Definition: xtrxinput.cpp:509
const XTRXInputSettings & getSettings() const
Definition: xtrxinput.h:46
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
Definition: xtrxinput.cpp:1507
void setThread(XTRXInputThread *thread)
Definition: xtrxinput.h:201
XTRXInputThread * m_XTRXInputThread
Definition: xtrxinput.h:255
MsgReportStreamInfo(bool success, bool active, uint32_t fifoFilledCount, uint32_t fifoSize)
Definition: xtrxinput.h:141
void apply_gain_auto(uint32_t gain)
Definition: xtrxinput.cpp:795
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const XTRXInputSettings &settings, bool force)
Definition: xtrxinput.cpp:1532
bool openDevice()
Definition: xtrxinput.cpp:86
XTRXInputSettings m_settings
Definition: xtrxinput.h:254
XTRXInputThread * getThread()
Definition: xtrxinput.h:200
XTRXInputThread * findThread()
Definition: xtrxinput.cpp:200
void closeDevice()
Definition: xtrxinput.cpp:168
void apply_gain_pga(double gain)
Definition: xtrxinput.cpp:832
DeviceXTRXShared m_deviceShared
Definition: xtrxinput.h:258
void getSRRange(float &minF, float &maxF, float &stepF) const
Definition: xtrxinput.cpp:585
std::size_t getChannelIndex()
Definition: xtrxinput.cpp:571
virtual void stop()
Definition: xtrxinput.cpp:365
static MsgStartStop * create(bool startStop)
Definition: xtrxinput.h:161
static MsgReportStreamInfo * create(bool success, bool active, uint32_t fifoFilledCount, uint32_t fifoSize)
Definition: xtrxinput.h:119
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const XTRXInputSettings &settings)
Definition: xtrxinput.cpp:1429
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
Definition: xtrxinput.cpp:195
void resumeTxThread()
Definition: xtrxinput.cpp:460
virtual ~XTRXInput()
Definition: xtrxinput.cpp:67
uint32_t getDevSampleRate() const
Definition: xtrxinput.cpp:520
void networkManagerFinished(QNetworkReply *reply)
Definition: xtrxinput.cpp:1647
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: xtrxinput.h:206
uint32_t getFifoFilledCount() const
Definition: xtrxinput.h:116
virtual bool start()
Definition: xtrxinput.cpp:249
FileRecord * m_fileSink
File sink to record device I/Q output.
Definition: xtrxinput.h:262