Skip to content

Commit

Permalink
Merge pull request #1983 from mxi-box/simpleptt_enhance
Browse files Browse the repository at this point in the history
SimplePTT: bugfix and enhancement
  • Loading branch information
f4exb authored Feb 12, 2024
2 parents f35ea35 + 4937ad7 commit 4f2824d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
29 changes: 17 additions & 12 deletions plugins/feature/simpleptt/simplepttgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ void SimplePTTGUI::updateDeviceSetLists()

ui->rxDevice->clear();
ui->txDevice->clear();
ui->rxDevice->addItem(tr("None"), -1);
ui->txDevice->addItem(tr("None"), -1);
unsigned int deviceIndex = 0;
unsigned int rxIndex = 0;
unsigned int txIndex = 0;
Expand All @@ -296,6 +298,7 @@ void SimplePTTGUI::updateDeviceSetLists()
{
DSPDeviceSourceEngine *deviceSourceEngine = (*it)->m_deviceSourceEngine;
DSPDeviceSinkEngine *deviceSinkEngine = (*it)->m_deviceSinkEngine;
DSPDeviceMIMOEngine *deviceMIMOEngine = (*it)->m_deviceMIMOEngine;

if (deviceSourceEngine)
{
Expand All @@ -307,18 +310,23 @@ void SimplePTTGUI::updateDeviceSetLists()
ui->txDevice->addItem(QString("T%1").arg(deviceIndex), deviceIndex);
txIndex++;
}
else if (deviceMIMOEngine)
{
QString text = QString("M%1").arg(deviceIndex);
ui->rxDevice->addItem(text, deviceIndex);
ui->txDevice->addItem(text, deviceIndex);
rxIndex++;
txIndex++;
}
}

int rxDeviceIndex;
int txDeviceIndex;

if (rxIndex > 0)
{
if (m_settings.m_rxDeviceSetIndex < 0) {
ui->rxDevice->setCurrentIndex(0);
} else {
ui->rxDevice->setCurrentIndex(m_settings.m_rxDeviceSetIndex);
}
int index = ui->rxDevice->findData(m_settings.m_rxDeviceSetIndex);
ui->rxDevice->setCurrentIndex(index == -1 ? 0 : index);

rxDeviceIndex = ui->rxDevice->currentData().toInt();
}
Expand All @@ -330,11 +338,8 @@ void SimplePTTGUI::updateDeviceSetLists()

if (txIndex > 0)
{
if (m_settings.m_txDeviceSetIndex < 0) {
ui->txDevice->setCurrentIndex(0);
} else {
ui->txDevice->setCurrentIndex(m_settings.m_txDeviceSetIndex);
}
int index = ui->txDevice->findData(m_settings.m_txDeviceSetIndex);
ui->txDevice->setCurrentIndex(index == -1 ? 0 : index);

txDeviceIndex = ui->txDevice->currentData().toInt();
}
Expand Down Expand Up @@ -425,7 +430,7 @@ void SimplePTTGUI::on_rxDevice_currentIndexChanged(int index)
{
if (index >= 0)
{
m_settings.m_rxDeviceSetIndex = index;
m_settings.m_rxDeviceSetIndex = ui->rxDevice->currentData().toInt();
m_settingsKeys.append("rxDeviceSetIndex");
applySettings();
}
Expand All @@ -435,7 +440,7 @@ void SimplePTTGUI::on_txDevice_currentIndexChanged(int index)
{
if (index >= 0)
{
m_settings.m_txDeviceSetIndex = index;
m_settings.m_txDeviceSetIndex = ui->txDevice->currentData().toInt();
m_settingsKeys.append("txDeviceSetIndex");
applySettings();
}
Expand Down
29 changes: 24 additions & 5 deletions plugins/feature/simpleptt/simplepttworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SWGSuccessResponse.h"
#include "SWGErrorResponse.h"

#include "maincore.h"
#include "webapi/webapiadapterinterface.h"
#include "audio/audiodevicemanager.h"
#include "dsp/dspengine.h"
Expand Down Expand Up @@ -242,13 +243,31 @@ bool SimplePTTWorker::turnDevice(bool on)
SWGSDRangel::SWGDeviceState response;
SWGSDRangel::SWGErrorResponse error;
int httpCode;

unsigned int deviceSetIndex = m_tx ? m_settings.m_txDeviceSetIndex : m_settings.m_rxDeviceSetIndex;
MainCore *mainCore = MainCore::instance();
auto deviceSets = mainCore->getDeviceSets();
if (deviceSetIndex >= deviceSets.size())
{
qWarning("SimplePTTWorker::turnDevice: deviceSetIndex out of range");
return false;
}
bool isDeviceMIMO = mainCore->getDeviceSetTypeId(deviceSets[deviceSetIndex]) == 'M';
if (on) {
httpCode = m_webAPIAdapterInterface->devicesetDeviceRunPost(
m_tx ? m_settings.m_txDeviceSetIndex : m_settings.m_rxDeviceSetIndex, response, error);
if (isDeviceMIMO) {
httpCode = m_webAPIAdapterInterface->devicesetDeviceSubsystemRunPost(
deviceSetIndex, m_tx ? 1 : 0, response, error);
} else {
httpCode = m_webAPIAdapterInterface->devicesetDeviceRunPost(
deviceSetIndex, response, error);
}
} else {
httpCode = m_webAPIAdapterInterface->devicesetDeviceRunDelete(
m_tx ? m_settings.m_txDeviceSetIndex : m_settings.m_rxDeviceSetIndex, response, error);
if (isDeviceMIMO) {
httpCode = m_webAPIAdapterInterface->devicesetDeviceSubsystemRunDelete(
deviceSetIndex, m_tx ? 1 : 0, response, error);
} else {
httpCode = m_webAPIAdapterInterface->devicesetDeviceRunDelete(
deviceSetIndex, response, error);
}
}

if (httpCode/100 == 2)
Expand Down

0 comments on commit 4f2824d

Please sign in to comment.