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.
sdrplaygui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016 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 <QDebug>
19 #include <QMessageBox>
20 
21 #include "sdrplaygui.h"
22 
23 #include "device/deviceapi.h"
24 #include "device/deviceuiset.h"
25 
26 #include "ui_sdrplaygui.h"
27 #include "gui/colormapper.h"
28 #include "gui/glspectrum.h"
29 #include "gui/crightclickenabler.h"
31 #include "dsp/dspengine.h"
32 #include "dsp/dspcommands.h"
33 
34 
35 SDRPlayGui::SDRPlayGui(DeviceUISet *deviceUISet, QWidget* parent) :
36  QWidget(parent),
37  ui(new Ui::SDRPlayGui),
38  m_deviceUISet(deviceUISet),
39  m_doApplySettings(true),
40  m_forceSettings(true)
41 {
43 
44  ui->setupUi(this);
45  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
46  ui->centerFrequency->setValueRange(7, 10U, 12000U);
47 
48  ui->fBand->clear();
49  for (unsigned int i = 0; i < SDRPlayBands::getNbBands(); i++)
50  {
51  ui->fBand->addItem(SDRPlayBands::getBandName(i));
52  }
53 
54  ui->ifFrequency->clear();
55  for (unsigned int i = 0; i < SDRPlayIF::getNbIFs(); i++)
56  {
57  ui->ifFrequency->addItem(QString::number(SDRPlayIF::getIF(i)/1000));
58  }
59 
60  ui->samplerate->clear();
61  for (unsigned int i = 0; i < SDRPlaySampleRates::getNbRates(); i++)
62  {
63  ui->samplerate->addItem(QString::number(SDRPlaySampleRates::getRate(i)/1000));
64  }
65 
66  ui->bandwidth->clear();
67  for (unsigned int i = 0; i < SDRPlayBandwidths::getNbBandwidths(); i++)
68  {
69  ui->bandwidth->addItem(QString::number(SDRPlayBandwidths::getBandwidth(i)/1000));
70  }
71 
72  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
73  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
74  m_statusTimer.start(500);
75 
76  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
77  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
78 
80 
81  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
83 }
84 
86 {
87  delete ui;
88 }
89 
91 {
92  delete this;
93 }
94 
95 void SDRPlayGui::setName(const QString& name)
96 {
97  setObjectName(name);
98 }
99 
100 QString SDRPlayGui::getName() const
101 {
102  return objectName();
103 }
104 
106 {
108  displaySettings();
109  sendSettings();
110 }
111 
113 {
115 }
116 
117 void SDRPlayGui::setCenterFrequency(qint64 centerFrequency)
118 {
119  m_settings.m_centerFrequency = centerFrequency;
120  displaySettings();
121  sendSettings();
122 }
123 
124 QByteArray SDRPlayGui::serialize() const
125 {
126  return m_settings.serialize();
127 }
128 
129 bool SDRPlayGui::deserialize(const QByteArray& data)
130 {
131  if(m_settings.deserialize(data))
132  {
133  displaySettings();
134  m_forceSettings = true;
135  sendSettings();
136  return true;
137  }
138  else
139  {
140  resetToDefaults();
141  return false;
142  }
143 }
144 
145 bool SDRPlayGui::handleMessage(const Message& message)
146 {
148  {
150  m_settings = cfg.getSettings();
151  blockApplySettings(true);
152  displaySettings();
153  blockApplySettings(false);
154  return true;
155  }
157  {
158  qDebug() << "SDRPlayGui::handleMessage: MsgReportSDRPlayGains";
159 
161 
163  {
164  ui->gainLNA->setChecked(msg.getLNAGain() != 0);
165  ui->gainMixer->setChecked(msg.getMixerGain() != 0);
166  ui->gainBaseband->setValue(msg.getBasebandGain());
167 
168  QString gainText;
169  gainText.sprintf("%02d", msg.getBasebandGain());
170  ui->gainBasebandText->setText(gainText);
171  }
172  else
173  {
174  ui->gainTuner->setValue(msg.getTunerGain());
175 
176  QString gainText;
177  gainText.sprintf("%03d", msg.getTunerGain());
178  ui->gainTunerText->setText(gainText);
179  }
180 
181  return true;
182  }
183  else if (SDRPlayInput::MsgStartStop::match(message))
184  {
186  blockApplySettings(true);
187  ui->startStop->setChecked(notif.getStartStop());
188  blockApplySettings(false);
189 
190  return true;
191  }
192  else
193  {
194  return false;
195  }
196 }
197 
199 {
200  Message* message;
201 
202  while ((message = m_inputMessageQueue.pop()) != 0)
203  {
204  qDebug("SDRPlayGui::handleInputMessages: message: %s", message->getIdentifier());
205 
206  if (DSPSignalNotification::match(*message))
207  {
208  DSPSignalNotification* notif = (DSPSignalNotification*) message;
209  m_sampleRate = notif->getSampleRate();
211  qDebug("SDRPlayGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
213 
214  delete message;
215  }
216  else
217  {
218  if (handleMessage(*message))
219  {
220  delete message;
221  }
222  }
223  }
224 }
225 
227 {
230  ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
231 }
232 
233 
235 {
236  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
237 
238  ui->ppm->setValue(m_settings.m_LOppmTenths);
239  ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
240 
241  ui->samplerate->setCurrentIndex(m_settings.m_devSampleRateIndex);
242 
243  ui->dcOffset->setChecked(m_settings.m_dcBlock);
244  ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
245 
246  ui->fBand->setCurrentIndex(m_settings.m_frequencyBandIndex);
247  ui->bandwidth->setCurrentIndex(m_settings.m_bandwidthIndex);
248  ui->ifFrequency->setCurrentIndex(m_settings.m_ifFrequencyIndex);
249  ui->samplerate->setCurrentIndex(m_settings.m_devSampleRateIndex);
250 
251  ui->decim->setCurrentIndex(m_settings.m_log2Decim);
252  ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
253 
254  ui->gainTunerOn->setChecked(m_settings.m_tunerGainMode);
255 
257  {
258  ui->gainTuner->setEnabled(true);
259  ui->gainLNA->setEnabled(false);
260  ui->gainMixer->setEnabled(false);
261  ui->gainBaseband->setEnabled(false);
262 
263  int gain = m_settings.m_tunerGain;
264  ui->gainTuner->setValue(gain);
265  QString gainText;
266  gainText.sprintf("%03d", gain);
267  ui->gainTunerText->setText(gainText);
268  m_settings.m_tunerGain = gain;
269  }
270  else
271  {
272  ui->gainTuner->setEnabled(false);
273  ui->gainLNA->setEnabled(true);
274  ui->gainMixer->setEnabled(true);
275  ui->gainBaseband->setEnabled(true);
276 
277  ui->gainLNA->setChecked(m_settings.m_lnaOn != 0);
278  ui->gainMixer->setChecked(m_settings.m_mixerAmpOn != 0);
279 
280  int gain = m_settings.m_basebandGain;
281  ui->gainBaseband->setValue(gain);
282  QString gainText;
283  gainText.sprintf("%02d", gain);
284  ui->gainBasebandText->setText(gainText);
285  }
286 }
287 
289 {
290  if(!m_updateTimer.isActive())
291  m_updateTimer.start(100);
292 }
293 
295 {
296  qDebug() << "SDRPlayGui::updateHardware";
299  m_forceSettings = false;
300  m_updateTimer.stop();
301 }
302 
304 {
305  int state = m_deviceUISet->m_deviceAPI->state();
306 
307  if(m_lastEngineState != state)
308  {
309  switch(state)
310  {
312  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
313  break;
314  case DeviceAPI::StIdle:
315  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
316  break;
318  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
319  break;
320  case DeviceAPI::StError:
321  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
322  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
323  break;
324  default:
325  break;
326  }
327 
328  m_lastEngineState = state;
329  }
330 }
331 
333 {
334  m_settings.m_centerFrequency = value * 1000;
335  sendSettings();
336 }
337 
339 {
340  m_settings.m_LOppmTenths = value;
341  ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
342  sendSettings();
343 }
344 
346 {
347  qDebug("SDRPlayGui::on_dcOffset_toggled: %s", checked ? "on" : "off");
348  m_settings.m_dcBlock = checked;
349  sendSettings();
350 }
351 
353 {
354  m_settings.m_iqCorrection = checked;
355  sendSettings();
356 }
357 
359 {
360  ui->centerFrequency->setValueRange(
361  7,
364 
365  ui->centerFrequency->setValue((SDRPlayBands::getBandLow(index)+SDRPlayBands::getBandHigh(index)) / 2);
368 
369  sendSettings();
370 }
371 
373 {
375  sendSettings();
376 }
377 
379 {
381  sendSettings();
382 }
383 
385 {
387  sendSettings();
388 }
389 
391 {
392  m_settings.m_log2Decim = index;
393  sendSettings();
394 }
395 
397 {
399  sendSettings();
400 }
401 
403 {
404  qDebug("SDRPlayGui::on_gainTunerOn_toggled: %s", checked ? "on" : "off");
406  ui->gainTuner->setEnabled(true);
407  ui->gainLNA->setEnabled(false);
408  ui->gainMixer->setEnabled(false);
409  ui->gainBaseband->setEnabled(false);
410 
411  sendSettings();
412 }
413 
415 {
416  int gain = value;
417  QString gainText;
418  gainText.sprintf("%03d", gain);
419  ui->gainTunerText->setText(gainText);
420  m_settings.m_tunerGain = gain;
421 
422  sendSettings();
423 }
424 
426 {
427  qDebug("SDRPlayGui::on_gainManualOn_toggled: %s", checked ? "on" : "off");
428  m_settings.m_tunerGainMode = false;
429  ui->gainTuner->setEnabled(false);
430  ui->gainLNA->setEnabled(true);
431  ui->gainMixer->setEnabled(true);
432  ui->gainBaseband->setEnabled(true);
433 
434  sendSettings();
435 }
436 
438 {
439  m_settings.m_lnaOn = checked ? 1 : 0;
440  sendSettings();
441 }
442 
444 {
445  m_settings.m_mixerAmpOn = checked ? 1 : 0;
446  sendSettings();
447 }
448 
450 {
451  m_settings.m_basebandGain = value;
452 
453  QString gainText;
454  gainText.sprintf("%02d", value);
455  ui->gainBasebandText->setText(gainText);
456 
457  sendSettings();
458 }
459 
461 {
462  if (m_doApplySettings)
463  {
466  }
467 }
468 
470 {
471  if (checked) {
472  ui->record->setStyleSheet("QToolButton { background-color : red; }");
473  } else {
474  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
475  }
476 
479 }
480 
482 {
483  BasicDeviceSettingsDialog dialog(this);
488 
489  dialog.move(p);
490  dialog.exec();
491 
496 
497  sendSettings();
498 }
static unsigned int getNbRates()
uint32_t m_ifFrequencyIndex
void blockApplySettings(bool block)
Definition: sdrplaygui.h:71
QTimer m_updateTimer
Definition: sdrplaygui.h:63
void updateSampleRateAndFrequency()
Definition: sdrplaygui.cpp:226
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
uint16_t m_reverseAPIPort
void on_fBand_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:358
void on_gainLNA_toggled(bool checked)
Definition: sdrplaygui.cpp:437
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
static MsgStartStop * create(bool startStop)
Definition: sdrplayinput.h:125
void handleInputMessages()
Definition: sdrplaygui.cpp:198
MessageQueue * getInputMessageQueue()
bool m_forceSettings
Definition: sdrplaygui.h:61
static unsigned int getNbBands()
static unsigned int getNbBandwidths()
virtual ~SDRPlayGui()
Definition: sdrplaygui.cpp:85
SDRPlaySettings m_settings
Definition: sdrplaygui.h:62
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: sdrplaygui.h:67
static unsigned int getNbIFs()
bool m_doApplySettings
Definition: sdrplaygui.h:60
static MsgFileRecord * create(bool startStop)
Definition: sdrplayinput.h:106
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
void updateHardware()
Definition: sdrplaygui.cpp:294
const SDRPlaySettings & getSettings() const
Definition: sdrplayinput.h:52
void on_fcPos_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:396
void setName(const QString &name)
Definition: sdrplaygui.cpp:95
int m_sampleRate
Definition: sdrplaygui.h:66
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
int m_lastEngineState
Definition: sdrplaygui.h:68
virtual void resetToDefaults()
Definition: sdrplaygui.cpp:105
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 qint64 getCenterFrequency() const
Definition: sdrplaygui.cpp:112
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
void on_startStop_toggled(bool checked)
Definition: sdrplaygui.cpp:460
QString m_reverseAPIAddress
QByteArray serialize() const
void on_gainBaseband_valueChanged(int value)
Definition: sdrplaygui.cpp:449
static MsgConfigureSDRPlay * create(const SDRPlaySettings &settings, bool force)
Definition: sdrplayinput.h:55
virtual QByteArray serialize() const
Definition: sdrplaygui.cpp:124
int32_t i
Definition: decimators.h:244
void displaySettings()
Definition: sdrplaygui.cpp:234
static bool match(const Message *message)
Definition: message.cpp:45
void on_gainTunerOn_toggled(bool checked)
Definition: sdrplaygui.cpp:402
Ui::SDRPlayGui * ui
Definition: sdrplaygui.h:57
uint64_t m_centerFrequency
static unsigned int getBandLow(unsigned int band_index)
static unsigned int getBandwidth(unsigned int bandwidth_index)
uint32_t m_frequencyBandIndex
void on_ppm_valueChanged(int value)
Definition: sdrplaygui.cpp:338
void on_ifFrequency_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:384
void on_centerFrequency_changed(quint64 value)
Definition: sdrplaygui.cpp:332
virtual bool deserialize(const QByteArray &data)
Definition: sdrplaygui.cpp:129
void on_record_toggled(bool checked)
Definition: sdrplaygui.cpp:469
uint32_t m_log2Decim
virtual bool handleMessage(const Message &message)
Definition: sdrplaygui.cpp:145
uint32_t m_bandwidthIndex
MessageQueue m_inputMessageQueue
Definition: sdrplaygui.h:69
void openDeviceSettingsDialog(const QPoint &p)
Definition: sdrplaygui.cpp:481
void on_dcOffset_toggled(bool checked)
Definition: sdrplaygui.cpp:345
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: sdrplaygui.cpp:117
void sendSettings()
Definition: sdrplaygui.cpp:288
bool deserialize(const QByteArray &data)
void on_samplerate_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:378
virtual void destroy()
Definition: sdrplaygui.cpp:90
void updateStatus()
Definition: sdrplaygui.cpp:303
int getSampleRate() const
Definition: dspcommands.h:328
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
virtual const char * getIdentifier() const
Definition: message.cpp:35
QString getName() const
Definition: sdrplaygui.cpp:100
static unsigned int getRate(unsigned int rate_index)
void setReverseAPIAddress(const QString &address)
static unsigned int getIF(unsigned int if_index)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
static unsigned int getBandHigh(unsigned int band_index)
DeviceUISet * m_deviceUISet
Definition: sdrplaygui.h:59
void on_gainTuner_valueChanged(int value)
Definition: sdrplaygui.cpp:414
virtual void setMessageQueueToGUI(MessageQueue *queue)=0
engine is running
Definition: deviceapi.h:56
void on_iqImbalance_toggled(bool checked)
Definition: sdrplaygui.cpp:352
static QString getBandName(unsigned int band_index)
uint16_t m_reverseAPIDeviceIndex
uint32_t m_devSampleRateIndex
SDRPlayGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Definition: sdrplaygui.cpp:35
DeviceSampleSource * m_sampleSource
Definition: sdrplaygui.h:65
QTimer m_statusTimer
Definition: sdrplaygui.h:64
void on_decim_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:390
engine is in error
Definition: deviceapi.h:57
void on_gainManualOn_toggled(bool checked)
Definition: sdrplaygui.cpp:425
void on_bandwidth_currentIndexChanged(int index)
Definition: sdrplaygui.cpp:372
void on_gainMixer_toggled(bool checked)
Definition: sdrplaygui.cpp:443