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.
bladerf2output.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_BLADERF2OUTPUT_BLADERF2OUTPUT_H_
19 #define PLUGINS_SAMPLESINK_BLADERF2OUTPUT_BLADERF2OUTPUT_H_
20 
21 #include <QString>
22 #include <QNetworkRequest>
23 
24 #include <libbladeRF.h>
25 
26 #include "dsp/devicesamplesink.h"
28 #include "bladerf2outputsettings.h"
29 
30 class QNetworkAccessManager;
31 class QNetworkReply;
32 class DeviceAPI;
34 struct bladerf_gain_modes;
35 
37  Q_OBJECT
38 public:
39  class MsgConfigureBladeRF2 : public Message {
41 
42  public:
43  const BladeRF2OutputSettings& getSettings() const { return m_settings; }
44  bool getForce() const { return m_force; }
45 
46  static MsgConfigureBladeRF2* create(const BladeRF2OutputSettings& settings, bool force)
47  {
48  return new MsgConfigureBladeRF2(settings, force);
49  }
50 
51  private:
53  bool m_force;
54 
55  MsgConfigureBladeRF2(const BladeRF2OutputSettings& settings, bool force) :
56  Message(),
57  m_settings(settings),
58  m_force(force)
59  { }
60  };
61 
62  class MsgStartStop : public Message {
64 
65  public:
66  bool getStartStop() const { return m_startStop; }
67 
68  static MsgStartStop* create(bool startStop) {
69  return new MsgStartStop(startStop);
70  }
71 
72  protected:
74 
75  MsgStartStop(bool startStop) :
76  Message(),
77  m_startStop(startStop)
78  { }
79  };
80 
81  class MsgReportGainRange : public Message {
83 
84  public:
85  int getMin() const { return m_min; }
86  int getMax() const { return m_max; }
87  int getStep() const { return m_step; }
88 
89  static MsgReportGainRange* create(int min, int max, int step) {
90  return new MsgReportGainRange(min, max, step);
91  }
92 
93  protected:
94  int m_min;
95  int m_max;
96  int m_step;
97 
98  MsgReportGainRange(int min, int max, int step) :
99  Message(),
100  m_min(min),
101  m_max(max),
102  m_step(step)
103  {}
104  };
105 
106  BladeRF2Output(DeviceAPI *deviceAPI);
107  virtual ~BladeRF2Output();
108  virtual void destroy();
109 
110  virtual void init();
111  virtual bool start();
112  virtual void stop();
114  void setThread(BladeRF2OutputThread *thread) { m_thread = thread; }
115 
116  virtual QByteArray serialize() const;
117  virtual bool deserialize(const QByteArray& data);
118 
119  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
120  virtual const QString& getDeviceDescription() const;
121  virtual int getSampleRate() const;
122  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
123  virtual quint64 getCenterFrequency() const;
124  virtual void setCenterFrequency(qint64 centerFrequency);
125 
126  void getFrequencyRange(uint64_t& min, uint64_t& max, int& step);
127  void getSampleRateRange(int& min, int& max, int& step);
128  void getBandwidthRange(int& min, int& max, int& step);
129  void getGlobalGainRange(int& min, int& max, int& step);
130 
131  virtual bool handleMessage(const Message& message);
132 
133  virtual int webapiSettingsGet(
135  QString& errorMessage);
136 
137  virtual int webapiSettingsPutPatch(
138  bool force,
139  const QStringList& deviceSettingsKeys,
140  SWGSDRangel::SWGDeviceSettings& response, // query + response
141  QString& errorMessage);
142 
143  virtual int webapiReportGet(
145  QString& errorMessage);
146 
147  virtual int webapiRunGet(
148  SWGSDRangel::SWGDeviceState& response,
149  QString& errorMessage);
150 
151  virtual int webapiRun(
152  bool run,
153  SWGSDRangel::SWGDeviceState& response,
154  QString& errorMessage);
155 
156 private:
158  QMutex m_mutex;
160  struct bladerf* m_dev;
164  bool m_running;
165  QNetworkAccessManager *m_networkManager;
166  QNetworkRequest m_networkRequest;
167 
168  bool openDevice();
169  void closeDevice();
171  void moveThreadToBuddy();
172  bool applySettings(const BladeRF2OutputSettings& settings, bool force);
173  int getNbChannels();
174  bool setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
177  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF2OutputSettings& settings, bool force);
178  void webapiReverseSendStartStop(bool start);
179 
180 private slots:
181  void networkManagerFinished(QNetworkReply *reply);
182 };
183 
184 #endif /* PLUGINS_SAMPLESINK_BLADERF2OUTPUT_BLADERF2OUTPUT_H_ */
BladeRF2OutputSettings m_settings
QNetworkRequest m_networkRequest
const BladeRF2OutputSettings & getSettings() const
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
void networkManagerFinished(QNetworkReply *reply)
virtual const QString & getDeviceDescription() const
BladeRF2OutputThread * m_thread
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
virtual void destroy()
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
void webapiReverseSendStartStop(bool start)
virtual void setSampleRate(int sampleRate)
For when the sink sample rate is set externally.
virtual int getSampleRate() const
Sample rate exposed by the sink.
void getBandwidthRange(int &min, int &max, int &step)
bool setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths)
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
virtual bool start()
virtual bool deserialize(const QByteArray &data)
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
MsgConfigureBladeRF2(const BladeRF2OutputSettings &settings, bool force)
DeviceAPI * m_deviceAPI
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
DeviceBladeRF2Shared m_deviceShared
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
QString m_deviceDescription
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual void stop()
static MsgStartStop * create(bool startStop)
virtual void setMessageQueueToGUI(MessageQueue *queue)
virtual QByteArray serialize() const
static MsgReportGainRange * create(int min, int max, int step)
BladeRF2OutputSettings m_settings
struct bladerf * m_dev
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const BladeRF2OutputSettings &settings)
virtual bool handleMessage(const Message &message)
BladeRF2Output(DeviceAPI *deviceAPI)
void setThread(BladeRF2OutputThread *thread)
void getGlobalGainRange(int &min, int &max, int &step)
virtual void setCenterFrequency(qint64 centerFrequency)
MsgReportGainRange(int min, int max, int step)
void getFrequencyRange(uint64_t &min, uint64_t &max, int &step)
BladeRF2OutputThread * getThread()
void getSampleRateRange(int &min, int &max, int &step)
virtual ~BladeRF2Output()
virtual quint64 getCenterFrequency() const
Center frequency exposed by the sink.
QNetworkAccessManager * m_networkManager
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const BladeRF2OutputSettings &settings, bool force)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
static MsgConfigureBladeRF2 * create(const BladeRF2OutputSettings &settings, bool force)
T max(const T &x, const T &y)
Definition: framework.h:446
BladeRF2OutputThread * findThread()
bool applySettings(const BladeRF2OutputSettings &settings, bool force)
T min(const T &x, const T &y)
Definition: framework.h:440
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48