mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 09:18:54 -05:00
Server: Web API: implemented /sdrangel/deviceset/{deviceSetIndex} GET and /sdrangel/deviceset/{deviceSetIndex}/device PUT
This commit is contained in:
parent
a945d582bc
commit
e7c73b8449
@ -40,6 +40,7 @@ MESSAGE_CLASS_DEFINITION(MainCore::MsgSavePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeletePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgSetDevice, Message)
|
||||
|
||||
MainCore *MainCore::m_instance = 0;
|
||||
|
||||
@ -141,6 +142,18 @@ bool MainCore::handleMessage(const Message& cmd)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgSetDevice::match(cmd))
|
||||
{
|
||||
MsgSetDevice& notif = (MsgSetDevice&) cmd;
|
||||
|
||||
if (notif.isTx()) {
|
||||
changeSampleSink(notif.getDeviceSetIndex(), notif.getDeviceIndex());
|
||||
} else {
|
||||
changeSampleSource(notif.getDeviceSetIndex(), notif.getDeviceIndex());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
@ -311,6 +324,142 @@ void MainCore::removeLastDevice()
|
||||
m_deviceSets.pop_back();
|
||||
}
|
||||
|
||||
void MainCore::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
|
||||
{
|
||||
if (deviceSetIndex >= 0)
|
||||
{
|
||||
qDebug("MainCore::changeSampleSource: deviceSet at %d", deviceSetIndex);
|
||||
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
|
||||
deviceSet->m_deviceSourceAPI->saveSourceSettings(m_settings.getWorkingPreset()); // save old API settings
|
||||
deviceSet->m_deviceSourceAPI->stopAcquisition();
|
||||
|
||||
// deletes old UI and input object
|
||||
deviceSet->m_deviceSourceAPI->resetSampleSourceId();
|
||||
deviceSet->m_deviceSourceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput(
|
||||
deviceSet->m_deviceSourceAPI->getSampleSource());
|
||||
deviceSet->m_deviceSourceAPI->clearBuddiesLists(); // clear old API buddies lists
|
||||
|
||||
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSourceSequence(samplingDevice.sequence);
|
||||
deviceSet->m_deviceSourceAPI->setNbItems(samplingDevice.deviceNbItems);
|
||||
deviceSet->m_deviceSourceAPI->setItemIndex(samplingDevice.deviceItemIndex);
|
||||
deviceSet->m_deviceSourceAPI->setHardwareId(samplingDevice.hardwareId);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSourceId(samplingDevice.id);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSourceSerial(samplingDevice.serial);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSourceDisplayName(samplingDevice.displayedName);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSourcePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(selectedDeviceIndex));
|
||||
|
||||
// add to buddies list
|
||||
std::vector<DeviceSet*>::iterator it = m_deviceSets.begin();
|
||||
int nbOfBuddies = 0;
|
||||
|
||||
for (; it != m_deviceSets.end(); ++it)
|
||||
{
|
||||
if (*it != deviceSet) // do not add to itself
|
||||
{
|
||||
if ((*it)->m_deviceSourceEngine) // it is a source device
|
||||
{
|
||||
if ((deviceSet->m_deviceSourceAPI->getHardwareId() == (*it)->m_deviceSourceAPI->getHardwareId()) &&
|
||||
(deviceSet->m_deviceSourceAPI->getSampleSourceSerial() == (*it)->m_deviceSourceAPI->getSampleSourceSerial()))
|
||||
{
|
||||
(*it)->m_deviceSourceAPI->addSourceBuddy(deviceSet->m_deviceSourceAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*it)->m_deviceSinkEngine) // it is a sink device
|
||||
{
|
||||
if ((deviceSet->m_deviceSourceAPI->getHardwareId() == (*it)->m_deviceSinkAPI->getHardwareId()) &&
|
||||
(deviceSet->m_deviceSourceAPI->getSampleSourceSerial() == (*it)->m_deviceSinkAPI->getSampleSinkSerial()))
|
||||
{
|
||||
(*it)->m_deviceSinkAPI->addSourceBuddy(deviceSet->m_deviceSourceAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nbOfBuddies == 0) {
|
||||
deviceSet->m_deviceSourceAPI->setBuddyLeader(true);
|
||||
}
|
||||
|
||||
// constructs new GUI and input object
|
||||
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getPluginInterface()->createSampleSourcePluginInstanceInput(
|
||||
deviceSet->m_deviceSourceAPI->getSampleSourceId(), deviceSet->m_deviceSourceAPI);
|
||||
deviceSet->m_deviceSourceAPI->setSampleSource(source);
|
||||
|
||||
deviceSet->m_deviceSourceAPI->loadSourceSettings(m_settings.getWorkingPreset()); // load new API settings
|
||||
}
|
||||
}
|
||||
|
||||
void MainCore::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex)
|
||||
{
|
||||
if (deviceSetIndex >= 0)
|
||||
{
|
||||
qDebug("MainCore::changeSampleSink: device set at %d", deviceSetIndex);
|
||||
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
|
||||
deviceSet->m_deviceSinkAPI->saveSinkSettings(m_settings.getWorkingPreset()); // save old API settings
|
||||
deviceSet->m_deviceSinkAPI->stopGeneration();
|
||||
|
||||
// deletes old UI and output object
|
||||
deviceSet->m_deviceSinkAPI->resetSampleSinkId();
|
||||
deviceSet->m_deviceSinkAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(
|
||||
deviceSet->m_deviceSinkAPI->getSampleSink());
|
||||
deviceSet->m_deviceSinkAPI->clearBuddiesLists(); // clear old API buddies lists
|
||||
|
||||
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(selectedDeviceIndex);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSinkSequence(samplingDevice.sequence);
|
||||
deviceSet->m_deviceSinkAPI->setNbItems(samplingDevice.deviceNbItems);
|
||||
deviceSet->m_deviceSinkAPI->setItemIndex(samplingDevice.deviceItemIndex);
|
||||
deviceSet->m_deviceSinkAPI->setHardwareId(samplingDevice.hardwareId);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSinkId(samplingDevice.id);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSinkSerial(samplingDevice.serial);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSinkDisplayName(samplingDevice.displayedName);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSinkPluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(selectedDeviceIndex));
|
||||
|
||||
// add to buddies list
|
||||
std::vector<DeviceSet*>::iterator it = m_deviceSets.begin();
|
||||
int nbOfBuddies = 0;
|
||||
|
||||
for (; it != m_deviceSets.end(); ++it)
|
||||
{
|
||||
if (*it != deviceSet) // do not add to itself
|
||||
{
|
||||
if ((*it)->m_deviceSourceEngine) // it is a source device
|
||||
{
|
||||
if ((deviceSet->m_deviceSinkAPI->getHardwareId() == (*it)->m_deviceSourceAPI->getHardwareId()) &&
|
||||
(deviceSet->m_deviceSinkAPI->getSampleSinkSerial() == (*it)->m_deviceSourceAPI->getSampleSourceSerial()))
|
||||
{
|
||||
(*it)->m_deviceSourceAPI->addSinkBuddy(deviceSet->m_deviceSinkAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*it)->m_deviceSinkEngine) // it is a sink device
|
||||
{
|
||||
if ((deviceSet->m_deviceSinkAPI->getHardwareId() == (*it)->m_deviceSinkAPI->getHardwareId()) &&
|
||||
(deviceSet->m_deviceSinkAPI->getSampleSinkSerial() == (*it)->m_deviceSinkAPI->getSampleSinkSerial()))
|
||||
{
|
||||
(*it)->m_deviceSinkAPI->addSinkBuddy(deviceSet->m_deviceSinkAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nbOfBuddies == 0) {
|
||||
deviceSet->m_deviceSinkAPI->setBuddyLeader(true);
|
||||
}
|
||||
|
||||
// constructs new GUI and output object
|
||||
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getPluginInterface()->createSampleSinkPluginInstanceOutput(
|
||||
deviceSet->m_deviceSinkAPI->getSampleSinkId(), deviceSet->m_deviceSinkAPI);
|
||||
deviceSet->m_deviceSinkAPI->setSampleSink(sink);
|
||||
|
||||
deviceSet->m_deviceSinkAPI->loadSinkSettings(m_settings.getWorkingPreset()); // load new API settings
|
||||
}
|
||||
}
|
||||
|
||||
void MainCore::loadPresetSettings(const Preset* preset, int tabIndex)
|
||||
{
|
||||
qDebug("MainCore::loadPresetSettings: preset [%s | %s]",
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
void addSourceDevice();
|
||||
void addSinkDevice();
|
||||
void removeLastDevice();
|
||||
void changeSampleSource(int deviceSetIndex, int selectedDeviceIndex);
|
||||
void changeSampleSink(int deviceSetIndex, int selectedDeviceIndex);
|
||||
|
||||
friend class WebAPIAdapterSrv;
|
||||
|
||||
@ -189,6 +191,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)
|
||||
{ }
|
||||
};
|
||||
|
||||
static MainCore *m_instance;
|
||||
MainSettings m_settings;
|
||||
int m_masterTabIndex;
|
||||
|
@ -725,6 +725,104 @@ int WebAPIAdapterSrv::instanceDeviceSetsDelete(
|
||||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterSrv::devicesetGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceSet& response,
|
||||
SWGSDRangel::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
|
||||
{
|
||||
const DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
|
||||
getDeviceSet(&response, deviceSet, deviceSetIndex);
|
||||
|
||||
return 200;
|
||||
}
|
||||
else
|
||||
{
|
||||
error.init();
|
||||
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterSrv::devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceListItem& response,
|
||||
SWGSDRangel::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
|
||||
{
|
||||
DeviceSet *deviceSet = m_mainCore.m_deviceSets[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;
|
||||
}
|
||||
|
||||
MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, response.getTx() != 0);
|
||||
m_mainCore.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 202;
|
||||
}
|
||||
|
||||
*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 WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
||||
{
|
||||
deviceSetList->init();
|
||||
|
@ -125,6 +125,16 @@ public:
|
||||
SWGSDRangel::SWGSuccessResponse& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceSet& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceListItem& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainCore& m_mainCore;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user