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.
localoutputgui.cpp
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 #include <stdint.h>
19 #include <sstream>
20 #include <iostream>
21 #include <cassert>
22 
23 #include <QDebug>
24 #include <QMessageBox>
25 #include <QTime>
26 #include <QDateTime>
27 #include <QString>
28 #include <QNetworkAccessManager>
29 #include <QNetworkReply>
30 #include <QJsonParseError>
31 #include <QJsonObject>
32 
33 #include "ui_localoutputgui.h"
34 #include "gui/colormapper.h"
35 #include "gui/glspectrum.h"
36 #include "gui/crightclickenabler.h"
38 #include "dsp/dspengine.h"
39 #include "dsp/dspcommands.h"
40 #include "mainwindow.h"
41 #include "util/simpleserializer.h"
42 #include "device/deviceapi.h"
43 #include "device/deviceuiset.h"
44 #include "localoutputgui.h"
45 
46 
47 LocalOutputGui::LocalOutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
48  QWidget(parent),
49  ui(new Ui::LocalOutputGui),
50  m_deviceUISet(deviceUISet),
51  m_settings(),
52  m_sampleSink(0),
53  m_acquisition(false),
54  m_streamSampleRate(0),
55  m_streamCenterFrequency(0),
56  m_lastEngineState(DeviceAPI::StNotStarted),
57  m_samplesCount(0),
58  m_tickCount(0),
59  m_doApplySettings(true),
60  m_forceSettings(true)
61 {
62  m_paletteGreenText.setColor(QPalette::WindowText, Qt::green);
63  m_paletteWhiteText.setColor(QPalette::WindowText, Qt::white);
64 
65  ui->setupUi(this);
66 
67  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
68  ui->centerFrequency->setValueRange(7, 0, 9999999U);
69 
70  ui->centerFrequencyHz->setColorMapper(ColorMapper(ColorMapper::GrayGold));
71  ui->centerFrequencyHz->setValueRange(3, 0, 999U);
72 
73  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
74  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
75 
77 
78  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
79  m_statusTimer.start(500);
80  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
81 
83 
84  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
86 
87  m_networkManager = new QNetworkAccessManager();
88  connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
89 
90  m_forceSettings = true;
91  sendSettings();
92 }
93 
95 {
96  disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
97  delete m_networkManager;
98  delete ui;
99 }
100 
102 {
103  m_doApplySettings = !block;
104 }
105 
107 {
108  delete this;
109 }
110 
111 void LocalOutputGui::setName(const QString& name)
112 {
113  setObjectName(name);
114 }
115 
116 QString LocalOutputGui::getName() const
117 {
118  return objectName();
119 }
120 
122 {
124  displaySettings();
125  m_forceSettings = true;
126  sendSettings();
127 }
128 
129 QByteArray LocalOutputGui::serialize() const
130 {
131  return m_settings.serialize();
132 }
133 
134 bool LocalOutputGui::deserialize(const QByteArray& data)
135 {
136  qDebug("LocalOutputGui::deserialize");
137 
138  if (m_settings.deserialize(data))
139  {
140  displaySettings();
141  m_forceSettings = true;
142  sendSettings();
143 
144  return true;
145  }
146  else
147  {
148  return false;
149  }
150 }
151 
153 {
155 }
156 
157 void LocalOutputGui::setCenterFrequency(qint64 centerFrequency)
158 {
159  (void) centerFrequency;
160 }
161 
163 {
165  {
167  m_settings = cfg.getSettings();
168  blockApplySettings(true);
169  displaySettings();
170  blockApplySettings(false);
171  return true;
172  }
173  else if (LocalOutput::MsgStartStop::match(message))
174  {
176  blockApplySettings(true);
177  ui->startStop->setChecked(notif.getStartStop());
178  blockApplySettings(false);
179 
180  return true;
181  }
183  {
188 
189  return true;
190  }
191  else
192  {
193  return false;
194  }
195 }
196 
198 {
199  Message* message;
200 
201  while ((message = m_inputMessageQueue.pop()) != 0)
202  {
203  //qDebug("LocalOutputGui::handleInputMessages: message: %s", message->getIdentifier());
204 
205  if (DSPSignalNotification::match(*message))
206  {
207  DSPSignalNotification* notif = (DSPSignalNotification*) message;
208 
209  if (notif->getSampleRate() != m_streamSampleRate) {
211  }
212 
214 
215  qDebug("LocalOutputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
216 
218  DSPSignalNotification *fwd = new DSPSignalNotification(*notif);
220 
221  delete message;
222  }
223  else
224  {
225  if (handleMessage(*message))
226  {
227  delete message;
228  }
229  }
230  }
231 }
232 
234 {
237  ui->deviceRateText->setText(tr("%1k").arg((float)m_streamSampleRate / 1000));
238  blockApplySettings(true);
239  ui->centerFrequency->setValue(m_streamCenterFrequency / 1000);
240  ui->centerFrequencyHz->setValue(m_streamCenterFrequency % 1000);
241  blockApplySettings(false);
242 }
243 
245 {
246  blockApplySettings(true);
247 
248  ui->centerFrequency->setValue(m_streamCenterFrequency / 1000);
249  ui->centerFrequencyHz->setValue(m_streamCenterFrequency % 1000);
250  ui->deviceRateText->setText(tr("%1k").arg(m_streamSampleRate / 1000.0));
251 
252  blockApplySettings(false);
253 }
254 
256 {
257  if(!m_updateTimer.isActive())
258  m_updateTimer.start(100);
259 }
260 
262 {
263  if (m_doApplySettings)
264  {
267  }
268 }
269 
271 {
272  if (m_doApplySettings)
273  {
274  qDebug() << "LocalOutputGui::updateHardware";
278  m_forceSettings = false;
279  m_updateTimer.stop();
280  }
281 }
282 
284 {
285  int state = m_deviceUISet->m_deviceAPI->state();
286 
287  if(m_lastEngineState != state)
288  {
289  switch(state)
290  {
292  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
293  break;
294  case DeviceAPI::StIdle:
295  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
296  break;
298  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
299  break;
300  case DeviceAPI::StError:
301  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
302  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
303  break;
304  default:
305  break;
306  }
307 
308  m_lastEngineState = state;
309  }
310 }
311 
313 {
314  BasicDeviceSettingsDialog dialog(this);
319 
320  dialog.move(p);
321  dialog.exec();
322 
327 
328  sendSettings();
329 }
virtual ~LocalOutputGui()
LocalOutputSettings m_settings
current settings
virtual void setMessageQueueToGUI(MessageQueue *queue)
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
QPalette m_paletteWhiteText
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
void setUseReverseAPI(bool useReverseAPI)
static MsgStartStop * create(bool startStop)
Definition: localoutput.h:71
QByteArray serialize() const
void updateSampleRateAndFrequency()
QByteArray serialize() const
DeviceUISet * m_deviceUISet
MessageQueue m_inputMessageQueue
Ui::LocalOutputGui * ui
int m_streamSampleRate
Sample rate of received stream.
QNetworkAccessManager * m_networkManager
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
DeviceSampleSink * getSampleSink()
Return pointer to the device sample sink (single Tx) or nullptr.
Definition: deviceapi.cpp:222
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
bool getStartStop() const
Definition: localoutput.h:69
bool deserialize(const QByteArray &data)
engine is before initialization
Definition: deviceapi.h:53
qint64 getCenterFrequency() const
Definition: dspcommands.h:329
EngineState state() const
Return the state of the device engine corresponding to the stream type.
Definition: deviceapi.cpp:277
virtual void setCenterFrequency(qint64 centerFrequency)
LocalOutput * m_sampleSink
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
MessageQueue * getInputMessageQueue()
virtual qint64 getCenterFrequency() const
void handleInputMessages()
void setName(const QString &name)
QTimer m_updateTimer
static bool match(const Message *message)
Definition: message.cpp:45
bool deserialize(const QByteArray &data)
const LocalOutputSettings & getSettings() const
Definition: localoutput.h:46
QString getName() const
int getSampleRate() const
Definition: dspcommands.h:328
static MsgConfigureLocalOutput * create(const LocalOutputSettings &settings, bool force=false)
Definition: localoutput.h:49
quint64 m_streamCenterFrequency
Center frequency of received stream.
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
void setReverseAPIAddress(const QString &address)
LocalOutputGui(DeviceUISet *deviceUISet, QWidget *parent=0)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
QTimer m_statusTimer
void on_startStop_toggled(bool checked)
engine is running
Definition: deviceapi.h:56
QPalette m_paletteGreenText
void openDeviceSettingsDialog(const QPoint &p)
virtual bool handleMessage(const Message &message)
virtual void destroy()
engine is in error
Definition: deviceapi.h:57
void blockApplySettings(bool block)