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.
webapiadaptersrv.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 <QCoreApplication>
21 #include <QList>
22 #include <QTextStream>
23 #include <QSysInfo>
24 
29 #include "SWGLoggingInfo.h"
30 #include "SWGAudioDevices.h"
31 #include "SWGLocationInformation.h"
32 #include "SWGDVSerialDevices.h"
33 #include "SWGAMBEDevices.h"
34 #include "SWGPresetImport.h"
35 #include "SWGPresetExport.h"
36 #include "SWGPresets.h"
37 #include "SWGPresetTransfer.h"
38 #include "SWGDeviceSettings.h"
39 #include "SWGChannelsDetail.h"
40 #include "SWGChannelSettings.h"
41 #include "SWGChannelReport.h"
42 #include "SWGSuccessResponse.h"
43 #include "SWGErrorResponse.h"
44 #include "SWGDeviceState.h"
45 #include "SWGDeviceReport.h"
46 
47 #include "maincore.h"
48 #include "loggerwithfile.h"
49 #include "device/deviceset.h"
50 #include "device/deviceapi.h"
52 #include "dsp/devicesamplesink.h"
53 #include "dsp/devicesamplesource.h"
56 #include "dsp/dspengine.h"
57 #include "channel/channelapi.h"
58 #include "plugin/pluginapi.h"
59 #include "plugin/pluginmanager.h"
61 #include "webapiadaptersrv.h"
62 
64  m_mainCore(mainCore)
65 {
66 }
67 
69 {
70 }
71 
75 {
76  response.init();
77  *response.getAppname() = QCoreApplication::applicationName();
78  *response.getVersion() = QCoreApplication::applicationVersion();
79  *response.getQtVersion() = QString(QT_VERSION_STR);
80  response.setDspRxBits(SDR_RX_SAMP_SZ);
81  response.setDspTxBits(SDR_TX_SAMP_SZ);
82  response.setPid(QCoreApplication::applicationPid());
83 #if QT_VERSION >= 0x050400
84  *response.getArchitecture() = QString(QSysInfo::currentCpuArchitecture());
85  *response.getOs() = QString(QSysInfo::prettyProductName());
86 #endif
87 
88  SWGSDRangel::SWGLoggingInfo *logging = response.getLogging();
89  logging->init();
91 
92  if (logging->getDumpToFile()) {
95  }
96 
98 
99  SWGSDRangel::SWGDeviceSetList *deviceSetList = response.getDevicesetlist();
100  getDeviceSetList(deviceSetList);
101 
102  return 200;
103 }
104 
108 {
111 
112  response.init();
113  *response.getMessage() = QString("Message to stop the SDRangel instance (MsgDeleteInstance) was submitted successfully");
114 
115  return 202;
116 }
117 
121 {
122  response.init();
123  SWGSDRangel::SWGPreferences *preferences = response.getPreferences();
125  SWGSDRangel::SWGPreset *workingPreset = response.getWorkingPreset();
127 
128  int nbPresets = m_mainCore.m_settings.getPresetCount();
129  QList<SWGSDRangel::SWGPreset*> *swgPresets = response.getPresets();
130 
131  for (int i = 0; i < nbPresets; i++)
132  {
133  const Preset *preset = m_mainCore.m_settings.getPreset(i);
134  swgPresets->append(new SWGSDRangel::SWGPreset);
135  WebAPIAdapterBase::webapiFormatPreset(swgPresets->back(), *preset);
136  }
137 
138  return 200;
139 }
140 
142  int direction,
145 {
146  response.init();
147 
148  int nbSamplingDevices;
149 
150  if (direction == 0) { // Single Rx stream device
151  nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
152  } else if (direction == 1) { // Single Tx stream device
153  nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
154  } else { // not supported
155  nbSamplingDevices = 0;
156  }
157 
158 
159  response.setDevicecount(nbSamplingDevices);
160  QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices();
161 
162  for (int i = 0; i < nbSamplingDevices; i++)
163  {
164  const PluginInterface::SamplingDevice *samplingDevice = nullptr;
165 
166  if (direction == 0) {
167  samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
168  } else if (direction == 1) {
169  samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
170  } else {
171  continue;
172  }
173 
174  devices->append(new SWGSDRangel::SWGDeviceListItem);
175  devices->back()->init();
176  *devices->back()->getDisplayedName() = samplingDevice->displayedName;
177  *devices->back()->getHwType() = samplingDevice->hardwareId;
178  *devices->back()->getSerial() = samplingDevice->serial;
179  devices->back()->setSequence(samplingDevice->sequence);
180  devices->back()->setDirection((int) samplingDevice->streamType);
181  devices->back()->setDeviceNbStreams(samplingDevice->deviceNbItems);
182  devices->back()->setDeviceSetIndex(samplingDevice->claimed);
183  devices->back()->setIndex(i);
184  }
185 
186  return 200;
187 }
188 
190  int direction,
193 {
194  response.init();
195  PluginAPI::ChannelRegistrations *channelRegistrations;
196  int nbChannelDevices;
197 
198  if (direction == 0) // Single sink (Rx) channel
199  {
200  channelRegistrations = m_mainCore.m_pluginManager->getRxChannelRegistrations();
201  nbChannelDevices = channelRegistrations->size();
202  }
203  else if (direction == 1) // Single source (Tx) channel
204  {
205  channelRegistrations = m_mainCore.m_pluginManager->getTxChannelRegistrations();
206  nbChannelDevices = channelRegistrations->size();
207  }
208  else // not supported
209  {
210  channelRegistrations = nullptr;
211  nbChannelDevices = 0;
212  }
213 
214  response.setChannelcount(nbChannelDevices);
215  QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels();
216 
217  for (int i = 0; i < nbChannelDevices; i++)
218  {
219  channels->append(new SWGSDRangel::SWGChannelListItem);
220  channels->back()->init();
221  PluginInterface *channelInterface = channelRegistrations->at(i).m_plugin;
222  const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor();
223  *channels->back()->getVersion() = pluginDescriptor.version;
224  *channels->back()->getName() = pluginDescriptor.displayedName;
225  channels->back()->setDirection(direction);
226  *channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI;
227  *channels->back()->getId() = channelRegistrations->at(i).m_channelId;
228  channels->back()->setIndex(i);
229  }
230 
231  return 200;
232 }
233 
235  SWGSDRangel::SWGLoggingInfo& response,
237 {
238  response.init();
239  response.setDumpToFile(m_mainCore.m_logger->getUseFileLogger() ? 1 : 0);
240 
241  if (response.getDumpToFile()) {
244  }
245 
247 
248  return 200;
249 }
250 
253  SWGSDRangel::SWGLoggingInfo& response,
255 {
256  // response input is the query actually
257  bool dumpToFile = (query.getDumpToFile() != 0);
258  QString* consoleLevel = query.getConsoleLevel();
259  QString* fileLevel = query.getFileLevel();
260  QString* fileName = query.getFileName();
261 
262  // perform actions
263  if (consoleLevel) {
265  }
266 
267  if (fileLevel) {
269  }
270 
271  m_mainCore.m_settings.setUseLogFile(dumpToFile);
272 
273  if (fileName) {
275  }
276 
278 
279  // build response
280  response.init();
282  response.setDumpToFile(m_mainCore.m_settings.getUseLogFile() ? 1 : 0);
285 
286  return 200;
287 }
288 
292 {
293  const QList<QAudioDeviceInfo>& audioInputDevices = m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDevices();
294  const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDevices();
295  int nbInputDevices = audioInputDevices.size();
296  int nbOutputDevices = audioOutputDevices.size();
297 
298  response.init();
299  response.setNbInputDevices(nbInputDevices);
300  response.setNbOutputDevices(nbOutputDevices);
301  QList<SWGSDRangel::SWGAudioInputDevice*> *inputDevices = response.getInputDevices();
302  QList<SWGSDRangel::SWGAudioOutputDevice*> *outputDevices = response.getOutputDevices();
303  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
304  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
305 
306  // system default input device
307  inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
308  inputDevices->back()->init();
310  *inputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
311  inputDevices->back()->setIndex(-1);
312  inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
313  inputDevices->back()->setIsSystemDefault(0);
314  inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
315  inputDevices->back()->setVolume(inputDeviceInfo.volume);
316 
317  // real input devices
318  for (int i = 0; i < nbInputDevices; i++)
319  {
320  inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
321  inputDevices->back()->init();
322  inputDeviceInfo.resetToDefaults();
323  found = m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(audioInputDevices.at(i).deviceName(), inputDeviceInfo);
324  *inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
325  inputDevices->back()->setIndex(i);
326  inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
327  inputDevices->back()->setIsSystemDefault(audioInputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultInputDevice().deviceName() ? 1 : 0);
328  inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
329  inputDevices->back()->setVolume(inputDeviceInfo.volume);
330  }
331 
332  // system default output device
333  outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
334  outputDevices->back()->init();
336  *outputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
337  outputDevices->back()->setIndex(-1);
338  outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
339  inputDevices->back()->setIsSystemDefault(0);
340  outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
341  outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
342  outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
343  outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
344  outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec);
345  outputDevices->back()->setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
346  *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
347  outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
348 
349  // real output devices
350  for (int i = 0; i < nbOutputDevices; i++)
351  {
352  outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
353  outputDevices->back()->init();
354  outputDeviceInfo.resetToDefaults();
355  found = m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(audioOutputDevices.at(i).deviceName(), outputDeviceInfo);
356  *outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
357  outputDevices->back()->setIndex(i);
358  outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
359  outputDevices->back()->setIsSystemDefault(audioOutputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultOutputDevice().deviceName() ? 1 : 0);
360  outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
361  outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
362  outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
363  outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
364  outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec);
365  outputDevices->back()->setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
366  *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
367  outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
368  }
369 
370  return 200;
371 }
372 
375  const QStringList& audioInputKeys,
377 {
378  // TODO
379  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
380  QString deviceName;
381  int deviceIndex = response.getIndex();
382 
383  if (!m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
384  {
385  error.init();
386  *error.getMessage() = QString("There is no input audio device at index %1").arg(deviceIndex);
387  return 404;
388  }
389 
390  m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
391 
392  if (audioInputKeys.contains("sampleRate")) {
393  inputDeviceInfo.sampleRate = response.getSampleRate();
394  }
395  if (audioInputKeys.contains("volume")) {
396  inputDeviceInfo.volume = response.getVolume();
397  }
398 
399  m_mainCore.m_dspEngine->getAudioDeviceManager()->setInputDeviceInfo(deviceIndex, inputDeviceInfo);
400  m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
401 
402  response.setSampleRate(inputDeviceInfo.sampleRate);
403  response.setVolume(inputDeviceInfo.volume);
404 
405  return 200;
406 }
407 
410  const QStringList& audioOutputKeys,
412 {
413  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
414  QString deviceName;
415  int deviceIndex = response.getIndex();
416 
417  if (!m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
418  {
419  error.init();
420  *error.getMessage() = QString("There is no output audio device at index %1").arg(deviceIndex);
421  return 404;
422  }
423 
424  m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
425 
426  if (audioOutputKeys.contains("sampleRate")) {
427  outputDeviceInfo.sampleRate = response.getSampleRate();
428  }
429  if (audioOutputKeys.contains("copyToUDP")) {
430  outputDeviceInfo.copyToUDP = response.getCopyToUdp() == 0 ? 0 : 1;
431  }
432  if (audioOutputKeys.contains("udpUsesRTP")) {
433  outputDeviceInfo.udpUseRTP = response.getUdpUsesRtp() == 0 ? 0 : 1;
434  }
435  if (audioOutputKeys.contains("udpChannelMode")) {
436  outputDeviceInfo.udpChannelMode = static_cast<AudioOutput::UDPChannelMode>(response.getUdpChannelMode() % 4);
437  }
438  if (audioOutputKeys.contains("udpAddress")) {
439  outputDeviceInfo.udpAddress = *response.getUdpAddress();
440  }
441  if (audioOutputKeys.contains("udpPort")) {
442  outputDeviceInfo.udpPort = response.getUdpPort() % (1<<16);
443  }
444 
445  m_mainCore.m_dspEngine->getAudioDeviceManager()->setOutputDeviceInfo(deviceIndex, outputDeviceInfo);
446  m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
447 
448  response.setSampleRate(outputDeviceInfo.sampleRate);
449  response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
450  response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
451  response.setUdpChannelMode(outputDeviceInfo.udpChannelMode);
452  response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec);
453  response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
454 
455  if (response.getUdpAddress()) {
456  *response.getUdpAddress() = outputDeviceInfo.udpAddress;
457  } else {
458  response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
459  }
460 
461  response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
462 
463  return 200;
464 }
465 
469 {
470  AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
471  QString deviceName;
472  int deviceIndex = response.getIndex();
473 
474  if (!m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
475  {
476  error.init();
477  *error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
478  return 404;
479  }
480 
482  m_mainCore.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
483 
484  response.setSampleRate(inputDeviceInfo.sampleRate);
485  response.setVolume(inputDeviceInfo.volume);
486 
487  return 200;
488 }
489 
493 {
494  AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
495  QString deviceName;
496  int deviceIndex = response.getIndex();
497 
498  if (!m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
499  {
500  error.init();
501  *error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
502  return 404;
503  }
504 
506  m_mainCore.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
507 
508  response.setSampleRate(outputDeviceInfo.sampleRate);
509  response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
510  response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
511  response.setUdpChannelMode(outputDeviceInfo.udpChannelMode);
512  response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec);
513  response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor);
514 
515  if (response.getUdpAddress()) {
516  *response.getUdpAddress() = outputDeviceInfo.udpAddress;
517  } else {
518  response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
519  }
520 
521  response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
522 
523  return 200;
524 }
525 
529 {
531 
532  response.init();
533  *response.getMessage() = QString("Unregistered parameters for devices not in list of available input devices for this instance");
534 
535  return 200;
536 }
537 
541 {
543 
544  response.init();
545  *response.getMessage() = QString("Unregistered parameters for devices not in list of available output devices for this instance");
546 
547  return 200;
548 }
549 
553 {
554  response.init();
557 
558  return 200;
559 }
560 
564 {
565  float latitude = response.getLatitude();
566  float longitude = response.getLongitude();
567 
568  latitude = latitude < -90.0 ? -90.0 : latitude > 90.0 ? 90.0 : latitude;
569  longitude = longitude < -180.0 ? -180.0 : longitude > 180.0 ? 180.0 : longitude;
570 
573 
576 
577  return 200;
578 }
579 
583 {
584  response.init();
585 
586  std::vector<std::string> deviceNames;
588  response.setNbDevices((int) deviceNames.size());
589  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
590 
591  std::vector<std::string>::iterator it = deviceNames.begin();
592 
593  while (it != deviceNames.end())
594  {
595  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
596  deviceNamesList->back()->init();
597  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
598  ++it;
599  }
600 
601  return 200;
602 }
603 
605  bool dvserial,
608 {
610  response.init();
611 
612  if (dvserial)
613  {
614  std::vector<std::string> deviceNames;
616  response.setNbDevices((int) deviceNames.size());
617  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
618 
619  std::vector<std::string>::iterator it = deviceNames.begin();
620  std::string deviceNamesStr = "DV Serial devices found: ";
621 
622  while (it != deviceNames.end())
623  {
624  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
625  deviceNamesList->back()->init();
626  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
627  ++it;
628  }
629  }
630  else
631  {
632  response.setNbDevices(0);
633  }
634 
635  return 200;
636 }
637 
641 {
642  (void) error;
643  response.init();
644 
645  std::vector<std::string> deviceNames;
646  std::vector<QString> qDeviceNames;
647  m_mainCore.m_dspEngine->getAMBEEngine()->scan(qDeviceNames);
648 
649  for (std::vector<QString>::const_iterator it = qDeviceNames.begin(); it != qDeviceNames.end(); ++it) {
650  deviceNames.push_back(it->toStdString());
651  }
652 
653  response.setNbDevices((int) deviceNames.size());
654  QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
655 
656  std::vector<std::string>::iterator it = deviceNames.begin();
657 
658  while (it != deviceNames.end())
659  {
660  deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
661  deviceNamesList->back()->init();
662  *deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
663  ++it;
664  }
665 
666  return 200;
667 }
668 
670  SWGSDRangel::SWGAMBEDevices& response,
672 {
673  (void) error;
674  response.init();
675 
676  std::vector<std::string> deviceNames;
678  response.setNbDevices((int) deviceNames.size());
679  QList<SWGSDRangel::SWGAMBEDevice*> *deviceNamesList = response.getAmbeDevices();
680 
681  std::vector<std::string>::iterator it = deviceNames.begin();
682 
683  while (it != deviceNames.end())
684  {
685  deviceNamesList->append(new SWGSDRangel::SWGAMBEDevice);
686  deviceNamesList->back()->init();
687  *deviceNamesList->back()->getDeviceRef() = QString::fromStdString(*it);
688  deviceNamesList->back()->setDelete(0);
689  ++it;
690  }
691 
692  return 200;
693 }
694 
698 {
699  (void) error;
701 
702  response.init();
703  *response.getMessage() = QString("All AMBE devices released");
704 
705  return 200;
706 }
707 
710  SWGSDRangel::SWGAMBEDevices& response,
712 {
714 
715  QList<SWGSDRangel::SWGAMBEDevice *> *ambeList = query.getAmbeDevices();
716 
717  for (QList<SWGSDRangel::SWGAMBEDevice *>::const_iterator it = ambeList->begin(); it != ambeList->end(); ++it) {
718  m_mainCore.m_dspEngine->getAMBEEngine()->registerController((*it)->getDeviceRef()->toStdString());
719  }
720 
721  instanceAMBEDevicesGet(response, error);
722  return 200;
723 }
724 
727  SWGSDRangel::SWGAMBEDevices& response,
729 {
730  QList<SWGSDRangel::SWGAMBEDevice *> *ambeList = query.getAmbeDevices();
731 
732  for (QList<SWGSDRangel::SWGAMBEDevice *>::const_iterator it = ambeList->begin(); it != ambeList->end(); ++it)
733  {
734  if ((*it)->getDelete()) {
735  m_mainCore.m_dspEngine->getAMBEEngine()->releaseController((*it)->getDeviceRef()->toStdString());
736  } else {
737  m_mainCore.m_dspEngine->getAMBEEngine()->registerController((*it)->getDeviceRef()->toStdString());
738  }
739  }
740 
741  instanceAMBEDevicesGet(response, error);
742  return 200;
743 }
744 
749 {
750  const QString& fileName = *query.getFilePath();
751 
752  if (fileName != "")
753  {
754  QFile exportFile(fileName);
755 
756  if (exportFile.open(QIODevice::ReadOnly | QIODevice::Text))
757  {
758  QByteArray base64Str;
759  QTextStream instream(&exportFile);
760  instream >> base64Str;
761  exportFile.close();
762 
763  Preset* preset = m_mainCore.m_settings.newPreset("", "");
764  preset->deserialize(QByteArray::fromBase64(base64Str));
765 
766  if (query.getGroupName() && (query.getGroupName()->size() > 0)) {
767  preset->setGroup(*query.getGroupName());
768  }
769 
770  if (query.getDescription() && (query.getDescription()->size() > 0)) {
771  preset->setDescription(*query.getDescription());
772  }
773 
774  response.init();
775  response.setCenterFrequency(preset->getCenterFrequency());
776  *response.getGroupName() = preset->getGroup();
777  *response.getType() = preset->isSourcePreset() ? "R" : "T";
778  *response.getName() = preset->getDescription();
779 
780  return 200;
781  }
782  else
783  {
784  error.init();
785  *error.getMessage() = QString("File %1 not found or not readable").arg(fileName);
786  return 404;
787  }
788  }
789  else
790  {
791  error.init();
792  *error.getMessage() = QString("Empty file path");
793  return 404;
794  }
795 }
796 
801 {
802  QString filePath = *query.getFilePath();
803  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
804 
805  const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
806  presetIdentifier->getCenterFrequency(),
807  *presetIdentifier->getName(),
808  *presetIdentifier->getType());
809 
810  if (selectedPreset == 0)
811  {
812  error.init();
813  *error.getMessage() = QString("There is no preset [%1, %2, %3, %4]")
814  .arg(*presetIdentifier->getGroupName())
815  .arg(presetIdentifier->getCenterFrequency())
816  .arg(*presetIdentifier->getName())
817  .arg(*presetIdentifier->getType());
818  return 404;
819  }
820 
821  QString base64Str = selectedPreset->serialize().toBase64();
822 
823  if (filePath != "")
824  {
825  QFileInfo fileInfo(filePath);
826 
827  if (fileInfo.suffix() != "prex") {
828  filePath += ".prex";
829  }
830 
831  QFile exportFile(filePath);
832 
833  if (exportFile.open(QIODevice::WriteOnly | QIODevice::Text))
834  {
835  QTextStream outstream(&exportFile);
836  outstream << base64Str;
837  exportFile.close();
838 
839  response.init();
840  response.setCenterFrequency(selectedPreset->getCenterFrequency());
841  *response.getGroupName() = selectedPreset->getGroup();
842  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
843  *response.getName() = selectedPreset->getDescription();
844 
845  return 200;
846  }
847  else
848  {
849  error.init();
850  *error.getMessage() = QString("File %1 cannot be written").arg(filePath);
851  return 404;
852  }
853  }
854  else
855  {
856  error.init();
857  *error.getMessage() = QString("Empty file path");
858  return 404;
859  }
860 }
861 
863  SWGSDRangel::SWGPresets& response,
865 {
866  int nbPresets = m_mainCore.m_settings.getPresetCount();
867  int nbGroups = 0;
868  int nbPresetsThisGroup = 0;
869  QString groupName;
870  response.init();
871  QList<SWGSDRangel::SWGPresetGroup*> *groups = response.getGroups();
872  QList<SWGSDRangel::SWGPresetItem*> *swgPresets = 0;
873  int i = 0;
874 
875  // Presets are sorted by group first
876 
877  for (; i < nbPresets; i++)
878  {
879  const Preset *preset = m_mainCore.m_settings.getPreset(i);
880 
881  if ((i == 0) || (groupName != preset->getGroup())) // new group
882  {
883  if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
884  groups->append(new SWGSDRangel::SWGPresetGroup);
885  groups->back()->init();
886  groupName = preset->getGroup();
887  *groups->back()->getGroupName() = groupName;
888  swgPresets = groups->back()->getPresets();
889  nbGroups++;
890  nbPresetsThisGroup = 0;
891  }
892 
893  swgPresets->append(new SWGSDRangel::SWGPresetItem);
894  swgPresets->back()->init();
895  swgPresets->back()->setCenterFrequency(preset->getCenterFrequency());
896  *swgPresets->back()->getType() = preset->isSourcePreset() ? "R" : "T";
897  *swgPresets->back()->getName() = preset->getDescription();
898  nbPresetsThisGroup++;
899  }
900 
901  if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
902  response.setNbGroups(nbGroups);
903 
904  return 200;
905 }
906 
911 {
912  int deviceSetIndex = query.getDeviceSetIndex();
913  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
914  int nbDeviceSets = m_mainCore.m_deviceSets.size();
915 
916  if (deviceSetIndex >= nbDeviceSets)
917  {
918  error.init();
919  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
920  return 404;
921  }
922 
923  const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
924  presetIdentifier->getCenterFrequency(),
925  *presetIdentifier->getName(),
926  *presetIdentifier->getType());
927 
928  if (selectedPreset == 0)
929  {
930  error.init();
931  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
932  .arg(*presetIdentifier->getGroupName())
933  .arg(presetIdentifier->getCenterFrequency())
934  .arg(*presetIdentifier->getName())
935  .arg(*presetIdentifier->getType());
936  return 404;
937  }
938 
939  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
940 
941  if (deviceSet->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
942  {
943  error.init();
944  *error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
945  return 404;
946  }
947 
948  if (deviceSet->m_deviceSinkEngine && selectedPreset->isSourcePreset())
949  {
950  error.init();
951  *error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
952  return 404;
953  }
954 
955  MainCore::MsgLoadPreset *msg = MainCore::MsgLoadPreset::create(selectedPreset, deviceSetIndex);
957 
958  response.init();
959  response.setCenterFrequency(selectedPreset->getCenterFrequency());
960  *response.getGroupName() = selectedPreset->getGroup();
961  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
962  *response.getName() = selectedPreset->getDescription();
963 
964  return 202;
965 }
966 
971 {
972  int deviceSetIndex = query.getDeviceSetIndex();
973  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
974  int nbDeviceSets = m_mainCore.m_deviceSets.size();
975 
976  if (deviceSetIndex >= nbDeviceSets)
977  {
978  error.init();
979  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
980  return 404;
981  }
982 
983  const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
984  presetIdentifier->getCenterFrequency(),
985  *presetIdentifier->getName(),
986  *presetIdentifier->getType());
987 
988  if (selectedPreset == 0)
989  {
990  error.init();
991  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
992  .arg(*presetIdentifier->getGroupName())
993  .arg(presetIdentifier->getCenterFrequency())
994  .arg(*presetIdentifier->getName())
995  .arg(*presetIdentifier->getType());
996  return 404;
997  }
998  else // update existing preset
999  {
1000  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1001 
1002  if (deviceSet->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
1003  {
1004  error.init();
1005  *error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
1006  return 404;
1007  }
1008 
1009  if (deviceSet->m_deviceSinkEngine && selectedPreset->isSourcePreset())
1010  {
1011  error.init();
1012  *error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
1013  return 404;
1014  }
1015  }
1016 
1017  MainCore::MsgSavePreset *msg = MainCore::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, false);
1019 
1020  response.init();
1021  response.setCenterFrequency(selectedPreset->getCenterFrequency());
1022  *response.getGroupName() = selectedPreset->getGroup();
1023  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
1024  *response.getName() = selectedPreset->getDescription();
1025 
1026  return 202;
1027 }
1028 
1033 {
1034  int deviceSetIndex = query.getDeviceSetIndex();
1035  SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
1036  int nbDeviceSets = m_mainCore.m_deviceSets.size();
1037 
1038  if (deviceSetIndex >= nbDeviceSets)
1039  {
1040  error.init();
1041  *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
1042  return 404;
1043  }
1044 
1045  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1046  int deviceCenterFrequency = 0;
1047  bool isSourcePreset;
1048 
1049  if (deviceSet->m_deviceSourceEngine) { // Rx
1050  deviceCenterFrequency = deviceSet->m_deviceSourceEngine->getSource()->getCenterFrequency();
1051  isSourcePreset = true;
1052  } else if (deviceSet->m_deviceSinkEngine) { // Tx
1053  deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency();
1054  isSourcePreset = false;
1055  } else {
1056  error.init();
1057  *error.getMessage() = QString("Device set error");
1058  return 500;
1059  }
1060 
1061  const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
1062  deviceCenterFrequency,
1063  *presetIdentifier->getName(),
1064  *presetIdentifier->getType());
1065 
1066  if (selectedPreset == 0) // save on a new preset
1067  {
1068  selectedPreset = m_mainCore.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
1069  }
1070  else
1071  {
1072  error.init();
1073  *error.getMessage() = QString("Preset already exists [%1, %2, %3 %4]")
1074  .arg(*presetIdentifier->getGroupName())
1075  .arg(deviceCenterFrequency)
1076  .arg(*presetIdentifier->getName())
1077  .arg(*presetIdentifier->getType());
1078  return 409;
1079  }
1080 
1081  MainCore::MsgSavePreset *msg = MainCore::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, true);
1083 
1084  response.init();
1085  response.setCenterFrequency(deviceCenterFrequency);
1086  *response.getGroupName() = selectedPreset->getGroup();
1087  *response.getType() = isSourcePreset ? "R" : "T";
1088  *response.getName() = selectedPreset->getDescription();
1089 
1090  return 202;
1091 }
1092 
1096 {
1097  const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*response.getGroupName(),
1098  response.getCenterFrequency(),
1099  *response.getName(),
1100  *response.getType());
1101 
1102  if (selectedPreset == 0)
1103  {
1104  error.init();
1105  *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
1106  .arg(*response.getGroupName())
1107  .arg(response.getCenterFrequency())
1108  .arg(*response.getName())
1109  .arg(*response.getType());
1110  return 404;
1111  }
1112 
1113  response.setCenterFrequency(selectedPreset->getCenterFrequency());
1114  *response.getGroupName() = selectedPreset->getGroup();
1115  *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
1116  *response.getName() = selectedPreset->getDescription();
1117 
1118  MainCore::MsgDeletePreset *msg = MainCore::MsgDeletePreset::create(const_cast<Preset*>(selectedPreset));
1120 
1121  return 202;
1122 }
1123 
1127 {
1128  getDeviceSetList(&response);
1129  return 200;
1130 }
1131 
1133  int direction,
1136 {
1139 
1140  response.init();
1141  *response.getMessage() = QString("Message to add a new device set (MsgAddDeviceSet) was submitted successfully");
1142 
1143  return 202;
1144 }
1145 
1149 {
1150  if (m_mainCore.m_deviceSets.size() > 0)
1151  {
1154 
1155  response.init();
1156  *response.getMessage() = QString("Message to remove last device set (MsgRemoveLastDeviceSet) was submitted successfully");
1157 
1158  return 202;
1159  }
1160  else
1161  {
1162  error.init();
1163  *error.getMessage() = "No more device sets to be removed";
1164 
1165  return 404;
1166  }
1167 }
1168 
1170  int deviceSetIndex,
1171  SWGSDRangel::SWGDeviceSet& response,
1173 {
1174  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1175  {
1176  const DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1177  getDeviceSet(&response, deviceSet, deviceSetIndex);
1178 
1179  return 200;
1180  }
1181  else
1182  {
1183  error.init();
1184  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1185 
1186  return 404;
1187  }
1188 }
1189 
1191  int deviceSetIndex,
1194 {
1195  *error.getMessage() = QString("Not supported in server instance");
1196  return 400;
1197 }
1198 
1200  int deviceSetIndex,
1204 {
1205  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1206  {
1207  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1208 
1209  if ((query.getDirection() != 1) && (deviceSet->m_deviceSinkEngine))
1210  {
1211  error.init();
1212  *error.getMessage() = QString("Device type and device set type (Tx) mismatch");
1213  return 404;
1214  }
1215 
1216  if ((query.getDirection() != 0) && (deviceSet->m_deviceSourceEngine))
1217  {
1218  error.init();
1219  *error.getMessage() = QString("Device type and device set type (Rx) mismatch");
1220  return 404;
1221  }
1222 
1223  int nbSamplingDevices;
1224 
1225  if (query.getDirection() == 0) {
1226  nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
1227  } else if (query.getDirection() == 1) {
1228  nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
1229  } else {
1230  nbSamplingDevices = 0; // TODO: not implemented yet
1231  }
1232 
1233  for (int i = 0; i < nbSamplingDevices; i++)
1234  {
1235  int direction;
1236  const PluginInterface::SamplingDevice *samplingDevice;
1237 
1238  if (query.getDirection() == 0)
1239  {
1240  direction = 0;
1241  samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
1242  }
1243  else if (query.getDirection() == 1)
1244  {
1245  direction = 1;
1246  samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
1247  }
1248  else
1249  {
1250  continue; // TODO: any device (2) not supported yet
1251  }
1252 
1253  if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice->displayedName)) {
1254  continue;
1255  }
1256 
1257  if (query.getHwType() && (*query.getHwType() != samplingDevice->hardwareId)) {
1258  continue;
1259  }
1260 
1261  if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice->sequence)) {
1262  continue;
1263  }
1264 
1265  if (query.getSerial() && (*query.getSerial() != samplingDevice->serial)) {
1266  continue;
1267  }
1268 
1269  if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice->deviceItemIndex)) {
1270  continue;
1271  }
1272 
1273  MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, query.getDirection());
1275 
1276  response.init();
1277  *response.getDisplayedName() = samplingDevice->displayedName;
1278  *response.getHwType() = samplingDevice->hardwareId;
1279  *response.getSerial() = samplingDevice->serial;
1280  response.setSequence(samplingDevice->sequence);
1281  response.setDirection(direction);
1282  response.setDeviceNbStreams(samplingDevice->deviceNbItems);
1283  response.setDeviceStreamIndex(samplingDevice->deviceItemIndex);
1284  response.setDeviceSetIndex(deviceSetIndex);
1285  response.setIndex(i);
1286 
1287  return 202;
1288  }
1289 
1290  error.init();
1291  *error.getMessage() = QString("Device not found");
1292  return 404;
1293  }
1294  else
1295  {
1296  error.init();
1297  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1298 
1299  return 404;
1300  }
1301 }
1302 
1304  int deviceSetIndex,
1307 {
1308  error.init();
1309 
1310  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1311  {
1312  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1313 
1314  if (deviceSet->m_deviceSourceEngine) // Single Rx
1315  {
1316  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1317  response.setDirection(0);
1318  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1319  return source->webapiSettingsGet(response, *error.getMessage());
1320  }
1321  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1322  {
1323  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1324  response.setDirection(1);
1325  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1326  return sink->webapiSettingsGet(response, *error.getMessage());
1327  }
1328  else
1329  {
1330  *error.getMessage() = QString("DeviceSet error");
1331  return 500;
1332  }
1333  }
1334  else
1335  {
1336  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1337  return 404;
1338  }
1339 }
1340 
1342  int deviceSetIndex,
1343  bool force,
1344  const QStringList& deviceSettingsKeys,
1347 {
1348  error.init();
1349 
1350  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1351  {
1352  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1353 
1354  if (deviceSet->m_deviceSourceEngine) // Single Rx
1355  {
1356  if (response.getDirection() != 0)
1357  {
1358  *error.getMessage() = QString("Single Rx device found but other type of device requested");
1359  return 400;
1360  }
1361  if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType())
1362  {
1363  *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceAPI->getHardwareId());
1364  return 400;
1365  }
1366  else
1367  {
1368  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1369  return source->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
1370  }
1371  }
1372  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1373  {
1374  if (response.getDirection() != 1)
1375  {
1376  *error.getMessage() = QString("Single Tx device found but other type of device requested");
1377  return 400;
1378  }
1379  else if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType())
1380  {
1381  *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId());
1382  return 400;
1383  }
1384  else
1385  {
1386  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1387  return sink->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
1388  }
1389  }
1390  else
1391  {
1392  *error.getMessage() = QString("DeviceSet error");
1393  return 500;
1394  }
1395  }
1396  else
1397  {
1398  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1399  return 404;
1400  }
1401 }
1402 
1404  int deviceSetIndex,
1405  SWGSDRangel::SWGDeviceState& response,
1407 {
1408  error.init();
1409 
1410  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1411  {
1412  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1413 
1414  if (deviceSet->m_deviceSourceEngine) // Rx
1415  {
1416  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1417  response.init();
1418  return source->webapiRunGet(response, *error.getMessage());
1419  }
1420  else if (deviceSet->m_deviceSinkEngine) // Tx
1421  {
1422  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1423  response.init();
1424  return sink->webapiRunGet(response, *error.getMessage());
1425  }
1426  else
1427  {
1428  *error.getMessage() = QString("DeviceSet error");
1429  return 500;
1430  }
1431  }
1432  else
1433  {
1434  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1435  return 404;
1436  }
1437 }
1438 
1440  int deviceSetIndex,
1441  SWGSDRangel::SWGDeviceState& response,
1443 {
1444  error.init();
1445 
1446  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1447  {
1448  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1449 
1450  if (deviceSet->m_deviceSourceEngine) // Rx
1451  {
1452  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1453  response.init();
1454  return source->webapiRun(true, response, *error.getMessage());
1455  }
1456  else if (deviceSet->m_deviceSinkEngine) // Tx
1457  {
1458  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1459  response.init();
1460  return sink->webapiRun(true, response, *error.getMessage());
1461  }
1462  else
1463  {
1464  *error.getMessage() = QString("DeviceSet error");
1465  return 500;
1466  }
1467  }
1468  else
1469  {
1470  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1471  return 404;
1472  }
1473 }
1474 
1476  int deviceSetIndex,
1477  SWGSDRangel::SWGDeviceState& response,
1479 {
1480  error.init();
1481 
1482  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1483  {
1484  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1485 
1486  if (deviceSet->m_deviceSourceEngine) // Rx
1487  {
1488  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1489  response.init();
1490  return source->webapiRun(false, response, *error.getMessage());
1491  }
1492  else if (deviceSet->m_deviceSinkEngine) // Tx
1493  {
1494  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1495  response.init();
1496  return sink->webapiRun(false, response, *error.getMessage());
1497  }
1498  else
1499  {
1500  *error.getMessage() = QString("DeviceSet error");
1501  return 500;
1502  }
1503  }
1504  else
1505  {
1506  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1507  return 404;
1508  }
1509 }
1510 
1512  int deviceSetIndex,
1513  SWGSDRangel::SWGDeviceReport& response,
1515 {
1516  error.init();
1517 
1518  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1519  {
1520  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1521 
1522  if (deviceSet->m_deviceSourceEngine) // Single Rx
1523  {
1524  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1525  response.setDirection(0);
1526  DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
1527  return source->webapiReportGet(response, *error.getMessage());
1528  }
1529  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1530  {
1531  response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId()));
1532  response.setDirection(1);
1533  DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink();
1534  return sink->webapiReportGet(response, *error.getMessage());
1535  }
1536  else
1537  {
1538  *error.getMessage() = QString("DeviceSet error");
1539  return 500;
1540  }
1541  }
1542  else
1543  {
1544  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1545  return 404;
1546  }
1547 }
1548 
1550  int deviceSetIndex,
1553 {
1554  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1555  {
1556  const DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1557  getChannelsDetail(&response, deviceSet);
1558 
1559  return 200;
1560  }
1561  else
1562  {
1563  error.init();
1564  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1565 
1566  return 404;
1567  }
1568 }
1569 
1571  int deviceSetIndex,
1575 {
1576  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1577  {
1578  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1579 
1580  if (query.getDirection() == 0) // Single Rx
1581  {
1582  if (deviceSet->m_deviceSourceEngine == 0)
1583  {
1584  error.init();
1585  *error.getMessage() = QString("Device set at %1 is not a receive device set").arg(deviceSetIndex);
1586  return 400;
1587  }
1588 
1590  int nbRegistrations = channelRegistrations->size();
1591  int index = 0;
1592  for (; index < nbRegistrations; index++)
1593  {
1594  if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
1595  break;
1596  }
1597  }
1598 
1599  if (index < nbRegistrations)
1600  {
1601  MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, false);
1603 
1604  response.init();
1605  *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
1606 
1607  return 202;
1608  }
1609  else
1610  {
1611  error.init();
1612  *error.getMessage() = QString("There is no receive channel with id %1").arg(*query.getChannelType());
1613  return 404;
1614  }
1615  }
1616  else if (query.getDirection() == 1) // single Tx
1617  {
1618  if (deviceSet->m_deviceSinkEngine == 0)
1619  {
1620  error.init();
1621  *error.getMessage() = QString("Device set at %1 is not a transmit device set").arg(deviceSetIndex);
1622  return 400;
1623  }
1624 
1626  int nbRegistrations = channelRegistrations->size();
1627  int index = 0;
1628  for (; index < nbRegistrations; index++)
1629  {
1630  if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
1631  break;
1632  }
1633  }
1634 
1635  if (index < nbRegistrations)
1636  {
1637  MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, true);
1639 
1640  response.init();
1641  *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
1642 
1643  return 202;
1644  }
1645  else
1646  {
1647  error.init();
1648  *error.getMessage() = QString("There is no transmit channel with id %1").arg(*query.getChannelType());
1649  return 404;
1650  }
1651  }
1652  else
1653  {
1654  error.init();
1655  *error.getMessage() = QString("This type of device is not implemented yet");
1656  return 400;
1657  }
1658  }
1659  else
1660  {
1661  error.init();
1662  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1663  return 404;
1664  }
1665 }
1666 
1668  int deviceSetIndex,
1669  int channelIndex,
1672 {
1673  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1674  {
1675  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1676 
1677  if (deviceSet->m_deviceSourceEngine) // Rx
1678  {
1679  if (channelIndex < deviceSet->getNumberOfRxChannels())
1680  {
1681  MainCore::MsgDeleteChannel *msg = MainCore::MsgDeleteChannel::create(deviceSetIndex, channelIndex, false);
1683 
1684  response.init();
1685  *response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
1686 
1687  return 202;
1688  }
1689  else
1690  {
1691  error.init();
1692  *error.getMessage() = QString("There is no channel at index %1. There are %2 Rx channels")
1693  .arg(channelIndex)
1694  .arg(channelIndex < deviceSet->getNumberOfRxChannels());
1695  return 400;
1696  }
1697  }
1698  else if (deviceSet->m_deviceSinkEngine) // Tx
1699  {
1700  if (channelIndex < deviceSet->getNumberOfTxChannels())
1701  {
1702  MainCore::MsgDeleteChannel *msg = MainCore::MsgDeleteChannel::create(deviceSetIndex, channelIndex, true);
1704 
1705  response.init();
1706  *response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
1707 
1708  return 202;
1709  }
1710  else
1711  {
1712  error.init();
1713  *error.getMessage() = QString("There is no channel at index %1. There are %2 Tx channels")
1714  .arg(channelIndex)
1715  .arg(channelIndex < deviceSet->getNumberOfRxChannels());
1716  return 400;
1717  }
1718  }
1719  else
1720  {
1721  error.init();
1722  *error.getMessage() = QString("DeviceSet error");
1723  return 500;
1724  }
1725  }
1726  else
1727  {
1728  error.init();
1729  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1730  return 404;
1731  }
1732 }
1733 
1735  int deviceSetIndex,
1736  int channelIndex,
1739 {
1740  error.init();
1741 
1742  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1743  {
1744  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1745 
1746  if (deviceSet->m_deviceSourceEngine) // Single Rx
1747  {
1748  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1749 
1750  if (channelAPI == 0)
1751  {
1752  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1753  return 404;
1754  }
1755  else
1756  {
1757  response.setChannelType(new QString());
1758  channelAPI->getIdentifier(*response.getChannelType());
1759  response.setDirection(0);
1760  return channelAPI->webapiSettingsGet(response, *error.getMessage());
1761  }
1762  }
1763  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1764  {
1765  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1766 
1767  if (channelAPI == 0)
1768  {
1769  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1770  return 404;
1771  }
1772  else
1773  {
1774  response.setChannelType(new QString());
1775  channelAPI->getIdentifier(*response.getChannelType());
1776  response.setDirection(1);
1777  return channelAPI->webapiSettingsGet(response, *error.getMessage());
1778  }
1779  }
1780  else
1781  {
1782  *error.getMessage() = QString("DeviceSet error");
1783  return 500;
1784  }
1785  }
1786  else
1787  {
1788  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1789  return 404;
1790  }
1791 }
1792 
1794  int deviceSetIndex,
1795  int channelIndex,
1798 {
1799  error.init();
1800 
1801  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1802  {
1803  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1804 
1805  if (deviceSet->m_deviceSourceEngine) // Single Rx
1806  {
1807  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1808 
1809  if (channelAPI == 0)
1810  {
1811  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1812  return 404;
1813  }
1814  else
1815  {
1816  response.setChannelType(new QString());
1817  channelAPI->getIdentifier(*response.getChannelType());
1818  response.setDirection(0);
1819  return channelAPI->webapiReportGet(response, *error.getMessage());
1820  }
1821  }
1822  else if (deviceSet->m_deviceSinkEngine) // Single Tx
1823  {
1824  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1825 
1826  if (channelAPI == 0)
1827  {
1828  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1829  return 404;
1830  }
1831  else
1832  {
1833  response.setChannelType(new QString());
1834  channelAPI->getIdentifier(*response.getChannelType());
1835  response.setDirection(1);
1836  return channelAPI->webapiReportGet(response, *error.getMessage());
1837  }
1838  }
1839  else
1840  {
1841  *error.getMessage() = QString("DeviceSet error");
1842  return 500;
1843  }
1844  }
1845  else
1846  {
1847  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1848  return 404;
1849  }
1850 }
1851 
1853  int deviceSetIndex,
1854  int channelIndex,
1855  bool force,
1856  const QStringList& channelSettingsKeys,
1859 {
1860  error.init();
1861 
1862  if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
1863  {
1864  DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
1865 
1866  if (deviceSet->m_deviceSourceEngine) // Rx
1867  {
1868  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
1869 
1870  if (channelAPI == 0)
1871  {
1872  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1873  return 404;
1874  }
1875  else
1876  {
1877  QString channelType;
1878  channelAPI->getIdentifier(channelType);
1879 
1880  if (channelType == *response.getChannelType())
1881  {
1882  return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
1883  }
1884  else
1885  {
1886  *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.")
1887  .arg(*response.getChannelType())
1888  .arg(channelIndex)
1889  .arg(channelType);
1890  return 404;
1891  }
1892  }
1893  }
1894  else if (deviceSet->m_deviceSinkEngine) // Tx
1895  {
1896  ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex);
1897 
1898  if (channelAPI == 0)
1899  {
1900  *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex);
1901  return 404;
1902  }
1903  else
1904  {
1905  QString channelType;
1906  channelAPI->getIdentifier(channelType);
1907 
1908  if (channelType == *response.getChannelType())
1909  {
1910  return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
1911  }
1912  else
1913  {
1914  *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.")
1915  .arg(*response.getChannelType())
1916  .arg(channelIndex)
1917  .arg(channelType);
1918  return 404;
1919  }
1920  }
1921  }
1922  else
1923  {
1924  *error.getMessage() = QString("DeviceSet error");
1925  return 500;
1926  }
1927  }
1928  else
1929  {
1930  *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
1931  return 404;
1932  }
1933 }
1934 
1936 {
1937  deviceSetList->init();
1938  deviceSetList->setDevicesetcount((int) m_mainCore.m_deviceSets.size());
1939 
1940  std::vector<DeviceSet*>::const_iterator it = m_mainCore.m_deviceSets.begin();
1941 
1942  for (int i = 0; it != m_mainCore.m_deviceSets.end(); ++it, i++)
1943  {
1944  QList<SWGSDRangel::SWGDeviceSet*> *deviceSets = deviceSetList->getDeviceSets();
1945  deviceSets->append(new SWGSDRangel::SWGDeviceSet());
1946 
1947  getDeviceSet(deviceSets->back(), *it, i);
1948  }
1949 }
1950 
1951 void WebAPIAdapterSrv::getDeviceSet(SWGSDRangel::SWGDeviceSet *swgDeviceSet, const DeviceSet* deviceSet, int deviceUISetIndex)
1952 {
1953  swgDeviceSet->init();
1954  SWGSDRangel::SWGSamplingDevice *samplingDevice = swgDeviceSet->getSamplingDevice();
1955  samplingDevice->init();
1956  samplingDevice->setIndex(deviceUISetIndex);
1957 
1958  if (deviceSet->m_deviceSinkEngine) // Single Tx data
1959  {
1960  samplingDevice->setDirection(1);
1961  *samplingDevice->getHwType() = deviceSet->m_deviceAPI->getHardwareId();
1962  *samplingDevice->getSerial() = deviceSet->m_deviceAPI->getSamplingDeviceSerial();
1963  samplingDevice->setSequence(deviceSet->m_deviceAPI->getSamplingDeviceSequence());
1964  samplingDevice->setDeviceNbStreams(deviceSet->m_deviceAPI->getDeviceNbItems());
1965  samplingDevice->setDeviceStreamIndex(deviceSet->m_deviceAPI->getDeviceItemIndex());
1966  deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
1967  DeviceSampleSink *sampleSink = deviceSet->m_deviceSinkEngine->getSink();
1968 
1969  if (sampleSink) {
1970  samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency());
1971  samplingDevice->setBandwidth(sampleSink->getSampleRate());
1972  }
1973 
1974  swgDeviceSet->setChannelcount(deviceSet->m_deviceAPI->getNbSourceChannels());
1975  QList<SWGSDRangel::SWGChannel*> *channels = swgDeviceSet->getChannels();
1976 
1977  for (int i = 0; i < swgDeviceSet->getChannelcount(); i++)
1978  {
1979  channels->append(new SWGSDRangel::SWGChannel);
1980  channels->back()->init();
1981  ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i);
1982  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
1983  channels->back()->setIndex(channel->getIndexInDeviceSet());
1984  channels->back()->setUid(channel->getUID());
1985  channel->getIdentifier(*channels->back()->getId());
1986  channel->getTitle(*channels->back()->getTitle());
1987  }
1988  }
1989 
1990  if (deviceSet->m_deviceSourceEngine) // Single Rx data
1991  {
1992  samplingDevice->setDirection(0);
1993  *samplingDevice->getHwType() = deviceSet->m_deviceAPI->getHardwareId();
1994  *samplingDevice->getSerial() = deviceSet->m_deviceAPI->getSamplingDeviceSerial();
1995  samplingDevice->setSequence(deviceSet->m_deviceAPI->getSamplingDeviceSequence());
1996  samplingDevice->setDeviceNbStreams(deviceSet->m_deviceAPI->getDeviceNbItems());
1997  samplingDevice->setDeviceStreamIndex(deviceSet->m_deviceAPI->getDeviceItemIndex());
1998  deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
1999  DeviceSampleSource *sampleSource = deviceSet->m_deviceSourceEngine->getSource();
2000 
2001  if (sampleSource) {
2002  samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency());
2003  samplingDevice->setBandwidth(sampleSource->getSampleRate());
2004  }
2005 
2006  swgDeviceSet->setChannelcount(deviceSet->m_deviceAPI->getNbSinkChannels());
2007  QList<SWGSDRangel::SWGChannel*> *channels = swgDeviceSet->getChannels();
2008 
2009  for (int i = 0; i < swgDeviceSet->getChannelcount(); i++)
2010  {
2011  channels->append(new SWGSDRangel::SWGChannel);
2012  channels->back()->init();
2013  ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i);
2014  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
2015  channels->back()->setIndex(channel->getIndexInDeviceSet());
2016  channels->back()->setUid(channel->getUID());
2017  channel->getIdentifier(*channels->back()->getId());
2018  channel->getTitle(*channels->back()->getTitle());
2019  }
2020  }
2021 }
2022 
2024 {
2025  channelsDetail->init();
2026  SWGSDRangel::SWGChannelReport *channelReport;
2027  QString channelReportError;
2028 
2029  if (deviceSet->m_deviceSinkEngine) // Tx data
2030  {
2031  channelsDetail->setChannelcount(deviceSet->m_deviceAPI->getNbSourceChannels());
2032  QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
2033 
2034  for (int i = 0; i < channelsDetail->getChannelcount(); i++)
2035  {
2036  channels->append(new SWGSDRangel::SWGChannel);
2037  channels->back()->init();
2038  ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i);
2039  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
2040  channels->back()->setIndex(channel->getIndexInDeviceSet());
2041  channels->back()->setUid(channel->getUID());
2042  channel->getIdentifier(*channels->back()->getId());
2043  channel->getTitle(*channels->back()->getTitle());
2044 
2045  channelReport = new SWGSDRangel::SWGChannelReport();
2046 
2047  if (channel->webapiReportGet(*channelReport, channelReportError) != 501) {
2048  channels->back()->setReport(channelReport);
2049  } else {
2050  delete channelReport;
2051  }
2052  }
2053  }
2054 
2055  if (deviceSet->m_deviceSourceEngine) // Rx data
2056  {
2057  channelsDetail->setChannelcount(deviceSet->m_deviceAPI->getNbSinkChannels());
2058  QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
2059 
2060  for (int i = 0; i < channelsDetail->getChannelcount(); i++)
2061  {
2062  channels->append(new SWGSDRangel::SWGChannel);
2063  channels->back()->init();
2064  ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i);
2065  channels->back()->setDeltaFrequency(channel->getCenterFrequency());
2066  channels->back()->setIndex(channel->getIndexInDeviceSet());
2067  channels->back()->setUid(channel->getUID());
2068  channel->getIdentifier(*channels->back()->getId());
2069  channel->getTitle(*channels->back()->getTitle());
2070 
2071  channelReport = new SWGSDRangel::SWGChannelReport();
2072 
2073  if (channel->webapiReportGet(*channelReport, channelReportError) != 501) {
2074  channels->back()->setReport(channelReport);
2075  } else {
2076  delete channelReport;
2077  }
2078  }
2079  }
2080 }
2081 
2082 QtMsgType WebAPIAdapterSrv::getMsgTypeFromString(const QString& msgTypeString)
2083 {
2084  if (msgTypeString == "debug") {
2085  return QtDebugMsg;
2086  } else if (msgTypeString == "info") {
2087  return QtInfoMsg;
2088  } else if (msgTypeString == "warning") {
2089  return QtWarningMsg;
2090  } else if (msgTypeString == "error") {
2091  return QtCriticalMsg;
2092  } else {
2093  return QtDebugMsg;
2094  }
2095 }
2096 
2097 void WebAPIAdapterSrv::getMsgTypeString(const QtMsgType& msgType, QString& levelStr)
2098 {
2099  switch (msgType)
2100  {
2101  case QtDebugMsg:
2102  levelStr = "debug";
2103  break;
2104  case QtInfoMsg:
2105  levelStr = "info";
2106  break;
2107  case QtWarningMsg:
2108  levelStr = "warning";
2109  break;
2110  case QtCriticalMsg:
2111  case QtFatalMsg:
2112  levelStr = "error";
2113  break;
2114  default:
2115  levelStr = "debug";
2116  break;
2117  }
2118 }
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: channelapi.h:59
const QString version
QList< SWGChannel * > * getChannels()
static const QString m_defaultDeviceName
void setLoggingOptions()
Definition: maincore.cpp:209
float getLatitude() const
Definition: mainsettings.h:55
const QList< QAudioDeviceInfo > & getInputDevices() const
DSPEngine * m_dspEngine
Definition: maincore.h:275
void setDeviceStreamIndex(qint32 device_stream_index)
const QString & getLogFileName() const
Definition: mainsettings.h:65
static MsgAddDeviceSet * create(int direction)
Definition: maincore.h:165
void setDeviceHwType(QString *device_hw_type)
QList< ChannelRegistration > ChannelRegistrations
Definition: pluginapi.h:44
const QString displayedName
virtual int instanceAudioInputCleanupPatch(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instancePresetFilePut(SWGSDRangel::SWGPresetImport &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
DeviceSampleSink * getSink()
int sequence
The device sequence. >0 when more than one device of the same type is connected.
virtual int devicesetDeviceReportGet(int deviceSetIndex, SWGSDRangel::SWGDeviceReport &response, SWGSDRangel::SWGErrorResponse &error)
QList< SWGDeviceSet * > * getDeviceSets()
std::vector< DeviceSet * > m_deviceSets
Definition: maincore.h:281
void push(Message *message, bool emitSignal=true)
Push message onto queue.
QString displayedName
The human readable name.
virtual int instanceDVSerialGet(SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
virtual int devicesetChannelReportGet(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGChannelReport &response, SWGSDRangel::SWGErrorResponse &error)
bool getUseFileLogger() const
static MsgSavePreset * create(Preset *preset, int deviceSetIndex, bool newPreset)
Definition: maincore.h:106
virtual ~WebAPIAdapterSrv()
virtual int instanceAMBEDevicesPut(SWGSDRangel::SWGAMBEDevices &query, SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
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
void getDeviceSetList(SWGSDRangel::SWGDeviceSetList *deviceSetList)
PluginAPI::ChannelRegistrations * getRxChannelRegistrations()
Definition: pluginmanager.h:74
void setDeviceSetIndex(qint32 device_set_index)
virtual int instanceDeviceSetDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
quint64 getCenterFrequency() const
Definition: preset.h:76
void outputInfosCleanup()
Remove output info from map for output devices not present.
static void getMsgTypeString(const QtMsgType &msgType, QString &level)
virtual int instanceSummary(SWGSDRangel::SWGInstanceSummaryResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual void getIdentifier(QString &id)=0
DeviceSampleSource * getSource()
bool getUseLogFile() const
Definition: mainsettings.h:64
virtual int devicesetDeviceRunDelete(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceDeviceSetsGet(SWGSDRangel::SWGDeviceSetList &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAudioOutputDelete(SWGSDRangel::SWGAudioOutputDevice &response, SWGSDRangel::SWGErrorResponse &error)
uint32_t getDeviceItemIndex() const
Definition: deviceapi.h:129
virtual int instanceLoggingGet(SWGSDRangel::SWGLoggingInfo &response, SWGSDRangel::SWGErrorResponse &error)
QString hardwareId
The internal id that identifies the type of hardware (i.e. HackRF, BladeRF, ...)
virtual int instanceLocationGet(SWGSDRangel::SWGLocationInformation &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAMBEDevicesGet(SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
DSPDeviceSourceEngine * m_deviceSourceEngine
Definition: deviceset.h:35
virtual const PluginDescriptor & getPluginDescriptor() const =0
void setDirection(qint32 direction)
virtual int instanceDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int devicesetChannelSettingsGet(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGChannelSettings &response, SWGSDRangel::SWGErrorResponse &error)
bool isSourcePreset() const
Definition: preset.h:66
MessageQueue m_inputMessageQueue
Definition: maincore.h:279
void setNbOutputDevices(qint32 nb_output_devices)
uint32_t getDeviceNbItems() const
Definition: deviceapi.h:128
void setDirection(qint32 direction)
void scan(std::vector< QString > &ambeDevices)
Definition: ambeengine.cpp:191
QList< SWGAudioInputDevice * > * getInputDevices()
WebAPIAdapterSrv(MainCore &mainCore)
void setChannelType(QString *channel_type)
AudioOutput::UDPChannelCodec udpChannelCodec
virtual int instanceDevices(int direction, SWGSDRangel::SWGInstanceDevicesResponse &response, SWGSDRangel::SWGErrorResponse &error)
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
bool registerController(const std::string &deviceRef)
create a new controller for the device in reference
Definition: ambeengine.cpp:214
void setConsoleMinLogLevel(const QtMsgType &minLogLevel)
Definition: mainsettings.h:58
Preset * newPreset(const QString &group, const QString &description)
void setCenterFrequency(qint64 center_frequency)
virtual int devicesetFocusPatch(int deviceSetIndex, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setChannelcount(qint32 channelcount)
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 webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
SWGPresetIdentifier * getPreset()
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
virtual int instanceConfigGet(SWGSDRangel::SWGInstanceConfigResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int getSampleRate() const =0
Sample rate exposed by the source.
virtual int instanceAudioOutputCleanupPatch(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
static MsgDeleteChannel * create(int deviceSetIndex, int channelIndex, bool tx)
Definition: maincore.h:254
QList< SWGChannel * > * getChannels()
MainSettings m_settings
Definition: maincore.h:273
SWGSamplingDevice * getSamplingDevice()
bool getInputDeviceName(int inputDeviceIndex, QString &deviceName) const
void setUdpAddress(QString *udp_address)
virtual int instanceAMBEDevicesDelete(SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void getDeviceSet(SWGSDRangel::SWGDeviceSet *swgDeviceSet, const DeviceSet *deviceSet, int deviceUISetIndex)
void setOutputDeviceInfo(int outputDeviceIndex, const OutputDeviceInfo &deviceInfo)
virtual int devicesetDeviceSettingsGet(int deviceSetIndex, SWGSDRangel::SWGDeviceSettings &response, SWGSDRangel::SWGErrorResponse &error)
void getChannelsDetail(SWGSDRangel::SWGChannelsDetail *channelsDetail, const DeviceSet *deviceSet)
uint64_t getUID() const
Definition: channelapi.h:93
int getPresetCount() const
Definition: mainsettings.h:30
void setChannelType(QString *channel_type)
virtual quint64 getCenterFrequency() const =0
Center frequency exposed by the sink.
AMBEEngine * getAMBEEngine()
Definition: dspengine.h:56
void setSampleRate(qint32 sample_rate)
virtual int devicesetChannelDelete(int deviceSetIndex, int channelIndex, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void releaseAll()
Definition: ambeengine.cpp:261
virtual int instancePresetsGet(SWGSDRangel::SWGPresets &response, SWGSDRangel::SWGErrorResponse &error)
void setNbDevices(qint32 nb_devices)
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: channelapi.h:67
virtual int instanceAudioInputDelete(SWGSDRangel::SWGAudioInputDevice &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceDVSerialPatch(bool dvserial, SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
QtMsgType getFileMinLogLevel() const
Definition: mainsettings.h:63
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
QByteArray serialize() const
Definition: preset.cpp:43
virtual int instanceAMBEDevicesPatch(SWGSDRangel::SWGAMBEDevices &query, SWGSDRangel::SWGAMBEDevices &response, SWGSDRangel::SWGErrorResponse &error)
Definition: preset.h:28
virtual int instancePresetPost(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
void inputInfosCleanup()
Remove input info from map for input devices not present.
static MsgDeletePreset * create(const Preset *preset)
Definition: maincore.h:130
void setDescription(const QString &description)
Definition: preset.h:73
static MsgAddChannel * create(int deviceSetIndex, int channelRegistrationIndex, bool tx)
Definition: maincore.h:228
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)
static QtMsgType getMsgTypeFromString(const QString &msgTypeString)
virtual int devicesetDeviceSettingsPutPatch(int deviceSetIndex, bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, SWGSDRangel::SWGErrorResponse &error)
bool getOutputDeviceInfo(const QString &deviceName, OutputDeviceInfo &deviceInfo) const
void setGroup(const QString &group)
Definition: preset.h:71
PluginManager * m_pluginManager
Definition: maincore.h:282
void setDeviceStreamIndex(qint32 device_stream_index)
qtwebapp::LoggerWithFile * m_logger
Definition: maincore.h:277
DeviceAPI * m_deviceAPI
Definition: deviceset.h:34
void setDVSerialSupport(bool support)
Definition: dspengine.cpp:163
void setLongitude(float longitude)
Definition: mainsettings.h:54
bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const
const MainSettings & getMainSettings() const
Definition: maincore.h:59
virtual int instanceAudioGet(SWGSDRangel::SWGAudioDevices &response, SWGSDRangel::SWGErrorResponse &error)
void setNbInputDevices(qint32 nb_input_devices)
#define SDR_TX_SAMP_SZ
Definition: dsptypes.h:38
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
const QList< QAudioDeviceInfo > & getOutputDevices() const
virtual int instancePresetPut(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
void unsetInputDeviceInfo(int inputDeviceIndex)
int claimed
This is the device set index if claimed else -1.
virtual int instanceLoggingPut(SWGSDRangel::SWGLoggingInfo &query, SWGSDRangel::SWGLoggingInfo &response, SWGSDRangel::SWGErrorResponse &error)
void setDeviceNbStreams(qint32 device_nb_streams)
virtual int instancePresetPatch(SWGSDRangel::SWGPresetTransfer &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
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
static MsgRemoveLastDeviceSet * create()
Definition: maincore.h:183
void setUdpChannelCodec(qint32 udp_channel_codec)
void setUseLogFile(bool useLogFile)
Definition: mainsettings.h:60
const QString & getSamplingDeviceSerial() const
Definition: deviceapi.h:121
MessageQueue * getInputMessageQueue()
Definition: maincore.h:56
virtual int instanceLocationPut(SWGSDRangel::SWGLocationInformation &response, SWGSDRangel::SWGErrorResponse &error)
int getNbRxSamplingDevices() const
AudioDeviceManager * getAudioDeviceManager()
Definition: dspengine.h:55
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
AudioOutput::UDPChannelMode udpChannelMode
void getFileMinMessageLevelStr(QString &levelStr)
virtual int instanceDeviceSetPost(int direction, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
static MsgLoadPreset * create(const Preset *preset, int deviceSetIndex)
Definition: maincore.h:82
const PluginInterface::SamplingDevice * getTxSamplingDevice(int deviceIndex) const
const Preferences & getPreferences() const
Definition: mainsettings.h:26
virtual int devicesetChannelsReportGet(int deviceSetIndex, SWGSDRangel::SWGChannelsDetail &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instancePresetDelete(SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
const QString & getHardwareId() const
Definition: deviceapi.h:119
static MsgDeleteInstance * create()
Definition: maincore.h:148
QList< SWGAudioOutputDevice * > * getOutputDevices()
QList< SWGAMBEDevice * > * getAmbeDevices()
int getNbSourceChannels() const
Definition: deviceapi.h:143
virtual int devicesetChannelSettingsPutPatch(int deviceSetIndex, int channelIndex, bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, SWGSDRangel::SWGErrorResponse &error)
bool deserialize(const QByteArray &data)
Definition: preset.cpp:94
virtual int devicesetGet(int deviceSetIndex, SWGSDRangel::SWGDeviceSet &response, SWGSDRangel::SWGErrorResponse &error)
void setDevicesetcount(qint32 devicesetcount)
void setInputDeviceInfo(int inputDeviceIndex, const InputDeviceInfo &deviceInfo)
virtual int instanceAudioInputPatch(SWGSDRangel::SWGAudioInputDevice &response, const QStringList &audioInputKeys, SWGSDRangel::SWGErrorResponse &error)
virtual int devicesetChannelPost(int deviceSetIndex, SWGSDRangel::SWGChannelSettings &query, SWGSDRangel::SWGSuccessResponse &response, SWGSDRangel::SWGErrorResponse &error)
void setLatitude(float latitude)
Definition: mainsettings.h:53
const PluginInterface::SamplingDevice * getRxSamplingDevice(int deviceIndex) const
void getConsoleMinMessageLevelStr(QString &levelStr)
virtual int devicesetDeviceRunPost(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
StreamType streamType
This is the type of stream supported.
virtual int instanceChannels(int direction, SWGSDRangel::SWGInstanceChannelsResponse &response, SWGSDRangel::SWGErrorResponse &error)
virtual int instanceAudioOutputPatch(SWGSDRangel::SWGAudioOutputDevice &response, const QStringList &audioOutputKeys, 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)
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 quint64 getCenterFrequency() const =0
Center frequency exposed by the source.
void setBandwidth(qint32 bandwidth)
virtual int instancePresetFilePost(SWGSDRangel::SWGPresetExport &query, SWGSDRangel::SWGPresetIdentifier &response, SWGSDRangel::SWGErrorResponse &error)
static DeviceEnumerator * instance()
virtual int instanceAMBESerialGet(SWGSDRangel::SWGDVSerialDevices &response, SWGSDRangel::SWGErrorResponse &error)
DSPDeviceSinkEngine * m_deviceSinkEngine
Definition: deviceset.h:36
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)
virtual int devicesetDevicePut(int deviceSetIndex, SWGSDRangel::SWGDeviceListItem &query, SWGSDRangel::SWGDeviceListItem &response, SWGSDRangel::SWGErrorResponse &error)
void getLogFileName(QString &fileName)
const Preset & getWorkingPresetConst() const
Definition: mainsettings.h:46
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
const QString & getGroup() const
Definition: preset.h:72
virtual int devicesetDeviceRunGet(int deviceSetIndex, SWGSDRangel::SWGDeviceState &response, SWGSDRangel::SWGErrorResponse &error)
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 MsgSetDevice * create(int deviceSetIndex, int deviceIndex, int deviceType)
Definition: maincore.h:202
void setUdpChannelMode(qint32 udp_channel_mode)
int getNbSinkChannels() const
Definition: deviceapi.h:144