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.
bladerf2outputgui.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 <libbladeRF.h>
22 
23 #include "ui_bladerf2outputgui.h"
24 #include "gui/colormapper.h"
25 #include "gui/glspectrum.h"
26 #include "gui/crightclickenabler.h"
28 #include "dsp/dspengine.h"
29 #include "dsp/dspcommands.h"
30 #include "device/deviceapi.h"
31 #include "device/deviceuiset.h"
32 
33 #include "bladerf2outputgui.h"
34 
35 BladeRF2OutputGui::BladeRF2OutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
36  QWidget(parent),
37  ui(new Ui::BladeRF2OutputGui),
38  m_deviceUISet(deviceUISet),
39  m_doApplySettings(true),
40  m_forceSettings(true),
41  m_settings(),
42  m_sampleRateMode(true),
43  m_sampleRate(0),
44  m_lastEngineState(DeviceAPI::StNotStarted)
45 {
47  int max, min, step;
48  uint64_t f_min, f_max;
49 
50  ui->setupUi(this);
51 
52  m_sampleSink->getFrequencyRange(f_min, f_max, step);
53  qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getFrequencyRange: [%lu,%lu] step: %d", f_min, f_max, step);
54  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
55  ui->centerFrequency->setValueRange(7, f_min/1000, f_max/1000);
56 
57  m_sampleSink->getSampleRateRange(min, max, step);
58  qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getSampleRateRange: [%d,%d] step: %d", min, max, step);
59  ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
60  ui->sampleRate->setValueRange(8, min, max);
61 
62  m_sampleSink->getBandwidthRange(min, max, step);
63  qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getBandwidthRange: [%d,%d] step: %d", min, max, step);
64  ui->bandwidth->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
65  ui->bandwidth->setValueRange(5, min/1000, max/1000);
66 
67  m_sampleSink->getGlobalGainRange(min, max, step);
68  qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getGlobalGainRange: [%d,%d] step: %d", min, max, step);
69  ui->gain->setMinimum((min-max)/1000);
70  ui->gain->setMaximum(0);
71  ui->gain->setPageStep(1);
72  ui->gain->setSingleStep(1);
73 
74  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
75  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
76  m_statusTimer.start(500);
77 
78  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
79  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
80 
82 
83  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
85 }
86 
88 {
89  delete ui;
90 }
91 
93 {
94  delete this;
95 }
96 
97 void BladeRF2OutputGui::setName(const QString& name)
98 {
99  setObjectName(name);
100 }
101 
103 {
104  return objectName();
105 }
106 
108 {
110  displaySettings();
111  sendSettings();
112 }
113 
115 {
117 }
118 
119 void BladeRF2OutputGui::setCenterFrequency(qint64 centerFrequency)
120 {
121  m_settings.m_centerFrequency = centerFrequency;
122  displaySettings();
123  sendSettings();
124 }
125 
127 {
128  return m_settings.serialize();
129 }
130 
131 bool BladeRF2OutputGui::deserialize(const QByteArray& data)
132 {
133  if(m_settings.deserialize(data)) {
134  displaySettings();
135  m_forceSettings = true;
136  sendSettings();
137  return true;
138  } else {
139  resetToDefaults();
140  return false;
141  }
142 }
143 
145 {
146  // values in kHz
147  uint64_t f_min, f_max;
148  int step;
149  qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0;
150  m_sampleSink->getFrequencyRange(f_min, f_max, step);
151  qint64 minLimit = f_min/1000 + deltaFrequency;
152  qint64 maxLimit = f_max/1000 + deltaFrequency;
153 
154  minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit;
155  maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit;
156 
157  qDebug("BladeRF2OutputGui::updateFrequencyLimits: delta: %lld min: %lld max: %lld", deltaFrequency, minLimit, maxLimit);
158 
159  ui->centerFrequency->setValueRange(7, minLimit, maxLimit);
160 }
161 
163 {
164  int64_t centerFrequency = kHzValue*1000;
165 
166  m_settings.m_centerFrequency = centerFrequency < 0 ? 0 : (uint64_t) centerFrequency;
167  ui->centerFrequency->setToolTip(QString("Main center frequency in kHz (LO: %1 kHz)").arg(centerFrequency/1000));
168 }
169 
171 {
173  {
175  m_settings = cfg.getSettings();
176  blockApplySettings(true);
177  int min, max, step;
178  m_sampleSink->getGlobalGainRange(min, max, step);
179  ui->gain->setMinimum((min-max)/1000);
180  ui->gain->setMaximum(0);
181  ui->gain->setPageStep(1);
182  ui->gain->setSingleStep(1);
183  displaySettings();
184  blockApplySettings(false);
185 
186  return true;
187  }
189  {
191  ui->gain->setMinimum((cfg.getMin()-cfg.getMax())/1000);
192  ui->gain->setMaximum(0);
193  ui->gain->setSingleStep(1);
194  ui->gain->setPageStep(1);
195 
196  return true;
197  }
198  else if (BladeRF2Output::MsgStartStop::match(message))
199  {
201  blockApplySettings(true);
202  ui->startStop->setChecked(notif.getStartStop());
203  blockApplySettings(false);
204 
205  return true;
206  }
207  else
208  {
209  return false;
210  }
211 }
212 
214 {
215  Message* message;
216 
217  while ((message = m_inputMessageQueue.pop()) != 0)
218  {
219  qDebug("BladeRF2OutputGui::handleInputMessages: message: %s", message->getIdentifier());
220 
221  if (DSPSignalNotification::match(*message))
222  {
223  DSPSignalNotification* notif = (DSPSignalNotification*) message;
224  m_sampleRate = notif->getSampleRate();
226  qDebug("BladeRF2OutputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
228 
229  delete message;
230  }
231  else
232  {
233  if (handleMessage(*message))
234  {
235  delete message;
236  }
237  }
238  }
239 }
240 
242 {
246 }
247 
249 {
250  int max, min, step;
251  m_sampleSink->getSampleRateRange(min, max, step);
252 
253  ui->sampleRate->blockSignals(true);
254 
255  if (m_sampleRateMode)
256  {
257  ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(60,60,60); }");
258  ui->sampleRateMode->setText("SR");
259  ui->sampleRate->setValueRange(8, min, max);
260  ui->sampleRate->setValue(m_settings.m_devSampleRate);
261  ui->sampleRate->setToolTip("Host to device sample rate (S/s)");
262  ui->deviceRateText->setToolTip("Baseband sample rate (S/s)");
263  uint32_t basebandSampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp);
264  ui->deviceRateText->setText(tr("%1k").arg(QString::number(basebandSampleRate / 1000.0f, 'g', 5)));
265  }
266  else
267  {
268  ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(50,50,50); }");
269  ui->sampleRateMode->setText("BB");
270  ui->sampleRate->setValueRange(8, min/(1<<m_settings.m_log2Interp), max/(1<<m_settings.m_log2Interp));
271  ui->sampleRate->setValue(m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp));
272  ui->sampleRate->setToolTip("Baseband sample rate (S/s)");
273  ui->deviceRateText->setToolTip("Host to device sample rate (S/s)");
274  ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_settings.m_devSampleRate / 1000.0f, 'g', 5)));
275  }
276 
277  ui->sampleRate->blockSignals(false);
278 }
279 
281 {
282  blockApplySettings(true);
283 
284  ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency);
285  ui->transverter->setDeltaFrequencyActive(m_settings.m_transverterMode);
286 
287  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
288  ui->LOppm->setValue(m_settings.m_LOppmTenths);
289  ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
291  ui->bandwidth->setValue(m_settings.m_bandwidth / 1000);
292 
293  ui->interp->setCurrentIndex(m_settings.m_log2Interp);
294 
295  ui->gainText->setText(tr("%1 dB").arg(m_settings.m_globalGain));
296  ui->gain->setValue(m_settings.m_globalGain);
297  ui->biasTee->setChecked(m_settings.m_biasTee);
298 
299  blockApplySettings(false);
300 }
301 
303 {
304  if(!m_updateTimer.isActive())
305  m_updateTimer.start(100);
306 }
307 
309 {
310  m_settings.m_centerFrequency = value * 1000;
311  sendSettings();
312 }
313 
315 {
316  ui->LOppmText->setText(QString("%1").arg(QString::number(value/10.0, 'f', 1)));
317  m_settings.m_LOppmTenths = value;
318  sendSettings();
319 }
320 
322 {
323  if (m_sampleRateMode) {
324  m_settings.m_devSampleRate = value;
325  } else {
327  }
328 
329  sendSettings();
330 }
331 
333 {
334  m_settings.m_biasTee = checked;
335  sendSettings();
336 }
337 
339 {
340  m_settings.m_bandwidth = value * 1000;
341  sendSettings();
342 }
343 
345 {
346  if ((index <0) || (index > 6)) {
347  return;
348  }
349 
350  m_settings.m_log2Interp = index;
352 
353  if (m_sampleRateMode) {
354  m_settings.m_devSampleRate = ui->sampleRate->getValueNew();
355  } else {
356  m_settings.m_devSampleRate = ui->sampleRate->getValueNew() * (1 << m_settings.m_log2Interp);
357  }
358 
359  sendSettings();
360 }
361 
363 {
364  ui->gainText->setText(tr("%1 dB").arg(value));
365  m_settings.m_globalGain = value;
366  sendSettings();
367 }
368 
370 {
371  m_settings.m_transverterMode = ui->transverter->getDeltaFrequencyAcive();
372  m_settings.m_transverterDeltaFrequency = ui->transverter->getDeltaFrequency();
373  qDebug("LimeSDRInputGUI::on_transverter_clicked: %lld Hz %s", m_settings.m_transverterDeltaFrequency, m_settings.m_transverterMode ? "on" : "off");
375  setCenterFrequencySetting(ui->centerFrequency->getValueNew());
376  sendSettings();
377 }
378 
380 {
381  if (m_doApplySettings)
382  {
385  }
386 }
387 
389 {
390  m_sampleRateMode = checked;
392 }
393 
395 {
396  if (m_doApplySettings)
397  {
398  qDebug() << "BladeRF2OutputGui::updateHardware";
401  m_forceSettings = false;
402  m_updateTimer.stop();
403  }
404 }
405 
407 {
408  int state = m_deviceUISet->m_deviceAPI->state();
409 
410  if(m_lastEngineState != state)
411  {
412  switch(state)
413  {
415  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
416  break;
417  case DeviceAPI::StIdle:
418  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
419  break;
421  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
422  break;
423  case DeviceAPI::StError:
424  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
425  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
426  break;
427  default:
428  break;
429  }
430 
431  m_lastEngineState = state;
432  }
433 }
434 
436 {
437  BasicDeviceSettingsDialog dialog(this);
442 
443  dialog.move(p);
444  dialog.exec();
445 
450 
451  sendSettings();
452 }
const BladeRF2OutputSettings & getSettings() const
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
Ui::BladeRF2OutputGui * ui
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
void on_biasTee_toggled(bool checked)
void setCenterFrequencySetting(uint64_t kHzValue)
void setUseReverseAPI(bool useReverseAPI)
virtual QByteArray serialize() const
DeviceUISet * m_deviceUISet
BladeRF2Output * m_sampleSink
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
__int64 int64_t
Definition: rtptypes_win.h:47
unsigned int uint32_t
Definition: rtptypes_win.h:46
void getBandwidthRange(int &min, int &max, int &step)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
QString getName() const
void on_gain_valueChanged(int value)
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
engine is before initialization
Definition: deviceapi.h:53
void openDeviceSettingsDialog(const QPoint &p)
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 bool deserialize(const QByteArray &data)
virtual qint64 getCenterFrequency() const
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
MessageQueue * getInputMessageQueue()
void on_startStop_toggled(bool checked)
quint64 m_deviceCenterFrequency
Center frequency in device.
void setName(const QString &name)
virtual void setCenterFrequency(qint64 centerFrequency)
void on_sampleRate_changed(quint64 value)
static bool match(const Message *message)
Definition: message.cpp:45
BladeRF2OutputSettings m_settings
bool m_sampleRateMode
true: device, false: base band sample rate update mode
virtual bool handleMessage(const Message &message)
static MsgStartStop * create(bool startStop)
void on_bandwidth_changed(quint64 value)
virtual void setMessageQueueToGUI(MessageQueue *queue)
void on_sampleRateMode_toggled(bool checked)
MessageQueue m_inputMessageQueue
void on_centerFrequency_changed(quint64 value)
void blockApplySettings(bool block)
int getSampleRate() const
Definition: dspcommands.h:328
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
virtual const char * getIdentifier() const
Definition: message.cpp:35
void getGlobalGainRange(int &min, int &max, int &step)
void on_interp_currentIndexChanged(int index)
void setReverseAPIAddress(const QString &address)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void getFrequencyRange(uint64_t &min, uint64_t &max, int &step)
engine is running
Definition: deviceapi.h:56
void getSampleRateRange(int &min, int &max, int &step)
virtual void destroy()
BladeRF2OutputGui(DeviceUISet *deviceUISet, QWidget *parent=0)
static MsgConfigureBladeRF2 * create(const BladeRF2OutputSettings &settings, bool force)
engine is in error
Definition: deviceapi.h:57
T max(const T &x, const T &y)
Definition: framework.h:446
bool deserialize(const QByteArray &data)
void on_LOppm_valueChanged(int value)
T min(const T &x, const T &y)
Definition: framework.h:440
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48