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.
hackrfinput.h
Go to the documentation of this file.
1 // Copyright (C) 2015 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 INCLUDE_HACKRFINPUT_H
19 #define INCLUDE_HACKRFINPUT_H
20 
21 #include <QString>
22 #include <QByteArray>
23 #include <QNetworkRequest>
24 
25 #include "libhackrf/hackrf.h"
26 #include "dsp/devicesamplesource.h"
27 #include "hackrf/devicehackrf.h"
29 #include "hackrfinputsettings.h"
30 
31 class QNetworkAccessManager;
32 class QNetworkReply;
33 class DeviceAPI;
34 class HackRFInputThread;
35 class FileRecord;
36 
38  Q_OBJECT
39 public:
40 
41  class MsgConfigureHackRF : public Message {
43 
44  public:
45  const HackRFInputSettings& getSettings() const { return m_settings; }
46  bool getForce() const { return m_force; }
47 
48  static MsgConfigureHackRF* create(const HackRFInputSettings& settings, bool force = false)
49  {
50  return new MsgConfigureHackRF(settings, force);
51  }
52 
53  private:
55  bool m_force;
56 
57  MsgConfigureHackRF(const HackRFInputSettings& settings, bool force) :
58  Message(),
59  m_settings(settings),
60  m_force(force)
61  { }
62  };
63 
64  class MsgReportHackRF : public Message {
66 
67  public:
68 
70  {
71  return new MsgReportHackRF();
72  }
73 
74  protected:
75 
77  Message()
78  { }
79  };
80 
81  class MsgStartStop : public Message {
83 
84  public:
85  bool getStartStop() const { return m_startStop; }
86 
87  static MsgStartStop* create(bool startStop) {
88  return new MsgStartStop(startStop);
89  }
90 
91  protected:
93 
94  MsgStartStop(bool startStop) :
95  Message(),
96  m_startStop(startStop)
97  { }
98  };
99 
100  class MsgFileRecord : public Message {
102 
103  public:
104  bool getStartStop() const { return m_startStop; }
105 
106  static MsgFileRecord* create(bool startStop) {
107  return new MsgFileRecord(startStop);
108  }
109 
110  protected:
112 
113  MsgFileRecord(bool startStop) :
114  Message(),
115  m_startStop(startStop)
116  { }
117  };
118 
119  HackRFInput(DeviceAPI *deviceAPI);
120  virtual ~HackRFInput();
121  virtual void destroy();
122 
123  virtual void init();
124  virtual bool start();
125  virtual void stop();
126 
127  virtual QByteArray serialize() const;
128  virtual bool deserialize(const QByteArray& data);
129 
130  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
131  virtual const QString& getDeviceDescription() const;
132  virtual int getSampleRate() const;
133  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
134  virtual quint64 getCenterFrequency() const;
135  virtual void setCenterFrequency(qint64 centerFrequency);
136 
137  virtual bool handleMessage(const Message& message);
138 
139  virtual int webapiSettingsGet(
141  QString& errorMessage);
142 
143  virtual int webapiSettingsPutPatch(
144  bool force,
145  const QStringList& deviceSettingsKeys,
146  SWGSDRangel::SWGDeviceSettings& response, // query + response
147  QString& errorMessage);
148 
149  virtual int webapiRunGet(
150  SWGSDRangel::SWGDeviceState& response,
151  QString& errorMessage);
152 
153  virtual int webapiRun(
154  bool run,
155  SWGSDRangel::SWGDeviceState& response,
156  QString& errorMessage);
157 
158 
159 private:
161  QMutex m_mutex;
163  struct hackrf_device* m_dev;
167  bool m_running;
169  QNetworkAccessManager *m_networkManager;
170  QNetworkRequest m_networkRequest;
171 
172  bool openDevice();
173  void closeDevice();
174  bool applySettings(const HackRFInputSettings& settings, bool force);
175  void setDeviceCenterFrequency(quint64 freq, qint32 LOppmTenths);
177  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const HackRFInputSettings& settings, bool force);
178  void webapiReverseSendStartStop(bool start);
179 
180 private slots:
181  void networkManagerFinished(QNetworkReply *reply);
182 };
183 
184 #endif // INCLUDE_HACKRFINPUT_H
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: hackrfinput.h:130
DeviceHackRFParams m_sharedParams
Definition: hackrfinput.h:166
const HackRFInputSettings & getSettings() const
Definition: hackrfinput.h:45
bool applySettings(const HackRFInputSettings &settings, bool force)
MsgFileRecord(bool startStop)
Definition: hackrfinput.h:113
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual bool handleMessage(const Message &message)
virtual void destroy()
Definition: hackrfinput.cpp:79
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const HackRFInputSettings &settings)
struct hackrf_device * m_dev
Definition: hackrfinput.h:163
HackRFInputThread * m_hackRFThread
Definition: hackrfinput.h:164
bool openDevice()
Definition: hackrfinput.cpp:84
QNetworkRequest m_networkRequest
Definition: hackrfinput.h:170
static MsgConfigureHackRF * create(const HackRFInputSettings &settings, bool force=false)
Definition: hackrfinput.h:48
DeviceAPI * m_deviceAPI
Definition: hackrfinput.h:160
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
virtual QByteArray serialize() const
MsgStartStop(bool startStop)
Definition: hackrfinput.h:94
virtual bool start()
virtual bool deserialize(const QByteArray &data)
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const HackRFInputSettings &settings, bool force)
void closeDevice()
HackRFInput(DeviceAPI *deviceAPI)
Definition: hackrfinput.cpp:44
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual ~HackRFInput()
Definition: hackrfinput.cpp:64
static MsgFileRecord * create(bool startStop)
Definition: hackrfinput.h:106
HackRFInputSettings m_settings
Definition: hackrfinput.h:54
virtual const QString & getDeviceDescription() const
virtual int getSampleRate() const
Sample rate exposed by the source.
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
virtual void stop()
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
bool m_running
Definition: hackrfinput.h:167
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: hackrfinput.h:133
bool getStartStop() const
Definition: hackrfinput.h:85
void setDeviceCenterFrequency(quint64 freq, qint32 LOppmTenths)
static MsgStartStop * create(bool startStop)
Definition: hackrfinput.h:87
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual void setCenterFrequency(qint64 centerFrequency)
void networkManagerFinished(QNetworkReply *reply)
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
QString m_deviceDescription
Definition: hackrfinput.h:165
MsgConfigureHackRF(const HackRFInputSettings &settings, bool force)
Definition: hackrfinput.h:57
FileRecord * m_fileSink
File sink to record device I/Q output.
Definition: hackrfinput.h:168
void webapiReverseSendStartStop(bool start)
static MsgReportHackRF * create()
Definition: hackrfinput.h:69
QNetworkAccessManager * m_networkManager
Definition: hackrfinput.h:169
HackRFInputSettings m_settings
Definition: hackrfinput.h:162
QMutex m_mutex
Definition: hackrfinput.h:161