mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-07 16:34:45 -04:00
Web API: /sdrangel/deviceset/{index}/device (PUT) implementation
This commit is contained in:
@@ -67,6 +67,7 @@ MESSAGE_CLASS_DEFINITION(MainWindow::MsgSavePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgDeletePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgAddDeviceSet, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgRemoveLastDeviceSet, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgSetDevice, Message)
|
||||
|
||||
MainWindow *MainWindow::m_instance = 0;
|
||||
|
||||
@@ -728,6 +729,21 @@ bool MainWindow::handleMessage(const Message& cmd)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgSetDevice::match(cmd))
|
||||
{
|
||||
MsgSetDevice& notif = (MsgSetDevice&) cmd;
|
||||
ui->tabInputsSelect->setCurrentIndex(notif.getDeviceSetIndex());
|
||||
DeviceUISet *deviceUI = m_deviceUIs[notif.getDeviceSetIndex()];
|
||||
deviceUI->m_samplingDeviceControl->setSelectedDeviceIndex(notif.getDeviceIndex());
|
||||
|
||||
if (notif.isTx()) {
|
||||
on_sampleSink_changed();
|
||||
} else {
|
||||
on_sampleSource_changed();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -188,6 +188,32 @@ private:
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgSetDevice : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getDeviceSetIndex() const { return m_deviceSetIndex; }
|
||||
int getDeviceIndex() const { return m_deviceIndex; }
|
||||
bool isTx() const { return m_tx; }
|
||||
|
||||
static MsgSetDevice* create(int deviceSetIndex, int deviceIndex, bool tx)
|
||||
{
|
||||
return new MsgSetDevice(deviceSetIndex, deviceIndex, tx);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_deviceSetIndex;
|
||||
int m_deviceIndex;
|
||||
bool m_tx;
|
||||
|
||||
MsgSetDevice(int deviceSetIndex, int deviceIndex, bool tx) :
|
||||
Message(),
|
||||
m_deviceSetIndex(deviceSetIndex),
|
||||
m_deviceIndex(deviceIndex),
|
||||
m_tx(tx)
|
||||
{ }
|
||||
};
|
||||
|
||||
enum {
|
||||
PGroup,
|
||||
PItem
|
||||
|
||||
@@ -614,6 +614,83 @@ int WebAPIAdapterGUI::devicesetGet(
|
||||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
Swagger::SWGDeviceListItem& response,
|
||||
Swagger::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||
{
|
||||
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||
|
||||
if ((response.getTx() == 0) && (deviceSet->m_deviceSinkEngine))
|
||||
{
|
||||
*error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch");
|
||||
return 404;
|
||||
}
|
||||
|
||||
if ((response.getTx() != 0) && (deviceSet->m_deviceSourceEngine))
|
||||
{
|
||||
*error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch");
|
||||
return 404;
|
||||
}
|
||||
|
||||
int nbSamplingDevices = response.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
|
||||
int tx = response.getTx();
|
||||
|
||||
for (int i = 0; i < nbSamplingDevices; i++)
|
||||
{
|
||||
PluginInterface::SamplingDevice samplingDevice = response.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i);
|
||||
|
||||
if (response.getDisplayedName() && (*response.getDisplayedName() != samplingDevice.displayedName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (response.getHwType() && (*response.getHwType() != samplingDevice.hardwareId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((response.getSequence() >= 0) && (response.getSequence() != samplingDevice.sequence)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (response.getSerial() && (*response.getSerial() != samplingDevice.serial)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((response.getStreamIndex() >= 0) && (response.getStreamIndex() != samplingDevice.deviceItemIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MainWindow::MsgSetDevice *msg = MainWindow::MsgSetDevice::create(deviceSetIndex, i, response.getTx() != 0);
|
||||
m_mainWindow.m_inputMessageQueue.push(msg);
|
||||
|
||||
response.init();
|
||||
*response.getDisplayedName() = samplingDevice.displayedName;
|
||||
*response.getHwType() = samplingDevice.hardwareId;
|
||||
*response.getSerial() = samplingDevice.serial;
|
||||
response.setSequence(samplingDevice.sequence);
|
||||
response.setTx(tx);
|
||||
response.setNbStreams(samplingDevice.deviceNbItems);
|
||||
response.setStreamIndex(samplingDevice.deviceItemIndex);
|
||||
response.setDeviceSetIndex(deviceSetIndex);
|
||||
response.setIndex(i);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
*error.getMessage() = QString("Device not found");
|
||||
return 404;
|
||||
}
|
||||
else
|
||||
{
|
||||
error.init();
|
||||
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIAdapterGUI::getDeviceSetList(Swagger::SWGDeviceSetList* deviceSetList)
|
||||
{
|
||||
deviceSetList->init();
|
||||
|
||||
@@ -115,6 +115,11 @@ public:
|
||||
Swagger::SWGDeviceSet& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
Swagger::SWGDeviceListItem& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user