From f04b6eb975ffed1351c0a3d9b52e800120ceb123 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 20 Jul 2019 05:47:22 +0200 Subject: [PATCH] New AMBE engine (2) --- sdrbase/ambe/ambeengine.cpp | 9 +- sdrbase/ambe/ambeengine.h | 5 +- sdrgui/gui/ambedevicesdialog.cpp | 135 ++++++++++++++++++++++++++- sdrgui/gui/ambedevicesdialog.h | 9 ++ sdrgui/gui/ambedevicesdialog.ui | 63 +++++++++---- sdrgui/resources/double_arrow_up.png | Bin 0 -> 295 bytes sdrgui/resources/res.qrc | 1 + 7 files changed, 197 insertions(+), 25 deletions(-) create mode 100644 sdrgui/resources/double_arrow_up.png diff --git a/sdrbase/ambe/ambeengine.cpp b/sdrbase/ambe/ambeengine.cpp index 05078e45e..b132e7182 100644 --- a/sdrbase/ambe/ambeengine.cpp +++ b/sdrbase/ambe/ambeengine.cpp @@ -180,7 +180,7 @@ std::string AMBEEngine::get_driver(const std::string& tty) bool AMBEEngine::scan(std::vector& ambeDevices) { getComList(); - std::list::iterator it = m_comList.begin(); + std::list::const_iterator it = m_comList.begin(); ambeDevices.clear(); while (it != m_comList.end()) @@ -236,6 +236,7 @@ void AMBEEngine::releaseController(const std::string& deviceRef) it->thread->wait(100); it->worker->m_inputMessageQueue.clear(); it->worker->close(); + m_controllers.erase(it); qDebug() << "DVSerialEngine::releaseController: closed device at: " << it->device.c_str(); break; } @@ -263,13 +264,13 @@ void AMBEEngine::releaseAll() m_controllers.clear(); } -void AMBEEngine::getDeviceRefs(std::vector& deviceNames) +void AMBEEngine::getDeviceRefs(std::vector& deviceNames) { - std::vector::iterator it = m_controllers.begin(); + std::vector::const_iterator it = m_controllers.begin(); while (it != m_controllers.end()) { - deviceNames.push_back(it->device); + deviceNames.push_back(QString(it->device.c_str())); ++it; } } diff --git a/sdrbase/ambe/ambeengine.h b/sdrbase/ambe/ambeengine.h index 43e494608..199c9e44c 100644 --- a/sdrbase/ambe/ambeengine.h +++ b/sdrbase/ambe/ambeengine.h @@ -44,7 +44,7 @@ public: void releaseAll(); int getNbDevices() const { return m_controllers.size(); } //!< number of devices used - void getDeviceRefs(std::vector& devicesRefs); //!< reference of the devices used (device path or url) + void getDeviceRefs(std::vector& devicesRefs); //!< reference of the devices used (device path or url) bool registerController(const std::string& deviceRef); //!< create a new controller for the device in reference void releaseController(const std::string& deviceRef); //!< release controller resources for the device in reference @@ -74,8 +74,7 @@ private: std::list m_comList; std::list m_comList8250; - std::vector m_ambeSerial; - std::vector m_controllers; + std::vector m_controllers; QMutex m_mutex; }; diff --git a/sdrgui/gui/ambedevicesdialog.cpp b/sdrgui/gui/ambedevicesdialog.cpp index b535e39f4..d6e685e32 100644 --- a/sdrgui/gui/ambedevicesdialog.cpp +++ b/sdrgui/gui/ambedevicesdialog.cpp @@ -17,6 +17,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include "ambedevicesdialog.h" #include "ui_ambedevicesdialog.h" @@ -28,6 +29,7 @@ AMBEDevicesDialog::AMBEDevicesDialog(AMBEEngine& ambeEngine, QWidget* parent) : { ui->setupUi(this); populateSerialList(); + refreshInUseList(); } AMBEDevicesDialog::~AMBEDevicesDialog() @@ -39,10 +41,141 @@ void AMBEDevicesDialog::populateSerialList() { std::vector ambeSerialDevices; m_ambeEngine.scan(ambeSerialDevices); + ui->ambeSerialDevices->clear(); std::vector::const_iterator it = ambeSerialDevices.begin(); for (; it != ambeSerialDevices.end(); ++it) { ui->ambeSerialDevices->addItem(QString(*it)); } -} \ No newline at end of file +} + +void AMBEDevicesDialog::refreshInUseList() +{ + std::vector inUseDevices; + m_ambeEngine.getDeviceRefs(inUseDevices); + ui->ambeDeviceRefs->clear(); + std::vector::const_iterator it = inUseDevices.begin(); + + for (; it != inUseDevices.end(); ++it) + { + qDebug("AMBEDevicesDialog::refreshInUseList: %s", qPrintable(*it)); + ui->ambeDeviceRefs->addItem(*it); + } +} + +void AMBEDevicesDialog::on_importSerial_clicked(bool checked) +{ + (void) checked; + QListWidgetItem *serialItem = ui->ambeSerialDevices->currentItem(); + + if (!serialItem) + { + ui->statusText->setText("No selection"); + return; + } + + QString serialName = serialItem->text(); + QList foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive); + + if (foundItems.size() == 0) + { + if (m_ambeEngine.registerController(serialName.toStdString())) + { + ui->ambeDeviceRefs->addItem(serialName); + ui->statusText->setText(tr("%1 added").arg(serialName)); + } + else + { + ui->statusText->setText(tr("Cannot open %1").arg(serialName)); + } + } + else + { + ui->statusText->setText("Device already in use"); + } +} + +void AMBEDevicesDialog::on_importAllSerial_clicked(bool checked) +{ + (void) checked; + int count = 0; + + for (int i = 0; i < ui->ambeSerialDevices->count(); i++) + { + const QListWidgetItem *serialItem = ui->ambeSerialDevices->item(i); + QString serialName = serialItem->text(); + QList foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive); + + if (foundItems.size() == 0) + { + if (m_ambeEngine.registerController(serialName.toStdString())) + { + ui->ambeDeviceRefs->addItem(serialName); + count++; + } + } + } + + ui->statusText->setText(tr("%1 devices added").arg(count)); +} + +void AMBEDevicesDialog::on_removeAmbeDevice_clicked(bool checked) +{ + (void) checked; + QListWidgetItem *deviceItem = ui->ambeDeviceRefs->currentItem(); + + if (!deviceItem) + { + ui->statusText->setText("No selection"); + return; + } + + QString deviceName = deviceItem->text(); + m_ambeEngine.releaseController(deviceName.toStdString()); + ui->statusText->setText(tr("%1 removed").arg(deviceName)); + refreshInUseList(); +} + +void AMBEDevicesDialog::on_refreshAmbeList_clicked(bool checked) +{ + refreshInUseList(); + ui->statusText->setText("In use refreshed"); +} + +void AMBEDevicesDialog::on_clearAmbeList_clicked(bool checked) +{ + if (ui->ambeDeviceRefs->count() == 0) + { + ui->statusText->setText("No active items"); + return; + } + + m_ambeEngine.releaseAll(); + ui->ambeDeviceRefs->clear(); + ui->statusText->setText("All items released"); +} + +void AMBEDevicesDialog::on_importAddress_clicked(bool checked) +{ + QString addressAndPort = ui->ambeAddressText->text(); + + QList foundItems = ui->ambeDeviceRefs->findItems(addressAndPort, Qt::MatchFixedString|Qt::MatchCaseSensitive); + + if (foundItems.size() == 0) + { + if (m_ambeEngine.registerController(addressAndPort.toStdString())) + { + ui->ambeDeviceRefs->addItem(addressAndPort); + ui->statusText->setText(tr("%1 added").arg(addressAndPort)); + } + else + { + ui->statusText->setText(tr("Cannot open %1").arg(addressAndPort)); + } + } + else + { + ui->statusText->setText("Address already in use"); + } +} diff --git a/sdrgui/gui/ambedevicesdialog.h b/sdrgui/gui/ambedevicesdialog.h index 35c6a0fdc..dba322820 100644 --- a/sdrgui/gui/ambedevicesdialog.h +++ b/sdrgui/gui/ambedevicesdialog.h @@ -39,9 +39,18 @@ public: private: void populateSerialList(); + void refreshInUseList(); Ui::AMBEDevicesDialog* ui; AMBEEngine& m_ambeEngine; + +private slots: + void on_importSerial_clicked(bool checked); + void on_importAllSerial_clicked(bool checked); + void on_removeAmbeDevice_clicked(bool checked); + void on_refreshAmbeList_clicked(bool checked); + void on_clearAmbeList_clicked(bool checked); + void on_importAddress_clicked(bool checked); }; #endif // SDRGUI_GUI_AMBEDEVICESDIALOG_H_ \ No newline at end of file diff --git a/sdrgui/gui/ambedevicesdialog.ui b/sdrgui/gui/ambedevicesdialog.ui index fb82b19a8..c7a14ed7e 100644 --- a/sdrgui/gui/ambedevicesdialog.ui +++ b/sdrgui/gui/ambedevicesdialog.ui @@ -16,9 +16,9 @@ - 50 + 310 410 - 341 + 81 32 @@ -73,7 +73,7 @@ 10 10 - 171 + 201 17 @@ -93,6 +93,9 @@ AMBE server address as ip:port + + 000.000.000.000:00000 + @@ -114,7 +117,7 @@ :/recycle.png:/recycle.png - + 280 @@ -147,17 +150,17 @@ In use - + - 110 + 120 250 24 23 - Use device + Use serial device @@ -167,10 +170,10 @@ :/arrow_up.png:/arrow_up.png - + - 110 + 120 60 24 23 @@ -197,7 +200,7 @@ - Refresh list of devices and servers in use + Remove all devices @@ -207,14 +210,40 @@ :/sweep.png:/sweep.png + + + + 10 + 420 + 291 + 19 + + + + ... + + + + + + 150 + 250 + 24 + 23 + + + + Use all serial devices + + + + + + + :/double_arrow_up.png:/double_arrow_up.png + + - - - ButtonSwitch - QToolButton -
gui/buttonswitch.h
-
-
diff --git a/sdrgui/resources/double_arrow_up.png b/sdrgui/resources/double_arrow_up.png new file mode 100644 index 0000000000000000000000000000000000000000..fc01b7d1aa5afc4794e119cc70867aa7bba7effc GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYYs>cdx@v7EBj-15oQ@F4W6S~K%p(3E{-7{$KOuT=3_FHXi=BuVd9oh z5jxBpu%pyNrIF>J?8H0C&N~>Soy_FhT9|HMVm~>nFYDI(_dfH3!qzls8hEF29lsHG z>6ts9{IOZ<7+-}P3#)jrG*{=b(Tbi&TGKZA#xa%O3vDx6+s-30DQr@e{2i;7!lm+z z;`>V3)b{nfo~5VC8@=cFBr(RGQdac`TvyyS-QN8E#pxe8SMO-tJ8HCUx{blDzbwao khW>HAxuCjv&AYD*>K`;t#6Q{80dzlur>mdKI;Vst01F0fRsaA1 literal 0 HcmV?d00001 diff --git a/sdrgui/resources/res.qrc b/sdrgui/resources/res.qrc index 74030e747..897b8261f 100644 --- a/sdrgui/resources/res.qrc +++ b/sdrgui/resources/res.qrc @@ -1,5 +1,6 @@ + double_arrow_up.png no_film.png gps.png linear.png