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.
remotesourcegui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 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 "remotesourcegui.h"
19 
20 #include "device/deviceapi.h"
21 #include "device/deviceuiset.h"
23 #include "mainwindow.h"
24 
25 #include "remotesource.h"
26 #include "ui_remotesourcegui.h"
27 
29 {
30  RemoteSourceGUI* gui = new RemoteSourceGUI(pluginAPI, deviceUISet, channelTx);
31  return gui;
32 }
33 
35 {
36  delete this;
37 }
38 
39 void RemoteSourceGUI::setName(const QString& name)
40 {
41  setObjectName(name);
42 }
43 
44 QString RemoteSourceGUI::getName() const
45 {
46  return objectName();
47 }
48 
50  return 0;
51 }
52 
53 void RemoteSourceGUI::setCenterFrequency(qint64 centerFrequency)
54 {
55  (void) centerFrequency;
56 }
57 
59 {
62  applySettings(true);
63 }
64 
65 QByteArray RemoteSourceGUI::serialize() const
66 {
67  return m_settings.serialize();
68 }
69 
70 bool RemoteSourceGUI::deserialize(const QByteArray& data)
71 {
72  if(m_settings.deserialize(data)) {
74  applySettings(true);
75  return true;
76  } else {
78  return false;
79  }
80 }
81 
83 {
85  {
88  return true;
89  }
91  {
93  m_settings = cfg.getSettings();
94  blockApplySettings(true);
96  blockApplySettings(false);
97  return true;
98  }
100  {
102  ui->sampleRate->setText(QString("%1").arg(report.get_sampleRate()));
103  QString nominalNbBlocksText = QString("%1/%2")
104  .arg(report.get_nbOriginalBlocks() + report.get_nbFECBlocks())
105  .arg(report.get_nbFECBlocks());
106  ui->nominalNbBlocksText->setText(nominalNbBlocksText);
107  QString queueLengthText = QString("%1/%2").arg(report.get_queueLength()).arg(report.get_queueSize());
108  ui->queueLengthText->setText(queueLengthText);
109  int queueLengthPercent = (report.get_queueLength()*100)/report.get_queueSize();
110  ui->queueLengthGauge->setValue(queueLengthPercent);
111  int unrecoverableCount = report.get_nbUncorrectableErrors();
112  int recoverableCount = report.get_nbCorrectableErrors();
113  uint64_t timestampUs = report.get_tv_sec()*1000000ULL + report.get_tv_usec();
114 
115  if (!m_resetCounts)
116  {
117  int recoverableCountDelta = recoverableCount - m_lastCountRecovered;
118  int unrecoverableCountDelta = unrecoverableCount - m_lastCountUnrecoverable;
119  displayEventStatus(recoverableCountDelta, unrecoverableCountDelta);
120  m_countRecovered += recoverableCountDelta;
121  m_countUnrecoverable += unrecoverableCountDelta;
123  }
124 
125  uint32_t sampleCountDelta, sampleCount;
126  sampleCount = report.get_readSamplesCount();
127 
128  if (sampleCount < m_lastSampleCount) {
129  sampleCountDelta = (0xFFFFFFFFU - sampleCount) + m_lastSampleCount + 1;
130  } else {
131  sampleCountDelta = sampleCount - m_lastSampleCount;
132  }
133 
134  if (sampleCountDelta == 0) {
135  ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : blue; }");
136  }
137 
138  double remoteStreamRate = sampleCountDelta*1e6 / (double) (timestampUs - m_lastTimestampUs);
139 
140  if (remoteStreamRate != 0) {
141  ui->streamRateText->setText(QString("%1").arg(remoteStreamRate, 0, 'f', 0));
142  }
143 
144  m_resetCounts = false;
145  m_lastCountRecovered = recoverableCount;
146  m_lastCountUnrecoverable = unrecoverableCount;
147  m_lastSampleCount = sampleCount;
148  m_lastTimestampUs = timestampUs;
149 
150  return true;
151  }
152  else
153  {
154  return false;
155  }
156 }
157 
158 RemoteSourceGUI::RemoteSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent) :
159  RollupWidget(parent),
160  ui(new Ui::RemoteSourceGUI),
161  m_pluginAPI(pluginAPI),
162  m_deviceUISet(deviceUISet),
164  m_countRecovered(0),
169  m_resetCounts(true),
170  m_tickCount(0)
171 {
172  (void) channelTx;
173  ui->setupUi(this);
174  setAttribute(Qt::WA_DeleteOnClose, true);
175  connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
176  connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
177 
178  m_remoteSrc = (RemoteSource*) channelTx;
180 
181  connect(&(m_deviceUISet->m_deviceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
182 
183  m_channelMarker.blockSignals(true);
186  m_channelMarker.setTitle("Remote source");
188  m_channelMarker.blockSignals(false);
189  m_channelMarker.setVisible(true); // activate signal on the last setting only
190 
192 
196 
197  connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
198  connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
199 
200  m_time.start();
201 
202  displaySettings();
203  applySettings(true);
204 }
205 
207 {
209  delete m_remoteSrc;
210  delete ui;
211 }
212 
214 {
215  m_doApplySettings = !block;
216 }
217 
219 {
220  if (m_doApplySettings)
221  {
223 
226  }
227 }
228 
230 {
231  m_channelMarker.blockSignals(true);
234  m_channelMarker.setBandwidth(5000); // TODO
235  m_channelMarker.blockSignals(false);
236  m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
237 
239  setWindowTitle(m_channelMarker.getTitle());
240 
241  blockApplySettings(true);
242  ui->dataAddress->setText(m_settings.m_dataAddress);
243  ui->dataPort->setText(tr("%1").arg(m_settings.m_dataPort));
244  blockApplySettings(false);
245 }
246 
248 {
250 }
251 
253 {
255 }
256 
258 {
259  Message* message;
260 
261  while ((message = getInputMessageQueue()->pop()) != 0)
262  {
263  if (handleMessage(*message))
264  {
265  delete message;
266  }
267  }
268 }
269 
270 void RemoteSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown)
271 {
272  (void) widget;
273  (void) rollDown;
274 }
275 
277 {
279  {
286 
287  dialog.move(p);
288  dialog.exec();
289 
297 
298  setWindowTitle(m_settings.m_title);
300 
301  applySettings();
302  }
303 
305 }
306 
308 {
309  m_settings.m_dataAddress = ui->dataAddress->text();
310  applySettings();
311 }
312 
314 {
315  bool dataOk;
316  int dataPort = ui->dataPort->text().toInt(&dataOk);
317 
318  if((!dataOk) || (dataPort < 1024) || (dataPort > 65535))
319  {
320  return;
321  }
322  else
323  {
324  m_settings.m_dataPort = dataPort;
325  }
326 
327  applySettings();
328 }
329 
331 {
332  (void) checked;
333  m_settings.m_dataAddress = ui->dataAddress->text();
334 
335  bool dataOk;
336  int udpDataPort = ui->dataPort->text().toInt(&dataOk);
337 
338  if((dataOk) && (udpDataPort >= 1024) && (udpDataPort < 65535))
339  {
340  m_settings.m_dataPort = udpDataPort;
341  }
342 
343  applySettings();
344 }
345 
347 {
348  (void) checked;
350  m_countRecovered = 0;
351  m_time.start();
354 }
355 
357 {
358  QString nstr = QString("%1").arg(m_countUnrecoverable, 3, 10, QChar('0'));
359  ui->eventUnrecText->setText(nstr);
360  nstr = QString("%1").arg(m_countRecovered, 3, 10, QChar('0'));
361  ui->eventRecText->setText(nstr);
362 }
363 
364 void RemoteSourceGUI::displayEventStatus(int recoverableCount, int unrecoverableCount)
365 {
366 
367  if (unrecoverableCount == 0)
368  {
369  if (recoverableCount == 0) {
370  ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : green; }");
371  } else {
372  ui->allFramesDecoded->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
373  }
374  }
375  else
376  {
377  ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : red; }");
378  }
379 }
380 
382 {
383  int elapsedTimeMillis = m_time.elapsed();
384  QTime recordLength(0, 0, 0, 0);
385  recordLength = recordLength.addSecs(elapsedTimeMillis/1000);
386  QString s_time = recordLength.toString("HH:mm:ss");
387  ui->eventCountsTimeText->setText(s_time);
388 }
389 
391 {
392  if (++m_tickCount == 20) // once per second
393  {
396 
398 
399  m_tickCount = 0;
400  }
401 }
402 
404 {
405 }
void removeTxChannelInstance(PluginInstanceGUI *pluginGUI)
uint32_t get_nbOriginalBlocks() const
Definition: remotesource.h:112
const QString & getReverseAPIAddress() const
RemoteSourceGUI(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget *parent=0)
void on_dataPort_returnPressed()
QByteArray serialize() const
void registerTxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:88
RemoteSource * m_remoteSrc
void push(Message *message, bool emitSignal=true)
Push message onto queue.
QString getName() const
void enterEvent(QEvent *)
uint32_t m_countRecovered
void displayEventStatus(int recoverableCount, int unrecoverableCount)
bool deserialize(const QByteArray &data)
bool deserialize(const QByteArray &data)
virtual qint64 getCenterFrequency() const
void on_eventCountsReset_clicked(bool checked)
const RemoteSourceSettings & getSettings() const
Definition: remotesource.h:52
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
const QTimer & getMasterTimer() const
This is the DSPEngine master timer.
Definition: deviceapi.h:173
uint32_t m_tickCount
void setReverseAPIChannelIndex(uint16_t channelIndex)
void resetContextMenuType()
Definition: rollupwidget.h:50
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
uint32_t m_lastCountRecovered
uint32_t get_readSamplesCount() const
Definition: remotesource.h:109
virtual void destroy()
ChannelMarker m_channelMarker
DeviceUISet * m_deviceUISet
void onWidgetRolled(QWidget *widget, bool rollDown)
unsigned int uint32_t
Definition: rtptypes_win.h:46
ContextMenuType m_contextMenuType
Definition: rollupwidget.h:33
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
void setName(const QString &name)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void channelMarkerChangedByCursor()
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
void blockApplySettings(bool block)
void onMenuDialogCalled(const QPoint &p)
void setSourceOrSinkStream(bool sourceOrSinkStream)
Definition: channelmarker.h:75
void setTitleColor(const QColor &c)
uint16_t m_dataPort
Listening data port.
void setHighlighted(bool highlighted)
static MsgConfigureRemoteSource * create(const RemoteSourceSettings &settings, bool force)
Definition: remotesource.h:55
void addRollupWidget(QWidget *widget)
Add rollup widget to channel window.
Definition: deviceuiset.cpp:77
virtual void setMessageQueueToGUI(MessageQueue *queue)
static RemoteSourceGUI * create(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx)
const QString & getTitle() const
Definition: channelmarker.h:38
static bool match(const Message *message)
Definition: message.cpp:45
uint32_t m_countUnrecoverable
QString m_dataAddress
Listening (local) data address.
void applySettings(bool force=false)
uint32_t m_lastSampleCount
void setChannelMarker(Serializable *channelMarker)
QByteArray serialize() const
void setReverseAPIAddress(const QString &address)
static MsgQueryStreamData * create()
Definition: remotesource.h:94
RemoteSourceSettings m_settings
void setColor(const QColor &color)
uint32_t m_lastCountUnrecoverable
uint32_t get_nbCorrectableErrors() const
Definition: remotesource.h:110
void leaveEvent(QEvent *)
uint32_t get_nbUncorrectableErrors() const
Definition: remotesource.h:111
void setVisible(bool visible)
virtual ~RemoteSourceGUI()
void setBandwidth(int bandwidth)
const QColor & getColor() const
Definition: channelmarker.h:64
void on_dataApplyButton_clicked(bool checked)
void setTitle(const QString &title)
static const QString m_channelIdURI
Definition: remotesource.h:228
virtual bool handleMessage(const Message &message)
PluginAPI * m_pluginAPI
void setCenterFrequency(int centerFrequency)
virtual void setCenterFrequency(qint64 centerFrequency)
virtual MessageQueue * getInputMessageQueue()
void widgetRolled(QWidget *widget, bool rollDown)
void setUseReverseAPI(bool useReverseAPI)
Ui::RemoteSourceGUI * ui
uint64_t m_lastTimestampUs
void on_dataAddress_returnPressed()
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48