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.
webapiadaptergui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB. //
3 // //
4 // Swagger server adapter interface //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #include <QApplication>
21 #include <QList>
22 #include <QSysInfo>
23 
24 #include "mainwindow.h"
25 #include "ui_mainwindow.h"
26 #include "loggerwithfile.h"
27 #include "device/deviceapi.h"
28 #include "device/deviceuiset.h"
30 #include "dsp/devicesamplesource.h"
31 #include "dsp/devicesamplesink.h"
34 #include "dsp/dspengine.h"
35 #include "plugin/pluginapi.h"
36 #include "plugin/pluginmanager.h"
37 #include "channel/channelapi.h"
39 
44 #include "SWGDeviceListItem.h"
45 #include "SWGAudioDevices.h"
46 #include "SWGLocationInformation.h"
47 #include "SWGDVSerialDevices.h"
48 #include "SWGDVSerialDevice.h"
49 #include "SWGAMBEDevices.h"
50 #include "SWGPresets.h"
51 #include "SWGPresetGroup.h"
52 #include "SWGPresetItem.h"
53 #include "SWGPresetTransfer.h"
54 #include "SWGPresetIdentifier.h"
55 #include "SWGDeviceSettings.h"
56 #include "SWGDeviceState.h"
57 #include "SWGDeviceReport.h"
58 #include "SWGChannelsDetail.h"
59 #include "SWGChannelSettings.h"
60 #include "SWGChannelReport.h"
61 #include "SWGSuccessResponse.h"
62 #include "SWGErrorResponse.h"
63 #include "SWGDeviceState.h"
64 
65 #include "webapiadaptergui.h"
66 
68  m_mainWindow(mainWindow)
69 {
70 }
71 
73 {
74 }
75 
79 {
80  (void) error;
81  response.init();
82  *response.getAppname() = qApp->applicationName();
83  *response.getVersion() = qApp->applicationVersion();
84  *response.getQtVersion() = QString(QT_VERSION_STR);
85  response.setDspRxBits(SDR_RX_SAMP_SZ);
86  response.setDspTxBits(SDR_TX_SAMP_SZ);
87  response.setPid(qApp->applicationPid());
88 #if QT_VERSION >= 0x050400
89  *response.getArchitecture() = QString(QSysInfo::currentCpuArchitecture());
90  *response.getOs() = QString(QSysInfo::prettyProductName());
91 #endif
92 
93  SWGSDRangel::SWGLoggingInfo *logging = response.getLogging();
94  logging->init();
96 
97  if (logging->getDumpToFile()) {
100  }
101 
103 
104  SWGSDRangel::SWGDeviceSetList *deviceSetList = response.getDevicesetlist();
105  getDeviceSetList(deviceSetList);
106 
107  return 200;
108 }
109 
113 {
114  (void) response;
115  *error.getMessage() = QString("Not supported in GUI instance");
116  return 400;
117 }
118 
122 {
123  response.init();
124  SWGSDRangel::SWGPreferences *preferences = response.getPreferences();
126  SWGSDRangel::SWGPreset *workingPreset = response.getWorkingPreset();
128 
129  int nbPresets = m_mainWindow.m_settings.getPresetCount();
130  QList<SWGSDRangel::SWGPreset*> *swgPresets = response.getPresets();
131 
132  for (int i = 0; i < nbPresets; i++)
133  {
134  const Preset *preset = m_mainWindow.m_settings.getPreset(i);
135  swgPresets->append(new SWGSDRangel::SWGPreset);
136  WebAPIAdapterBase::webapiFormatPreset(swgPresets->back(), *preset);
137  }
138 
139  return 200;
140 }
141 
143  int direction,
146 {
147  (void) error;
148  response.init();
149 
150  int nbSamplingDevices;
151 
152  if (direction == 0) { // Single Rx stream device
153  nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
154  } else if (direction == 1) { // Single Tx stream device
155  nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
156  } else { // not supported
157  nbSamplingDevices = 0;
158  }
159 
160  response.setDevicecount(nbSamplingDevices);
161  QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices();
162 
163  for (int i = 0; i < nbSamplingDevices; i++)
164  {
165  const PluginInterface::SamplingDevice *samplingDevice = nullptr;
166 
167  if (direction == 0) {
168  samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
169  } else if (direction == 1) {
170  samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
171  } else {
172  continue;
173  }
174 
175  devices->append(new SWGSDRangel::SWGDeviceListItem);
176  devices->back()->init();
177  *devices->back()->getDisplayedName() = samplingDevice->displayedName;
178  *devices->back()->getHwType() = samplingDevice->hardwareId;
179  *devices->back()->getSerial() = samplingDevice->serial;
180  devices->back()->setSequence(samplingDevice->sequence);
181  devices->back()->setDirection((int) samplingDevice->streamType);
182  devices->back()->setDeviceNbStreams(samplingDevice->deviceNbItems);
183  devices->back()->setDeviceSetIndex(samplingDevice->claimed);
184  devices->back()->setIndex(i);
185  }
186 
187  return 200;
188 }
189 
191  int direction,
194 {
195  (void) error;
196  response.init();
197  PluginAPI::ChannelRegistrations *channelRegistrations;
198  int nbChannelDevices;
199 
200  if (direction == 0) // Single sink (Rx) channel
201  {
202  channelRegistrations = m_mainWindow.m_pluginManager->getRxChannelRegistrations();
203  nbChannelDevices = channelRegistrations->size();
204  }
205  else if (direction == 1) // Single source (Tx) channel
206  {
207  channelRegistrations = m_mainWindow.m_pluginManager->getTxChannelRegistrations();
208  nbChannelDevices = channelRegistrations->size();
209  }
210  else // not supported
211  {
212  channelRegistrations = nullptr;
213  nbChannelDevices = 0;
214  }
215 
216  response.setChannelcount(nbChannelDevices);
217  QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels();
218 
219  for (int i = 0; i < nbChannelDevices; i++)
220  {
221  channels->append(new SWGSDRangel::SWGChannelListItem);
222  channels->back()->init();
223  PluginInterface *channelInterface = channelRegistrations->at(i).m_plugin;
224  const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor();
225  *channels->back()->getVersion() = pluginDescriptor.version;
226  *channels->back()->getName() = pluginDescriptor.displayedName;
227  channels->back()->setDirection(direction);
228  *channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI;
229  *channels->back()->getId() = channelRegistrations->at(i).m_channelId;
230  channels->back()->setIndex(i);
231  }
232 
233  return 200;
234 }
235 
237  SWGSDRangel::SWGLoggingInfo& response,
239 {
240  (void) error;
241  response.init();
243 
244  if (response.getDumpToFile()) {
247  }
248 
250 
251  return 200;
252 }
253 
256  SWGSDRangel::SWGLoggingInfo& response,
258 {
259  (void) error;
260  // response input is the query actually
261  bool dumpToFile = (query.getDumpToFile() != 0);
262  QString* consoleLevel = query.getConsoleLevel();
263  QString* fileLevel = query.getFileLevel();
264  QString* fileName = query.getFileName();
265 
266  // perform actions
267  if (consoleLevel) {
269  }
270 
271  if (fileLevel) {
273  }
274 
276 
277  if (fileName) {
279  }
280 
282 
283  // build response
284  response.init();
289 
290  return 200;
291 }
292 
296 {
297  (void) error;
298  const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDevices();
299  const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDevices();
300  int nbInputDevices = audioInputDevices.size();
301  int nbOutputDevices = audioOutputDevices.size();
302 
303  response.init();
304  response.setNbInputDevices(nbInputDevices);
305  response.setNbOutputDevices(nbOutputDevices);
306  QList<SWGSDRangel::SWGAudioInputDevice*> *inputDevices = response.getInputDevices();
307  QList<SWGSDRangel::SWGAudioOutputDevice*> *outputDevices = response.getOutputDevices();
308  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
309  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
310 
311  // system default input device
312  inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
313  inputDevices->back()->init();
315  *inputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
316  inputDevices->back()->setIndex(-1);
317  inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
318  inputDevices->back()->setIsSystemDefault(0);
319  inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
320  inputDevices->back()->setVolume(inputDeviceInfo.volume);
321 
322  // real input devices
323  for (int i = 0; i < nbInputDevices; i++)
324  {
325  inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
326  inputDevices->back()->init();
327  inputDeviceInfo.resetToDefaults();
328  found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(audioInputDevices.at(i).deviceName(), inputDeviceInfo);
329  *inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
330  inputDevices->back()->setIndex(i);
331  inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
332  inputDevices->back()->setIsSystemDefault(audioInputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultInputDevice().deviceName() ? 1 : 0);
333  inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
334  inputDevices->back()->setVolume(inputDeviceInfo.volume);
335  }
336 
337  // system default output device
338  outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
339  outputDevices->back()->init();
341  *outputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
342  outputDevices->back()->setIndex(-1);
343  outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
344  inputDevices->back()->setIsSystemDefault(0);
345  outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
346  outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
347  outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
348  outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
349  outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec);
350  outputDevices->back()->setUdpDecimationFactor((int) outputDeviceInfo.udpDecimationFactor);
351  *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
352  outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
353 
354  // real output devices
355  for (int i = 0; i < nbOutputDevices; i++)
356  {
357  outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
358  outputDevices->back()->init();
359  outputDeviceInfo.resetToDefaults();
360  found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(audioOutputDevices.at(i).deviceName(), outputDeviceInfo);
361  *outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
362  outputDevices->back()->setIndex(i);
363  outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
364  outputDevices->back()->setIsSystemDefault(audioOutputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultOutputDevice().deviceName() ? 1 : 0);
365  outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
366  outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
367  outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
368  outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
369  outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec);
370  outputDevices->back()->setUdpDecimationFactor((int) outputDeviceInfo.udpDecimationFactor);
371  *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
372  outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
373  }
374 
375  return 200;
376 }
377 
380  const QStringList& audioInputKeys,
382 {
383  // TODO
384  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
385  QString deviceName;
386  int deviceIndex = response.getIndex();
387 
388  if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
389  {
390  error.init();
391  *error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
392  return 404;
393  }
394 
395  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
396 
397  if (audioInputKeys.contains("sampleRate")) {
398  inputDeviceInfo.sampleRate = response.getSampleRate();
399  }
400  if (audioInputKeys.contains("volume")) {
401  inputDeviceInfo.volume = response.getVolume();
402  }
403 
404  m_mainWindow.m_dspEngine->getAudioDeviceManager()->setInputDeviceInfo(deviceIndex, inputDeviceInfo);
405  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
406 
407  response.setSampleRate(inputDeviceInfo.sampleRate);
408  response.setVolume(inputDeviceInfo.volume);
409 
410  return 200;
411 }
412 
415  const QStringList& audioOutputKeys,
417 {
418  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
419  QString deviceName;
420  int deviceIndex = response.getIndex();
421 
422  if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
423  {
424  error.init();
425  *error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
426  return 404;
427  }
428 
429  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
430 
431  if (audioOutputKeys.contains("sampleRate")) {
432  outputDeviceInfo.sampleRate = response.getSampleRate();
433  }
434  if (audioOutputKeys.contains("copyToUDP")) {
435  outputDeviceInfo.copyToUDP = response.getCopyToUdp() == 0 ? 0 : 1;
436  }
437  if (audioOutputKeys.contains("udpUsesRTP")) {
438  outputDeviceInfo.udpUseRTP = response.getUdpUsesRtp() == 0 ? 0 : 1;
439  }
440  if (audioOutputKeys.contains("udpChannelMode")) {
441  outputDeviceInfo.udpChannelMode = static_cast<AudioOutput::UDPChannelMode>(response.getUdpChannelMode());
442  }
443  if (audioOutputKeys.contains("udpChannelCodec")) {
444  outputDeviceInfo.udpChannelCodec = static_cast<AudioOutput::UDPChannelCodec>(response.getUdpChannelCodec());
445  }
446  if (audioOutputKeys.contains("udpDecimatiobFactor")) {
447  outputDeviceInfo.udpDecimationFactor = response.getUdpDecimationFactor();
448  }
449  if (audioOutputKeys.contains("udpAddress")) {
450  outputDeviceInfo.udpAddress = *response.getUdpAddress();
451  }
452  if (audioOutputKeys.contains("udpPort")) {
453  outputDeviceInfo.udpPort = response.getUdpPort() % (1<<16);
454  }
455 
456  m_mainWindow.m_dspEngine->getAudioDeviceManager()->setOutputDeviceInfo(deviceIndex, outputDeviceInfo);
457  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
458 
459  response.setSampleRate(outputDeviceInfo.sampleRate);
460  response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
461  response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
462  response.setUdpChannelMode(outputDeviceInfo.udpChannelMode);
463  response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec);
464  response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
465 
466  if (response.getUdpAddress()) {
467  *response.getUdpAddress() = outputDeviceInfo.udpAddress;
468  } else {
469  response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
470  }
471 
472  response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
473 
474  return 200;
475 }
476 
480 {
481  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
482  QString deviceName;
483  int deviceIndex = response.getIndex();
484 
485  if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
486  {
487  error.init();
488  *error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
489  return 404;
490  }
491 
493  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
494 
495  response.setSampleRate(inputDeviceInfo.sampleRate);
496  response.setVolume(inputDeviceInfo.volume);
497 
498  return 200;
499 }
500 
504 {
505  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
506  QString deviceName;
507  int deviceIndex = response.getIndex();
508 
509  if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
510  {
511  error.init();
512  *error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
513  return 404;
514  }
515 
517  m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
518 
519  response.setSampleRate(outputDeviceInfo.sampleRate);
520  response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
521  response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
522  response.setUdpChannelMode(outputDeviceInfo.udpChannelMode);
523  response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec);
524  response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
525 
526  if (response.getUdpAddress()) {
527  *response.getUdpAddress() = outputDeviceInfo.udpAddress;
528  } else {
529  response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
530  }
531 
532  response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
533 
534  return 200;
535 }
536 
540 {
541  (void) error;
543 
544  response.init();
545  *response.getMessage() = QString("Unregistered parameters for devices not in list of available input devices for this instance");
546 
547  return 200;
548 }
549 
553 {
554  (void) error;
556 
557  response.init();
558  *response.getMessage() = QString("Unregistered parameters for devices not in list of available output devices for this instance");
559 
560  return 200;
561 }
562 
566 {
567  (void) error;
568  response.init();
571 
572  return 200;
573 }
574 
578 {
579  (void) error;
580  float latitude = response.getLatitude();
581  float longitude = response.getLongitude();
582 
583  latitude = latitude < -90.0 ? -90.0 : latitude > 90.0 ? 90.0 : latitude;
584  longitude = longitude < -180.0 ? -180.0 : longitude > 180.0 ? 180.0 : longitude;
585 
588 
591 
592  return 200;
593 }
594 
598 {
599  (void) error;
600  response.init();
601 
602  std::vector<std::string> deviceNames;
604  response.setNbDevices((int) deviceNames.size());
605  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
606 
607  std::vector<std::string>::iterator it = deviceNames.begin();
608 
609  while (it != deviceNames.end())
610  {
611  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
612  deviceNamesList->back()->init();
613  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
614  ++it;
615  }
616 
617  return 200;
618 }
619 
621  bool dvserial,
624 {
625  (void) error;
627  m_mainWindow.ui->action_DV_Serial->setChecked(dvserial);
628  response.init();
629 
630  if (dvserial)
631  {
632  std::vector<std::string> deviceNames;
634  response.setNbDevices((int) deviceNames.size());
635  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
636 
637  std::vector<std::string>::iterator it = deviceNames.begin();
638 
639  while (it != deviceNames.end())
640  {
641  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
642  deviceNamesList->back()->init();
643  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
644  ++it;
645  }
646  }
647  else
648  {
649  response.setNbDevices(0);
650  }
651 
652  return 200;
653 }
654 
658 {
659  (void) error;
660  response.init();
661 
662  std::vector<std::string> deviceNames;
663  std::vector<QString> qDeviceNames;
664  m_mainWindow.m_dspEngine->getAMBEEngine()->scan(qDeviceNames);
665 
666  for (std::vector<QString>::const_iterator it = qDeviceNames.begin(); it != qDeviceNames.end(); ++it) {
667  deviceNames.push_back(it->toStdString());
668  }
669 
670  response.setNbDevices((int) deviceNames.size());
671  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
672 
673  std::vector<std::string>::iterator it = deviceNames.begin();
674 
675  while (it != deviceNames.end())
676  {
677  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
678  deviceNamesList->back()->init();
679  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
680  ++it;
681  }
682 
683  return 200;
684 }
685 
687  SWGSDRangel::SWGAMBEDevices& response,
689 {
690  (void) error;
691  response.init();
692 
693  std::vector<std::string> deviceNames;
695  response.setNbDevices((int) deviceNames.size());
696  QList<SWGSDRangel::SWGAMBEDevice*> *deviceNamesList = response.getAmbeDevices();
697 
698  std::vector<std::string>::iterator it = deviceNames.begin();
699 
700  while (it != deviceNames.end())
701  {
702  deviceNamesList->append(new SWGSDRangel::SWGAMBEDevice);
703  deviceNamesList->back()->init();
704  *deviceNamesList->back()->getDeviceRef() = QString::fromStdString(*it);
705  deviceNamesList->back()->setDelete(0);
706  ++it;
707  }
708 
709  return 200;
710 }
711 
715 {
716  (void) error;
718 
719  response.init();
720  *response.getMessage() = QString("All AMBE devices released");
721 
722  return 200;
723 }
724 
727  SWGSDRangel::SWGAMBEDevices& response,
729 {
731 
732  QList<SWGSDRangel::SWGAMBEDevice *> *ambeList = query.getAmbeDevices();
733 
734  for (QList<SWGSDRangel::SWGAMBEDevice *>::const_iterator it = ambeList->begin(); it != ambeList->end(); ++it) {
735  m_mainWindow.m_dspEngine->getAMBEEngine()->registerController((*it)->getDeviceRef()->toStdString());
736  }
737 
738  instanceAMBEDevicesGet(response, error);
739  return 200;
740 }
741 
744  SWGSDRangel::SWGAMBEDevices& response,
746 {
747  QList<SWGSDRangel::SWGAMBEDevice *> *ambeList = query.getAmbeDevices();
748 
749  for (QList<SWGSDRangel::SWGAMBEDevice *>::const_iterator it = ambeList->begin(); it != ambeList->end(); ++it)
750  {
751  if ((*it)->getDelete()) {
752  m_mainWindow.m_dspEngine->getAMBEEngine()->releaseController((*it)->getDeviceRef()->toStdString());
753  } else {
754  m_mainWindow.m_dspEngine->getAMBEEngine()->registerController((*it)->getDeviceRef()->toStdString());
755  }
756  }
757 
758  instanceAMBEDevicesGet(response, error);
759  return 200;
760 }
761 
763  SWGSDRangel::SWGPresets& response,
765 {
766  (void) error;
767  int nbPresets = m_mainWindow.m_settings.getPresetCount();
768  int nbGroups = 0;
769  int nbPresetsThisGroup = 0;
770  QString groupName;
771  response.init();
772  QList<SWGSDRangel::SWGPresetGroup*> *groups = response.getGroups();
773  QList<SWGSDRangel::SWGPresetItem*> *swgPresets = 0;
774  int i = 0;
775 
776  // Presets are sorted by group first
777 
778  for (; i < nbPresets; i++)
779  {
780  const Preset *preset = m_mainWindow.m_settings.getPreset(i);
781 
782  if ((i == 0) || (groupName != preset->getGroup())) // new group
783  {
784  if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
785  groups->append(new SWGSDRangel::SWGPresetGroup);
786  groups->back()->init();
787  groupName = preset->getGroup();
788  *groups->back()->getGroupName() = groupName;
789  swgPresets = groups->back()->getPresets();
790  nbGroups++;
791  nbPresetsThisGroup = 0;
792  }
793 
794  swgPresets->append(new SWGSDRangel::SWGPresetItem);
795  swgPresets->back()->init();
796  swgPresets->back()->setCenterFrequency(preset->getCenterFrequency());
797  *swgPresets->back()->getType() = preset->isSourcePreset() ? "R" : "T";
798  *swgPresets->back()->getName() = preset->getDescription();
799  nbPresetsThisGroup++;
800  }
801 
802  if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
803  response.setNbGroups(nbGroups);
804 
805  return 200;
806 }
807 
812 {
813  int deviceSetIndex = query.getDeviceSetIndex();
814  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
815  int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
816 
817  if (deviceSetIndex >= nbDeviceSets)
818  {
819  error.init();
820  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
821  return 404;
822  }
823 
824  const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
825  presetIdentifier->getCenterFrequency(),
826  *presetIdentifier->getName(),
827  *presetIdentifier->getType());
828 
829  if (selectedPreset == 0)
830  {
831  error.init();
832  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
833  .arg(*presetIdentifier->getGroupName())
834  .arg(presetIdentifier->getCenterFrequency())
835  .arg(*presetIdentifier->getName())
836  .arg(*presetIdentifier->getType());
837  return 404;
838  }
839 
840  DeviceUISet *deviceUI = m_mainWindow.m_deviceUIs[deviceSetIndex];
841 
842  if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
843  {
844  error.init();
845  *error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
846  return 404;
847  }
848 
849  if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
850  {
851  error.init();
852  *error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
853  return 404;
854  }
855 
856  MainWindow::MsgLoadPreset *msg = MainWindow::MsgLoadPreset::create(selectedPreset, deviceSetIndex);
858 
859  response.init();
860  response.setCenterFrequency(selectedPreset->getCenterFrequency());
861  *response.getGroupName() = selectedPreset->getGroup();
862  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
863  *response.getName() = selectedPreset->getDescription();
864 
865  return 202;
866 }
867 
872 {
873  int deviceSetIndex = query.getDeviceSetIndex();
874  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
875  int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
876 
877  if (deviceSetIndex >= nbDeviceSets)
878  {
879  error.init();
880  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
881  return 404;
882  }
883 
884  const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
885  presetIdentifier->getCenterFrequency(),
886  *presetIdentifier->getName(),
887  *presetIdentifier->getType());
888 
889  if (selectedPreset == 0)
890  {
891  error.init();
892  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
893  .arg(*presetIdentifier->getGroupName())
894  .arg(presetIdentifier->getCenterFrequency())
895  .arg(*presetIdentifier->getName())
896  .arg(*presetIdentifier->getType());
897  return 404;
898  }
899  else // update existing preset
900  {
901  DeviceUISet *deviceUI = m_mainWindow.m_deviceUIs[deviceSetIndex];
902 
903  if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
904  {
905  error.init();
906  *error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
907  return 404;
908  }
909 
910  if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
911  {
912  error.init();
913  *error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
914  return 404;
915  }
916  }
917 
918  MainWindow::MsgSavePreset *msg = MainWindow::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, false);
920 
921  response.init();
922  response.setCenterFrequency(selectedPreset->getCenterFrequency());
923  *response.getGroupName() = selectedPreset->getGroup();
924  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
925  *response.getName() = selectedPreset->getDescription();
926 
927  return 202;
928 }
929 
934 {
935  int deviceSetIndex = query.getDeviceSetIndex();
936  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
937  int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
938 
939  if (deviceSetIndex >= nbDeviceSets)
940  {
941  error.init();
942  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
943  return 404;
944  }
945 
946  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
947  int deviceCenterFrequency = 0;
948 
949  if (deviceSet->m_deviceSourceEngine) { // Rx
950  deviceCenterFrequency = deviceSet->m_deviceSourceEngine->getSource()->getCenterFrequency();
951  } else if (deviceSet->m_deviceSinkEngine) { // Tx
952  deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency();
953  } else {
954  error.init();
955  *error.getMessage() = QString("Device set error");
956  return 500;
957  }
958 
959  const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
960  deviceCenterFrequency,
961  *presetIdentifier->getName(),
962  *presetIdentifier->getType());
963 
964  if (selectedPreset == 0) // save on a new preset
965  {
966  selectedPreset = m_mainWindow.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
967  }
968  else
969  {
970  error.init();
971  *error.getMessage() = QString("Preset already exists [%1, %2, %3 %4]")
972  .arg(*presetIdentifier->getGroupName())
973  .arg(deviceCenterFrequency)
974  .arg(*presetIdentifier->getName())
975  .arg(*presetIdentifier->getType());
976  return 409;
977  }
978 
979  MainWindow::MsgSavePreset *msg = MainWindow::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, true);
981 
982  response.init();
983  response.setCenterFrequency(selectedPreset->getCenterFrequency());
984  *response.getGroupName() = selectedPreset->getGroup();
985  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
986  *response.getName() = selectedPreset->getDescription();
987 
988  return 202;
989 }
990 
994 {
995  const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*response.getGroupName(),
996  response.getCenterFrequency(),
997  *response.getName(),
998  *response.getType());
999 
1000  if (selectedPreset == 0)
1001  {
1002  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
1003  .arg(*response.getGroupName())
1004  .arg(response.getCenterFrequency())
1005  .arg(*response.getName())
1006  .arg(*response.getType());
1007  return 404;
1008  }
1009 
1010  response.setCenterFrequency(selectedPreset->getCenterFrequency());
1011  *response.getGroupName() = selectedPreset->getGroup();
1012  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
1013  *response.getName() = selectedPreset->getDescription();
1014 
1015  MainWindow::MsgDeletePreset *msg = MainWindow::MsgDeletePreset::create(const_cast<Preset*>(selectedPreset));
1017 
1018  return 202;
1019 }
1020 
1024 {
1025  (void) error;
1026  getDeviceSetList(&response);
1027  return 200;
1028 }
1029 
1031  int direction,
1034 {
1035  (void) error;
1038 
1039  response.init();
1040  *response.getMessage() = QString("Message to add a new device set (MsgAddDeviceSet) was submitted successfully");
1041 
1042  return 202;
1043 }
1044 
1048 {
1049  if (m_mainWindow.m_deviceUIs.size() > 1)
1050  {
1053 
1054  response.init();
1055  *response.getMessage() = QString("Message to remove last device set (MsgRemoveLastDeviceSet) was submitted successfully");
1056 
1057  return 202;
1058  }
1059  else
1060  {
1061  error.init();
1062  *error.getMessage() = "No more device sets to be removed";
1063 
1064  return 404;
1065  }
1066 }
1067 
1069  int deviceSetIndex,
1070  SWGSDRangel::SWGDeviceSet& response,
1072 {
1073  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1074  {
1075  const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1076  getDeviceSet(&response, deviceSet, deviceSetIndex);
1077 
1078  return 200;
1079  }
1080  else
1081  {
1082  error.init();
1083  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1084 
1085  return 404;
1086  }
1087  }
1088 
1090  int deviceSetIndex,
1093 {
1094  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1095  {
1098 
1099  response.init();
1100  *response.getMessage() = QString("Message to focus on device set (MsgDeviceSetFocus) was submitted successfully");
1101 
1102  return 202;
1103  }
1104  else
1105  {
1106  error.init();
1107  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1108 
1109  return 404;
1110  }
1111 }
1112 
1114  int deviceSetIndex,
1118 {
1119  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1120  {
1121  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1122 
1123  if ((query.getDirection() != 1) && (deviceSet->m_deviceSinkEngine))
1124  {
1125  error.init();
1126  *error.getMessage() = QString("Device type and device set type (Tx) mismatch");
1127  return 404;
1128  }
1129 
1130  if ((query.getDirection() != 0) && (deviceSet->m_deviceSourceEngine))
1131  {
1132  error.init();
1133  *error.getMessage() = QString("Device type and device set type (Rx) mismatch");
1134  return 404;
1135  }
1136 
1137  int nbSamplingDevices;
1138 
1139  if (query.getDirection() == 0) {
1140  nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
1141  } else if (query.getDirection() == 1) {
1142  nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
1143  } else {
1144  nbSamplingDevices = 0; // TODO: not implemented yet
1145  }
1146 
1147 
1148  for (int i = 0; i < nbSamplingDevices; i++)
1149  {
1150  int tx;
1151  const PluginInterface::SamplingDevice *samplingDevice;
1152 
1153  if (query.getDirection() == 0)
1154  {
1155  tx = 0;
1156  samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
1157  }
1158  else if (query.getDirection() == 1)
1159  {
1160  tx = 1;
1161  samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
1162  }
1163  else
1164  {
1165  continue; // TODO: any device (2) not supported yet
1166  }
1167 
1168  if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice->displayedName)) {
1169  continue;
1170  }
1171 
1172  if (query.getHwType() && (*query.getHwType() != samplingDevice->hardwareId)) {
1173  continue;
1174  }
1175 
1176  if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice->sequence)) {
1177  continue;
1178  }
1179 
1180  if (query.getSerial() && (*query.getSerial() != samplingDevice->serial)) {
1181  continue;
1182  }
1183 
1184  if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice->deviceItemIndex)) {
1185  continue;
1186  }
1187 
1190 
1191  response.init();
1192  *response.getDisplayedName() = samplingDevice->displayedName;
1193  *response.getHwType() = samplingDevice->hardwareId;
1194  *response.getSerial() = samplingDevice->serial;
1195  response.setSequence(samplingDevice->sequence);
1196  response.setDirection(tx);
1197  response.setDeviceNbStreams(samplingDevice->deviceNbItems);
1198  response.setDeviceStreamIndex(samplingDevice->deviceItemIndex);
1199  response.setDeviceSetIndex(deviceSetIndex);
1200  response.setIndex(i);
1201 
1202  return 202;
1203  }
1204 
1205  error.init();
1206  *error.getMessage() = QString("Device not found");
1207  return 404;
1208  }
1209  else
1210  {
1211  error.init();
1212  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1213  return 404;
1214  }
1215 }
1216 
1218  int deviceSetIndex,
1221 {
1222  error.init();
1223 
1224  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1225  {
1226  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1227 
1228  if (deviceSet->m_deviceSourceEngine) // Single Rx
1229  {
1230  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1231  response.setDirection(0);
1232  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1233  return source->webapiSettingsGet(response, *error.getMessage());
1234  }
1235  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1236  {
1237  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1238  response.setDirection(1);
1239  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1240  return sink->webapiSettingsGet(response, *error.getMessage());
1241  }
1242  else
1243  {
1244  *error.getMessage() = QString("DeviceSet error");
1245  return 500;
1246  }
1247  }
1248  else
1249  {
1250  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1251  return 404;
1252  }
1253 }
1254 
1256  int deviceSetIndex,
1257  bool force,
1258  const QStringList& deviceSettingsKeys,
1261 {
1262  error.init();
1263 
1264  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1265  {
1266  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1267 
1268  if (deviceSet->m_deviceSourceEngine) // Single Rx
1269  {
1270  if (response.getDirection() != 0)
1271  {
1272  *error.getMessage() = QString("Single Rx device found but other type of device requested");
1273  return 400;
1274  }
1275  if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType())
1276  {
1277  *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceAPI->getHardwareId());
1278  return 400;
1279  }
1280  else
1281  {
1282  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1283  return source->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
1284  }
1285  }
1286  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1287  {
1288  if (response.getDirection() != 1)
1289  {
1290  *error.getMessage() = QString("Single Tx device found but other type of device requested");
1291  return 400;
1292  }
1293  else if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType())
1294  {
1295  *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId());
1296  return 400;
1297  }
1298  else
1299  {
1300  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1301  return sink->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
1302  }
1303  }
1304  else
1305  {
1306  *error.getMessage() = QString("DeviceSet error");
1307  return 500;
1308  }
1309  }
1310  else
1311  {
1312  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1313  return 404;
1314  }
1315 }
1316 
1318  int deviceSetIndex,
1319  SWGSDRangel::SWGDeviceState& response,
1321 {
1322  error.init();
1323 
1324  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1325  {
1326  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1327 
1328  if (deviceSet->m_deviceSourceEngine) // Rx
1329  {
1330  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1331  response.init();
1332  return source->webapiRunGet(response, *error.getMessage());
1333  }
1334  else if (deviceSet->m_deviceSinkEngine) // Tx
1335  {
1336  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1337  response.init();
1338  return sink->webapiRunGet(response, *error.getMessage());
1339  }
1340  else
1341  {
1342  *error.getMessage() = QString("DeviceSet error");
1343  return 500;
1344  }
1345  }
1346  else
1347  {
1348  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1349  return 404;
1350  }
1351 }
1352 
1354  int deviceSetIndex,
1355  SWGSDRangel::SWGDeviceState& response,
1357 {
1358  error.init();
1359 
1360  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1361  {
1362  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1363 
1364  if (deviceSet->m_deviceSourceEngine) // Rx
1365  {
1366  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1367  response.init();
1368  return source->webapiRun(true, response, *error.getMessage());
1369  }
1370  else if (deviceSet->m_deviceSinkEngine) // Tx
1371  {
1372  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1373  response.init();
1374  return sink->webapiRun(true, response, *error.getMessage());
1375  }
1376  else
1377  {
1378  *error.getMessage() = QString("DeviceSet error");
1379  return 500;
1380  }
1381  }
1382  else
1383  {
1384  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1385  return 404;
1386  }
1387 }
1388 
1390  int deviceSetIndex,
1391  SWGSDRangel::SWGDeviceState& response,
1393 {
1394  error.init();
1395 
1396  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1397  {
1398  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1399 
1400  if (deviceSet->m_deviceSourceEngine) // Rx
1401  {
1402  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1403  response.init();
1404  return source->webapiRun(false, response, *error.getMessage());
1405  }
1406  else if (deviceSet->m_deviceSinkEngine) // Tx
1407  {
1408  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1409  response.init();
1410  return sink->webapiRun(false, response, *error.getMessage());
1411  }
1412  else
1413  {
1414  *error.getMessage() = QString("DeviceSet error");
1415  return 500;
1416  }
1417  }
1418  else
1419  {
1420  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1421  return 404;
1422  }
1423 }
1424 
1425 
1427  int deviceSetIndex,
1428  SWGSDRangel::SWGDeviceReport& response,
1430 {
1431  error.init();
1432 
1433  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1434  {
1435  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1436 
1437  if (deviceSet->m_deviceSourceEngine) // Single Rx
1438  {
1439  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1440  response.setDirection(0);
1441  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1442  return source->webapiReportGet(response, *error.getMessage());
1443  }
1444  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1445  {
1446  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1447  response.setDirection(1);
1448  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1449  return sink->webapiReportGet(response, *error.getMessage());
1450  }
1451  else
1452  {
1453  *error.getMessage() = QString("DeviceSet error");
1454  return 500;
1455  }
1456  }
1457  else
1458  {
1459  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1460  return 404;
1461  }
1462 }
1463 
1465  int deviceSetIndex,
1468 {
1469  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1470  {
1471  const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1472  getChannelsDetail(&response, deviceSet);
1473 
1474  return 200;
1475  }
1476  else
1477  {
1478  error.init();
1479  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1480 
1481  return 404;
1482  }
1483 }
1484 
1486  int deviceSetIndex,
1490 {
1491  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1492  {
1493  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1494 
1495  if (query.getDirection() == 0) // Single Rx
1496  {
1497  if (deviceSet->m_deviceSourceEngine == 0)
1498  {
1499  error.init();
1500  *error.getMessage() = QString("Device set at %1 is not a receive device set").arg(deviceSetIndex);
1501  return 400;
1502  }
1503 
1505  int nbRegistrations = channelRegistrations->size();
1506  int index = 0;
1507  for (; index < nbRegistrations; index++)
1508  {
1509  if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
1510  break;
1511  }
1512  }
1513 
1514  if (index < nbRegistrations)
1515  {
1516  MainWindow::MsgAddChannel *msg = MainWindow::MsgAddChannel::create(deviceSetIndex, index, false);
1518 
1519  response.init();
1520  *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
1521 
1522  return 202;
1523  }
1524  else
1525  {
1526  error.init();
1527  *error.getMessage() = QString("There is no receive channel with id %1").arg(*query.getChannelType());
1528  return 404;
1529  }
1530  }
1531  else if (query.getDirection() == 1) // single Tx
1532  {
1533  if (deviceSet->m_deviceSinkEngine == 0)
1534  {
1535  error.init();
1536  *error.getMessage() = QString("Device set at %1 is not a transmit device set").arg(deviceSetIndex);
1537  return 400;
1538  }
1539 
1541  int nbRegistrations = channelRegistrations->size();
1542  int index = 0;
1543  for (; index < nbRegistrations; index++)
1544  {
1545  if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
1546  break;
1547  }
1548  }
1549 
1550  if (index < nbRegistrations)
1551  {
1552  MainWindow::MsgAddChannel *msg = MainWindow::MsgAddChannel::create(deviceSetIndex, index, true);
1554 
1555  response.init();
1556  *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
1557 
1558  return 202;
1559  }
1560  else
1561  {
1562  error.init();
1563  *error.getMessage() = QString("There is no transmit channel with id %1").arg(*query.getChannelType());
1564  return 404;
1565  }
1566  }
1567  else
1568  {
1569  error.init();
1570  *error.getMessage() = QString("This type of device is not implemented yet");
1571  return 400;
1572  }
1573  }
1574  else
1575  {
1576  error.init();
1577  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1578  return 404;
1579  }
1580 }
1581 
1583  int deviceSetIndex,
1584  int channelIndex,
1587 {
1588  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1589  {
1590  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1591 
1592  if (deviceSet->m_deviceSourceEngine) // Rx
1593  {
1594  if (channelIndex < deviceSet->getNumberOfRxChannels())
1595  {
1596  MainWindow::MsgDeleteChannel *msg = MainWindow::MsgDeleteChannel::create(deviceSetIndex, channelIndex, false);
1598 
1599  response.init();
1600  *response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
1601 
1602  return 202;
1603  }
1604  else
1605  {
1606  error.init();
1607  *error.getMessage() = QString("There is no channel at index %1. There are %2 Rx channels")
1608  .arg(channelIndex)
1609  .arg(channelIndex < deviceSet->getNumberOfRxChannels());
1610  return 400;
1611  }
1612  }
1613  else if (deviceSet->m_deviceSinkEngine) // Tx
1614  {
1615  if (channelIndex < deviceSet->getNumberOfTxChannels())
1616  {
1617  MainWindow::MsgDeleteChannel *msg = MainWindow::MsgDeleteChannel::create(deviceSetIndex, channelIndex, true);
1619 
1620  response.init();
1621  *response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
1622 
1623  return 202;
1624  }
1625  else
1626  {
1627  error.init();
1628  *error.getMessage() = QString("There is no channel at index %1. There are %2 Tx channels")
1629  .arg(channelIndex)
1630  .arg(channelIndex < deviceSet->getNumberOfRxChannels());
1631  return 400;
1632  }
1633  }
1634  else
1635  {
1636  error.init();
1637  *error.getMessage() = QString("DeviceSet error");
1638  return 500;
1639  }
1640  }
1641  else
1642  {
1643  error.init();
1644  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1645  return 404;
1646  }
1647 }
1648 
1650  int deviceSetIndex,
1651  int channelIndex,
1654 {
1655  error.init();
1656 
1657  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1658  {
1659  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1660 
1661  if (deviceSet->m_deviceSourceEngine) // Single Rx
1662  {
1663  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1664 
1665  if (channelAPI == 0)
1666  {
1667  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1668  return 404;
1669  }
1670  else
1671  {
1672  response.setChannelType(new QString());
1673  channelAPI->getIdentifier(*response.getChannelType());
1674  response.setDirection(0);
1675  return channelAPI->webapiSettingsGet(response, *error.getMessage());
1676  }
1677  }
1678  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1679  {
1680  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1681 
1682  if (channelAPI == 0)
1683  {
1684  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1685  return 404;
1686  }
1687  else
1688  {
1689  response.setChannelType(new QString());
1690  channelAPI->getIdentifier(*response.getChannelType());
1691  response.setDirection(1);
1692  return channelAPI->webapiSettingsGet(response, *error.getMessage());
1693  }
1694  }
1695  else
1696  {
1697  *error.getMessage() = QString("DeviceSet error");
1698  return 500;
1699  }
1700  }
1701  else
1702  {
1703  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1704  return 404;
1705  }
1706 }
1707 
1708 
1710  int deviceSetIndex,
1711  int channelIndex,
1714 {
1715  error.init();
1716 
1717  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1718  {
1719  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1720 
1721  if (deviceSet->m_deviceSourceEngine) // Single Rx
1722  {
1723  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1724 
1725  if (channelAPI == 0)
1726  {
1727  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1728  return 404;
1729  }
1730  else
1731  {
1732  response.setChannelType(new QString());
1733  channelAPI->getIdentifier(*response.getChannelType());
1734  response.setDirection(0);
1735  return channelAPI->webapiReportGet(response, *error.getMessage());
1736  }
1737  }
1738  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1739  {
1740  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1741 
1742  if (channelAPI == 0)
1743  {
1744  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1745  return 404;
1746  }
1747  else
1748  {
1749  response.setChannelType(new QString());
1750  channelAPI->getIdentifier(*response.getChannelType());
1751  response.setDirection(1);
1752  return channelAPI->webapiReportGet(response, *error.getMessage());
1753  }
1754  }
1755  else
1756  {
1757  *error.getMessage() = QString("DeviceSet error");
1758  return 500;
1759  }
1760  }
1761  else
1762  {
1763  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1764  return 404;
1765  }
1766 }
1767 
1769  int deviceSetIndex,
1770  int channelIndex,
1771  bool force,
1772  const QStringList& channelSettingsKeys,
1775 {
1776  error.init();
1777 
1778  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
1779  {
1780  DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
1781 
1782  if (deviceSet->m_deviceSourceEngine) // Single Rx
1783  {
1784  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1785 
1786  if (channelAPI == 0)
1787  {
1788  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1789  return 404;
1790  }
1791  else
1792  {
1793  QString channelType;
1794  channelAPI->getIdentifier(channelType);
1795 
1796  if (channelType == *response.getChannelType())
1797  {
1798  return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
1799  }
1800  else
1801  {
1802  *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.")
1803  .arg(*response.getChannelType())
1804  .arg(channelIndex)
1805  .arg(channelType);
1806  return 404;
1807  }
1808  }
1809  }
1810  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1811  {
1812  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1813 
1814  if (channelAPI == 0)
1815  {
1816  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1817  return 404;
1818  }
1819  else
1820  {
1821  QString channelType;
1822  channelAPI->getIdentifier(channelType);
1823 
1824  if (channelType == *response.getChannelType())
1825  {
1826  return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
1827  }
1828  else
1829  {
1830  *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.")
1831  .arg(*response.getChannelType())
1832  .arg(channelIndex)
1833  .arg(channelType);
1834  return 404;
1835  }
1836  }
1837  }
1838  else
1839  {
1840  *error.getMessage() = QString("DeviceSet error");
1841  return 500;
1842  }
1843  }
1844  else
1845  {
1846  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1847  return 404;
1848  }
1849 
1850 }
1851 
1853 {
1854  deviceSetList->init();
1855  deviceSetList->setDevicesetcount((int) m_mainWindow.m_deviceUIs.size());
1856 
1857  if (m_mainWindow.m_deviceUIs.size() > 0) {
1858  deviceSetList->setDevicesetfocus(m_mainWindow.ui->tabInputsView->currentIndex());
1859  }
1860 
1861  std::vector<DeviceUISet*>::const_iterator it = m_mainWindow.m_deviceUIs.begin();
1862 
1863  for (int i = 0; it != m_mainWindow.m_deviceUIs.end(); ++it, i++)
1864  {
1865  QList<SWGSDRangel::SWGDeviceSet*> *deviceSets = deviceSetList->getDeviceSets();
1866  deviceSets->append(new SWGSDRangel::SWGDeviceSet());
1867 
1868  getDeviceSet(deviceSets->back(), *it, i);
1869  }
1870 }
1871 
1872 void WebAPIAdapterGUI::getDeviceSet(SWGSDRangel::SWGDeviceSet *deviceSet, const DeviceUISet* deviceUISet, int deviceUISetIndex)
1873 {
1874  deviceSet->init();
1875  SWGSDRangel::SWGSamplingDevice *samplingDevice = deviceSet->getSamplingDevice();
1876  samplingDevice->init();
1877  samplingDevice->setIndex(deviceUISetIndex);
1878 
1879  if (deviceUISet->m_deviceSinkEngine) // Single Tx data
1880  {
1881  samplingDevice->setDirection(1);
1882  *samplingDevice->getHwType() = deviceUISet->m_deviceAPI->getHardwareId();
1883  *samplingDevice->getSerial() = deviceUISet->m_deviceAPI->getSamplingDeviceSerial();
1884  samplingDevice->setSequence(deviceUISet->m_deviceAPI->getSamplingDeviceSequence());
1885  samplingDevice->setDeviceNbStreams(deviceUISet->m_deviceAPI->getDeviceNbItems());
1886  samplingDevice->setDeviceStreamIndex(deviceUISet->m_deviceAPI->getDeviceItemIndex());
1887  deviceUISet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
1888  DeviceSampleSink *sampleSink = deviceUISet->m_deviceSinkEngine->getSink();
1889 
1890  if (sampleSink) {
1891  samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency());
1892  samplingDevice->setBandwidth(sampleSink->getSampleRate());
1893  }
1894 
1895  deviceSet->setChannelcount(deviceUISet->m_deviceAPI->getNbSourceChannels());
1896  QList<SWGSDRangel::SWGChannel*> *channels = deviceSet->getChannels();
1897 
1898  for (int i = 0; i < deviceSet->getChannelcount(); i++)
1899  {
1900  channels->append(new SWGSDRangel::SWGChannel);
1901  channels->back()->init();
1902  ChannelAPI *channel = deviceUISet->m_deviceAPI->getChanelSourceAPIAt(i);
1903  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
1904  channels->back()->setIndex(channel->getIndexInDeviceSet());
1905  channels->back()->setUid(channel->getUID());
1906  channel->getIdentifier(*channels->back()->getId());
1907  channel->getTitle(*channels->back()->getTitle());
1908  }
1909  }
1910 
1911  if (deviceUISet->m_deviceSourceEngine) // Rx data
1912  {
1913  samplingDevice->setDirection(0);
1914  *samplingDevice->getHwType() = deviceUISet->m_deviceAPI->getHardwareId();
1915  *samplingDevice->getSerial() = deviceUISet->m_deviceAPI->getSamplingDeviceSerial();
1916  samplingDevice->setSequence(deviceUISet->m_deviceAPI->getSamplingDeviceSequence());
1917  samplingDevice->setDeviceNbStreams(deviceUISet->m_deviceAPI->getDeviceNbItems());
1918  samplingDevice->setDeviceStreamIndex(deviceUISet->m_deviceAPI->getDeviceItemIndex());
1919  deviceUISet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
1920  DeviceSampleSource *sampleSource = deviceUISet->m_deviceSourceEngine->getSource();
1921 
1922  if (sampleSource) {
1923  samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency());
1924  samplingDevice->setBandwidth(sampleSource->getSampleRate());
1925  }
1926 
1927  deviceSet->setChannelcount(deviceUISet->m_deviceAPI->getNbSinkChannels());
1928  QList<SWGSDRangel::SWGChannel*> *channels = deviceSet->getChannels();
1929 
1930  for (int i = 0; i < deviceSet->getChannelcount(); i++)
1931  {
1932  channels->append(new SWGSDRangel::SWGChannel);
1933  channels->back()->init();
1934  ChannelAPI *channel = deviceUISet->m_deviceAPI->getChanelSinkAPIAt(i);
1935  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
1936  channels->back()->setIndex(channel->getIndexInDeviceSet());
1937  channels->back()->setUid(channel->getUID());
1938  channel->getIdentifier(*channels->back()->getId());
1939  channel->getTitle(*channels->back()->getTitle());
1940  }
1941  }
1942 }
1943 
1945 {
1946  channelsDetail->init();
1947  SWGSDRangel::SWGChannelReport *channelReport;
1948  QString channelReportError;
1949 
1950  if (deviceUISet->m_deviceSinkEngine) // Tx data
1951  {
1952  channelsDetail->setChannelcount(deviceUISet->m_deviceAPI->getNbSourceChannels());
1953  QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
1954 
1955  for (int i = 0; i < channelsDetail->getChannelcount(); i++)
1956  {
1957  channels->append(new SWGSDRangel::SWGChannel);
1958  channels->back()->init();
1959  ChannelAPI *channel = deviceUISet->m_deviceAPI->getChanelSourceAPIAt(i);
1960  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
1961  channels->back()->setIndex(channel->getIndexInDeviceSet());
1962  channels->back()->setUid(channel->getUID());
1963  channel->getIdentifier(*channels->back()->getId());
1964  channel->getTitle(*channels->back()->getTitle());
1965 
1966  channelReport = new SWGSDRangel::SWGChannelReport();
1967 
1968  if (channel->webapiReportGet(*channelReport, channelReportError) != 501) {
1969  channels->back()->setReport(channelReport);
1970  } else {
1971  delete channelReport;
1972  }
1973  }
1974  }
1975 
1976  if (deviceUISet->m_deviceSourceEngine) // Rx data
1977  {
1978  channelsDetail->setChannelcount(deviceUISet->m_deviceAPI->getNbSinkChannels());
1979  QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
1980 
1981  for (int i = 0; i < channelsDetail->getChannelcount(); i++)
1982  {
1983  channels->append(new SWGSDRangel::SWGChannel);
1984  channels->back()->init();
1985  ChannelAPI *channel = deviceUISet->m_deviceAPI->getChanelSinkAPIAt(i);
1986  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
1987  channels->back()->setIndex(channel->getIndexInDeviceSet());
1988  channels->back()->setUid(channel->getUID());
1989  channel->getIdentifier(*channels->back()->getId());
1990  channel->getTitle(*channels->back()->getTitle());
1991 
1992  channelReport = new SWGSDRangel::SWGChannelReport();
1993 
1994  if (channel->webapiReportGet(*channelReport, channelReportError) != 501) {
1995  channels->back()->setReport(channelReport);
1996  } else {
1997  delete channelReport;
1998  }
1999  }
2000  }
2001 }
2002 
2003 QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
2004 {
2005  if (msgTypeString == "debug") {
2006  return QtDebugMsg;
2007  } else if (msgTypeString == "info") {
2008  return QtInfoMsg;
2009  } else if (msgTypeString == "warning") {
2010  return QtWarningMsg;
2011  } else if (msgTypeString == "error") {
2012  return QtCriticalMsg;
2013  } else {
2014  return QtDebugMsg;
2015  }
2016 }
2017 
2018 void WebAPIAdapterGUI::getMsgTypeString(const QtMsgType& msgType, QString& levelStr)
2019 {
2020  switch (msgType)
2021  {
2022  case QtDebugMsg:
2023  levelStr = "debug";
2024  break;
2025  case QtInfoMsg:
2026  levelStr = "info";
2027  break;
2028  case QtWarningMsg:
2029  levelStr = "warning";
2030  break;
2031  case QtCriticalMsg:
2032  case QtFatalMsg:
2033  levelStr = "error";
2034  break;
2035  default:
2036  levelStr = "debug";
2037  break;
2038  }
2039 }
MessageQueue m_inputMessageQueue
Definition: mainwindow.h:306
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: channelapi.h:59
const QString version
QList< SWGChannel * > * getChannels()
static const QString m_defaultDeviceName
float getLatitude() const
Definition: mainsettings.h:55
static MsgLoadPreset * create(const Preset *preset, int deviceSetIndex)
Definition: mainwindow.h:97
virtual int instanceConfigGet(SWGSDRangel::SWGInstanceConfigResponse &response, SWGSDRangel::SWGErrorResponse &error)
const QList< QAudioDeviceInfo > & getInputDevices() const
DSPEngine * m_dspEngine
Definition: mainwindow.h:312
virtual int instanceAudioInputCleanupPatch(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setDeviceStreamIndex(qint32 device_stream_index)
const QString & getLogFileName() const
Definition: mainsettings.h:65
void setDeviceHwType(QString *device_hw_type)
virtual int instanceAMBEDevicesGet(SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
QList< ChannelRegistration > ChannelRegistrations
Definition: pluginapi.h:44
const QString displayedName
virtual int devicesetDeviceRunPost(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
DeviceSampleSink * getSink()
int sequence
The device sequence. >0 when more than one device of the same type is connected.
Ui::MainWindow * ui
Definition: mainwindow.h:305
QList< SWGDeviceSet * > * getDeviceSets()
void push(Message *message, bool emitSignal=true)
Push message onto queue.
QString displayedName
The human readable name.
bool getUseFileLogger() const
ChannelAPI * getChanelSinkAPIAt(int index, int streamIndex=0)
Definition: deviceapi.cpp:445
DeviceSampleSource * getSampleSource()
Return pointer to the device sample source (single Rx) or nullptr.
Definition: deviceapi.cpp:213
std::vector< DeviceUISet * > m_deviceUIs
Definition: mainwindow.h:308
PluginAPI::ChannelRegistrations * getRxChannelRegistrations()
Definition: pluginmanager.h:74
void setDeviceSetIndex(qint32 device_set_index)
quint64 getCenterFrequency() const
Definition: preset.h:76
virtual int instancePresetPatch(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
void outputInfosCleanup()
Remove output info from map for output devices not present.
void setLoggingOptions()
virtual int instanceAudioGet(SWGSDRangel::SWGAudioDevices &response, SWGSDRangel::SWGErrorResponse &error)
virtual void getIdentifier(QString &id)=0
DeviceSampleSource * getSource()
bool getUseLogFile() const
Definition: mainsettings.h:64
virtual int instanceChannels(int direction, SWGSDRangel::SWGInstanceChannelsResponse &response, SWGSDRangel::SWGErrorResponse &error)
uint32_t getDeviceItemIndex() const
Definition: deviceapi.h:129
QString hardwareId
The internal id that identifies the type of hardware (i.e. HackRF, BladeRF, ...)
static MsgSetDevice * create(int deviceSetIndex, int deviceIndex, bool tx)
Definition: mainwindow.h:202
MainWindow & m_mainWindow
virtual const PluginDescriptor & getPluginDescriptor() const =0
qtwebapp::LoggerWithFile * m_logger
Definition: mainwindow.h:328
void setDirection(qint32 direction)
bool isSourcePreset() const
Definition: preset.h:66
static MsgAddDeviceSet * create(int direction)
Definition: mainwindow.h:165
const MainSettings & getMainSettings() const
Definition: mainwindow.h:83
virtual int instanceAMBESerialGet(SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
void setNbOutputDevices(qint32 nb_output_devices)
virtual int devicesetChannelReportGet(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGChannelReport &response, SWGSDRangel::SWGErrorResponse &error)
uint32_t getDeviceNbItems() const
Definition: deviceapi.h:128
void setDirection(qint32 direction)
void scan(std::vector< QString > &ambeDevices)
Definition: ambeengine.cpp:191
static MsgDeviceSetFocus * create(int deviceSetIndex)
Definition: mainwindow.h:290
QList< SWGAudioInputDevice * > * getInputDevices()
void setChannelType(QString *channel_type)
AudioOutput::UDPChannelCodec udpChannelCodec
void getChannelsDetail(SWGSDRangel::SWGChannelsDetail *channelsDetail, const DeviceUISet *deviceUISet)
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
Definition: channelapi.h:79
PluginAPI::ChannelRegistrations * getTxChannelRegistrations()
Definition: pluginmanager.h:75
DeviceSampleSink * getSampleSink()
Return pointer to the device sample sink (single Tx) or nullptr.
Definition: deviceapi.cpp:222
virtual int instanceAudioInputPatch(SWGSDRangel::SWGAudioInputDevice &response, const QStringList &audioInputKeys, SWGSDRangel::SWGErrorResponse &error)
static MsgRemoveLastDeviceSet * create()
Definition: mainwindow.h:183
bool registerController(const std::string &deviceRef)
create a new controller for the device in reference
Definition: ambeengine.cpp:214
virtual int devicesetChannelSettingsPutPatch(int deviceSetIndex, int channelIndex, bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, SWGSDRangel::SWGErrorResponse &error)
void setConsoleMinLogLevel(const QtMsgType &minLogLevel)
Definition: mainsettings.h:58
Preset * newPreset(const QString &group, const QString &description)
void setCenterFrequency(qint64 center_frequency)
DSPDeviceSourceEngine * m_deviceSourceEngine
Definition: deviceuiset.h:49
void setChannelcount(qint32 channelcount)
virtual int instanceAudioOutputPatch(SWGSDRangel::SWGAudioOutputDevice &response, const QStringList &audioOutputKeys, SWGSDRangel::SWGErrorResponse &error)
static MsgDeletePreset * create(const Preset *preset)
Definition: mainwindow.h:145
QList< SWGPresetGroup * > * getGroups()
Definition: SWGPresets.cpp:113
virtual qint64 getCenterFrequency() const =0
Applies to a default stream.
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
void getDVSerialNames(std::vector< std::string > &deviceNames)
Definition: dspengine.cpp:166
SWGPresetIdentifier * getPreset()
virtual int instanceAMBEDevicesPatch(SWGSDRangel::SWGAMBEDevices &query, SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
WebAPIAdapterGUI(MainWindow &mainWindow)
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual int instanceLoggingPut(SWGSDRangel::SWGLoggingInfo &query, SWGSDRangel::SWGLoggingInfo &response, SWGSDRangel::SWGErrorResponse &error)
virtual int getSampleRate() const =0
Sample rate exposed by the source.
QList< SWGChannel * > * getChannels()
SWGSamplingDevice * getSamplingDevice()
virtual int instanceDeviceSetDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
bool getInputDeviceName(int inputDeviceIndex, QString &deviceName) const
virtual int devicesetDevicePut(int deviceSetIndex, SWGSDRangel::SWGDeviceListItem &query, SWGSDRangel::SWGDeviceListItem &response, SWGSDRangel::SWGErrorResponse &error)
void setUdpAddress(QString *udp_address)
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
void setOutputDeviceInfo(int outputDeviceIndex, const OutputDeviceInfo &deviceInfo)
uint64_t getUID() const
Definition: channelapi.h:93
int getPresetCount() const
Definition: mainsettings.h:30
void setChannelType(QString *channel_type)
virtual int instanceLocationGet(SWGSDRangel::SWGLocationInformation &response, SWGSDRangel::SWGErrorResponse &error)
virtual quint64 getCenterFrequency() const =0
Center frequency exposed by the sink.
AMBEEngine * getAMBEEngine()
Definition: dspengine.h:56
virtual int instanceDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setSampleRate(qint32 sample_rate)
void releaseAll()
Definition: ambeengine.cpp:261
void setNbDevices(qint32 nb_devices)
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: channelapi.h:67
QtMsgType getFileMinLogLevel() const
Definition: mainsettings.h:63
void getDeviceSet(SWGSDRangel::SWGDeviceSet *deviceSet, const DeviceUISet *deviceUISet, int deviceUISetIndex)
virtual int instanceDeviceSetPost(int direction, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setChannelcount(qint32 channelcount)
QList< SWGDVSerialDevice * > * getDvSerialDevices()
int deviceNbItems
Number of items (or streams) in the device. >1 for composite devices.
void setDirection(qint32 direction)
bool getInputDeviceInfo(const QString &deviceName, InputDeviceInfo &deviceInfo) const
void setFileMinLogLevel(const QtMsgType &minLogLevel)
Definition: mainsettings.h:59
Definition: preset.h:28
void inputInfosCleanup()
Remove input info from map for input devices not present.
virtual int devicesetDeviceRunGet(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instancePresetsGet(SWGSDRangel::SWGPresets &response, SWGSDRangel::SWGErrorResponse &error)
int32_t i
Definition: decimators.h:244
static void webapiFormatPreferences(SWGSDRangel::SWGPreferences *apiPreferences, const Preferences &preferences)
void setNbGroups(qint32 nb_groups)
Definition: SWGPresets.cpp:107
void setNbDevices(qint32 nb_devices)
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
void setUdpDecimationFactor(qint32 udp_decimation_factor)
bool getOutputDeviceInfo(const QString &deviceName, OutputDeviceInfo &deviceInfo) const
virtual int devicesetChannelDelete(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setDeviceStreamIndex(qint32 device_stream_index)
virtual int devicesetChannelPost(int deviceSetIndex, SWGSDRangel::SWGChannelSettings &query, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setDVSerialSupport(bool support)
Definition: dspengine.cpp:163
virtual int devicesetDeviceRunDelete(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAMBEDevicesPut(SWGSDRangel::SWGAMBEDevices &query, SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
void setLongitude(float longitude)
Definition: mainsettings.h:54
bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const
virtual int devicesetFocusPatch(int deviceSetIndex, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAudioOutputCleanupPatch(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setNbInputDevices(qint32 nb_input_devices)
#define SDR_TX_SAMP_SZ
Definition: dsptypes.h:38
virtual int instancePresetPut(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
ChannelAPI * getChanelSourceAPIAt(int index, int streamIndex=0)
Definition: deviceapi.cpp:463
float getLongitude() const
Definition: mainsettings.h:56
virtual int devicesetDeviceSettingsPutPatch(int deviceSetIndex, bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, SWGSDRangel::SWGErrorResponse &error)
const QList< QAudioDeviceInfo > & getOutputDevices() const
void unsetInputDeviceInfo(int inputDeviceIndex)
int claimed
This is the device set index if claimed else -1.
virtual int instanceDVSerialPatch(bool dvserial, SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
DSPDeviceSinkEngine * m_deviceSinkEngine
Definition: deviceuiset.h:50
virtual int devicesetDeviceSettingsGet(int deviceSetIndex, SWGSDRangel::SWGDeviceSettings &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAudioOutputDelete(SWGSDRangel::SWGAudioOutputDevice &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instancePresetPost(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
void setDeviceNbStreams(qint32 device_nb_streams)
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
const Preset * getPreset(int index) const
Definition: mainsettings.h:31
void setDeviceNbStreams(qint32 device_nb_streams)
QString serial
The device serial number defined by the vendor or a fake one (SDRplay)
void getDeviceEngineStateStr(QString &state)
Definition: deviceapi.cpp:389
virtual void getTitle(QString &title)=0
void setUdpChannelCodec(qint32 udp_channel_codec)
void setUseLogFile(bool useLogFile)
Definition: mainsettings.h:60
const QString & getSamplingDeviceSerial() const
Definition: deviceapi.h:121
int getNbRxSamplingDevices() const
AudioDeviceManager * getAudioDeviceManager()
Definition: dspengine.h:55
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
AudioOutput::UDPChannelMode udpChannelMode
virtual int devicesetDeviceReportGet(int deviceSetIndex, SWGSDRangel::SWGDeviceReport &response, SWGSDRangel::SWGErrorResponse &error)
void getFileMinMessageLevelStr(QString &levelStr)
static MsgAddChannel * create(int deviceSetIndex, int channelRegistrationIndex, bool tx)
Definition: mainwindow.h:228
virtual int devicesetChannelSettingsGet(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGChannelSettings &response, SWGSDRangel::SWGErrorResponse &error)
MainSettings m_settings
Definition: mainwindow.h:307
const PluginInterface::SamplingDevice * getTxSamplingDevice(int deviceIndex) const
const Preferences & getPreferences() const
Definition: mainsettings.h:26
const QString & getHardwareId() const
Definition: deviceapi.h:119
static void getMsgTypeString(const QtMsgType &msgType, QString &level)
void getDeviceSetList(SWGSDRangel::SWGDeviceSetList *deviceSetList)
QList< SWGAudioOutputDevice * > * getOutputDevices()
virtual int instanceLocationPut(SWGSDRangel::SWGLocationInformation &response, SWGSDRangel::SWGErrorResponse &error)
QList< SWGAMBEDevice * > * getAmbeDevices()
int getNbSourceChannels() const
Definition: deviceapi.h:143
static QtMsgType getMsgTypeFromString(const QString &msgTypeString)
void setDevicesetcount(qint32 devicesetcount)
void setInputDeviceInfo(int inputDeviceIndex, const InputDeviceInfo &deviceInfo)
void setLatitude(float latitude)
Definition: mainsettings.h:53
const PluginInterface::SamplingDevice * getRxSamplingDevice(int deviceIndex) const
virtual int instanceDVSerialGet(SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
void setDevicesetfocus(qint32 devicesetfocus)
void getConsoleMinMessageLevelStr(QString &levelStr)
StreamType streamType
This is the type of stream supported.
virtual int instanceDevices(int direction, SWGSDRangel::SWGInstanceDevicesResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int getSampleRate() const =0
Sample rate exposed by the sink.
void setCenterFrequency(qint64 center_frequency)
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
static MsgSavePreset * create(Preset *preset, int deviceSetIndex, bool newPreset)
Definition: mainwindow.h:121
virtual int instanceAudioInputDelete(SWGSDRangel::SWGAudioInputDevice &response, SWGSDRangel::SWGErrorResponse &error)
QtMsgType getConsoleMinLogLevel() const
Definition: mainsettings.h:62
static void webapiFormatPreset(SWGSDRangel::SWGPreset *apiPreset, const Preset &preset)
void setUdpUsesRtp(qint32 udp_uses_rtp)
const QString & getDescription() const
Definition: preset.h:74
int getIndexInDeviceSet() const
Definition: channelapi.h:87
virtual int instanceSummary(SWGSDRangel::SWGInstanceSummaryResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual ~WebAPIAdapterGUI()
PluginManager * m_pluginManager
Definition: mainwindow.h:313
virtual quint64 getCenterFrequency() const =0
Center frequency exposed by the source.
void setBandwidth(qint32 bandwidth)
static DeviceEnumerator * instance()
virtual int instancePresetDelete(SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
uint32_t getSamplingDeviceSequence() const
Definition: deviceapi.h:123
int deviceItemIndex
For composite devices this is the Rx or Tx stream index. -1 if not initialized.
void setDirection(qint32 direction)
void setDirection(qint32 direction)
void getLogFileName(QString &fileName)
virtual int instanceAMBEDevicesDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int devicesetGet(int deviceSetIndex, SWGSDRangel::SWGDeviceSet &response, SWGSDRangel::SWGErrorResponse &error)
const Preset & getWorkingPresetConst() const
Definition: mainsettings.h:46
virtual int devicesetChannelsReportGet(int deviceSetIndex, SWGSDRangel::SWGChannelsDetail &response, SWGSDRangel::SWGErrorResponse &error)
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
const QString & getGroup() const
Definition: preset.h:72
void setDeviceHwType(QString *device_hw_type)
void releaseController(const std::string &deviceRef)
release controller resources for the device in reference
Definition: ambeengine.cpp:239
void setLogFileName(const QString &value)
Definition: mainsettings.h:61
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
int getNbTxSamplingDevices() const
void setDumpToFile(qint32 dump_to_file)
static MsgDeleteChannel * create(int deviceSetIndex, int channelIndex, bool tx)
Definition: mainwindow.h:254
virtual int instanceLoggingGet(SWGSDRangel::SWGLoggingInfo &response, SWGSDRangel::SWGErrorResponse &error)
void setUdpChannelMode(qint32 udp_channel_mode)
virtual int instanceDeviceSetsGet(SWGSDRangel::SWGDeviceSetList &response, SWGSDRangel::SWGErrorResponse &error)
int getNbSinkChannels() const
Definition: deviceapi.h:144