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.
remotesinkgui.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 <QLocale>
19 
20 #include "device/deviceuiset.h"
23 #include "mainwindow.h"
24 
25 #include "remotesinkgui.h"
26 #include "remotesink.h"
27 #include "ui_remotesinkgui.h"
28 
30 {
31  RemoteSinkGUI* gui = new RemoteSinkGUI(pluginAPI, deviceUISet, channelRx);
32  return gui;
33 }
34 
36 {
37  delete this;
38 }
39 
40 void RemoteSinkGUI::setName(const QString& name)
41 {
42  setObjectName(name);
43 }
44 
45 QString RemoteSinkGUI::getName() const
46 {
47  return objectName();
48 }
49 
51  return 0;
52 }
53 
54 void RemoteSinkGUI::setCenterFrequency(qint64 centerFrequency)
55 {
56  (void) centerFrequency;
57 }
58 
60 {
63  applySettings(true);
64 }
65 
66 QByteArray RemoteSinkGUI::serialize() const
67 {
68  return m_settings.serialize();
69 }
70 
71 bool RemoteSinkGUI::deserialize(const QByteArray& data)
72 {
73  if(m_settings.deserialize(data)) {
75  applySettings(true);
76  return true;
77  } else {
79  return false;
80  }
81 }
82 
84 {
86  {
88  //m_channelMarker.setBandwidth(notif.getSampleRate());
89  m_sampleRate = notif.getSampleRate();
92  return true;
93  }
95  {
97  m_settings = cfg.getSettings();
98  blockApplySettings(true);
100  blockApplySettings(false);
101  return true;
102  }
103  else
104  {
105  return false;
106  }
107 }
108 
109 RemoteSinkGUI::RemoteSinkGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *channelrx, QWidget* parent) :
110  RollupWidget(parent),
111  ui(new Ui::RemoteSinkGUI),
112  m_pluginAPI(pluginAPI),
113  m_deviceUISet(deviceUISet),
114  m_sampleRate(0),
115  m_tickCount(0)
116 {
117  ui->setupUi(this);
118  setAttribute(Qt::WA_DeleteOnClose, true);
119  connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
120  connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
121 
122  m_remoteSink = (RemoteSink*) channelrx;
124 
125  m_channelMarker.blockSignals(true);
128  m_channelMarker.setTitle("Remote source");
129  m_channelMarker.blockSignals(false);
130  m_channelMarker.setVisible(true); // activate signal on the last setting only
131 
133 
137 
138  connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
139  //connect(&(m_deviceUISet->m_deviceSourceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
140 
141  m_time.start();
142 
143  displaySettings();
144  applySettings(true);
145 }
146 
148 {
150  delete m_remoteSink; // TODO: check this: when the GUI closes it has to delete the demodulator
151  delete ui;
152 }
153 
155 {
156  m_doApplySettings = !block;
157 }
158 
160 {
161  if (m_doApplySettings)
162  {
164 
167  }
168 }
169 
171 {
172  if (m_doApplySettings)
173  {
178  }
179 }
180 
182 {
183  m_channelMarker.blockSignals(true);
187  m_channelMarker.setMovable(false); // do not let user move the center arbitrarily
188  m_channelMarker.blockSignals(false);
189  m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
190 
192  setWindowTitle(m_channelMarker.getTitle());
193 
194  blockApplySettings(true);
195  ui->decimationFactor->setCurrentIndex(m_settings.m_log2Decim);
196  ui->dataAddress->setText(m_settings.m_dataAddress);
197  ui->dataPort->setText(tr("%1").arg(m_settings.m_dataPort));
198  QString s = QString::number(128 + m_settings.m_nbFECBlocks, 'f', 0);
199  QString s1 = QString::number(m_settings.m_nbFECBlocks, 'f', 0);
200  ui->nominalNbBlocksText->setText(tr("%1/%2").arg(s).arg(s1));
201  ui->txDelayText->setText(tr("%1%").arg(m_settings.m_txDelay));
202  ui->txDelay->setValue(m_settings.m_txDelay);
204  applyDecimation();
205  blockApplySettings(false);
206 }
207 
209 {
210  int shift = m_shiftFrequencyFactor * m_sampleRate;
211  double channelSampleRate = ((double) m_sampleRate) / (1<<m_settings.m_log2Decim);
212  QLocale loc;
213  ui->offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift)));
214  ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5)));
216  m_channelMarker.setBandwidth(channelSampleRate);
217 }
218 
220 {
222 }
223 
225 {
227 }
228 
230 {
231  Message* message;
232 
233  while ((message = getInputMessageQueue()->pop()) != 0)
234  {
235  if (handleMessage(*message))
236  {
237  delete message;
238  }
239  }
240 }
241 
242 void RemoteSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown)
243 {
244  (void) widget;
245  (void) rollDown;
246 }
247 
249 {
251  {
258 
259  dialog.move(p);
260  dialog.exec();
261 
269 
270  setWindowTitle(m_settings.m_title);
272 
273  applySettings();
274  }
275 
277 }
278 
280 {
281  m_settings.m_log2Decim = index;
282  applyDecimation();
283 }
284 
286 {
288  applyPosition();
289 }
290 
292 {
293  m_settings.m_dataAddress = ui->dataAddress->text();
294  applySettings();
295 }
296 
298 {
299  bool dataOk;
300  int dataPort = ui->dataPort->text().toInt(&dataOk);
301 
302  if((!dataOk) || (dataPort < 1024) || (dataPort > 65535))
303  {
304  return;
305  }
306  else
307  {
308  m_settings.m_dataPort = dataPort;
309  }
310 
311  applySettings();
312 }
313 
315 {
316  (void) checked;
317  m_settings.m_dataAddress = ui->dataAddress->text();
318 
319  bool dataOk;
320  int udpDataPort = ui->dataPort->text().toInt(&dataOk);
321 
322  if((dataOk) && (udpDataPort >= 1024) && (udpDataPort < 65535))
323  {
324  m_settings.m_dataPort = udpDataPort;
325  }
326 
327  applySettings();
328 }
329 
331 {
332  m_settings.m_txDelay = value; // percentage
333  ui->txDelayText->setText(tr("%1%").arg(value));
335  applySettings();
336 }
337 
339 {
340  m_settings.m_nbFECBlocks = value;
341  int nbOriginalBlocks = 128;
342  int nbFECBlocks = value;
343  QString s = QString::number(nbOriginalBlocks + nbFECBlocks, 'f', 0);
344  QString s1 = QString::number(nbFECBlocks, 'f', 0);
345  ui->nominalNbBlocksText->setText(tr("%1/%2").arg(s).arg(s1));
347  applySettings();
348 }
349 
351 {
352  double txDelayRatio = m_settings.m_txDelay / 100.0;
353  int samplesPerBlock = RemoteNbBytesPerBlock / sizeof(Sample);
354  double delay = m_sampleRate == 0 ? 0.0 : (127*samplesPerBlock*txDelayRatio) / m_sampleRate;
355  delay /= 128 + m_settings.m_nbFECBlocks;
356  ui->txDelayTime->setText(tr("%1µs").arg(QString::number(delay*1e6, 'f', 0)));
357 }
358 
360 {
361  uint32_t maxHash = 1;
362 
363  for (uint32_t i = 0; i < m_settings.m_log2Decim; i++) {
364  maxHash *= 3;
365  }
366 
367  ui->position->setMaximum(maxHash-1);
368  ui->position->setValue(m_settings.m_filterChainHash);
369  m_settings.m_filterChainHash = ui->position->value();
370  applyPosition();
371 }
372 
374 {
375  ui->filterChainIndex->setText(tr("%1").arg(m_settings.m_filterChainHash));
376  QString s;
378  ui->filterChainText->setText(s);
379 
382 }
383 
385 {
386  if (++m_tickCount == 20) { // once per second
387  m_tickCount = 0;
388  }
389 }
QByteArray serialize() const
uint32_t m_tickCount
Definition: remotesinkgui.h:74
const QString & getReverseAPIAddress() const
void handleSourceMessages()
void push(Message *message, bool emitSignal=true)
Push message onto queue.
uint16_t m_reverseAPIDeviceIndex
virtual ~RemoteSinkGUI()
void applyDecimation()
void applyChannelSettings()
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
bool deserialize(const QByteArray &data)
virtual MessageQueue * getInputMessageQueue()
Definition: remotesinkgui.h:56
RemoteSinkSettings m_settings
Definition: remotesinkgui.h:64
virtual void setCenterFrequency(qint64 centerFrequency)
void applySettings(bool force=false)
void leaveEvent(QEvent *)
void setReverseAPIChannelIndex(uint16_t channelIndex)
void resetContextMenuType()
Definition: rollupwidget.h:50
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: remotesink.h:96
virtual void destroy()
ChannelMarker m_channelMarker
Definition: remotesinkgui.h:63
void displaySettings()
static RemoteSinkGUI * create(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel)
DeviceUISet * m_deviceUISet
Definition: remotesinkgui.h:62
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 onMenuDialogCalled(const QPoint &p)
const RemoteSinkSettings & getSettings() const
Definition: remotesink.h:50
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
void enterEvent(QEvent *)
RemoteSink * m_remoteSink
Definition: remotesinkgui.h:70
uint16_t m_reverseAPIChannelIndex
virtual bool handleMessage(const Message &message)
void on_dataAddress_returnPressed()
static double convertToString(unsigned int log2, unsigned int chainHash, QString &chainString)
double m_shiftFrequencyFactor
Channel frequency shift factor.
Definition: remotesinkgui.h:67
static const QString m_channelIdURI
Definition: remotesink.h:160
virtual void setMessageQueueToGUI(MessageQueue *queue)
Ui::RemoteSinkGUI * ui
Definition: remotesinkgui.h:60
virtual qint64 getCenterFrequency() const
void setMovable(bool movable)
Definition: channelmarker.h:66
void setTitleColor(const QColor &c)
RemoteSinkGUI(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget *parent=0)
void setHighlighted(bool highlighted)
void displayRateAndShift()
void setName(const QString &name)
void resetToDefaults()
void on_decimationFactor_currentIndexChanged(int index)
void registerRxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:82
int32_t i
Definition: decimators.h:244
void addRollupWidget(QWidget *widget)
Add rollup widget to channel window.
Definition: deviceuiset.cpp:77
void removeRxChannelInstance(PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:94
const QString & getTitle() const
Definition: channelmarker.h:38
static bool match(const Message *message)
Definition: message.cpp:45
QString getName() const
void on_txDelay_valueChanged(int value)
bool m_doApplySettings
Definition: remotesinkgui.h:68
void on_nbFECBlocks_valueChanged(int value)
void on_dataPort_returnPressed()
QByteArray serialize() const
void setReverseAPIAddress(const QString &address)
void setColor(const QColor &color)
void onWidgetRolled(QWidget *widget, bool rollDown)
void blockApplySettings(bool block)
void setVisible(bool visible)
PluginAPI * m_pluginAPI
Definition: remotesinkgui.h:61
static MsgConfigureRemoteSink * create(const RemoteSinkSettings &settings, bool force)
Definition: remotesink.h:53
void setBandwidth(int bandwidth)
const QColor & getColor() const
Definition: channelmarker.h:64
void setTitle(const QString &title)
void setCenterFrequency(int centerFrequency)
void on_dataApplyButton_clicked(bool checked)
void setChannelMarker(Serializable *channelMarker)
bool deserialize(const QByteArray &data)
void widgetRolled(QWidget *widget, bool rollDown)
void on_position_valueChanged(int value)
void setUseReverseAPI(bool useReverseAPI)
void updateTxDelayTime()