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.
localinputgui.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_localinputgui.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 "localinputgui.h"
45 
46 
47 LocalInputGui::LocalInputGui(DeviceUISet *deviceUISet, QWidget* parent) :
48  QWidget(parent),
49  ui(new Ui::LocalInputGui),
50  m_deviceUISet(deviceUISet),
51  m_settings(),
52  m_sampleSource(0),
53  m_acquisition(false),
54  m_streamSampleRate(0),
55  m_streamCenterFrequency(0),
56  m_lastEngineState(DeviceAPI::StNotStarted),
57  m_framesDecodingStatus(0),
58  m_bufferLengthInSecs(0.0),
59  m_bufferGauge(-50),
60  m_nbOriginalBlocks(128),
61  m_nbFECBlocks(0),
62  m_sampleBits(16), // assume 16 bits to start with
63  m_sampleBytes(2),
64  m_samplesCount(0),
65  m_tickCount(0),
66  m_addressEdited(false),
67  m_dataPortEdited(false),
68  m_countUnrecoverable(0),
69  m_countRecovered(0),
70  m_doApplySettings(true),
71  m_forceSettings(true),
72  m_txDelay(0.0)
73 {
74  m_paletteGreenText.setColor(QPalette::WindowText, Qt::green);
75  m_paletteWhiteText.setColor(QPalette::WindowText, Qt::white);
76 
78  ui->setupUi(this);
79 
80  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
81  ui->centerFrequency->setValueRange(7, 0, 9999999U);
82 
83  ui->centerFrequencyHz->setColorMapper(ColorMapper(ColorMapper::GrayGold));
84  ui->centerFrequencyHz->setValueRange(3, 0, 999U);
85 
86  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
87  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
88 
90 
91  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
92  m_statusTimer.start(500);
93  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
94 
96 
97  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
99 
100  m_networkManager = new QNetworkAccessManager();
101  connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
102 
103  m_eventsTime.start();
104 
105  m_forceSettings = true;
106  sendSettings();
107 }
108 
110 {
111  disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
112  delete m_networkManager;
113  delete ui;
114 }
115 
117 {
118  m_doApplySettings = !block;
119 }
120 
122 {
123  delete this;
124 }
125 
126 void LocalInputGui::setName(const QString& name)
127 {
128  setObjectName(name);
129 }
130 
131 QString LocalInputGui::getName() const
132 {
133  return objectName();
134 }
135 
137 {
139  displaySettings();
140  m_forceSettings = true;
141  sendSettings();
142 }
143 
144 QByteArray LocalInputGui::serialize() const
145 {
146  return m_settings.serialize();
147 }
148 
149 bool LocalInputGui::deserialize(const QByteArray& data)
150 {
151  qDebug("LocalInputGui::deserialize");
152 
153  if (m_settings.deserialize(data))
154  {
155  displaySettings();
156  m_forceSettings = true;
157  sendSettings();
158 
159  return true;
160  }
161  else
162  {
163  return false;
164  }
165 }
166 
168 {
170 }
171 
172 void LocalInputGui::setCenterFrequency(qint64 centerFrequency)
173 {
174  (void) centerFrequency;
175 }
176 
178 {
180  {
182  m_settings = cfg.getSettings();
183  blockApplySettings(true);
184  displaySettings();
185  blockApplySettings(false);
186  return true;
187  }
188  else if (LocalInput::MsgStartStop::match(message))
189  {
191  blockApplySettings(true);
192  ui->startStop->setChecked(notif.getStartStop());
193  blockApplySettings(false);
194 
195  return true;
196  }
198  {
203 
204  return true;
205  }
206  else
207  {
208  return false;
209  }
210 }
211 
213 {
214  Message* message;
215 
216  while ((message = m_inputMessageQueue.pop()) != 0)
217  {
218  //qDebug("LocalInputGui::handleInputMessages: message: %s", message->getIdentifier());
219 
220  if (DSPSignalNotification::match(*message))
221  {
222  DSPSignalNotification* notif = (DSPSignalNotification*) message;
223 
224  if (notif->getSampleRate() != m_streamSampleRate) {
226  }
227 
229 
230  qDebug("LocalInputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
231 
233  DSPSignalNotification *fwd = new DSPSignalNotification(*notif);
235 
236  delete message;
237  }
238  else
239  {
240  if (handleMessage(*message))
241  {
242  delete message;
243  }
244  }
245  }
246 }
247 
249 {
252  ui->deviceRateText->setText(tr("%1k").arg((float)m_streamSampleRate / 1000));
253  blockApplySettings(true);
254  ui->centerFrequency->setValue(m_streamCenterFrequency / 1000);
255  ui->centerFrequencyHz->setValue(m_streamCenterFrequency % 1000);
256  blockApplySettings(false);
257 }
258 
260 {
261  blockApplySettings(true);
262 
263  ui->centerFrequency->setValue(m_streamCenterFrequency / 1000);
264  ui->centerFrequencyHz->setValue(m_streamCenterFrequency % 1000);
265  ui->deviceRateText->setText(tr("%1k").arg(m_streamSampleRate / 1000.0));
266 
267  ui->dcOffset->setChecked(m_settings.m_dcBlock);
268  ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
269 
270  blockApplySettings(false);
271 }
272 
274 {
275  if(!m_updateTimer.isActive())
276  m_updateTimer.start(100);
277 }
278 
280 {
281  m_settings.m_dcBlock = checked;
282  sendSettings();
283 }
284 
286 {
287  m_settings.m_iqCorrection = checked;
288  sendSettings();
289 }
290 
292 {
293  if (m_doApplySettings)
294  {
297  }
298 }
299 
301 {
302  if (checked) {
303  ui->record->setStyleSheet("QToolButton { background-color : red; }");
304  } else {
305  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
306  }
307 
310 }
311 
313 {
314  if (m_doApplySettings)
315  {
316  qDebug() << "LocalInputGui::updateHardware";
320  m_forceSettings = false;
321  m_updateTimer.stop();
322  }
323 }
324 
326 {
327  int state = m_deviceUISet->m_deviceAPI->state();
328 
329  if(m_lastEngineState != state)
330  {
331  switch(state)
332  {
334  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
335  break;
336  case DeviceAPI::StIdle:
337  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
338  break;
340  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
341  break;
342  case DeviceAPI::StError:
343  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
344  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
345  break;
346  default:
347  break;
348  }
349 
350  m_lastEngineState = state;
351  }
352 }
353 
355 {
356  BasicDeviceSettingsDialog dialog(this);
361 
362  dialog.move(p);
363  dialog.exec();
364 
369 
370  sendSettings();
371 }
LocalInputSettings m_settings
current settings
Definition: localinputgui.h:62
void openDeviceSettingsDialog(const QPoint &p)
static MsgStartStop * create(bool startStop)
Definition: localinput.h:90
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
void on_dcOffset_toggled(bool checked)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
void on_iqImbalance_toggled(bool checked)
void displaySettings()
QPalette m_paletteWhiteText
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
MessageQueue * getInputMessageQueue()
virtual ~LocalInputGui()
QTimer m_statusTimer
Definition: localinputgui.h:68
uint64_t m_startingTimeStampms
Definition: localinputgui.h:74
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
void on_startStop_toggled(bool checked)
MessageQueue m_inputMessageQueue
Definition: localinputgui.h:70
LocalInputGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
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
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
virtual bool handleMessage(const Message &message)
QByteArray serialize() const
LocalInput * m_sampleSource
Definition: localinputgui.h:63
Ui::LocalInputGui * ui
Definition: localinputgui.h:59
void blockApplySettings(bool block)
QString getName() const
static bool match(const Message *message)
Definition: message.cpp:45
QPalette m_paletteGreenText
void updateSampleRateAndFrequency()
const LocalInputSettings & getSettings() const
Definition: localinput.h:46
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: localinput.cpp:116
bool m_doApplySettings
quint64 m_streamCenterFrequency
Center frequency of received stream.
Definition: localinputgui.h:66
virtual void destroy()
uint16_t m_reverseAPIDeviceIndex
QTime m_eventsTime
Definition: localinputgui.h:98
int getSampleRate() const
Definition: dspcommands.h:328
virtual qint64 getCenterFrequency() const
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
void on_record_toggled(bool checked)
void setName(const QString &name)
void setReverseAPIAddress(const QString &address)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void resetToDefaults()
QNetworkAccessManager * m_networkManager
engine is running
Definition: deviceapi.h:56
int m_streamSampleRate
Sample rate of received stream.
Definition: localinputgui.h:65
static MsgFileRecord * create(bool startStop)
Definition: localinput.h:71
QByteArray serialize() const
virtual void setCenterFrequency(qint64 centerFrequency)
engine is in error
Definition: deviceapi.h:57
bool deserialize(const QByteArray &data)
bool getStartStop() const
Definition: localinput.h:88
void handleInputMessages()
DeviceUISet * m_deviceUISet
Definition: localinputgui.h:61
bool deserialize(const QByteArray &data)
static MsgConfigureLocalInput * create(const LocalInputSettings &settings, bool force=false)
Definition: localinput.h:49
QTimer m_updateTimer
Definition: localinputgui.h:67