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.
bladerf2input.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_BLADERF2INPUT_BLADERF2INPUT_H_
19 #define PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUT_H_
20 
21 #include <stdint.h>
22 
23 #include <QString>
24 #include <QByteArray>
25 #include <QNetworkRequest>
26 
27 #include "dsp/devicesamplesource.h"
29 #include "bladerf2inputsettings.h"
30 
31 class QNetworkAccessManager;
32 class QNetworkReply;
33 class DeviceAPI;
35 class FileRecord;
36 struct bladerf_gain_modes;
37 struct bladerf;
38 
40  Q_OBJECT
41 public:
42  class MsgConfigureBladeRF2 : public Message {
44 
45  public:
46  const BladeRF2InputSettings& getSettings() const { return m_settings; }
47  bool getForce() const { return m_force; }
48 
49  static MsgConfigureBladeRF2* create(const BladeRF2InputSettings& settings, bool force)
50  {
51  return new MsgConfigureBladeRF2(settings, force);
52  }
53 
54  private:
56  bool m_force;
57 
58  MsgConfigureBladeRF2(const BladeRF2InputSettings& settings, bool force) :
59  Message(),
60  m_settings(settings),
61  m_force(force)
62  { }
63  };
64 
65  class MsgFileRecord : public Message {
67 
68  public:
69  bool getStartStop() const { return m_startStop; }
70 
71  static MsgFileRecord* create(bool startStop) {
72  return new MsgFileRecord(startStop);
73  }
74 
75  protected:
77 
78  MsgFileRecord(bool startStop) :
79  Message(),
80  m_startStop(startStop)
81  { }
82  };
83 
84  class MsgStartStop : public Message {
86 
87  public:
88  bool getStartStop() const { return m_startStop; }
89 
90  static MsgStartStop* create(bool startStop) {
91  return new MsgStartStop(startStop);
92  }
93 
94  protected:
96 
97  MsgStartStop(bool startStop) :
98  Message(),
99  m_startStop(startStop)
100  { }
101  };
102 
103  class MsgReportGainRange : public Message {
105 
106  public:
107  int getMin() const { return m_min; }
108  int getMax() const { return m_max; }
109  int getStep() const { return m_step; }
110 
111  static MsgReportGainRange* create(int min, int max, int step) {
112  return new MsgReportGainRange(min, max, step);
113  }
114 
115  protected:
116  int m_min;
117  int m_max;
118  int m_step;
119 
120  MsgReportGainRange(int min, int max, int step) :
121  Message(),
122  m_min(min),
123  m_max(max),
124  m_step(step)
125  {}
126  };
127 
128  struct GainMode
129  {
130  QString m_name;
131  int m_value;
132  };
133 
134  BladeRF2Input(DeviceAPI *deviceAPI);
135  virtual ~BladeRF2Input();
136  virtual void destroy();
137 
138  virtual void init();
139  virtual bool start();
140  virtual void stop();
142  void setThread(BladeRF2InputThread *thread) { m_thread = thread; }
143 
144  virtual QByteArray serialize() const;
145  virtual bool deserialize(const QByteArray& data);
146 
147  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
148  virtual const QString& getDeviceDescription() const;
149  virtual int getSampleRate() const;
150  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
151  virtual quint64 getCenterFrequency() const;
152  virtual void setCenterFrequency(qint64 centerFrequency);
153 
154  void getFrequencyRange(uint64_t& min, uint64_t& max, int& step);
155  void getSampleRateRange(int& min, int& max, int& step);
156  void getBandwidthRange(int& min, int& max, int& step);
157  void getGlobalGainRange(int& min, int& max, int& step);
158  const std::vector<GainMode>& getGainModes() { return m_gainModes; }
159 
160  virtual bool handleMessage(const Message& message);
161 
162  virtual int webapiSettingsGet(
164  QString& errorMessage);
165 
166  virtual int webapiSettingsPutPatch(
167  bool force,
168  const QStringList& deviceSettingsKeys,
169  SWGSDRangel::SWGDeviceSettings& response, // query + response
170  QString& errorMessage);
171 
172  virtual int webapiReportGet(
174  QString& errorMessage);
175 
176  virtual int webapiRunGet(
177  SWGSDRangel::SWGDeviceState& response,
178  QString& errorMessage);
179 
180  virtual int webapiRun(
181  bool run,
182  SWGSDRangel::SWGDeviceState& response,
183  QString& errorMessage);
184 
185 private:
187  QMutex m_mutex;
190  bool m_running;
194  std::vector<GainMode> m_gainModes;
195  QNetworkAccessManager *m_networkManager;
196  QNetworkRequest m_networkRequest;
197 
198  bool openDevice();
199  void closeDevice();
201  void moveThreadToBuddy();
202  bool applySettings(const BladeRF2InputSettings& settings, bool force = false);
203  bool setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
206  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF2InputSettings& settings, bool force);
208 
209 private slots:
210  void networkManagerFinished(QNetworkReply *reply);
211 };
212 
213 #endif /* PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUT_H_ */
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
virtual ~BladeRF2Input()
MsgFileRecord(bool startStop)
Definition: bladerf2input.h:78
BladeRF2InputThread * findThread()
QString m_deviceDescription
virtual void setMessageQueueToGUI(MessageQueue *queue)
BladeRF2InputSettings m_settings
Definition: bladerf2input.h:55
BladeRF2InputSettings m_settings
const std::vector< GainMode > & getGainModes()
MsgStartStop(bool startStop)
Definition: bladerf2input.h:97
BladeRF2Input(DeviceAPI *deviceAPI)
void networkManagerFinished(QNetworkReply *reply)
void getFrequencyRange(uint64_t &min, uint64_t &max, int &step)
std::vector< GainMode > m_gainModes
void getGlobalGainRange(int &min, int &max, int &step)
void webapiReverseSendStartStop(bool start)
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const BladeRF2InputSettings &settings, bool force)
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
DeviceAPI * m_deviceAPI
static MsgReportGainRange * create(int min, int max, int step)
void getBandwidthRange(int &min, int &max, int &step)
FileRecord * m_fileSink
File sink to record device I/Q output.
static MsgStartStop * create(bool startStop)
Definition: bladerf2input.h:90
bool applySettings(const BladeRF2InputSettings &settings, bool force=false)
virtual const QString & getDeviceDescription() const
virtual void stop()
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual bool deserialize(const QByteArray &data)
BladeRF2InputThread * getThread()
void moveThreadToBuddy()
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
BladeRF2InputThread * m_thread
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
bool setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths)
void setThread(BladeRF2InputThread *thread)
virtual void setCenterFrequency(qint64 centerFrequency)
static MsgFileRecord * create(bool startStop)
Definition: bladerf2input.h:71
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
QNetworkRequest m_networkRequest
void getSampleRateRange(int &min, int &max, int &step)
virtual bool handleMessage(const Message &message)
virtual int getSampleRate() const
Sample rate exposed by the source.
QNetworkAccessManager * m_networkManager
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
MsgConfigureBladeRF2(const BladeRF2InputSettings &settings, bool force)
Definition: bladerf2input.h:58
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const BladeRF2InputSettings &settings)
DeviceBladeRF2Shared m_deviceShared
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual void destroy()
static MsgConfigureBladeRF2 * create(const BladeRF2InputSettings &settings, bool force)
Definition: bladerf2input.h:49
const BladeRF2InputSettings & getSettings() const
Definition: bladerf2input.h:46
MsgReportGainRange(int min, int max, int step)
T max(const T &x, const T &y)
Definition: framework.h:446
virtual bool start()
virtual QByteArray serialize() const
T min(const T &x, const T &y)
Definition: framework.h:440
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48