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.
localsinkgui.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 "localsinkgui.h"
26 #include "localsink.h"
27 #include "ui_localsinkgui.h"
28 
30 {
31  LocalSinkGUI* gui = new LocalSinkGUI(pluginAPI, deviceUISet, channelRx);
32  return gui;
33 }
34 
36 {
37  delete this;
38 }
39 
40 void LocalSinkGUI::setName(const QString& name)
41 {
42  setObjectName(name);
43 }
44 
45 QString LocalSinkGUI::getName() const
46 {
47  return objectName();
48 }
49 
51  return 0;
52 }
53 
54 void LocalSinkGUI::setCenterFrequency(qint64 centerFrequency)
55 {
56  (void) centerFrequency;
57 }
58 
60 {
63  applySettings(true);
64 }
65 
66 QByteArray LocalSinkGUI::serialize() const
67 {
68  return m_settings.serialize();
69 }
70 
71 bool LocalSinkGUI::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();
91  return true;
92  }
94  {
96  m_settings = cfg.getSettings();
97  blockApplySettings(true);
99  blockApplySettings(false);
100  return true;
101  }
102  else
103  {
104  return false;
105  }
106 }
107 
108 LocalSinkGUI::LocalSinkGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *channelrx, QWidget* parent) :
109  RollupWidget(parent),
110  ui(new Ui::LocalSinkGUI),
111  m_pluginAPI(pluginAPI),
112  m_deviceUISet(deviceUISet),
113  m_sampleRate(0),
114  m_tickCount(0)
115 {
116  ui->setupUi(this);
117  setAttribute(Qt::WA_DeleteOnClose, true);
118  connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
119  connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
120 
121  m_localSink = (LocalSink*) channelrx;
123 
124  m_channelMarker.blockSignals(true);
127  m_channelMarker.setTitle("Local Sink");
128  m_channelMarker.blockSignals(false);
129  m_channelMarker.setVisible(true); // activate signal on the last setting only
130 
132 
136 
137  connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
138  //connect(&(m_deviceUISet->m_deviceSourceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
139 
140  m_time.start();
141 
143  displaySettings();
144  applySettings(true);
145 }
146 
148 {
150  delete m_localSink; // 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  applyDecimation();
197  blockApplySettings(false);
198 }
199 
201 {
202  int shift = m_shiftFrequencyFactor * m_sampleRate;
203  double channelSampleRate = ((double) m_sampleRate) / (1<<m_settings.m_log2Decim);
204  QLocale loc;
205  ui->offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift)));
206  ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5)));
208  m_channelMarker.setBandwidth(channelSampleRate);
209 }
210 
212 {
213  std::vector<uint32_t> localDevicesIndexes;
214  m_localSink->getLocalDevices(localDevicesIndexes);
215  ui->localDevice->clear();
216  std::vector<uint32_t>::const_iterator it = localDevicesIndexes.begin();
217 
218  for (; it != localDevicesIndexes.end(); ++it) {
219  ui->localDevice->addItem(tr("%1").arg(*it), QVariant(*it));
220  }
221 }
222 
224 {
226 }
227 
229 {
231 }
232 
234 {
235  Message* message;
236 
237  while ((message = getInputMessageQueue()->pop()) != 0)
238  {
239  if (handleMessage(*message))
240  {
241  delete message;
242  }
243  }
244 }
245 
246 void LocalSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown)
247 {
248  (void) widget;
249  (void) rollDown;
250 }
251 
252 void LocalSinkGUI::onMenuDialogCalled(const QPoint &p)
253 {
255  {
262 
263  dialog.move(p);
264  dialog.exec();
265 
273 
274  setWindowTitle(m_settings.m_title);
276 
277  applySettings();
278  }
279 
281 }
282 
284 {
285  m_settings.m_log2Decim = index;
286  applyDecimation();
287 }
288 
290 {
292  applyPosition();
293 }
294 
296 {
297  m_settings.m_localDeviceIndex = ui->localDevice->itemData(index).toInt();
298  applySettings();
299 }
300 
302 {
303  (void) checked;
305 }
306 
308 {
309  uint32_t maxHash = 1;
310 
311  for (uint32_t i = 0; i < m_settings.m_log2Decim; i++) {
312  maxHash *= 3;
313  }
314 
315  ui->position->setMaximum(maxHash-1);
316  ui->position->setValue(m_settings.m_filterChainHash);
317  m_settings.m_filterChainHash = ui->position->value();
318  applyPosition();
319 }
320 
322 {
323  ui->filterChainIndex->setText(tr("%1").arg(m_settings.m_filterChainHash));
324  QString s;
326  ui->filterChainText->setText(s);
327 
330 }
331 
333 {
334  if (++m_tickCount == 20) { // once per second
335  m_tickCount = 0;
336  }
337 }
void on_decimationFactor_currentIndexChanged(int index)
void displaySettings()
void on_position_valueChanged(int value)
const QString & getReverseAPIAddress() const
Ui::LocalSinkGUI * ui
Definition: localsinkgui.h:60
void applyDecimation()
QByteArray serialize() const
void push(Message *message, bool emitSignal=true)
Push message onto queue.
LocalSink * m_localSink
Definition: localsinkgui.h:70
void setChannelMarker(Serializable *channelMarker)
QByteArray serialize() const
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
const LocalSinkSettings & getSettings() const
Definition: localsink.h:44
virtual bool handleMessage(const Message &message)
virtual MessageQueue * getInputMessageQueue()
Definition: localsinkgui.h:56
static LocalSinkGUI * create(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel)
void leaveEvent(QEvent *)
void applyChannelSettings()
QString getName() const
void resetToDefaults()
bool deserialize(const QByteArray &data)
void setReverseAPIChannelIndex(uint16_t channelIndex)
void setName(const QString &name)
void applyPosition()
void resetContextMenuType()
Definition: rollupwidget.h:50
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
void blockApplySettings(bool block)
double m_shiftFrequencyFactor
Channel frequency shift factor.
Definition: localsinkgui.h:67
unsigned int uint32_t
Definition: rtptypes_win.h:46
virtual qint64 getCenterFrequency() const
ContextMenuType m_contextMenuType
Definition: rollupwidget.h:33
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
LocalSinkGUI(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget *parent=0)
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
uint16_t m_reverseAPIChannelIndex
void on_localDevicesRefresh_clicked(bool checked)
static double convertToString(unsigned int log2, unsigned int chainHash, QString &chainString)
void updateLocalDevices()
PluginAPI * m_pluginAPI
Definition: localsinkgui.h:61
virtual void setMessageQueueToGUI(MessageQueue *queue)
virtual ~LocalSinkGUI()
void on_localDevice_currentIndexChanged(int index)
void onMenuDialogCalled(const QPoint &p)
bool deserialize(const QByteArray &data)
void setMovable(bool movable)
Definition: channelmarker.h:66
ChannelMarker m_channelMarker
Definition: localsinkgui.h:63
void setTitleColor(const QColor &c)
void setHighlighted(bool highlighted)
void registerRxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:82
virtual void setCenterFrequency(qint64 centerFrequency)
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
DeviceUISet * m_deviceUISet
Definition: localsinkgui.h:62
uint16_t m_reverseAPIDeviceIndex
void displayRateAndShift()
void applySettings(bool force=false)
void onWidgetRolled(QWidget *widget, bool rollDown)
LocalSinkSettings m_settings
Definition: localsinkgui.h:64
static MsgConfigureLocalSink * create(const LocalSinkSettings &settings, bool force)
Definition: localsink.h:47
void setReverseAPIAddress(const QString &address)
void setColor(const QColor &color)
void setVisible(bool visible)
void setBandwidth(int bandwidth)
const QColor & getColor() const
Definition: channelmarker.h:64
void setTitle(const QString &title)
static MsgConfigureChannelizer * create(unsigned int log2Decim, unsigned int filterChainHash)
Definition: localsink.h:90
void enterEvent(QEvent *)
void setCenterFrequency(int centerFrequency)
bool m_doApplySettings
Definition: localsinkgui.h:68
uint32_t m_tickCount
Definition: localsinkgui.h:74
static const QString m_channelIdURI
Definition: localsink.h:150
void widgetRolled(QWidget *widget, bool rollDown)
void setUseReverseAPI(bool useReverseAPI)
virtual void destroy()
void getLocalDevices(std::vector< uint32_t > &indexes)
Definition: localsink.cpp:223
void handleSourceMessages()