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.
ambedevicesdialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QString>
20 #include <QListWidgetItem>
21 
22 #include "ambedevicesdialog.h"
23 #include "ui_ambedevicesdialog.h"
24 
25 AMBEDevicesDialog::AMBEDevicesDialog(AMBEEngine* ambeEngine, QWidget* parent) :
26  QDialog(parent),
27  ui(new Ui::AMBEDevicesDialog),
28  m_ambeEngine(ambeEngine)
29 {
30  ui->setupUi(this);
33 }
34 
36 {
37  delete ui;
38 }
39 
41 {
42  std::vector<QString> ambeSerialDevices;
43  m_ambeEngine->scan(ambeSerialDevices);
44  ui->ambeSerialDevices->clear();
45  std::vector<QString>::const_iterator it = ambeSerialDevices.begin();
46 
47  for (; it != ambeSerialDevices.end(); ++it)
48  {
49  ui->ambeSerialDevices->addItem(QString(*it));
50  }
51 }
52 
54 {
55  std::vector<QString> inUseDevices;
56  m_ambeEngine->getDeviceRefs(inUseDevices);
57  ui->ambeDeviceRefs->clear();
58  std::vector<QString>::const_iterator it = inUseDevices.begin();
59 
60  for (; it != inUseDevices.end(); ++it)
61  {
62  qDebug("AMBEDevicesDialog::refreshInUseList: %s", qPrintable(*it));
63  ui->ambeDeviceRefs->addItem(*it);
64  }
65 }
66 
68 {
69  (void) checked;
70  QListWidgetItem *serialItem = ui->ambeSerialDevices->currentItem();
71 
72  if (!serialItem)
73  {
74  ui->statusText->setText("No selection");
75  return;
76  }
77 
78  QString serialName = serialItem->text();
79  QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
80 
81  if (foundItems.size() == 0)
82  {
83  if (m_ambeEngine->registerController(serialName.toStdString()))
84  {
85  ui->ambeDeviceRefs->addItem(serialName);
86  ui->statusText->setText(tr("%1 added").arg(serialName));
87  }
88  else
89  {
90  ui->statusText->setText(tr("Cannot open %1").arg(serialName));
91  }
92  }
93  else
94  {
95  ui->statusText->setText("Device already in use");
96  }
97 }
98 
100 {
101  (void) checked;
102  int count = 0;
103 
104  for (int i = 0; i < ui->ambeSerialDevices->count(); i++)
105  {
106  const QListWidgetItem *serialItem = ui->ambeSerialDevices->item(i);
107  QString serialName = serialItem->text();
108  QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
109 
110  if (foundItems.size() == 0)
111  {
112  if (m_ambeEngine->registerController(serialName.toStdString()))
113  {
114  ui->ambeDeviceRefs->addItem(serialName);
115  count++;
116  }
117  }
118  }
119 
120  ui->statusText->setText(tr("%1 devices added").arg(count));
121 }
122 
124 {
125  (void) checked;
126  QListWidgetItem *deviceItem = ui->ambeDeviceRefs->currentItem();
127 
128  if (!deviceItem)
129  {
130  ui->statusText->setText("No selection");
131  return;
132  }
133 
134  QString deviceName = deviceItem->text();
135  m_ambeEngine->releaseController(deviceName.toStdString());
136  ui->statusText->setText(tr("%1 removed").arg(deviceName));
138 }
139 
141 {
143  ui->statusText->setText("In use refreshed");
144 }
145 
147 {
148  if (ui->ambeDeviceRefs->count() == 0)
149  {
150  ui->statusText->setText("No active items");
151  return;
152  }
153 
155  ui->ambeDeviceRefs->clear();
156  ui->statusText->setText("All items released");
157 }
158 
160 {
161  QString addressAndPort = ui->ambeAddressText->text();
162 
163  QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(addressAndPort, Qt::MatchFixedString|Qt::MatchCaseSensitive);
164 
165  if (foundItems.size() == 0)
166  {
167  if (m_ambeEngine->registerController(addressAndPort.toStdString()))
168  {
169  ui->ambeDeviceRefs->addItem(addressAndPort);
170  ui->statusText->setText(tr("%1 added").arg(addressAndPort));
171  }
172  else
173  {
174  ui->statusText->setText(tr("Cannot open %1").arg(addressAndPort));
175  }
176  }
177  else
178  {
179  ui->statusText->setText("Address already in use");
180  }
181 }
void on_clearAmbeList_clicked(bool checked)
void on_refreshAmbeList_clicked(bool checked)
void on_importSerial_clicked(bool checked)
void on_importAddress_clicked(bool checked)
void getDeviceRefs(std::vector< QString > &devicesRefs)
reference of the devices used (device path or url)
Definition: ambeengine.cpp:279
void scan(std::vector< QString > &ambeDevices)
Definition: ambeengine.cpp:191
bool registerController(const std::string &deviceRef)
create a new controller for the device in reference
Definition: ambeengine.cpp:214
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
AMBEDevicesDialog(AMBEEngine *ambeEngine, QWidget *parent=nullptr)
void releaseAll()
Definition: ambeengine.cpp:261
void on_importAllSerial_clicked(bool checked)
void on_removeAmbeDevice_clicked(bool checked)
int32_t i
Definition: decimators.h:244
AMBEEngine * m_ambeEngine
void releaseController(const std::string &deviceRef)
release controller resources for the device in reference
Definition: ambeengine.cpp:239
Ui::AMBEDevicesDialog * ui