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.
perseusgui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 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 "device/deviceapi.h"
22 #include "device/deviceuiset.h"
23 #include "dsp/filerecord.h"
24 
25 #include "ui_perseusgui.h"
26 #include "gui/colormapper.h"
27 #include "gui/glspectrum.h"
28 #include "gui/crightclickenabler.h"
30 #include "dsp/dspengine.h"
31 #include "dsp/dspcommands.h"
32 #include "perseusgui.h"
33 
34 PerseusGui::PerseusGui(DeviceUISet *deviceUISet, QWidget* parent) :
35  QWidget(parent),
36  ui(new Ui::PerseusGui),
37  m_deviceUISet(deviceUISet),
38  m_doApplySettings(true),
39  m_forceSettings(true),
40  m_settings(),
41  m_sampleSource(0),
42  m_lastEngineState(DeviceAPI::StNotStarted)
43 {
45 
46  ui->setupUi(this);
47  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
49 
50  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
51  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
52  m_statusTimer.start(500);
53 
54  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
55  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
56 
58 
61  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
63 
64  sendSettings();
65 }
66 
68 {
69  delete ui;
70 }
71 
73 {
74  delete this;
75 }
76 
77 void PerseusGui::setName(const QString& name)
78 {
79  setObjectName(name);
80 }
81 
82 QString PerseusGui::getName() const
83 {
84  return objectName();
85 }
86 
88 {
91  sendSettings();
92 }
93 
95 {
97 }
98 
99 void PerseusGui::setCenterFrequency(qint64 centerFrequency)
100 {
101  m_settings.m_centerFrequency = centerFrequency;
102  displaySettings();
103  sendSettings();
104 }
105 
106 QByteArray PerseusGui::serialize() const
107 {
108  return m_settings.serialize();
109 }
110 
111 bool PerseusGui::deserialize(const QByteArray& data)
112 {
113  if(m_settings.deserialize(data)) {
114  displaySettings();
115  m_forceSettings = true;
116  sendSettings();
117  return true;
118  } else {
119  resetToDefaults();
120  return false;
121  }
122 }
123 
124 bool PerseusGui::handleMessage(const Message& message)
125 {
126  // Returned messages to update the GUI (usually from web interface)
128  {
130  m_settings = cfg.getSettings();
131  blockApplySettings(true);
132  displaySettings();
133  blockApplySettings(false);
134  return true;
135  }
136  else if (PerseusInput::MsgStartStop::match(message))
137  {
139  blockApplySettings(true);
140  ui->startStop->setChecked(notif.getStartStop());
141  blockApplySettings(false);
142 
143  return true;
144  }
145  else
146  {
147  return false;
148  }
149 }
150 
152 {
153  Message* message;
154 
155  while ((message = m_inputMessageQueue.pop()) != 0)
156  {
157  if (DSPSignalNotification::match(*message))
158  {
159  DSPSignalNotification* notif = (DSPSignalNotification*) message;
160  m_sampleRate = notif->getSampleRate();
162  qDebug("PerseusGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
164 
165  delete message;
166  }
167  else
168  {
169  qDebug("PerseusGui::handleInputMessages: message: %s", message->getIdentifier());
170 
171  if (handleMessage(*message))
172  {
173  delete message;
174  }
175  }
176  }
177 }
178 
180 {
183  ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
184 }
185 
187 {
188  blockApplySettings(true);
190  ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency);
191  ui->transverter->setDeltaFrequencyActive(m_settings.m_transverterMode);
192  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
193  ui->LOppm->setValue(m_settings.m_LOppmTenths);
194  ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
195  ui->sampleRate->setCurrentIndex(m_settings.m_devSampleRateIndex);
196  ui->decim->setCurrentIndex(m_settings.m_log2Decim);
197  ui->wideband->setChecked(m_settings.m_wideBand);
198  ui->adcDither->setChecked(m_settings.m_adcDither);
199  ui->adcPreamp->setChecked(m_settings.m_adcPreamp);
200  ui->attenuator->setCurrentIndex((int) m_settings.m_attenuator);
201  blockApplySettings(false);
202 }
203 
205 {
206  unsigned int savedIndex = m_settings.m_devSampleRateIndex;
207  ui->sampleRate->blockSignals(true);
208 
209  if (m_rates.size() > 0)
210  {
211  ui->sampleRate->clear();
212 
213  for (unsigned int i = 0; i < m_rates.size(); i++)
214  {
215  int sampleRate = m_rates[i]/1000;
216  ui->sampleRate->addItem(QString("%1").arg(QString("%1").arg(sampleRate, 5, 10, QChar(' '))));
217  }
218  }
219 
220  ui->sampleRate->blockSignals(false);
221 
222  if (savedIndex < m_rates.size())
223  {
224  ui->sampleRate->setCurrentIndex(savedIndex);
225  }
226  else
227  {
228  ui->sampleRate->setCurrentIndex((int) m_rates.size()-1);
229  }
230 }
231 
233 {
234  // values in kHz
235  qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0;
236 
237  qint64 minLimit = 10 + deltaFrequency;
238  qint64 maxLimit = 40000 + deltaFrequency;
239 
240  minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit;
241  maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit;
242 
243  qDebug("PerseusGui::updateFrequencyLimits: delta: %lld min: %lld max: %lld", deltaFrequency, minLimit, maxLimit);
244 
245  ui->centerFrequency->setValueRange(7, minLimit, maxLimit);
246 }
247 
249 {
250  if(!m_updateTimer.isActive())
251  m_updateTimer.start(100);
252 }
253 
255 {
256  m_settings.m_centerFrequency = value * 1000;
257  sendSettings();
258 }
259 
261 {
262  m_settings.m_LOppmTenths = value;
263  ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
264  sendSettings();
265 }
266 
268 {
269  ui->LOppm->setValue(0);
270 }
271 
273 {
275  sendSettings();
276 }
277 
279 {
280  m_settings.m_wideBand = checked;
281  sendSettings();
282 }
283 
285 {
286  if ((index < 0) || (index > 5))
287  return;
288  m_settings.m_log2Decim = index;
289  sendSettings();
290 }
291 
293 {
294  if (m_doApplySettings)
295  {
298  }
299 }
300 
302 {
303  if (checked) {
304  ui->record->setStyleSheet("QToolButton { background-color : red; }");
305  } else {
306  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
307  }
308 
311 }
312 
314 {
315  m_settings.m_transverterMode = ui->transverter->getDeltaFrequencyAcive();
316  m_settings.m_transverterDeltaFrequency = ui->transverter->getDeltaFrequency();
317  qDebug("PerseusGui::on_transverter_clicked: %lld Hz %s", m_settings.m_transverterDeltaFrequency, m_settings.m_transverterMode ? "on" : "off");
319  m_settings.m_centerFrequency = ui->centerFrequency->getValueNew()*1000;
320  sendSettings();
321 }
322 
324 {
325  if ((index < 0) || (index >= (int) PerseusSettings::Attenuator_last)) {
326  return;
327  }
329  sendSettings();
330 }
331 
333 {
334  m_settings.m_adcDither = checked;
335  sendSettings();
336 }
337 
339 {
340  m_settings.m_adcPreamp = checked;
341  sendSettings();
342 }
343 
345 {
346  qDebug() << "PerseusGui::updateHardware";
349  m_forceSettings = false;
350  m_updateTimer.stop();
351 }
352 
354 {
355  int state = m_deviceUISet->m_deviceAPI->state();
356 
357  if(m_lastEngineState != state)
358  {
359  switch(state)
360  {
362  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
363  break;
364  case DeviceAPI::StIdle:
365  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
366  break;
368  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
369  break;
370  case DeviceAPI::StError:
371  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
372  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
373  break;
374  default:
375  break;
376  }
377 
378  m_lastEngineState = state;
379  }
380 }
381 
382 uint32_t PerseusGui::getDevSampleRate(unsigned int rate_index)
383 {
384  if (rate_index < m_rates.size())
385  {
386  return m_rates[rate_index];
387  }
388  else
389  {
390  return m_rates[0];
391  }
392 }
393 
395 {
396  for (unsigned int i=0; i < m_rates.size(); i++)
397  {
398  if (sampeRate == m_rates[i])
399  {
400  return i;
401  }
402  }
403 
404  return -1;
405 }
406 
408 {
409  BasicDeviceSettingsDialog dialog(this);
414 
415  dialog.move(p);
416  dialog.exec();
417 
422 
423  sendSettings();
424 }
qint64 m_transverterDeltaFrequency
Attenuator m_attenuator
QTimer m_statusTimer
Definition: perseusgui.h:64
bool m_forceSettings
Definition: perseusgui.h:61
void resetToDefaults()
Definition: perseusgui.cpp:87
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
QString getName() const
Definition: perseusgui.cpp:82
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
void on_wideband_toggled(bool checked)
Definition: perseusgui.cpp:278
quint32 m_devSampleRateIndex
bool m_doApplySettings
Definition: perseusgui.h:60
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
const std::vector< uint32_t > & getSampleRates() const
Definition: perseusinput.h:143
MessageQueue * getInputMessageQueue()
uint16_t m_reverseAPIDeviceIndex
DeviceUISet * m_deviceUISet
Definition: perseusgui.h:59
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: perseusinput.h:111
std::vector< uint32_t > m_rates
Definition: perseusgui.h:65
void on_startStop_toggled(bool checked)
Definition: perseusgui.cpp:292
virtual void destroy()
Definition: perseusgui.cpp:72
uint32_t getDevSampleRate(unsigned int index)
Definition: perseusgui.cpp:382
void updateFrequencyLimits()
Definition: perseusgui.cpp:232
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
QByteArray serialize() const
Definition: perseusgui.cpp:106
unsigned int uint32_t
Definition: rtptypes_win.h:46
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
quint64 m_centerFrequency
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
engine is before initialization
Definition: deviceapi.h:53
virtual bool handleMessage(const Message &message)
Definition: perseusgui.cpp:124
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
Ui::PerseusGui * ui
Definition: perseusgui.h:57
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
void on_adcPreamp_toggled(bool checked)
Definition: perseusgui.cpp:338
void blockApplySettings(bool block)
Definition: perseusgui.h:72
QByteArray serialize() const
void on_sampleRate_currentIndexChanged(int index)
Definition: perseusgui.cpp:272
void displaySettings()
Definition: perseusgui.cpp:186
void on_decim_currentIndexChanged(int index)
Definition: perseusgui.cpp:284
void on_resetLOppm_clicked()
Definition: perseusgui.cpp:267
void on_attenuator_currentIndexChanged(int index)
Definition: perseusgui.cpp:323
bool deserialize(const QByteArray &data)
Definition: perseusgui.cpp:111
QString m_reverseAPIAddress
int32_t i
Definition: decimators.h:244
static MsgConfigurePerseus * create(const PerseusSettings &settings, bool force)
Definition: perseusinput.h:46
static bool match(const Message *message)
Definition: message.cpp:45
PerseusInput * m_sampleSource
Definition: perseusgui.h:66
static MsgStartStop * create(bool startStop)
Definition: perseusinput.h:87
void displaySampleRates()
Definition: perseusgui.cpp:204
int getDevSampleRateIndex(uint32_t sampleRate)
Definition: perseusgui.cpp:394
void on_record_toggled(bool checked)
Definition: perseusgui.cpp:301
PerseusSettings m_settings
Definition: perseusgui.h:62
void on_adcDither_toggled(bool checked)
Definition: perseusgui.cpp:332
bool deserialize(const QByteArray &data)
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: perseusgui.cpp:99
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: perseusgui.h:68
virtual ~PerseusGui()
Definition: perseusgui.cpp:67
void updateHardware()
Definition: perseusgui.cpp:344
void on_centerFrequency_changed(quint64 value)
Definition: perseusgui.cpp:254
void on_transverter_clicked()
Definition: perseusgui.cpp:313
int m_lastEngineState
Definition: perseusgui.h:69
int getSampleRate() const
Definition: dspcommands.h:328
uint16_t m_reverseAPIPort
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
virtual const char * getIdentifier() const
Definition: message.cpp:35
void updateSampleRateAndFrequency()
Definition: perseusgui.cpp:179
void setReverseAPIAddress(const QString &address)
int m_sampleRate
Definition: perseusgui.h:67
const PerseusSettings & getSettings() const
Definition: perseusinput.h:43
QTimer m_updateTimer
Definition: perseusgui.h:63
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void sendSettings()
Definition: perseusgui.cpp:248
engine is running
Definition: deviceapi.h:56
MessageQueue m_inputMessageQueue
Definition: perseusgui.h:70
void setName(const QString &name)
Definition: perseusgui.cpp:77
static MsgFileRecord * create(bool startStop)
Definition: perseusinput.h:68
void handleInputMessages()
Definition: perseusgui.cpp:151
void openDeviceSettingsDialog(const QPoint &p)
Definition: perseusgui.cpp:407
virtual qint64 getCenterFrequency() const
Definition: perseusgui.cpp:94
engine is in error
Definition: deviceapi.h:57
void on_LOppm_valueChanged(int value)
Definition: perseusgui.cpp:260
PerseusGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Definition: perseusgui.cpp:34
void updateStatus()
Definition: perseusgui.cpp:353