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.
remoteoutput.h
Go to the documentation of this file.
1 // Copyright (C) 2017 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_REMOTEOUTPUT_H
19 #define INCLUDE_REMOTEOUTPUT_H
20 
21 #include <ctime>
22 #include <iostream>
23 #include <fstream>
24 
25 #include <QObject>
26 #include <QString>
27 #include <QTimer>
28 #include <QNetworkRequest>
29 
30 #include "dsp/devicesamplesink.h"
31 
32 #include "remoteoutputsettings.h"
33 
34 class RemoteOutputThread;
35 class DeviceAPI;
36 class QNetworkAccessManager;
37 class QNetworkReply;
38 class QJsonObject;
39 
41  Q_OBJECT
42 public:
45 
46  public:
47  const RemoteOutputSettings& getSettings() const { return m_settings; }
48  bool getForce() const { return m_force; }
49 
50  static MsgConfigureRemoteOutput* create(const RemoteOutputSettings& settings, bool force = false)
51  {
52  return new MsgConfigureRemoteOutput(settings, force);
53  }
54 
55  private:
57  bool m_force;
58 
59  MsgConfigureRemoteOutput(const RemoteOutputSettings& settings, bool force) :
60  Message(),
61  m_settings(settings),
62  m_force(force)
63  { }
64  };
65 
68 
69  public:
70  bool isWorking() const { return m_working; }
71 
72  static MsgConfigureRemoteOutputWork* create(bool working)
73  {
74  return new MsgConfigureRemoteOutputWork(working);
75  }
76 
77  private:
78  bool m_working;
79 
81  Message(),
82  m_working(working)
83  { }
84  };
85 
86  class MsgStartStop : public Message {
88 
89  public:
90  bool getStartStop() const { return m_startStop; }
91 
92  static MsgStartStop* create(bool startStop) {
93  return new MsgStartStop(startStop);
94  }
95 
96  protected:
98 
99  MsgStartStop(bool startStop) :
100  Message(),
101  m_startStop(startStop)
102  { }
103  };
104 
107 
108  public:
109  int getChunkCorrection() const { return m_chunkCorrection; }
110 
111  static MsgConfigureRemoteOutputChunkCorrection* create(int chunkCorrection)
112  {
113  return new MsgConfigureRemoteOutputChunkCorrection(chunkCorrection);
114  }
115 
116  private:
118 
120  Message(),
121  m_chunkCorrection(chunkCorrection)
122  { }
123  };
124 
125  RemoteOutput(DeviceAPI *deviceAPI);
126  virtual ~RemoteOutput();
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) { m_guiMessageQueue = queue; }
137  virtual const QString& getDeviceDescription() const;
138  virtual int getSampleRate() const;
139  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
140  virtual quint64 getCenterFrequency() const;
141  virtual void setCenterFrequency(qint64 centerFrequency) { (void) centerFrequency; }
142  std::time_t getStartingTimeStamp() const;
143 
144  virtual bool handleMessage(const Message& message);
145 
146  virtual int webapiSettingsGet(
148  QString& errorMessage);
149 
150  virtual int webapiSettingsPutPatch(
151  bool force,
152  const QStringList& deviceSettingsKeys,
153  SWGSDRangel::SWGDeviceSettings& response, // query + response
154  QString& errorMessage);
155 
156  virtual int webapiReportGet(
158  QString& errorMessage);
159 
160  virtual int webapiRunGet(
161  SWGSDRangel::SWGDeviceState& response,
162  QString& errorMessage);
163 
164  virtual int webapiRun(
165  bool run,
166  SWGSDRangel::SWGDeviceState& response,
167  QString& errorMessage);
168 
169 private:
171  QMutex m_mutex;
176  std::time_t m_startingTimeStamp;
177  const QTimer& m_masterTimer;
180 
181  QNetworkAccessManager *m_networkManager;
182  QNetworkRequest m_networkRequest;
183 
193 
194  void applySettings(const RemoteOutputSettings& settings, bool force = false);
197 
198  void analyzeApiReply(const QJsonObject& jsonObject, const QString& answer);
199  void sampleRateCorrection(double remoteTimeDeltaUs, double timeDeltaUs, uint32_t remoteSampleCount, uint32_t sampleCount);
200  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RemoteOutputSettings& settings, bool force);
201  void webapiReverseSendStartStop(bool start);
202 
203 private slots:
204  void tick();
205  void networkManagerFinished(QNetworkReply *reply);
206 };
207 
208 #endif // INCLUDE_REMOTEOUTPUT_H
QMutex m_mutex
Definition: remoteoutput.h:171
virtual QByteArray serialize() const
RemoteOutputThread * m_remoteOutputThread
Definition: remoteoutput.h:174
QNetworkRequest m_networkRequest
Definition: remoteoutput.h:182
RemoteOutput(DeviceAPI *deviceAPI)
std::time_t m_startingTimeStamp
Definition: remoteoutput.h:176
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: remoteoutput.h:141
uint32_t m_nbRemoteSamplesSinceRateCorrection
Definition: remoteoutput.h:189
uint32_t m_tickCount
Definition: remoteoutput.h:178
virtual bool deserialize(const QByteArray &data)
std::time_t getStartingTimeStamp() const
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
const QTimer & m_masterTimer
Definition: remoteoutput.h:177
virtual int getSampleRate() const
Sample rate exposed by the sink.
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: remoteoutput.h:136
const RemoteOutputSettings & getSettings() const
Definition: remoteoutput.h:47
uint64_t m_centerFrequency
Definition: remoteoutput.h:173
virtual bool handleMessage(const Message &message)
static MsgConfigureRemoteOutput * create(const RemoteOutputSettings &settings, bool force=false)
Definition: remoteoutput.h:50
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
int m_lastQueueLength
Definition: remoteoutput.h:188
static const uint32_t NbSamplesForRateCorrection
Definition: remoteoutput.h:192
RemoteOutputSettings m_settings
Definition: remoteoutput.h:172
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t m_lastSampleCount
Definition: remoteoutput.h:185
void applySettings(const RemoteOutputSettings &settings, bool force=false)
QString m_deviceDescription
Definition: remoteoutput.h:175
void analyzeApiReply(const QJsonObject &jsonObject, const QString &answer)
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const RemoteOutputSettings &settings, bool force)
uint64_t m_lastTimestampRateCorrection
Definition: remoteoutput.h:187
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
static MsgStartStop * create(bool startStop)
Definition: remoteoutput.h:92
uint32_t m_nbSamplesSinceRateCorrection
Definition: remoteoutput.h:190
virtual ~RemoteOutput()
static MsgConfigureRemoteOutputWork * create(bool working)
Definition: remoteoutput.h:72
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual void destroy()
virtual const QString & getDeviceDescription() const
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual bool start()
virtual void setSampleRate(int sampleRate)
For when the sink sample rate is set externally.
Definition: remoteoutput.h:139
uint32_t m_lastRemoteSampleCount
Definition: remoteoutput.h:184
virtual void stop()
uint64_t m_lastRemoteTimestampRateCorrection
Definition: remoteoutput.h:186
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const RemoteOutputSettings &settings)
MsgStartStop(bool startStop)
Definition: remoteoutput.h:99
void sampleRateCorrection(double remoteTimeDeltaUs, double timeDeltaUs, uint32_t remoteSampleCount, uint32_t sampleCount)
void webapiReverseSendStartStop(bool start)
static MsgConfigureRemoteOutputChunkCorrection * create(int chunkCorrection)
Definition: remoteoutput.h:111
uint32_t m_tickMultiplier
Definition: remoteoutput.h:179
void networkManagerFinished(QNetworkReply *reply)
virtual quint64 getCenterFrequency() const
Center frequency exposed by the sink.
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
int m_chunkSizeCorrection
Definition: remoteoutput.h:191
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
QNetworkAccessManager * m_networkManager
Definition: remoteoutput.h:181
DeviceAPI * m_deviceAPI
Definition: remoteoutput.h:170
MsgConfigureRemoteOutput(const RemoteOutputSettings &settings, bool force)
Definition: remoteoutput.h:59
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48