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.
testmi.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 _TESTMI_TESTMI_H_
19 #define _TESTMI_TESTMI_H_
20 
21 #include <QString>
22 #include <QByteArray>
23 #include <QTimer>
24 #include <QNetworkRequest>
25 
26 #include "dsp/devicesamplemimo.h"
27 #include "testmisettings.h"
28 
29 class DeviceAPI;
30 class TestMIThread;
31 class FileRecord;
32 class QNetworkAccessManager;
33 class QNetworkReply;
34 
35 class TestMI : public DeviceSampleMIMO {
36  Q_OBJECT
37 public:
40 
41  public:
42  const TestMISettings& getSettings() const { return m_settings; }
43  bool getForce() const { return m_force; }
44 
45  static MsgConfigureTestSource* create(const TestMISettings& settings, bool force)
46  {
47  return new MsgConfigureTestSource(settings, force);
48  }
49 
50  private:
52  bool m_force;
53 
54  MsgConfigureTestSource(const TestMISettings& settings, bool force) :
55  Message(),
56  m_settings(settings),
57  m_force(force)
58  { }
59  };
60 
61  class MsgFileRecord : public Message {
63 
64  public:
65  bool getStartStop() const { return m_startStop; }
66  int getStreamIndex() const { return m_streamIndex; }
67 
68  static MsgFileRecord* create(bool startStop, int streamIndex) {
69  return new MsgFileRecord(startStop, streamIndex);
70  }
71 
72  protected:
75 
76  MsgFileRecord(bool startStop, int streamIndex) :
77  Message(),
78  m_startStop(startStop),
79  m_streamIndex(streamIndex)
80  { }
81  };
82 
83  class MsgStartStop : public Message {
85 
86  public:
87  bool getStartStop() const { return m_startStop; }
88 
89  static MsgStartStop* create(bool startStop) {
90  return new MsgStartStop(startStop);
91  }
92 
93  protected:
95 
96  MsgStartStop(bool startStop) :
97  Message(),
98  m_startStop(startStop)
99  { }
100  };
101 
102  TestMI(DeviceAPI *deviceAPI);
103  virtual ~TestMI();
104  virtual void destroy();
105 
106  virtual void init();
107  virtual bool start();
108  virtual void stop();
109 
110  virtual QByteArray serialize() const;
111  virtual bool deserialize(const QByteArray& data);
112 
113  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
114  virtual const QString& getDeviceDescription() const;
115 
116  virtual int getSourceSampleRate(int index) const;
117  virtual void setSourceSampleRate(int sampleRate, int index) { (void) sampleRate; (void) index; }
118  virtual quint64 getSourceCenterFrequency(int index) const;
119  virtual void setSourceCenterFrequency(qint64 centerFrequency, int index);
120 
121  virtual int getSinkSampleRate(int index) const { return 0; (void) index; }
122  virtual void setSinkSampleRate(int sampleRate, int index) { (void) sampleRate; (void) index; }
123  virtual quint64 getSinkCenterFrequency(int index) const { return 0; (void) index; }
124  virtual void setSinkCenterFrequency(qint64 centerFrequency, int index) { (void) centerFrequency; (void) index; }
125 
126  virtual bool handleMessage(const Message& message);
127 
128  virtual int webapiSettingsGet(
130  QString& errorMessage);
131 
132  virtual int webapiSettingsPutPatch(
133  bool force,
134  const QStringList& deviceSettingsKeys,
135  SWGSDRangel::SWGDeviceSettings& response, // query + response
136  QString& errorMessage);
137 
138  virtual int webapiRunGet(
139  SWGSDRangel::SWGDeviceState& response,
140  QString& errorMessage);
141 
142  virtual int webapiRun(
143  bool run,
144  SWGSDRangel::SWGDeviceState& response,
145  QString& errorMessage);
146 
147  bool isRecording(unsigned int istream) const;
148 
149 private:
151  {
152  QList<QString> m_commonSettingsKeys;
153  QList<QList<QString>> m_streamsSettingsKeys;
154  };
155 
157  std::vector<FileRecord *> m_fileSinks;
158  QMutex m_mutex;
160  std::vector<TestMIThread*> m_testSourceThreads;
162  bool m_running;
163  const QTimer& m_masterTimer;
164  QNetworkAccessManager *m_networkManager;
165  QNetworkRequest m_networkRequest;
166 
167  bool applySettings(const TestMISettings& settings, bool force);
169  void webapiReverseSendSettings(const DeviceSettingsKeys& deviceSettingsKeys, const TestMISettings& settings, bool force);
170  void webapiReverseSendStartStop(bool start);
171 
172 private slots:
173  void networkManagerFinished(QNetworkReply *reply);
174 };
175 
176 #endif // _TESTMI_TESTMI_H_
QMutex m_mutex
Definition: testmi.h:158
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: testmi.cpp:526
virtual void destroy()
Definition: testmi.cpp:83
virtual quint64 getSourceCenterFrequency(int index) const
Center frequency exposed by the source at index.
Definition: testmi.cpp:181
std::vector< FileRecord * > m_fileSinks
File sinks to record device I/Q output.
Definition: testmi.h:157
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
Definition: testmi.cpp:88
MsgConfigureTestSource(const TestMISettings &settings, bool force)
Definition: testmi.h:54
virtual int getSourceSampleRate(int index) const
Sample rate exposed by the source at index.
Definition: testmi.cpp:172
bool applySettings(const TestMISettings &settings, bool force)
Definition: testmi.cpp:277
static MsgFileRecord * create(bool startStop, int streamIndex)
Definition: testmi.h:68
int getStreamIndex() const
Definition: testmi.h:66
Definition: testmi.h:35
TestMISettings m_settings
Definition: testmi.h:51
virtual quint64 getSinkCenterFrequency(int index) const
Center frequency exposed by the sink at index.
Definition: testmi.h:123
void networkManagerFinished(QNetworkReply *reply)
Definition: testmi.cpp:844
static MsgConfigureTestSource * create(const TestMISettings &settings, bool force)
Definition: testmi.h:45
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: testmi.cpp:535
void webapiReverseSendSettings(const DeviceSettingsKeys &deviceSettingsKeys, const TestMISettings &settings, bool force)
Definition: testmi.cpp:719
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: testmi.h:113
TestMISettings m_settings
Definition: testmi.h:159
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
bool isRecording(unsigned int istream) const
Definition: testmi.cpp:862
static MsgStartStop * create(bool startStop)
Definition: testmi.h:89
virtual void setSinkCenterFrequency(qint64 centerFrequency, int index)
Definition: testmi.h:124
QString m_deviceDescription
Definition: testmi.h:161
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: testmi.cpp:554
virtual bool deserialize(const QByteArray &data)
Definition: testmi.cpp:145
QList< QString > m_commonSettingsKeys
Definition: testmi.h:152
virtual void stop()
Definition: testmi.cpp:123
virtual QByteArray serialize() const
Definition: testmi.cpp:140
bool getStartStop() const
Definition: testmi.h:87
std::vector< TestMIThread * > m_testSourceThreads
Definition: testmi.h:160
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: testmi.cpp:565
virtual void setSourceSampleRate(int sampleRate, int index)
For when the source sample rate is set externally.
Definition: testmi.h:117
MsgStartStop(bool startStop)
Definition: testmi.h:96
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
virtual void setSinkSampleRate(int sampleRate, int index)
For when the sink sample rate is set externally.
Definition: testmi.h:122
virtual const QString & getDeviceDescription() const
Definition: testmi.cpp:167
const TestMISettings & getSettings() const
Definition: testmi.h:42
QNetworkAccessManager * m_networkManager
Definition: testmi.h:164
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const TestMISettings &settings)
Definition: testmi.cpp:672
TestMI(DeviceAPI *deviceAPI)
Definition: testmi.cpp:45
virtual bool start()
Definition: testmi.cpp:98
MsgFileRecord(bool startStop, int streamIndex)
Definition: testmi.h:76
DeviceAPI * m_deviceAPI
Definition: testmi.h:156
void webapiReverseSendStartStop(bool start)
Definition: testmi.cpp:816
bool m_running
Definition: testmi.h:162
virtual void setSourceCenterFrequency(qint64 centerFrequency, int index)
Definition: testmi.cpp:190
const QTimer & m_masterTimer
Definition: testmi.h:163
QList< QList< QString > > m_streamsSettingsKeys
Definition: testmi.h:153
bool getStartStop() const
Definition: testmi.h:65
QNetworkRequest m_networkRequest
Definition: testmi.h:165
virtual bool handleMessage(const Message &message)
Definition: testmi.cpp:209
virtual int getSinkSampleRate(int index) const
Sample rate exposed by the sink at index.
Definition: testmi.h:121
virtual ~TestMI()
Definition: testmi.cpp:61