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.
airspygui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 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 <libairspy/airspy.h>
22 
23 #include "airspygui.h"
24 
25 #include "device/deviceapi.h"
26 #include "device/deviceuiset.h"
27 #include <dsp/filerecord.h>
28 
29 #include "ui_airspygui.h"
30 #include "gui/colormapper.h"
31 #include "gui/glspectrum.h"
32 #include "gui/crightclickenabler.h"
34 #include "dsp/dspengine.h"
35 #include "dsp/dspcommands.h"
36 
37 AirspyGui::AirspyGui(DeviceUISet *deviceUISet, QWidget* parent) :
38  QWidget(parent),
39  ui(new Ui::AirspyGui),
40  m_deviceUISet(deviceUISet),
41  m_doApplySettings(true),
42  m_forceSettings(true),
43  m_settings(),
44  m_sampleSource(0),
45  m_lastEngineState(DeviceAPI::StNotStarted)
46 {
48 
49  ui->setupUi(this);
50  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
52 
53  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
54  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
55  m_statusTimer.start(500);
56 
57  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
58  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
59 
61 
62  m_rates = ((AirspyInput*) m_sampleSource)->getSampleRates();
64  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
66 
67  sendSettings();
68 }
69 
71 {
72  delete ui;
73 }
74 
76 {
77  delete this;
78 }
79 
80 void AirspyGui::setName(const QString& name)
81 {
82  setObjectName(name);
83 }
84 
85 QString AirspyGui::getName() const
86 {
87  return objectName();
88 }
89 
91 {
94  sendSettings();
95 }
96 
98 {
100 }
101 
102 void AirspyGui::setCenterFrequency(qint64 centerFrequency)
103 {
104  m_settings.m_centerFrequency = centerFrequency;
105  displaySettings();
106  sendSettings();
107 }
108 
109 QByteArray AirspyGui::serialize() const
110 {
111  return m_settings.serialize();
112 }
113 
114 bool AirspyGui::deserialize(const QByteArray& data)
115 {
116  if(m_settings.deserialize(data)) {
117  displaySettings();
118  m_forceSettings = true;
119  sendSettings();
120  return true;
121  } else {
122  resetToDefaults();
123  return false;
124  }
125 }
126 
127 bool AirspyGui::handleMessage(const Message& message)
128 {
130  {
132  m_settings = cfg.getSettings();
133  blockApplySettings(true);
134  displaySettings();
135  blockApplySettings(false);
136  return true;
137  }
138  else if (AirspyInput::MsgStartStop::match(message))
139  {
141  blockApplySettings(true);
142  ui->startStop->setChecked(notif.getStartStop());
143  blockApplySettings(false);
144 
145  return true;
146  }
147  else
148  {
149  return false;
150  }
151 }
152 
154 {
155  Message* message;
156 
157  while ((message = m_inputMessageQueue.pop()) != 0)
158  {
159  qDebug("AirspyGui::handleInputMessages: message: %s", message->getIdentifier());
160 
161  if (DSPSignalNotification::match(*message))
162  {
163  DSPSignalNotification* notif = (DSPSignalNotification*) message;
164  m_sampleRate = notif->getSampleRate();
166  qDebug("AirspyGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
168 
169  delete message;
170  }
171  else
172  {
173  if (handleMessage(*message))
174  {
175  delete message;
176  }
177  }
178  }
179 }
180 
182 {
185  ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
186 }
187 
189 {
190  // values in kHz
191  qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0;
192  qint64 minLimit = AirspyInput::loLowLimitFreq/1000 + deltaFrequency;
193  qint64 maxLimit = AirspyInput::loHighLimitFreq/1000 + deltaFrequency;
194 
195  minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit;
196  maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit;
197 
198  qDebug("AirspyGui::updateFrequencyLimits: delta: %lld min: %lld max: %lld", deltaFrequency, minLimit, maxLimit);
199 
200  ui->centerFrequency->setValueRange(7, minLimit, maxLimit);
201 }
202 
204 {
205  ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency);
206  ui->transverter->setDeltaFrequencyActive(m_settings.m_transverterMode);
208  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
209 
210  ui->LOppm->setValue(m_settings.m_LOppmTenths);
211  ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
212 
213  ui->sampleRate->setCurrentIndex(m_settings.m_devSampleRateIndex);
214 
215  ui->biasT->setChecked(m_settings.m_biasT);
216  ui->dcOffset->setChecked(m_settings.m_dcBlock);
217  ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
218 
219  ui->decim->setCurrentIndex(m_settings.m_log2Decim);
220 
221  ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
222 
223  ui->lnaGainText->setText(tr("%1dB").arg(m_settings.m_lnaGain));
224  ui->lna->setValue(m_settings.m_lnaGain);
225 
226  ui->mixText->setText(tr("%1dB").arg(m_settings.m_mixerGain));
227  ui->mix->setValue(m_settings.m_mixerGain);
228 
229  ui->vgaText->setText(tr("%1dB").arg(m_settings.m_vgaGain));
230  ui->vga->setValue(m_settings.m_vgaGain);
231 
232  ui->lnaAGC->setChecked(m_settings.m_lnaAGC);
233  ui->mixAGC->setChecked(m_settings.m_mixerAGC);
234 }
235 
237 {
238  unsigned int savedIndex = m_settings.m_devSampleRateIndex;
239  ui->sampleRate->blockSignals(true);
240 
241  if (m_rates.size() > 0)
242  {
243  ui->sampleRate->clear();
244 
245  for (unsigned int i = 0; i < m_rates.size(); i++)
246  {
247  ui->sampleRate->addItem(QString("%1").arg(QString::number(m_rates[i]/1000000.0, 'f', 1)));
248  }
249  }
250 
251  ui->sampleRate->blockSignals(false);
252 
253  if (savedIndex < m_rates.size())
254  {
255  ui->sampleRate->setCurrentIndex(savedIndex);
256  }
257  else
258  {
259  ui->sampleRate->setCurrentIndex((int) m_rates.size()-1);
260  }
261 }
262 
264 {
265  if(!m_updateTimer.isActive())
266  m_updateTimer.start(100);
267 }
268 
270 {
271  m_settings.m_centerFrequency = value * 1000;
272  sendSettings();
273 }
274 
276 {
277  m_settings.m_LOppmTenths = value;
278  ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
279  sendSettings();
280 }
281 
283 {
284  m_settings.m_dcBlock = checked;
285  sendSettings();
286 }
287 
289 {
290  m_settings.m_iqCorrection = checked;
291  sendSettings();
292 }
293 
295 {
297  sendSettings();
298 }
299 
301 {
302  m_settings.m_biasT = (state == Qt::Checked);
303  sendSettings();
304 }
305 
307 {
308  m_settings.m_lnaAGC = (state == Qt::Checked);
309  sendSettings();
310 }
311 
313 {
314  m_settings.m_mixerAGC = (state == Qt::Checked);
315  sendSettings();
316 }
317 
319 {
320  if ((index <0) || (index > 6))
321  return;
322  m_settings.m_log2Decim = index;
323  sendSettings();
324 }
325 
327 {
328  if (index == 0) {
330  sendSettings();
331  } else if (index == 1) {
333  sendSettings();
334  } else if (index == 2) {
336  sendSettings();
337  }
338 }
339 
341 {
342  if ((value < 0) || (value > 14))
343  return;
344 
345  ui->lnaGainText->setText(tr("%1dB").arg(value));
346  m_settings.m_lnaGain = value;
347  sendSettings();
348 }
349 
351 {
352  if ((value < 0) || (value > 15))
353  return;
354 
355  ui->mixText->setText(tr("%1dB").arg(value));
356  m_settings.m_mixerGain = value;
357  sendSettings();
358 }
359 
361 {
362  if ((value < 0) || (value > 15))
363  return;
364 
365  ui->vgaText->setText(tr("%1dB").arg(value));
366  m_settings.m_vgaGain = value;
367  sendSettings();
368 }
369 
371 {
372  if (m_doApplySettings)
373  {
376  }
377 }
378 
380 {
381  if (checked) {
382  ui->record->setStyleSheet("QToolButton { background-color : red; }");
383  } else {
384  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
385  }
386 
389 }
390 
392 {
393  m_settings.m_transverterMode = ui->transverter->getDeltaFrequencyAcive();
394  m_settings.m_transverterDeltaFrequency = ui->transverter->getDeltaFrequency();
395  qDebug("AirspyGui::on_transverter_clicked: %lld Hz %s", m_settings.m_transverterDeltaFrequency, m_settings.m_transverterMode ? "on" : "off");
397  m_settings.m_centerFrequency = ui->centerFrequency->getValueNew()*1000;
398  sendSettings();
399 }
400 
402 {
403  qDebug() << "AirspyGui::updateHardware";
406  m_forceSettings = false;
407  m_updateTimer.stop();
408 }
409 
411 {
412  int state = m_deviceUISet->m_deviceAPI->state();
413 
414  if(m_lastEngineState != state)
415  {
416  switch(state)
417  {
419  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
420  break;
421  case DeviceAPI::StIdle:
422  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
423  break;
425  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
426  break;
427  case DeviceAPI::StError:
428  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
429  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
430  break;
431  default:
432  break;
433  }
434 
435  m_lastEngineState = state;
436  }
437 }
438 
439 uint32_t AirspyGui::getDevSampleRate(unsigned int rate_index)
440 {
441  if (rate_index < m_rates.size())
442  {
443  return m_rates[rate_index];
444  }
445  else
446  {
447  return m_rates[0];
448  }
449 }
450 
452 {
453  for (unsigned int i=0; i < m_rates.size(); i++)
454  {
455  if (sampeRate == m_rates[i])
456  {
457  return i;
458  }
459  }
460 
461  return -1;
462 }
463 
465 {
466  BasicDeviceSettingsDialog dialog(this);
471 
472  dialog.move(p);
473  dialog.exec();
474 
479 
480  sendSettings();
481 }
void on_record_toggled(bool checked)
Definition: airspygui.cpp:379
void on_centerFrequency_changed(quint64 value)
Definition: airspygui.cpp:269
QString getName() const
Definition: airspygui.cpp:85
quint32 m_devSampleRateIndex
AirspySettings m_settings
Definition: airspygui.h:62
quint64 m_centerFrequency
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
const AirspySettings & getSettings() const
Definition: airspyinput.h:42
static const qint64 loLowLimitFreq
Definition: airspyinput.h:143
std::vector< uint32_t > m_rates
Definition: airspygui.h:65
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
void blockApplySettings(bool block)
Definition: airspygui.h:72
uint32_t getDevSampleRate(unsigned int index)
Definition: airspygui.cpp:439
MessageQueue * getInputMessageQueue()
void on_biasT_stateChanged(int state)
Definition: airspygui.cpp:300
void on_LOppm_valueChanged(int value)
Definition: airspygui.cpp:275
quint32 m_log2Decim
void updateHardware()
Definition: airspygui.cpp:401
bool deserialize(const QByteArray &data)
Definition: airspygui.cpp:114
quint32 m_mixerGain
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
int m_lastEngineState
Definition: airspygui.h:69
static MsgStartStop * create(bool startStop)
Definition: airspyinput.h:86
void on_lna_valueChanged(int value)
Definition: airspygui.cpp:340
unsigned int uint32_t
Definition: rtptypes_win.h:46
virtual qint64 getCenterFrequency() const
Definition: airspygui.cpp:97
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
MessageQueue m_inputMessageQueue
Definition: airspygui.h:70
void updateSampleRateAndFrequency()
Definition: airspygui.cpp:181
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
DeviceSampleSource * m_sampleSource
Definition: airspygui.h:66
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
void on_decim_currentIndexChanged(int index)
Definition: airspygui.cpp:318
void on_iqImbalance_toggled(bool checked)
Definition: airspygui.cpp:288
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
void resetToDefaults()
Definition: airspygui.cpp:90
engine is idle
Definition: deviceapi.h:54
bool m_forceSettings
Definition: airspygui.h:61
void on_dcOffset_toggled(bool checked)
Definition: airspygui.cpp:282
int32_t i
Definition: decimators.h:244
void sendSettings()
Definition: airspygui.cpp:263
void updateFrequencyLimits()
Definition: airspygui.cpp:188
static bool match(const Message *message)
Definition: message.cpp:45
void on_lnaAGC_stateChanged(int state)
Definition: airspygui.cpp:306
qint64 m_transverterDeltaFrequency
void displaySampleRates()
Definition: airspygui.cpp:236
bool m_doApplySettings
Definition: airspygui.h:60
void on_sampleRate_currentIndexChanged(int index)
Definition: airspygui.cpp:294
void setName(const QString &name)
Definition: airspygui.cpp:80
QTimer m_updateTimer
Definition: airspygui.h:63
static const qint64 loHighLimitFreq
Definition: airspyinput.h:144
bool getStartStop() const
Definition: airspyinput.h:84
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: airspygui.cpp:102
uint16_t m_reverseAPIPort
virtual ~AirspyGui()
Definition: airspygui.cpp:70
virtual void destroy()
Definition: airspygui.cpp:75
void on_vga_valueChanged(int value)
Definition: airspygui.cpp:360
virtual bool handleMessage(const Message &message)
Definition: airspygui.cpp:127
void on_startStop_toggled(bool checked)
Definition: airspygui.cpp:370
int getSampleRate() const
Definition: dspcommands.h:328
void on_transverter_clicked()
Definition: airspygui.cpp:391
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
void displaySettings()
Definition: airspygui.cpp:203
virtual const char * getIdentifier() const
Definition: message.cpp:35
QString m_reverseAPIAddress
void setReverseAPIAddress(const QString &address)
QByteArray serialize() const
int getDevSampleRateIndex(uint32_t sampleRate)
Definition: airspygui.cpp:451
Ui::AirspyGui * ui
Definition: airspygui.h:57
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: airspygui.h:68
virtual void setMessageQueueToGUI(MessageQueue *queue)=0
engine is running
Definition: deviceapi.h:56
bool deserialize(const QByteArray &data)
uint16_t m_reverseAPIDeviceIndex
DeviceUISet * m_deviceUISet
Definition: airspygui.h:59
AirspyGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Definition: airspygui.cpp:37
void updateStatus()
Definition: airspygui.cpp:410
void on_mixAGC_stateChanged(int state)
Definition: airspygui.cpp:312
void on_mix_valueChanged(int value)
Definition: airspygui.cpp:350
qint32 m_LOppmTenths
QByteArray serialize() const
Definition: airspygui.cpp:109
int m_sampleRate
Definition: airspygui.h:67
void handleInputMessages()
Definition: airspygui.cpp:153
QTimer m_statusTimer
Definition: airspygui.h:64
engine is in error
Definition: deviceapi.h:57
static MsgConfigureAirspy * create(const AirspySettings &settings, bool force)
Definition: airspyinput.h:45
void on_fcPos_currentIndexChanged(int index)
Definition: airspygui.cpp:326
void openDeviceSettingsDialog(const QPoint &p)
Definition: airspygui.cpp:464
static MsgFileRecord * create(bool startStop)
Definition: airspyinput.h:67