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.
localinput.h
Go to the documentation of this file.
1 // Copyright (C) 2019 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_LOCALINPUT_H
19 #define INCLUDE_LOCALINPUT_H
20 
21 #include <ctime>
22 #include <iostream>
23 #include <stdint.h>
24 
25 #include <QString>
26 #include <QByteArray>
27 #include <QTimer>
28 #include <QNetworkRequest>
29 
30 #include "dsp/devicesamplesource.h"
31 
32 #include "localinputsettings.h"
33 
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 class DeviceAPI;
37 class FileRecord;
38 
40  Q_OBJECT
41 public:
44 
45  public:
46  const LocalInputSettings& getSettings() const { return m_settings; }
47  bool getForce() const { return m_force; }
48 
49  static MsgConfigureLocalInput* create(const LocalInputSettings& settings, bool force = false)
50  {
51  return new MsgConfigureLocalInput(settings, force);
52  }
53 
54  private:
56  bool m_force;
57 
58  MsgConfigureLocalInput(const LocalInputSettings& 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 
105 
106  public:
107  int getSampleRate() const { return m_sampleRate; }
108  int getCenterFrequency() const { return m_centerFrequency; }
109 
110  static MsgReportSampleRateAndFrequency* create(int sampleRate, qint64 centerFrequency) {
111  return new MsgReportSampleRateAndFrequency(sampleRate, centerFrequency);
112  }
113 
114  protected:
117 
118  MsgReportSampleRateAndFrequency(int sampleRate, qint64 centerFrequency) :
119  Message(),
120  m_sampleRate(sampleRate),
121  m_centerFrequency(centerFrequency)
122  { }
123  };
124 
125  LocalInput(DeviceAPI *deviceAPI);
126  virtual ~LocalInput();
127  virtual void destroy();
128 
129  virtual void init();
130  virtual bool start();
131  virtual void stop();
132 
133  virtual QByteArray serialize() const;
134  virtual bool deserialize(const QByteArray& data);
135 
136  virtual void setMessageQueueToGUI(MessageQueue *queue);
137  virtual const QString& getDeviceDescription() const;
138  virtual int getSampleRate() const;
139  virtual void setSampleRate(int sampleRate);
140  virtual quint64 getCenterFrequency() const;
141  virtual void setCenterFrequency(qint64 centerFrequency);
142 
143  virtual bool handleMessage(const Message& message);
144 
145  virtual int webapiSettingsGet(
147  QString& errorMessage);
148 
149  virtual int webapiSettingsPutPatch(
150  bool force,
151  const QStringList& deviceSettingsKeys,
152  SWGSDRangel::SWGDeviceSettings& response, // query + response
153  QString& errorMessage);
154 
155  virtual int webapiReportGet(
157  QString& errorMessage);
158 
159  virtual int webapiRunGet(
160  SWGSDRangel::SWGDeviceState& response,
161  QString& errorMessage);
162 
163  virtual int webapiRun(
164  bool run,
165  SWGSDRangel::SWGDeviceState& response,
166  QString& errorMessage);
167 
168 private:
170  QMutex m_mutex;
177  QNetworkAccessManager *m_networkManager;
178  QNetworkRequest m_networkRequest;
179 
180  void applySettings(const LocalInputSettings& settings, bool force = false);
183  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const LocalInputSettings& settings, bool force);
184  void webapiReverseSendStartStop(bool start);
185 
186 private slots:
187  void networkManagerFinished(QNetworkReply *reply);
188 };
189 
190 #endif // INCLUDE_LOCALINPUT_H
QString m_remoteAddress
Definition: localinput.h:174
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
Definition: localinput.cpp:145
QNetworkAccessManager * m_networkManager
Definition: localinput.h:177
static MsgStartStop * create(bool startStop)
Definition: localinput.h:90
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
Definition: localinput.cpp:392
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
Definition: localinput.cpp:381
LocalInput(DeviceAPI *deviceAPI)
Definition: localinput.cpp:43
DeviceAPI * m_deviceAPI
Definition: localinput.h:169
int m_sampleRate
Definition: localinput.h:173
virtual bool deserialize(const QByteArray &data)
Definition: localinput.cpp:94
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: localinput.cpp:275
virtual QByteArray serialize() const
Definition: localinput.cpp:89
LocalInputSettings m_settings
Definition: localinput.h:55
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: localinput.cpp:131
virtual ~LocalInput()
Definition: localinput.cpp:59
QNetworkRequest m_networkRequest
Definition: localinput.h:178
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: localinput.cpp:284
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: localinput.cpp:150
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
Definition: localinput.cpp:73
MsgReportSampleRateAndFrequency(int sampleRate, qint64 centerFrequency)
Definition: localinput.h:118
void applySettings(const LocalInputSettings &settings, bool force=false)
Definition: localinput.cpp:229
LocalInputSettings m_settings
Definition: localinput.h:171
QString m_deviceDescription
Definition: localinput.h:175
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
FileRecord * m_fileSink
File sink to record device I/Q output.
Definition: localinput.h:176
virtual bool start()
Definition: localinput.cpp:78
void webapiReverseSendStartStop(bool start)
Definition: localinput.cpp:437
MsgStartStop(bool startStop)
Definition: localinput.h:97
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: localinput.cpp:314
static MsgReportSampleRateAndFrequency * create(int sampleRate, qint64 centerFrequency)
Definition: localinput.h:110
bool getStartStop() const
Definition: localinput.h:69
const LocalInputSettings & getSettings() const
Definition: localinput.h:46
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: localinput.cpp:116
QMutex m_mutex
Definition: localinput.h:170
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const LocalInputSettings &settings, bool force)
Definition: localinput.cpp:398
virtual int getSampleRate() const
Sample rate exposed by the source.
Definition: localinput.cpp:126
virtual const QString & getDeviceDescription() const
Definition: localinput.cpp:121
virtual bool handleMessage(const Message &message)
Definition: localinput.cpp:164
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const LocalInputSettings &settings)
Definition: localinput.cpp:358
void networkManagerFinished(QNetworkReply *reply)
Definition: localinput.cpp:465
static MsgFileRecord * create(bool startStop)
Definition: localinput.h:71
virtual void destroy()
Definition: localinput.cpp:68
virtual void stop()
Definition: localinput.cpp:84
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: localinput.cpp:303
MsgConfigureLocalInput(const LocalInputSettings &settings, bool force)
Definition: localinput.h:58
bool getStartStop() const
Definition: localinput.h:88
static MsgConfigureLocalInput * create(const LocalInputSettings &settings, bool force=false)
Definition: localinput.h:49
MsgFileRecord(bool startStop)
Definition: localinput.h:78
qint64 m_centerFrequency
Definition: localinput.h:172