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.
kiwisdrgui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 Vort //
3 // Copyright (C) 2019 Edouard Griffiths, F4EXB //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QDebug>
20 
21 #include <QTime>
22 #include <QDateTime>
23 #include <QString>
24 #include <QMessageBox>
25 
26 #include "ui_kiwisdrgui.h"
27 #include "plugin/pluginapi.h"
28 #include "gui/colormapper.h"
29 #include "gui/glspectrum.h"
30 #include "gui/crightclickenabler.h"
32 #include "dsp/dspengine.h"
33 #include "dsp/dspcommands.h"
34 #include "util/db.h"
35 
36 #include "mainwindow.h"
37 
38 #include "kiwisdrgui.h"
39 #include "device/deviceapi.h"
40 #include "device/deviceuiset.h"
41 
42 KiwiSDRGui::KiwiSDRGui(DeviceUISet *deviceUISet, QWidget* parent) :
43  QWidget(parent),
44  ui(new Ui::KiwiSDRGui),
45  m_deviceUISet(deviceUISet),
46  m_settings(),
47  m_doApplySettings(true),
48  m_forceSettings(true),
49  m_sampleSource(0),
50  m_tickCount(0),
51  m_lastEngineState(DeviceAPI::StNotStarted)
52 {
53  qDebug("KiwiSDRGui::KiwiSDRGui");
55 
56  m_statusTooltips.push_back("Idle"); // 0
57  m_statusTooltips.push_back("Connecting..."); // 1
58  m_statusTooltips.push_back("Connected"); // 2
59  m_statusTooltips.push_back("Error"); // 3
60  m_statusTooltips.push_back("Disconnected"); // 4
61 
62  m_statusColors.push_back("gray"); // Idle
63  m_statusColors.push_back("rgb(232, 212, 35)"); // Connecting (yellow)
64  m_statusColors.push_back("rgb(35, 138, 35)"); // Connected (green)
65  m_statusColors.push_back("rgb(232, 85, 85)"); // Error (red)
66  m_statusColors.push_back("rgb(232, 85, 232)"); // Disconnected (magenta)
67 
68  ui->setupUi(this);
69  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
70  ui->centerFrequency->setValueRange(7, 0, 9999999);
71 
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  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
80 
81  CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
82  connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
83 }
84 
86 {
87  delete ui;
88 }
89 
91 {
92  delete this;
93 }
94 
95 void KiwiSDRGui::setName(const QString& name)
96 {
97  setObjectName(name);
98 }
99 
100 QString KiwiSDRGui::getName() const
101 {
102  return objectName();
103 }
104 
106 {
108  displaySettings();
109  sendSettings();
110 }
111 
113 {
115 }
116 
117 void KiwiSDRGui::setCenterFrequency(qint64 centerFrequency)
118 {
119  m_settings.m_centerFrequency = centerFrequency;
120  displaySettings();
121  sendSettings();
122 }
123 
124 QByteArray KiwiSDRGui::serialize() const
125 {
126  return m_settings.serialize();
127 }
128 
129 bool KiwiSDRGui::deserialize(const QByteArray& data)
130 {
131  if(m_settings.deserialize(data)) {
132  displaySettings();
133  m_forceSettings = true;
134  sendSettings();
135  return true;
136  } else {
137  resetToDefaults();
138  return false;
139  }
140 }
141 
143 {
144  if (m_doApplySettings)
145  {
148  }
149 }
150 
152 {
153  m_settings.m_centerFrequency = value * 1000;
154  sendSettings();
155 }
156 
158 {
160 }
161 
163 {
164  m_settings.m_serverAddress = ui->serverAddress->text();
165  sendSettings();
166 }
167 
169 {
170  m_settings.m_dcBlock = checked;
171  sendSettings();
172 }
173 
175 {
176  if (checked) {
177  ui->record->setStyleSheet("QToolButton { background-color : red; }");
178  } else {
179  ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
180  }
181 
184 }
185 
186 void KiwiSDRGui::on_agc_toggled(bool checked)
187 {
188  m_settings.m_useAGC = checked;
189  sendSettings();
190 }
191 
193 {
194  m_settings.m_gain = value;
195  ui->gainText->setText(QString::number(m_settings.m_gain) + " dB");
196  sendSettings();
197 }
198 
200 {
201  blockApplySettings(true);
202 
203  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
204  ui->serverAddress->setText(m_settings.m_serverAddress);
205  ui->gain->setValue(m_settings.m_gain);
206  ui->gainText->setText(QString::number(m_settings.m_gain) + " dB");
207  ui->agc->setChecked(m_settings.m_useAGC);
208  ui->dcBlock->setChecked(m_settings.m_dcBlock);
209 
210  blockApplySettings(false);
211 }
212 
214 {
215  if (!m_updateTimer.isActive()) {
216  m_updateTimer.start(100);
217  }
218 }
219 
221 {
222  if (m_doApplySettings)
223  {
226  m_forceSettings = false;
227  m_updateTimer.stop();
228  }
229 }
230 
232 {
233  int state = m_deviceUISet->m_deviceAPI->state();
234 
235  if (m_lastEngineState != state)
236  {
237  switch (state)
238  {
240  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
241  break;
242  case DeviceAPI::StIdle:
243  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
244  break;
246  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
247  break;
248  case DeviceAPI::StError:
249  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
250  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
251  break;
252  default:
253  break;
254  }
255 
256  m_lastEngineState = state;
257  }
258 }
259 
260 bool KiwiSDRGui::handleMessage(const Message& message)
261 {
263  {
264  qDebug("KiwiSDRGui::handleMessage: MsgConfigureKiwiSDR");
266  m_settings = cfg.getSettings();
267  displaySettings();
268  return true;
269  }
270  else if (KiwiSDRInput::MsgStartStop::match(message))
271  {
272  qDebug("KiwiSDRGui::handleMessage: MsgStartStop");
274  blockApplySettings(true);
275  ui->startStop->setChecked(notif.getStartStop());
276  blockApplySettings(false);
277 
278  return true;
279  }
280  else if (KiwiSDRInput::MsgSetStatus::match(message))
281  {
282  qDebug("KiwiSDRGui::handleMessage: MsgSetStatus");
284  int status = notif.getStatus();
285  ui->statusIndicator->setToolTip(m_statusTooltips[status]);
286  ui->statusIndicator->setStyleSheet("QLabel { background-color: " +
287  m_statusColors[status] + "; border-radius: 7px; }");
288  return true;
289  }
290  else
291  {
292  return false;
293  }
294 }
295 
297 {
298  Message* message;
299 
300  while ((message = m_inputMessageQueue.pop()) != 0)
301  {
302  if (DSPSignalNotification::match(*message))
303  {
304  DSPSignalNotification* notif = (DSPSignalNotification*) message;
307  qDebug("KiwiSDRGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu",
308  notif->getSampleRate(),
309  notif->getCenterFrequency());
311 
312  delete message;
313  }
314  else
315  {
316  if (handleMessage(*message))
317  {
318  delete message;
319  }
320  }
321  }
322 }
323 
325 {
328  ui->deviceRateText->setText(tr("%1k").arg((float)m_deviceSampleRate / 1000));
329 }
330 
332 {
333  BasicDeviceSettingsDialog dialog(this);
338 
339  dialog.move(p);
340  dialog.exec();
341 
346 
347  sendSettings();
348 }
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: kiwisdrgui.cpp:117
Message * pop()
Pop message from queue.
const QString & getReverseAPIAddress() const
virtual void destroy()
Definition: kiwisdrgui.cpp:90
void on_gain_valueChanged(int value)
Definition: kiwisdrgui.cpp:192
void push(Message *message, bool emitSignal=true)
Push message onto queue.
QString m_serverAddress
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
bool deserialize(const QByteArray &data)
Definition: kiwisdrgui.cpp:129
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
void setUseReverseAPI(bool useReverseAPI)
QByteArray serialize() const
Definition: kiwisdrgui.cpp:124
KiwiSDRSettings m_settings
Definition: kiwisdrgui.h:60
MessageQueue * getInputMessageQueue()
QTimer m_statusTimer
Definition: kiwisdrgui.h:62
void updateSampleRateAndFrequency()
Definition: kiwisdrgui.cpp:324
void setName(const QString &name)
Definition: kiwisdrgui.cpp:95
void displaySettings()
Definition: kiwisdrgui.cpp:199
void on_record_toggled(bool checked)
Definition: kiwisdrgui.cpp:174
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
std::vector< QString > m_statusTooltips
Definition: kiwisdrgui.h:72
bool m_doApplySettings
Definition: kiwisdrgui.h:63
QString getName() const
Definition: kiwisdrgui.cpp:100
QString m_reverseAPIAddress
void blockApplySettings(bool block)
Definition: kiwisdrgui.h:74
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
bool m_forceSettings
Definition: kiwisdrgui.h:64
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
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
virtual bool handleMessage(const Message &message)
Definition: kiwisdrgui.cpp:260
static MsgConfigureKiwiSDR * create(const KiwiSDRSettings &settings, bool force)
Definition: kiwisdrinput.h:47
DeviceUISet * m_deviceUISet
Definition: kiwisdrgui.h:59
QTimer m_updateTimer
Definition: kiwisdrgui.h:61
DeviceSampleSource * m_sampleSource
Definition: kiwisdrgui.h:65
static bool match(const Message *message)
Definition: message.cpp:45
uint16_t m_reverseAPIDeviceIndex
void on_dcBlock_toggled(bool checked)
Definition: kiwisdrgui.cpp:168
void handleInputMessages()
Definition: kiwisdrgui.cpp:296
void on_serverAddressApplyButton_clicked()
Definition: kiwisdrgui.cpp:162
int m_deviceSampleRate
Definition: kiwisdrgui.h:67
void resetToDefaults()
Definition: kiwisdrgui.cpp:105
std::vector< QString > m_statusColors
Definition: kiwisdrgui.h:71
void on_startStop_toggled(bool checked)
Definition: kiwisdrgui.cpp:142
static MsgStartStop * create(bool startStop)
Definition: kiwisdrinput.h:88
const KiwiSDRSettings & getSettings() const
Definition: kiwisdrinput.h:44
void on_agc_toggled(bool checked)
Definition: kiwisdrgui.cpp:186
int m_lastEngineState
Definition: kiwisdrgui.h:69
static MsgFileRecord * create(bool startStop)
Definition: kiwisdrinput.h:69
int getSampleRate() const
Definition: dspcommands.h:328
bool deserialize(const QByteArray &data)
KiwiSDRGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Definition: kiwisdrgui.cpp:42
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: kiwisdrgui.h:68
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
void updateStatus()
Definition: kiwisdrgui.cpp:231
uint16_t m_reverseAPIPort
void setReverseAPIAddress(const QString &address)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
quint64 m_centerFrequency
void updateHardware()
Definition: kiwisdrgui.cpp:220
void on_centerFrequency_changed(quint64 value)
Definition: kiwisdrgui.cpp:151
void openDeviceSettingsDialog(const QPoint &p)
Definition: kiwisdrgui.cpp:331
Ui::KiwiSDRGui * ui
Definition: kiwisdrgui.h:57
void sendSettings()
Definition: kiwisdrgui.cpp:213
virtual void setMessageQueueToGUI(MessageQueue *queue)=0
engine is running
Definition: deviceapi.h:56
QByteArray serialize() const
virtual qint64 getCenterFrequency() const
Definition: kiwisdrgui.cpp:112
engine is in error
Definition: deviceapi.h:57
MessageQueue m_inputMessageQueue
Definition: kiwisdrgui.h:70
void on_serverAddress_returnPressed()
Definition: kiwisdrgui.cpp:157
virtual ~KiwiSDRGui()
Definition: kiwisdrgui.cpp:85