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.
deviceuiset.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016 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 <QFont>
19 
20 #include "gui/glspectrum.h"
21 #include "dsp/spectrumvis.h"
22 #include "gui/glspectrumgui.h"
23 #include "gui/channelwindow.h"
28 #include "plugin/pluginapi.h"
29 #include "plugin/plugininterface.h"
30 #include "settings/preset.h"
31 
32 #include "deviceuiset.h"
33 
34 DeviceUISet::DeviceUISet(int tabIndex, int deviceType, QTimer& timer)
35 {
36  m_spectrum = new GLSpectrum;
37  if ((deviceType == 0) || (deviceType == 2)) { // Single Rx or MIMO
39  } else if (deviceType == 1) { // Single Tx
41  }
42  m_spectrum->connectTimer(timer);
46  m_samplingDeviceControl = new SamplingDeviceControl(tabIndex, deviceType);
47  m_deviceAPI = nullptr;
48  m_deviceSourceEngine = nullptr;
49  m_deviceSinkEngine = nullptr;
50  m_deviceMIMOEngine = nullptr;
51  m_deviceTabIndex = tabIndex;
52  m_nbAvailableRxChannels = 0; // updated at enumeration for UI selector
53  m_nbAvailableTxChannels = 0; // updated at enumeration for UI selector
54  m_nbAvailableMIMOChannels = 0; // updated at enumeration for UI selector
55 
56  // m_spectrum needs to have its font to be set since it cannot be inherited from the main window
57  QFont font;
58  font.setFamily(QStringLiteral("Liberation Sans"));
59  font.setPointSize(9);
60  m_spectrum->setFont(font);
61 }
62 
64 {
66  delete m_channelWindow;
67  delete m_spectrumGUI;
68  delete m_spectrumVis;
69  delete m_spectrum;
70 }
71 
73 {
74  m_spectrum->addChannelMarker(channelMarker);
75 }
76 
77 void DeviceUISet::addRollupWidget(QWidget *widget)
78 {
80 }
81 
82 void DeviceUISet::registerRxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI)
83 {
84  m_rxChannelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
86 }
87 
88 void DeviceUISet::registerTxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI)
89 {
90  m_txChannelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
92 }
93 
95 {
96  for(ChannelInstanceRegistrations::iterator it = m_rxChannelInstanceRegistrations.begin(); it != m_rxChannelInstanceRegistrations.end(); ++it)
97  {
98  if(it->m_gui == pluginGUI)
99  {
101  break;
102  }
103  }
104 
106 }
107 
109 {
110  for(ChannelInstanceRegistrations::iterator it = m_txChannelInstanceRegistrations.begin(); it != m_txChannelInstanceRegistrations.end(); ++it)
111  {
112  if(it->m_gui == pluginGUI)
113  {
115  break;
116  }
117  }
118 
120 }
121 
123 {
124  for(int i = 0; i < m_rxChannelInstanceRegistrations.count(); i++)
125  {
126  qDebug("DeviceUISet::freeAll: destroying channel [%s]", qPrintable(m_rxChannelInstanceRegistrations[i].m_channelName));
127  m_rxChannelInstanceRegistrations[i].m_gui->destroy();
128  }
129 }
130 
132 {
133  for(int i = 0; i < m_txChannelInstanceRegistrations.count(); i++)
134  {
135  qDebug("DeviceUISet::freeAll: destroying channel [%s]", qPrintable(m_txChannelInstanceRegistrations[i].m_channelName));
136  m_txChannelInstanceRegistrations[i].m_gui->destroy();
137  }
138 }
139 
140 void DeviceUISet::deleteRxChannel(int channelIndex)
141 {
142  if ((channelIndex >= 0) && (channelIndex < m_rxChannelInstanceRegistrations.count()))
143  {
144  qDebug("DeviceUISet::deleteRxChennel: delete channel [%s] at %d",
145  qPrintable(m_rxChannelInstanceRegistrations[channelIndex].m_channelName),
146  channelIndex);
147  m_rxChannelInstanceRegistrations[channelIndex].m_gui->destroy();
148  m_rxChannelInstanceRegistrations.removeAt(channelIndex);
150  }
151 }
152 
153 void DeviceUISet::deleteTxChannel(int channelIndex)
154 {
155  if ((channelIndex >= 0) && (channelIndex < m_txChannelInstanceRegistrations.count()))
156  {
157  qDebug("DeviceUISet::deleteTxChennel: delete channel [%s] at %d",
158  qPrintable(m_txChannelInstanceRegistrations[channelIndex].m_channelName),
159  channelIndex);
160  m_txChannelInstanceRegistrations[channelIndex].m_gui->destroy();
161  m_txChannelInstanceRegistrations.removeAt(channelIndex);
163  }
164 }
165 
166 void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
167 {
168  if (preset->isSourcePreset())
169  {
170  qDebug("DeviceUISet::loadRxChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
171 
172  // Available channel plugins
173  PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations();
174 
175  // copy currently open channels and clear list
178 
179  for(int i = 0; i < openChannels.count(); i++)
180  {
181  qDebug("DeviceUISet::loadRxChannelSettings: destroying old channel [%s]", qPrintable(openChannels[i].m_channelName));
182  openChannels[i].m_gui->destroy(); // FIXME: stop channel before
183  }
184 
185  qDebug("DeviceUISet::loadRxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
186 
187  for (int i = 0; i < preset->getChannelCount(); i++)
188  {
189  const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
191 
192  // create channel instance
193 
194  for(int i = 0; i < channelRegistrations->count(); i++)
195  {
196  //if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
197  if (compareRxChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI))
198  {
199  qDebug("DeviceUISet::loadRxChannelSettings: creating new channel [%s] from config [%s]",
200  qPrintable((*channelRegistrations)[i].m_channelIdURI),
201  qPrintable(channelConfig.m_channelIdURI));
202  BasebandSampleSink *rxChannel =
203  (*channelRegistrations)[i].m_plugin->createRxChannelBS(m_deviceAPI);
204  PluginInstanceGUI *rxChannelGUI =
205  (*channelRegistrations)[i].m_plugin->createRxChannelGUI(this, rxChannel);
206  reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, rxChannelGUI);
207  break;
208  }
209  }
210 
211  if (reg.m_gui != 0)
212  {
213  qDebug("DeviceUISet::loadRxChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channelIdURI));
214  reg.m_gui->deserialize(channelConfig.m_config);
215  }
216  }
217 
219  }
220  else
221  {
222  qDebug("DeviceUISet::loadRxChannelSettings: Loading preset [%s | %s] not a source preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
223  }
224 }
225 
227 {
228  if (preset->isSourcePreset())
229  {
230  qSort(m_rxChannelInstanceRegistrations.begin(), m_rxChannelInstanceRegistrations.end()); // sort by increasing delta frequency and type
231 
232  for(int i = 0; i < m_rxChannelInstanceRegistrations.count(); i++)
233  {
234  qDebug("DeviceUISet::saveRxChannelSettings: channel [%s] saved", qPrintable(m_rxChannelInstanceRegistrations[i].m_channelName));
235  preset->addChannel(m_rxChannelInstanceRegistrations[i].m_channelName, m_rxChannelInstanceRegistrations[i].m_gui->serialize());
236  }
237  }
238  else
239  {
240  qDebug("DeviceUISet::saveRxChannelSettings: not a source preset");
241  }
242 }
243 
244 void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
245 {
246  if (preset->isSourcePreset())
247  {
248  qDebug("DeviceUISet::loadTxChannelSettings: Loading preset [%s | %s] not a sink preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
249  }
250  else
251  {
252  qDebug("DeviceUISet::loadTxChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
253 
254  // Available channel plugins
255  PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations();
256 
257  // copy currently open channels and clear list
260 
261  for(int i = 0; i < openChannels.count(); i++)
262  {
263  qDebug("DeviceUISet::loadTxChannelSettings: destroying old channel [%s]", qPrintable(openChannels[i].m_channelName));
264  openChannels[i].m_gui->destroy();
265  }
266 
267  qDebug("DeviceUISet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
268 
269  for(int i = 0; i < preset->getChannelCount(); i++)
270  {
271  const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
273 
274  // create channel instance
275 
276  for(int i = 0; i < channelRegistrations->count(); i++)
277  {
278  if ((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
279  {
280  qDebug("DeviceUISet::loadTxChannelSettings: creating new channel [%s] from config [%s]",
281  qPrintable((*channelRegistrations)[i].m_channelIdURI),
282  qPrintable(channelConfig.m_channelIdURI));
283  BasebandSampleSource *txChannel =
284  (*channelRegistrations)[i].m_plugin->createTxChannelBS(m_deviceAPI);
285  PluginInstanceGUI *txChannelGUI =
286  (*channelRegistrations)[i].m_plugin->createTxChannelGUI(this, txChannel);
287  reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, txChannelGUI);
288  break;
289  }
290  }
291 
292  if(reg.m_gui != 0)
293  {
294  qDebug("DeviceUISet::loadTxChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channelIdURI));
295  reg.m_gui->deserialize(channelConfig.m_config);
296  }
297  }
298 
300  }
301 }
302 
304 {
305  if (preset->isSourcePreset())
306  {
307  qDebug("DeviceUISet::saveTxChannelSettings: not a sink preset");
308  }
309  else
310  {
311  qSort(m_txChannelInstanceRegistrations.begin(), m_txChannelInstanceRegistrations.end()); // sort by increasing delta frequency and type
312 
313  for(int i = 0; i < m_txChannelInstanceRegistrations.count(); i++)
314  {
315  qDebug("DeviceUISet::saveTxChannelSettings: channel [%s] saved", qPrintable(m_txChannelInstanceRegistrations[i].m_channelName));
316  preset->addChannel(m_txChannelInstanceRegistrations[i].m_channelName, m_txChannelInstanceRegistrations[i].m_gui->serialize());
317  }
318  }
319 }
320 
322 {
323  for(int i = 0; i < m_rxChannelInstanceRegistrations.count(); i++)
324  {
325  m_rxChannelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_rxChannelInstanceRegistrations[i].m_channelName).arg(i));
326  }
327 }
328 
330 {
331  for(int i = 0; i < m_txChannelInstanceRegistrations.count(); i++)
332  {
333  m_txChannelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_txChannelInstanceRegistrations[i].m_channelName).arg(i));
334  }
335 }
336 
337 // sort by increasing delta frequency and type (i.e. name)
339 {
340  if (m_gui && other.m_gui)
341  {
342  if (m_gui->getCenterFrequency() == other.m_gui->getCenterFrequency())
343  {
344  return m_gui->getName() < other.m_gui->getName();
345  }
346  else
347  {
348  return m_gui->getCenterFrequency() < other.m_gui->getCenterFrequency();
349  }
350  }
351  else
352  {
353  return false;
354  }
355 }
356 
357 bool DeviceUISet::compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI)
358 {
359  if ((xChannelURI == "sdrangel.channel.chanalyzerng") || (xChannelURI == "sdrangel.channel.chanalyzer")) { // renamed ChanalyzerNG to Chanalyzer in 4.0.0
360  return registerdChannelURI == "sdrangel.channel.chanalyzer";
361  } else if ((xChannelURI == "de.maintech.sdrangelove.channel.am") || (xChannelURI == "sdrangel.channel.amdemod")) {
362  return registerdChannelURI == "sdrangel.channel.amdemod";
363  } else if ((xChannelURI == "de.maintech.sdrangelove.channel.nfm") || (xChannelURI == "sdrangel.channel.nfmdemod")) {
364  return registerdChannelURI == "sdrangel.channel.nfmdemod";
365  } else if ((xChannelURI == "de.maintech.sdrangelove.channel.ssb") || (xChannelURI == "sdrangel.channel.ssbdemod")) {
366  return registerdChannelURI == "sdrangel.channel.ssbdemod";
367  } else if ((xChannelURI == "de.maintech.sdrangelove.channel.wfm") || (xChannelURI == "sdrangel.channel.wfmdemod")) {
368  return registerdChannelURI == "sdrangel.channel.wfmdemod";
369  } else {
370  return registerdChannelURI == xChannelURI;
371  }
372 }
void removeTxChannelInstance(PluginInstanceGUI *pluginGUI)
int getChannelCount() const
Definition: preset.h:86
bool compareRxChannelURIs(const QString &registerdChannelURI, const QString &xChannelURI)
int m_nbAvailableRxChannels
Number of Rx channels available for selection.
Definition: deviceuiset.h:108
ChannelRegistrations * getTxChannelRegistrations()
Definition: pluginapi.cpp:34
GLSpectrumGUI * m_spectrumGUI
Definition: deviceuiset.h:45
QList< ChannelRegistration > ChannelRegistrations
Definition: pluginapi.h:44
void connectTimer(const QTimer &timer)
void freeTxChannels()
void loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
void registerTxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:88
GLSpectrum * m_spectrum
Definition: deviceuiset.h:44
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
void saveTxChannelSettings(Preset *preset)
const ChannelConfig & getChannelConfig(int index) const
Definition: preset.h:87
virtual qint64 getCenterFrequency() const =0
QList< ChannelInstanceRegistration > ChannelInstanceRegistrations
Definition: deviceuiset.h:103
QString m_channelIdURI
Channel type ID in URI form.
Definition: preset.h:31
bool isSourcePreset() const
Definition: preset.h:66
ChannelInstanceRegistrations m_txChannelInstanceRegistrations
Definition: deviceuiset.h:106
virtual QString getName() const =0
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
void setBuddies(MessageQueue *messageQueue, SpectrumVis *spectrumVis, GLSpectrum *glSpectrum)
int m_deviceTabIndex
Definition: deviceuiset.h:107
DSPDeviceSourceEngine * m_deviceSourceEngine
Definition: deviceuiset.h:49
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
#define SDR_RX_SCALEF
Definition: dsptypes.h:33
ChannelRegistrations * getRxChannelRegistrations()
Definition: pluginapi.cpp:14
#define SDR_TX_SCALEF
Definition: dsptypes.h:39
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
SamplingDeviceControl * m_samplingDeviceControl
Definition: deviceuiset.h:47
void addChannel(const QString &channel, const QByteArray &config)
Definition: preset.h:85
void loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
void saveRxChannelSettings(Preset *preset)
void freeRxChannels()
void addRollupWidget(QWidget *rollupWidget)
Definition: preset.h:28
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
ChannelWindow * m_channelWindow
Definition: deviceuiset.h:46
void removeRxChannelInstance(PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:94
ChannelInstanceRegistrations m_rxChannelInstanceRegistrations
Definition: deviceuiset.h:105
void addChannelMarker(ChannelMarker *channelMarker)
Definition: glspectrum.cpp:315
int m_nbAvailableTxChannels
Number of Tx channels available for selection.
Definition: deviceuiset.h:109
DeviceUISet(int tabIndex, int deviceType, QTimer &timer)
Definition: deviceuiset.cpp:34
int m_nbAvailableMIMOChannels
Number of MIMO channels available for selection.
Definition: deviceuiset.h:110
DSPDeviceSinkEngine * m_deviceSinkEngine
Definition: deviceuiset.h:50
bool operator<(const ChannelInstanceRegistration &other) const
void deleteTxChannel(int channelIndex)
void renameRxChannelInstances()
QByteArray m_config
Definition: preset.h:33
void renameTxChannelInstances()
virtual bool deserialize(const QByteArray &data)=0
SpectrumVis * m_spectrumVis
Definition: deviceuiset.h:43
const QString & getDescription() const
Definition: preset.h:74
const QString & getGroup() const
Definition: preset.h:72
DSPDeviceMIMOEngine * m_deviceMIMOEngine
Definition: deviceuiset.h:51
void deleteRxChannel(int channelIndex)