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.
fcdproplusgui.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 "ui_fcdproplusgui.h"
22 #include "gui/colormapper.h"
23 #include "gui/glspectrum.h"
24 #include "gui/crightclickenabler.h"
26 #include "dsp/dspengine.h"
27 #include "dsp/dspcommands.h"
28 #include "fcdproplusgui.h"
29 
30 #include "device/deviceapi.h"
31 #include "device/deviceuiset.h"
32 #include "fcdproplusconst.h"
33 #include "fcdtraits.h"
34 
35 FCDProPlusGui::FCDProPlusGui(DeviceUISet *deviceUISet, QWidget* parent) :
36  QWidget(parent),
37  ui(new Ui::FCDProPlusGui),
38  m_deviceUISet(deviceUISet),
39  m_forceSettings(true),
40  m_settings(),
41  m_sampleSource(NULL),
42  m_lastEngineState(DeviceAPI::StNotStarted)
43 {
45 
46  ui->setupUi(this);
47 
48  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
50 
51  ui->filterIF->clear();
53  {
54  ui->filterIF->addItem(QString(FCDProPlusConstants::if_filters[i].label.c_str()), i);
55  }
56 
57  ui->filterRF->clear();
59  {
60  ui->filterRF->addItem(QString(FCDProPlusConstants::rf_filters[i].label.c_str()), i);
61  }
62 
63  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
64  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
65  m_statusTimer.start(500);
66 
67  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
68  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
69 
71 
72  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
74 }
75 
77 {
78  delete ui;
79 }
80 
82 {
83  delete this;
84 }
85 
86 void FCDProPlusGui::setName(const QString& name)
87 {
88  setObjectName(name);
89 }
90 
91 QString FCDProPlusGui::getName() const
92 {
93  return objectName();
94 }
95 
97 {
100  sendSettings();
101 }
102 
104 {
106 }
107 
108 void FCDProPlusGui::setCenterFrequency(qint64 centerFrequency)
109 {
110  m_settings.m_centerFrequency = centerFrequency;
111  displaySettings();
112  sendSettings();
113 }
114 
115 QByteArray FCDProPlusGui::serialize() const
116 {
117  return m_settings.serialize();
118 }
119 
120 bool FCDProPlusGui::deserialize(const QByteArray& data)
121 {
122  if(m_settings.deserialize(data))
123  {
124  displaySettings();
125  m_forceSettings = true;
126  sendSettings();
127  return true;
128  }
129  else
130  {
131  resetToDefaults();
132  return false;
133  }
134 }
135 
137 {
139  {
141  m_settings = cfg.getSettings();
142  blockApplySettings(true);
143  displaySettings();
144  blockApplySettings(false);
145  return true;
146  }
147  else if (FCDProPlusInput::MsgStartStop::match(message))
148  {
150  blockApplySettings(true);
151  ui->startStop->setChecked(notif.getStartStop());
152  blockApplySettings(false);
153 
154  return true;
155  }
156  else
157  {
158  return false;
159  }
160 }
161 
163 {
164  Message* message;
165 
166  while ((message = m_inputMessageQueue.pop()) != 0)
167  {
168  if (DSPSignalNotification::match(*message))
169  {
170  DSPSignalNotification* notif = (DSPSignalNotification*) message;
171  m_sampleRate = notif->getSampleRate();
173  qDebug("FCDProPlusGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
175 
176  delete message;
177  }
178  else
179  {
180  if (handleMessage(*message))
181  {
182  delete message;
183  }
184  }
185  }
186 }
187 
189 {
192  ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
193 }
194 
196 {
197  // values in kHz
198  qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0;
199  qint64 minLimit = fcd_traits<ProPlus>::loLowLimitFreq/1000 + deltaFrequency;
200  qint64 maxLimit = fcd_traits<ProPlus>::loHighLimitFreq/1000 + deltaFrequency;
201 
202  minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit;
203  maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit;
204 
205  qDebug("FCDProPlusGui::updateFrequencyLimits: delta: %lld min: %lld max: %lld", deltaFrequency, minLimit, maxLimit);
206 
207  ui->centerFrequency->setValueRange(7, minLimit, maxLimit);
208 }
209 
211 {
212  ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency);
213  ui->transverter->setDeltaFrequencyActive(m_settings.m_transverterMode);
215  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
216  ui->decim->setCurrentIndex(m_settings.m_log2Decim);
217  ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
218  ui->dcOffset->setChecked(m_settings.m_dcBlock);
219  ui->iqImbalance->setChecked(m_settings.m_iqImbalance);
220  ui->checkBoxG->setChecked(m_settings.m_lnaGain);
221  ui->checkBoxB->setChecked(m_settings.m_biasT);
222  ui->mixGain->setChecked(m_settings.m_mixGain);
223  ui->ifGain->setValue(m_settings.m_ifGain);
224  ui->ifGainText->setText(QString("%1dB").arg(m_settings.m_ifGain));
225  ui->filterIF->setCurrentIndex(m_settings.m_ifFilterIndex);
226  ui->filterRF->setCurrentIndex(m_settings.m_rfFilterIndex);
227  ui->ppm->setValue(m_settings.m_LOppmTenths);
228  ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
229 }
230 
232 {
233  if(!m_updateTimer.isActive())
234  m_updateTimer.start(100);
235 }
236 
238 {
239  m_settings.m_centerFrequency = value * 1000;
240  sendSettings();
241 }
242 
244 {
245  if ((index < 0) || (index > 6)) {
246  return;
247  }
248 
249  m_settings.m_log2Decim = index;
250  sendSettings();
251 }
252 
254 {
255  if (index == 0) {
257  sendSettings();
258  } else if (index == 1) {
260  sendSettings();
261  } else if (index == 2) {
263  sendSettings();
264  }
265 }
266 
268 {
269  m_settings.m_dcBlock = checked;
270  sendSettings();
271 }
272 
274 {
275  m_settings.m_iqImbalance = checked;
276  sendSettings();
277 }
278 
280 {
283  m_forceSettings = false;
284  m_updateTimer.stop();
285 }
286 
288 {
289  int state = m_deviceUISet->m_deviceAPI->state();
290 
291  if(m_lastEngineState != state)
292  {
293  switch(state)
294  {
296  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
297  break;
298  case DeviceAPI::StIdle:
299  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
300  break;
302  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
303  break;
304  case DeviceAPI::StError:
305  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
306  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
307  break;
308  default:
309  break;
310  }
311 
312  m_lastEngineState = state;
313  }
314 }
315 
317 {
318  m_settings.m_lnaGain = (state == Qt::Checked);
319  sendSettings();
320 }
321 
323 {
324  m_settings.m_biasT = (state == Qt::Checked);
325  sendSettings();
326 }
327 
329 {
330  m_settings.m_mixGain = (state == Qt::Checked);
331  sendSettings();
332 }
333 
335 {
336  m_settings.m_ifFilterIndex = index;
337  sendSettings();
338 }
339 
341 {
342  m_settings.m_rfFilterIndex = index;
343  sendSettings();
344 }
345 
347 {
348  m_settings.m_ifGain = value;
349  displaySettings();
350  sendSettings();
351 }
352 
354 {
355  m_settings.m_LOppmTenths = value;
356  displaySettings();
357  sendSettings();
358 }
359 
361 {
364 }
365 
367 {
368  if (checked) {
369  ui->record->setStyleSheet("QToolButton { background-color : red; }");
370  } else {
371  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
372  }
373 
376 }
377 
379 {
380  m_settings.m_transverterMode = ui->transverter->getDeltaFrequencyAcive();
381  m_settings.m_transverterDeltaFrequency = ui->transverter->getDeltaFrequency();
382  qDebug("FCDProPlusGui::on_transverter_clicked: %lld Hz %s", m_settings.m_transverterDeltaFrequency, m_settings.m_transverterMode ? "on" : "off");
384  m_settings.m_centerFrequency = ui->centerFrequency->getValueNew()*1000;
385  sendSettings();
386 }
387 
389 {
390  BasicDeviceSettingsDialog dialog(this);
395 
396  dialog.move(p);
397  dialog.exec();
398 
403 
404  sendSettings();
405 }
void on_decim_currentIndexChanged(int index)
QByteArray serialize() const
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
void on_mixGain_stateChanged(int state)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: fcdproplusgui.h:66
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
static const fcdproplus_rf_filter rf_filters[]
void on_fcPos_currentIndexChanged(int index)
void on_dcOffset_toggled(bool checked)
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
DeviceUISet * m_deviceUISet
Definition: fcdproplusgui.h:57
void on_checkBoxB_stateChanged(int state)
MessageQueue * getInputMessageQueue()
void on_iqImbalance_toggled(bool checked)
void on_checkBoxG_stateChanged(int state)
virtual ~FCDProPlusGui()
static const fcdproplus_if_filter if_filters[]
QByteArray serialize() const
QTimer m_updateTimer
Definition: fcdproplusgui.h:61
void on_record_toggled(bool checked)
QString getName() const
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
static int fcdproplus_rf_filter_nb_values()
void on_ifGain_valueChanged(int value)
void on_filterRF_currentIndexChanged(int index)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
MessageQueue m_inputMessageQueue
Definition: fcdproplusgui.h:68
engine is before initialization
Definition: deviceapi.h:53
void on_filterIF_currentIndexChanged(int index)
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 void destroy()
static MsgConfigureFCDProPlus * create(const FCDProPlusSettings &settings, bool force)
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
FCDProPlusGui(DeviceUISet *deviceUISet, QWidget *parent=0)
virtual bool handleMessage(const Message &message)
int32_t i
Definition: decimators.h:244
static int fcdproplus_if_filter_nb_values()
static bool match(const Message *message)
Definition: message.cpp:45
FCDProPlusSettings m_settings
Definition: fcdproplusgui.h:60
bool deserialize(const QByteArray &data)
void on_startStop_toggled(bool checked)
bool deserialize(const QByteArray &data)
void setName(const QString &name)
void on_transverter_clicked()
Ui::FCDProPlusGui * ui
Definition: fcdproplusgui.h:55
int getSampleRate() const
Definition: dspcommands.h:328
bool m_forceSettings
Definition: fcdproplusgui.h:59
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
void openDeviceSettingsDialog(const QPoint &p)
void setReverseAPIAddress(const QString &address)
DeviceSampleSource * m_sampleSource
Definition: fcdproplusgui.h:64
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void updateSampleRateAndFrequency()
void resetToDefaults()
const FCDProPlusSettings & getSettings() const
void updateFrequencyLimits()
virtual qint64 getCenterFrequency() const
virtual void setMessageQueueToGUI(MessageQueue *queue)=0
QTimer m_statusTimer
Definition: fcdproplusgui.h:62
engine is running
Definition: deviceapi.h:56
static MsgStartStop * create(bool startStop)
uint16_t m_reverseAPIDeviceIndex
void displaySettings()
void handleInputMessages()
void on_ppm_valueChanged(int value)
void on_centerFrequency_changed(quint64 value)
engine is in error
Definition: deviceapi.h:57
void blockApplySettings(bool block)
Definition: fcdproplusgui.h:70
virtual void setCenterFrequency(qint64 centerFrequency)
static MsgFileRecord * create(bool startStop)