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.
kiwisdrinput.h
Go to the documentation of this file.
1 // Copyright (C) 2019 Vort //
3 // Copyright (C) 2019 Edouard Griffiths, F4EXB //
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 _KIWISDR_KIWISDRINPUT_H_
20 #define _KIWISDR_KIWISDRINPUT_H_
21 
22 #include <QString>
23 #include <QByteArray>
24 #include <QTimer>
25 #include <QThread>
26 #include <QNetworkRequest>
27 
28 #include <dsp/devicesamplesource.h>
29 #include "kiwisdrsettings.h"
30 
31 class DeviceAPI;
32 class KiwiSDRWorker;
33 class FileRecord;
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 
38  Q_OBJECT
39 public:
40  class MsgConfigureKiwiSDR : public Message {
42 
43  public:
44  const KiwiSDRSettings& getSettings() const { return m_settings; }
45  bool getForce() const { return m_force; }
46 
47  static MsgConfigureKiwiSDR* create(const KiwiSDRSettings& settings, bool force)
48  {
49  return new MsgConfigureKiwiSDR(settings, force);
50  }
51 
52  private:
54  bool m_force;
55 
56  MsgConfigureKiwiSDR(const KiwiSDRSettings& settings, bool force) :
57  Message(),
58  m_settings(settings),
59  m_force(force)
60  { }
61  };
62 
63  class MsgFileRecord : public Message {
65 
66  public:
67  bool getStartStop() const { return m_startStop; }
68 
69  static MsgFileRecord* create(bool startStop) {
70  return new MsgFileRecord(startStop);
71  }
72 
73  protected:
75 
76  MsgFileRecord(bool startStop) :
77  Message(),
78  m_startStop(startStop)
79  { }
80  };
81 
82  class MsgStartStop : public Message {
84 
85  public:
86  bool getStartStop() const { return m_startStop; }
87 
88  static MsgStartStop* create(bool startStop) {
89  return new MsgStartStop(startStop);
90  }
91 
92  protected:
94 
95  MsgStartStop(bool startStop) :
96  Message(),
97  m_startStop(startStop)
98  { }
99  };
100 
101  class MsgSetStatus : public Message {
103 
104  public:
105  int getStatus() const { return m_status; }
106 
107  static MsgSetStatus* create(int status) {
108  return new MsgSetStatus(status);
109  }
110 
111  protected:
112  int m_status;
113 
114  MsgSetStatus(int status) :
115  Message(),
116  m_status(status)
117  { }
118  };
119 
120  KiwiSDRInput(DeviceAPI *deviceAPI);
121  virtual ~KiwiSDRInput();
122  virtual void destroy();
123 
124  virtual void init();
125  virtual bool start();
126  virtual void stop();
127 
128  virtual QByteArray serialize() const;
129  virtual bool deserialize(const QByteArray& data);
130 
131  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
132  virtual const QString& getDeviceDescription() const;
133  virtual int getSampleRate() const;
134  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
135  virtual quint64 getCenterFrequency() const;
136  virtual void setCenterFrequency(qint64 centerFrequency);
137 
138  virtual bool handleMessage(const Message& message);
139 
140  virtual int webapiSettingsGet(
142  QString& errorMessage);
143 
144  virtual int webapiSettingsPutPatch(
145  bool force,
146  const QStringList& deviceSettingsKeys,
147  SWGSDRangel::SWGDeviceSettings& response, // query + response
148  QString& errorMessage);
149 
150  virtual int webapiRunGet(
151  SWGSDRangel::SWGDeviceState& response,
152  QString& errorMessage);
153 
154  virtual int webapiRun(
155  bool run,
156  SWGSDRangel::SWGDeviceState& response,
157  QString& errorMessage);
158 
159  virtual int webapiReportGet(
161  QString& errorMessage);
162 
163 private:
166  QMutex m_mutex;
171  bool m_running;
172  const QTimer& m_masterTimer;
173  QNetworkAccessManager *m_networkManager;
174  QNetworkRequest m_networkRequest;
175 
176  int getStatus() const;
177  bool applySettings(const KiwiSDRSettings& settings, bool force);
180  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force);
181  void webapiReverseSendStartStop(bool start);
182 
183 signals:
184  void startWorker();
185  void stopWorker();
186  void setWorkerCenterFrequency(quint64 centerFrequency);
187  void setWorkerServerAddress(QString serverAddress);
188  void setWorkerGain(quint32 gain, bool useAGC);
189 
190 private slots:
191  void setWorkerStatus(int status);
192  void networkManagerFinished(QNetworkReply *reply);
193 };
194 
195 #endif // _KIWISDR_KIWISDRINPUT_H_
void setWorkerServerAddress(QString serverAddress)
QNetworkAccessManager * m_networkManager
Definition: kiwisdrinput.h:173
DeviceAPI * m_deviceAPI
Definition: kiwisdrinput.h:164
QThread m_kiwiSDRWorkerThread
Definition: kiwisdrinput.h:169
int getStatus() const
bool applySettings(const KiwiSDRSettings &settings, bool force)
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
void webapiReverseSendStartStop(bool start)
virtual bool start()
virtual bool deserialize(const QByteArray &data)
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
const QTimer & m_masterTimer
Definition: kiwisdrinput.h:172
virtual bool handleMessage(const Message &message)
static MsgSetStatus * create(int status)
Definition: kiwisdrinput.h:107
QNetworkRequest m_networkRequest
Definition: kiwisdrinput.h:174
virtual void destroy()
virtual void stop()
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
virtual QByteArray serialize() const
void networkManagerFinished(QNetworkReply *reply)
void stopWorker()
MsgFileRecord(bool startStop)
Definition: kiwisdrinput.h:76
static MsgConfigureKiwiSDR * create(const KiwiSDRSettings &settings, bool force)
Definition: kiwisdrinput.h:47
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
QString m_deviceDescription
Definition: kiwisdrinput.h:170
MsgStartStop(bool startStop)
Definition: kiwisdrinput.h:95
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
virtual ~KiwiSDRInput()
void setWorkerGain(quint32 gain, bool useAGC)
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setWorkerCenterFrequency(quint64 centerFrequency)
virtual const QString & getDeviceDescription() const
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: kiwisdrinput.h:134
void startWorker()
KiwiSDRInput(DeviceAPI *deviceAPI)
static MsgStartStop * create(bool startStop)
Definition: kiwisdrinput.h:88
const KiwiSDRSettings & getSettings() const
Definition: kiwisdrinput.h:44
MsgConfigureKiwiSDR(const KiwiSDRSettings &settings, bool force)
Definition: kiwisdrinput.h:56
virtual int getSampleRate() const
Sample rate exposed by the source.
static MsgFileRecord * create(bool startStop)
Definition: kiwisdrinput.h:69
FileRecord * m_fileSink
File sink to record device I/Q output.
Definition: kiwisdrinput.h:165
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const KiwiSDRSettings &settings, bool force)
void setWorkerStatus(int status)
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
KiwiSDRSettings m_settings
Definition: kiwisdrinput.h:167
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: kiwisdrinput.h:131
KiwiSDRWorker * m_kiwiSDRWorker
Definition: kiwisdrinput.h:168
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const KiwiSDRSettings &settings)
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
QMutex m_mutex
Definition: kiwisdrinput.h:166
virtual void setCenterFrequency(qint64 centerFrequency)