1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 13:51:47 -05:00

Single DeviceAPI: REST API fixes

This commit is contained in:
f4exb 2019-05-09 01:12:40 +02:00
parent 89e53cf179
commit 029e559824
14 changed files with 339 additions and 215 deletions

View File

@ -43,8 +43,8 @@ public:
void removeTxSelection(int tabIndex); void removeTxSelection(int tabIndex);
int getNbRxSamplingDevices() const { return m_rxEnumeration.size(); } int getNbRxSamplingDevices() const { return m_rxEnumeration.size(); }
int getNbTxSamplingDevices() const { return m_txEnumeration.size(); } int getNbTxSamplingDevices() const { return m_txEnumeration.size(); }
PluginInterface::SamplingDevice getRxSamplingDevice(int deviceIndex) const { return m_rxEnumeration[deviceIndex].m_samplingDevice; } const PluginInterface::SamplingDevice* getRxSamplingDevice(int deviceIndex) const { return &m_rxEnumeration[deviceIndex].m_samplingDevice; }
PluginInterface::SamplingDevice getTxSamplingDevice(int deviceIndex) const { return m_txEnumeration[deviceIndex].m_samplingDevice; } const PluginInterface::SamplingDevice* getTxSamplingDevice(int deviceIndex) const { return &m_txEnumeration[deviceIndex].m_samplingDevice; }
PluginInterface *getRxPluginInterface(int deviceIndex) { return m_rxEnumeration[deviceIndex].m_pluginInterface; } PluginInterface *getRxPluginInterface(int deviceIndex) { return m_rxEnumeration[deviceIndex].m_pluginInterface; }
PluginInterface *getTxPluginInterface(int deviceIndex) { return m_txEnumeration[deviceIndex].m_pluginInterface; } PluginInterface *getTxPluginInterface(int deviceIndex) { return m_txEnumeration[deviceIndex].m_pluginInterface; }
int getFileSourceDeviceIndex() const; int getFileSourceDeviceIndex() const;

View File

@ -179,7 +179,7 @@ void MainSettings::renamePresetGroup(const QString& oldGroupName, const QString&
} }
} }
const Preset* MainSettings::getPreset(const QString& groupName, quint64 centerFrequency, const QString& description) const const Preset* MainSettings::getPreset(const QString& groupName, quint64 centerFrequency, const QString& description, const QString& type) const
{ {
int nbPresets = getPresetCount(); int nbPresets = getPresetCount();
@ -189,7 +189,11 @@ const Preset* MainSettings::getPreset(const QString& groupName, quint64 centerFr
(getPreset(i)->getCenterFrequency() == centerFrequency) && (getPreset(i)->getCenterFrequency() == centerFrequency) &&
(getPreset(i)->getDescription() == description)) (getPreset(i)->getDescription() == description))
{ {
return getPreset(i); if (type == "R" && getPreset(i)->isSourcePreset()) {
return getPreset(i);
} else if (type == "T" && !getPreset(i)->isSourcePreset()) {
return getPreset(i);
}
} }
} }

View File

@ -25,7 +25,7 @@ public:
void deletePreset(const Preset* preset); void deletePreset(const Preset* preset);
int getPresetCount() const { return m_presets.count(); } int getPresetCount() const { return m_presets.count(); }
const Preset* getPreset(int index) const { return m_presets[index]; } const Preset* getPreset(int index) const { return m_presets[index]; }
const Preset* getPreset(const QString& groupName, quint64 centerFrequency, const QString& description) const; const Preset* getPreset(const QString& groupName, quint64 centerFrequency, const QString& description, const QString& type) const;
void sortPresets(); void sortPresets();
void renamePresetGroup(const QString& oldGroupName, const QString& newGroupName); void renamePresetGroup(const QString& oldGroupName, const QString& newGroupName);
void deletePresetGroup(const QString& groupName); void deletePresetGroup(const QString& groupName);

View File

@ -93,11 +93,11 @@ public:
* returns the Http status code (default 501: not implemented) * returns the Http status code (default 501: not implemented)
*/ */
virtual int instanceDevices( virtual int instanceDevices(
bool tx, int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response, SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) tx; (void) direction;
(void) response; (void) response;
error.init(); error.init();
*error.getMessage() = QString("Function not implemented"); *error.getMessage() = QString("Function not implemented");
@ -109,11 +109,11 @@ public:
* returns the Http status code (default 501: not implemented) * returns the Http status code (default 501: not implemented)
*/ */
virtual int instanceChannels( virtual int instanceChannels(
bool tx, int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response, SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) tx; (void) direction;
(void) response; (void) response;
error.init(); error.init();
*error.getMessage() = QString("Function not implemented"); *error.getMessage() = QString("Function not implemented");
@ -437,11 +437,11 @@ public:
* returns the Http status code (default 501: not implemented) * returns the Http status code (default 501: not implemented)
*/ */
virtual int instanceDeviceSetPost( virtual int instanceDeviceSetPost(
bool tx, int direction,
SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) tx; (void) direction;
(void) response; (void) response;
error.init(); error.init();
*error.getMessage() = QString("Function not implemented"); *error.getMessage() = QString("Function not implemented");

View File

@ -212,14 +212,19 @@ void WebAPIRequestMapper::instanceDevicesService(qtwebapp::HttpRequest& request,
if (request.getMethod() == "GET") if (request.getMethod() == "GET")
{ {
QByteArray txStr = request.getParameter("tx"); QByteArray dirStr = request.getParameter("direction");
bool tx = false; int direction = 0;
if (txStr.length() != 0) { if (dirStr.length() != 0)
tx = !(txStr == "0"); {
bool ok;
int tmp = dirStr.toInt(&ok);
if (ok) {
direction = tmp;
}
} }
int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse); int status = m_adapter->instanceDevices(direction, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
if (status/100 == 2) { if (status/100 == 2) {
@ -246,14 +251,19 @@ void WebAPIRequestMapper::instanceChannelsService(qtwebapp::HttpRequest& request
if (request.getMethod() == "GET") if (request.getMethod() == "GET")
{ {
QByteArray txStr = request.getParameter("tx"); QByteArray dirStr = request.getParameter("direction");
bool tx = false; int direction = 0;
if (txStr.length() != 0) { if (dirStr.length() != 0)
tx = !(txStr == "0"); {
bool ok;
int tmp = dirStr.toInt(&ok);
if (ok) {
direction = tmp;
}
} }
int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse); int status = m_adapter->instanceChannels(direction, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
if (status/100 == 2) { if (status/100 == 2) {
@ -962,14 +972,19 @@ void WebAPIRequestMapper::instanceDeviceSetService(qtwebapp::HttpRequest& reques
if (request.getMethod() == "POST") if (request.getMethod() == "POST")
{ {
SWGSDRangel::SWGSuccessResponse normalResponse; SWGSDRangel::SWGSuccessResponse normalResponse;
QByteArray txStr = request.getParameter("tx"); QByteArray dirStr = request.getParameter("direction");
bool tx = false; int direction = 0;
if (txStr.length() != 0) { if (dirStr.length() != 0)
tx = !(txStr == "0"); {
bool ok;
int tmp = dirStr.toInt(&ok);
if (ok) {
direction = tmp;
}
} }
int status = m_adapter->instanceDeviceSetPost(tx, normalResponse, errorResponse); int status = m_adapter->instanceDeviceSetPost(direction, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
if (status/100 == 2) { if (status/100 == 2) {

View File

@ -63,15 +63,15 @@ void SamplingDeviceControl::setSelectedDeviceIndex(int index)
{ {
if (m_rxElseTx) if (m_rxElseTx)
{ {
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(index); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(index);
DeviceEnumerator::instance()->changeRxSelection(m_deviceTabIndex, index); DeviceEnumerator::instance()->changeRxSelection(m_deviceTabIndex, index);
ui->deviceSelectedText->setText(samplingDevice.displayedName); ui->deviceSelectedText->setText(samplingDevice->displayedName);
} }
else else
{ {
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(index); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(index);
DeviceEnumerator::instance()->changeTxSelection(m_deviceTabIndex, index); DeviceEnumerator::instance()->changeTxSelection(m_deviceTabIndex, index);
ui->deviceSelectedText->setText(samplingDevice.displayedName); ui->deviceSelectedText->setText(samplingDevice->displayedName);
} }
m_selectedDeviceIndex = index; m_selectedDeviceIndex = index;

View File

@ -278,14 +278,14 @@ void MainWindow::addSourceDevice(int deviceIndex)
deviceIndex = DeviceEnumerator::instance()->getFileSourceDeviceIndex(); deviceIndex = DeviceEnumerator::instance()->getFileSourceDeviceIndex();
} }
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(deviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(deviceIndex);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceUIs.back()->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); m_deviceUIs.back()->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
m_deviceUIs.back()->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); m_deviceUIs.back()->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceIndex)); m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceIndex));
m_deviceUIs.back()->m_samplingDeviceControl->setSelectedDeviceIndex(deviceIndex); m_deviceUIs.back()->m_samplingDeviceControl->setSelectedDeviceIndex(deviceIndex);
@ -349,14 +349,14 @@ void MainWindow::addSinkDevice()
// create a file sink by default // create a file sink by default
int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileSinkDeviceIndex(); int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileSinkDeviceIndex();
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceUIs.back()->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); m_deviceUIs.back()->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
m_deviceUIs.back()->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); m_deviceUIs.back()->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex)); m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex));
m_deviceUIs.back()->m_samplingDeviceControl->setSelectedDeviceIndex(fileSinkDeviceIndex); m_deviceUIs.back()->m_samplingDeviceControl->setSelectedDeviceIndex(fileSinkDeviceIndex);
@ -795,12 +795,13 @@ bool MainWindow::handleMessage(const Message& cmd)
else if (MsgAddDeviceSet::match(cmd)) else if (MsgAddDeviceSet::match(cmd))
{ {
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd; MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;
int direction = notif.getDirection();
if (notif.isTx()) { if (direction == 1) { // Single stream Tx
addSinkDevice(); addSinkDevice();
} else { } else if (direction == 0) { // Single stream Rx
addSourceDevice(-1); // create with file source device by default addSourceDevice(-1); // create with file source device by default
} } // other device types not (yet) supported
return true; return true;
} }
@ -1506,15 +1507,15 @@ void MainWindow::sampleSourceChanged()
deviceUI->m_deviceAPI->getSampleSource()); deviceUI->m_deviceAPI->getSampleSource());
deviceUI->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists deviceUI->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice( const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(
deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex()); deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex());
deviceUI->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); deviceUI->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceUI->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); deviceUI->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
deviceUI->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); deviceUI->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
deviceUI->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); deviceUI->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceUI->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); deviceUI->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceUI->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); deviceUI->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceUI->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); deviceUI->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceUI->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex())); deviceUI->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex()));
// add to buddies list // add to buddies list
@ -1569,8 +1570,8 @@ void MainWindow::sampleSourceChanged()
if (currentSourceTabIndex == 0) // save as default starting device if (currentSourceTabIndex == 0) // save as default starting device
{ {
m_settings.setSourceIndex(samplingDevice.sequence); m_settings.setSourceIndex(samplingDevice->sequence);
m_settings.setSourceDeviceId(samplingDevice.id); m_settings.setSourceDeviceId(samplingDevice->id);
} }
} }
} }
@ -1596,14 +1597,14 @@ void MainWindow::sampleSinkChanged()
deviceUI->m_deviceAPI->getSampleSink()); deviceUI->m_deviceAPI->getSampleSink());
deviceUI->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists deviceUI->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex()); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex());
deviceUI->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); deviceUI->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceUI->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); deviceUI->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
deviceUI->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); deviceUI->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
deviceUI->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); deviceUI->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceUI->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); deviceUI->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceUI->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); deviceUI->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceUI->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); deviceUI->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceUI->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex())); deviceUI->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(deviceUI->m_samplingDeviceControl->getSelectedDeviceIndex()));
// add to buddies list // add to buddies list

View File

@ -159,19 +159,19 @@ private:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
bool isTx() const { return m_tx; } int getDirection() const { return m_direction; }
static MsgAddDeviceSet* create(bool tx) static MsgAddDeviceSet* create(int direction)
{ {
return new MsgAddDeviceSet(tx); return new MsgAddDeviceSet(direction);
} }
private: private:
bool m_tx; int m_direction;
MsgAddDeviceSet(bool tx) : MsgAddDeviceSet(int direction) :
Message(), Message(),
m_tx(tx) m_direction(direction)
{ } { }
}; };

View File

@ -115,28 +115,47 @@ int WebAPIAdapterGUI::instanceDelete(
} }
int WebAPIAdapterGUI::instanceDevices( int WebAPIAdapterGUI::instanceDevices(
bool tx, int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response, SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) error; (void) error;
response.init(); response.init();
int nbSamplingDevices = tx ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
int nbSamplingDevices;
if (direction == 0) { // Single Rx stream device
nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
} else if (direction == 1) { // Single Tx stream device
nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
} else { // not supported
nbSamplingDevices = 0;
}
response.setDevicecount(nbSamplingDevices); response.setDevicecount(nbSamplingDevices);
QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices(); QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices();
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
PluginInterface::SamplingDevice samplingDevice = tx ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); const PluginInterface::SamplingDevice *samplingDevice = nullptr;
if (direction == 0) {
samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
} else if (direction == 1) {
samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
} else {
continue;
}
devices->append(new SWGSDRangel::SWGDeviceListItem); devices->append(new SWGSDRangel::SWGDeviceListItem);
devices->back()->init(); devices->back()->init();
*devices->back()->getDisplayedName() = samplingDevice.displayedName; *devices->back()->getDisplayedName() = samplingDevice->displayedName;
*devices->back()->getHwType() = samplingDevice.hardwareId; *devices->back()->getHwType() = samplingDevice->hardwareId;
*devices->back()->getSerial() = samplingDevice.serial; *devices->back()->getSerial() = samplingDevice->serial;
devices->back()->setSequence(samplingDevice.sequence); devices->back()->setSequence(samplingDevice->sequence);
devices->back()->setDirection((int) samplingDevice.streamType); devices->back()->setDirection((int) samplingDevice->streamType);
devices->back()->setDeviceNbStreams(samplingDevice.deviceNbItems); devices->back()->setDeviceNbStreams(samplingDevice->deviceNbItems);
devices->back()->setDeviceSetIndex(samplingDevice.claimed); devices->back()->setDeviceSetIndex(samplingDevice->claimed);
devices->back()->setIndex(i); devices->back()->setIndex(i);
} }
@ -144,14 +163,31 @@ int WebAPIAdapterGUI::instanceDevices(
} }
int WebAPIAdapterGUI::instanceChannels( int WebAPIAdapterGUI::instanceChannels(
bool tx, int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response, SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) error; (void) error;
response.init(); response.init();
PluginAPI::ChannelRegistrations *channelRegistrations = tx ? m_mainWindow.m_pluginManager->getTxChannelRegistrations() : m_mainWindow.m_pluginManager->getRxChannelRegistrations(); PluginAPI::ChannelRegistrations *channelRegistrations;
int nbChannelDevices = channelRegistrations->size(); int nbChannelDevices;
if (direction == 0) // Single sink (Rx) channel
{
channelRegistrations = m_mainWindow.m_pluginManager->getRxChannelRegistrations();
nbChannelDevices = channelRegistrations->size();
}
else if (direction == 1) // Single source (Tx) channel
{
channelRegistrations = m_mainWindow.m_pluginManager->getTxChannelRegistrations();
nbChannelDevices = channelRegistrations->size();
}
else // not supported
{
channelRegistrations = nullptr;
nbChannelDevices = 0;
}
response.setChannelcount(nbChannelDevices); response.setChannelcount(nbChannelDevices);
QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels(); QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels();
@ -163,7 +199,7 @@ int WebAPIAdapterGUI::instanceChannels(
const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor(); const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor();
*channels->back()->getVersion() = pluginDescriptor.version; *channels->back()->getVersion() = pluginDescriptor.version;
*channels->back()->getName() = pluginDescriptor.displayedName; *channels->back()->getName() = pluginDescriptor.displayedName;
channels->back()->setDirection(tx ? 1 : 0); channels->back()->setDirection(direction);
*channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI; *channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI;
*channels->back()->getId() = channelRegistrations->at(i).m_channelId; *channels->back()->getId() = channelRegistrations->at(i).m_channelId;
channels->back()->setIndex(i); channels->back()->setIndex(i);
@ -655,15 +691,17 @@ int WebAPIAdapterGUI::instancePresetPatch(
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(), presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency()) .arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 404; return 404;
} }
@ -713,15 +751,17 @@ int WebAPIAdapterGUI::instancePresetPut(
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(), presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency()) .arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 404; return 404;
} }
else // update existing preset else // update existing preset
@ -786,7 +826,8 @@ int WebAPIAdapterGUI::instancePresetPost(
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
deviceCenterFrequency, deviceCenterFrequency,
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) // save on a new preset if (selectedPreset == 0) // save on a new preset
{ {
@ -795,10 +836,11 @@ int WebAPIAdapterGUI::instancePresetPost(
else else
{ {
error.init(); error.init();
*error.getMessage() = QString("Preset already exists [%1, %2, %3]") *error.getMessage() = QString("Preset already exists [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(deviceCenterFrequency) .arg(deviceCenterFrequency)
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 409; return 409;
} }
@ -820,14 +862,16 @@ int WebAPIAdapterGUI::instancePresetDelete(
{ {
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*response.getGroupName(), const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*response.getGroupName(),
response.getCenterFrequency(), response.getCenterFrequency(),
*response.getName()); *response.getName(),
*response.getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*response.getGroupName()) .arg(*response.getGroupName())
.arg(response.getCenterFrequency()) .arg(response.getCenterFrequency())
.arg(*response.getName()); .arg(*response.getName())
.arg(*response.getType());
return 404; return 404;
} }
@ -852,12 +896,12 @@ int WebAPIAdapterGUI::instanceDeviceSetsGet(
} }
int WebAPIAdapterGUI::instanceDeviceSetPost( int WebAPIAdapterGUI::instanceDeviceSetPost(
bool tx, int direction,
SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
(void) error; (void) error;
MainWindow::MsgAddDeviceSet *msg = MainWindow::MsgAddDeviceSet::create(tx); MainWindow::MsgAddDeviceSet *msg = MainWindow::MsgAddDeviceSet::create(direction);
m_mainWindow.m_inputMessageQueue.push(msg); m_mainWindow.m_inputMessageQueue.push(msg);
response.init(); response.init();
@ -972,34 +1016,40 @@ int WebAPIAdapterGUI::devicesetDevicePut(
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
int tx; int tx;
const PluginInterface::SamplingDevice *samplingDevice;
if (query.getDirection() == 0) { if (query.getDirection() == 0)
{
tx = 0; tx = 0;
} else if (query.getDirection() == 1) { samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
}
else if (query.getDirection() == 1)
{
tx = 1; tx = 1;
} else { samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
}
else
{
continue; // TODO: any device (2) not supported yet continue; // TODO: any device (2) not supported yet
} }
PluginInterface::SamplingDevice samplingDevice = query.getDirection() == 0 ? DeviceEnumerator::instance()->getRxSamplingDevice(i) : DeviceEnumerator::instance()->getTxSamplingDevice(i); if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice->displayedName)) {
if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice.displayedName)) {
continue; continue;
} }
if (query.getHwType() && (*query.getHwType() != samplingDevice.hardwareId)) { if (query.getHwType() && (*query.getHwType() != samplingDevice->hardwareId)) {
continue; continue;
} }
if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice.sequence)) { if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice->sequence)) {
continue; continue;
} }
if (query.getSerial() && (*query.getSerial() != samplingDevice.serial)) { if (query.getSerial() && (*query.getSerial() != samplingDevice->serial)) {
continue; continue;
} }
if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice.deviceItemIndex)) { if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice->deviceItemIndex)) {
continue; continue;
} }
@ -1007,13 +1057,13 @@ int WebAPIAdapterGUI::devicesetDevicePut(
m_mainWindow.m_inputMessageQueue.push(msg); m_mainWindow.m_inputMessageQueue.push(msg);
response.init(); response.init();
*response.getDisplayedName() = samplingDevice.displayedName; *response.getDisplayedName() = samplingDevice->displayedName;
*response.getHwType() = samplingDevice.hardwareId; *response.getHwType() = samplingDevice->hardwareId;
*response.getSerial() = samplingDevice.serial; *response.getSerial() = samplingDevice->serial;
response.setSequence(samplingDevice.sequence); response.setSequence(samplingDevice->sequence);
response.setDirection(tx); response.setDirection(tx);
response.setDeviceNbStreams(samplingDevice.deviceNbItems); response.setDeviceNbStreams(samplingDevice->deviceNbItems);
response.setDeviceStreamIndex(samplingDevice.deviceItemIndex); response.setDeviceStreamIndex(samplingDevice->deviceItemIndex);
response.setDeviceSetIndex(deviceSetIndex); response.setDeviceSetIndex(deviceSetIndex);
response.setIndex(i); response.setIndex(i);

View File

@ -42,12 +42,12 @@ public:
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDevices( virtual int instanceDevices(
bool tx, int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response, SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceChannels( virtual int instanceChannels(
bool tx, int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response, SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
@ -135,7 +135,7 @@ public:
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetPost( virtual int instanceDeviceSetPost(
bool tx, int direction,
SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);

View File

@ -142,12 +142,13 @@ bool MainCore::handleMessage(const Message& cmd)
else if (MsgAddDeviceSet::match(cmd)) else if (MsgAddDeviceSet::match(cmd))
{ {
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd; MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;
int direction = notif.getDirection();
if (notif.isTx()) { if (direction == 1) { // Single stream Tx
addSinkDevice(); addSinkDevice();
} else { } else if (direction == 0) { // Single stream Rx
addSourceDevice(); addSourceDevice();
} } // device type not (yet) supported
return true; return true;
} }
@ -283,14 +284,14 @@ void MainCore::addSinkDevice()
// create a file sink by default // create a file sink by default
int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileSinkDeviceIndex(); int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileSinkDeviceIndex();
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceSets.back()->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); m_deviceSets.back()->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
m_deviceSets.back()->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); m_deviceSets.back()->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex)); m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex));
// delete previous plugin instance // delete previous plugin instance
@ -323,14 +324,14 @@ void MainCore::addSourceDevice()
// Create a file source instance by default // Create a file source instance by default
int fileSourceDeviceIndex = DeviceEnumerator::instance()->getFileSourceDeviceIndex(); int fileSourceDeviceIndex = DeviceEnumerator::instance()->getFileSourceDeviceIndex();
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(fileSourceDeviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(fileSourceDeviceIndex);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceSets.back()->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); m_deviceSets.back()->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
m_deviceSets.back()->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); m_deviceSets.back()->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(fileSourceDeviceIndex)); m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(fileSourceDeviceIndex));
DeviceSampleSource *source = m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstanceInput( DeviceSampleSource *source = m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstanceInput(
@ -399,14 +400,14 @@ void MainCore::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
deviceSet->m_deviceAPI->getSampleSource()); deviceSet->m_deviceAPI->getSampleSource());
deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex);
deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceSet->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); deviceSet->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
deviceSet->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); deviceSet->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
deviceSet->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); deviceSet->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(selectedDeviceIndex)); deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(selectedDeviceIndex));
// add to buddies list // add to buddies list
@ -467,14 +468,14 @@ void MainCore::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex)
deviceSet->m_deviceAPI->getSampleSink()); deviceSet->m_deviceAPI->getSampleSink());
deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(selectedDeviceIndex); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(selectedDeviceIndex);
deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice.sequence); deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceSet->m_deviceAPI->setNbItems(samplingDevice.deviceNbItems); deviceSet->m_deviceAPI->setNbItems(samplingDevice->deviceNbItems);
deviceSet->m_deviceAPI->setItemIndex(samplingDevice.deviceItemIndex); deviceSet->m_deviceAPI->setItemIndex(samplingDevice->deviceItemIndex);
deviceSet->m_deviceAPI->setHardwareId(samplingDevice.hardwareId); deviceSet->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice.id); deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice.serial); deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice.displayedName); deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(selectedDeviceIndex)); deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(selectedDeviceIndex));
// add to buddies list // add to buddies list

View File

@ -160,19 +160,19 @@ private:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
bool isTx() const { return m_tx; } int getDirection() const { return m_direction; }
static MsgAddDeviceSet* create(bool tx) static MsgAddDeviceSet* create(int direction)
{ {
return new MsgAddDeviceSet(tx); return new MsgAddDeviceSet(direction);
} }
private: private:
bool m_tx; int m_direction;
MsgAddDeviceSet(bool tx) : MsgAddDeviceSet(int direction) :
Message(), Message(),
m_tx(tx) m_direction(direction)
{ } { }
}; };

View File

@ -116,27 +116,47 @@ int WebAPIAdapterSrv::instanceDelete(
} }
int WebAPIAdapterSrv::instanceDevices( int WebAPIAdapterSrv::instanceDevices(
bool tx, int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response, SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
{ {
response.init(); response.init();
int nbSamplingDevices = tx ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
int nbSamplingDevices;
if (direction == 0) { // Single Rx stream device
nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
} else if (direction == 1) { // Single Tx stream device
nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices();
} else { // not supported
nbSamplingDevices = 0;
}
response.setDevicecount(nbSamplingDevices); response.setDevicecount(nbSamplingDevices);
QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices(); QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices();
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
PluginInterface::SamplingDevice samplingDevice = tx ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); const PluginInterface::SamplingDevice *samplingDevice = nullptr;
if (direction == 0) {
samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
} else if (direction == 1) {
samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
} else {
continue;
}
devices->append(new SWGSDRangel::SWGDeviceListItem); devices->append(new SWGSDRangel::SWGDeviceListItem);
devices->back()->init(); devices->back()->init();
*devices->back()->getDisplayedName() = samplingDevice.displayedName; *devices->back()->getDisplayedName() = samplingDevice->displayedName;
*devices->back()->getHwType() = samplingDevice.hardwareId; *devices->back()->getHwType() = samplingDevice->hardwareId;
*devices->back()->getSerial() = samplingDevice.serial; *devices->back()->getSerial() = samplingDevice->serial;
devices->back()->setSequence(samplingDevice.sequence); devices->back()->setSequence(samplingDevice->sequence);
devices->back()->setDirection((int) samplingDevice.streamType); devices->back()->setDirection((int) samplingDevice->streamType);
devices->back()->setDeviceNbStreams(samplingDevice.deviceNbItems); devices->back()->setDeviceNbStreams(samplingDevice->deviceNbItems);
devices->back()->setDeviceSetIndex(samplingDevice.claimed); devices->back()->setDeviceSetIndex(samplingDevice->claimed);
devices->back()->setIndex(i); devices->back()->setIndex(i);
} }
@ -144,13 +164,30 @@ int WebAPIAdapterSrv::instanceDevices(
} }
int WebAPIAdapterSrv::instanceChannels( int WebAPIAdapterSrv::instanceChannels(
bool tx, int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response, SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
{ {
response.init(); response.init();
PluginAPI::ChannelRegistrations *channelRegistrations = tx ? m_mainCore.m_pluginManager->getTxChannelRegistrations() : m_mainCore.m_pluginManager->getRxChannelRegistrations(); PluginAPI::ChannelRegistrations *channelRegistrations;
int nbChannelDevices = channelRegistrations->size(); int nbChannelDevices;
if (direction == 0) // Single sink (Rx) channel
{
channelRegistrations = m_mainCore.m_pluginManager->getRxChannelRegistrations();
nbChannelDevices = channelRegistrations->size();
}
else if (direction == 1) // Single source (Tx) channel
{
channelRegistrations = m_mainCore.m_pluginManager->getTxChannelRegistrations();
nbChannelDevices = channelRegistrations->size();
}
else // not supported
{
channelRegistrations = nullptr;
nbChannelDevices = 0;
}
response.setChannelcount(nbChannelDevices); response.setChannelcount(nbChannelDevices);
QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels(); QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels();
@ -162,7 +199,7 @@ int WebAPIAdapterSrv::instanceChannels(
const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor(); const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor();
*channels->back()->getVersion() = pluginDescriptor.version; *channels->back()->getVersion() = pluginDescriptor.version;
*channels->back()->getName() = pluginDescriptor.displayedName; *channels->back()->getName() = pluginDescriptor.displayedName;
channels->back()->setDirection(tx ? 1 : 0); channels->back()->setDirection(direction);
*channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI; *channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI;
*channels->back()->getId() = channelRegistrations->at(i).m_channelId; *channels->back()->getId() = channelRegistrations->at(i).m_channelId;
channels->back()->setIndex(i); channels->back()->setIndex(i);
@ -637,15 +674,17 @@ int WebAPIAdapterSrv::instancePresetFilePost(
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(), presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3, %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency()) .arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 404; return 404;
} }
@ -753,15 +792,17 @@ int WebAPIAdapterSrv::instancePresetPatch(
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(), presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency()) .arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 404; return 404;
} }
@ -811,15 +852,17 @@ int WebAPIAdapterSrv::instancePresetPut(
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(), presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency()) .arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 404; return 404;
} }
else // update existing preset else // update existing preset
@ -887,7 +930,8 @@ int WebAPIAdapterSrv::instancePresetPost(
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(), const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
deviceCenterFrequency, deviceCenterFrequency,
*presetIdentifier->getName()); *presetIdentifier->getName(),
*presetIdentifier->getType());
if (selectedPreset == 0) // save on a new preset if (selectedPreset == 0) // save on a new preset
{ {
@ -896,10 +940,11 @@ int WebAPIAdapterSrv::instancePresetPost(
else else
{ {
error.init(); error.init();
*error.getMessage() = QString("Preset already exists [%1, %2, %3]") *error.getMessage() = QString("Preset already exists [%1, %2, %3 %4]")
.arg(*presetIdentifier->getGroupName()) .arg(*presetIdentifier->getGroupName())
.arg(deviceCenterFrequency) .arg(deviceCenterFrequency)
.arg(*presetIdentifier->getName()); .arg(*presetIdentifier->getName())
.arg(*presetIdentifier->getType());
return 409; return 409;
} }
@ -921,15 +966,17 @@ int WebAPIAdapterSrv::instancePresetDelete(
{ {
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*response.getGroupName(), const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*response.getGroupName(),
response.getCenterFrequency(), response.getCenterFrequency(),
*response.getName()); *response.getName(),
*response.getType());
if (selectedPreset == 0) if (selectedPreset == 0)
{ {
error.init(); error.init();
*error.getMessage() = QString("There is no preset [%1, %2, %3]") *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]")
.arg(*response.getGroupName()) .arg(*response.getGroupName())
.arg(response.getCenterFrequency()) .arg(response.getCenterFrequency())
.arg(*response.getName()); .arg(*response.getName())
.arg(*response.getType());
return 404; return 404;
} }
@ -953,11 +1000,11 @@ int WebAPIAdapterSrv::instanceDeviceSetsGet(
} }
int WebAPIAdapterSrv::instanceDeviceSetPost( int WebAPIAdapterSrv::instanceDeviceSetPost(
bool tx, int direction,
SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
{ {
MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(tx); MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(direction);
m_mainCore.m_inputMessageQueue.push(msg); m_mainCore.m_inputMessageQueue.push(msg);
response.init(); response.init();
@ -1055,35 +1102,41 @@ int WebAPIAdapterSrv::devicesetDevicePut(
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
int tx; int direction;
const PluginInterface::SamplingDevice *samplingDevice;
if (query.getDirection() == 0) { if (query.getDirection() == 0)
tx = 0; {
} else if (query.getDirection() == 1) { direction = 0;
tx = 1; samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
} else { }
else if (query.getDirection() == 1)
{
direction = 1;
samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i);
}
else
{
continue; // TODO: any device (2) not supported yet continue; // TODO: any device (2) not supported yet
} }
PluginInterface::SamplingDevice samplingDevice = query.getDirection() == 0 ? DeviceEnumerator::instance()->getRxSamplingDevice(i) : DeviceEnumerator::instance()->getTxSamplingDevice(i); if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice->displayedName)) {
if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice.displayedName)) {
continue; continue;
} }
if (query.getHwType() && (*query.getHwType() != samplingDevice.hardwareId)) { if (query.getHwType() && (*query.getHwType() != samplingDevice->hardwareId)) {
continue; continue;
} }
if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice.sequence)) { if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice->sequence)) {
continue; continue;
} }
if (query.getSerial() && (*query.getSerial() != samplingDevice.serial)) { if (query.getSerial() && (*query.getSerial() != samplingDevice->serial)) {
continue; continue;
} }
if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice.deviceItemIndex)) { if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice->deviceItemIndex)) {
continue; continue;
} }
@ -1091,13 +1144,13 @@ int WebAPIAdapterSrv::devicesetDevicePut(
m_mainCore.m_inputMessageQueue.push(msg); m_mainCore.m_inputMessageQueue.push(msg);
response.init(); response.init();
*response.getDisplayedName() = samplingDevice.displayedName; *response.getDisplayedName() = samplingDevice->displayedName;
*response.getHwType() = samplingDevice.hardwareId; *response.getHwType() = samplingDevice->hardwareId;
*response.getSerial() = samplingDevice.serial; *response.getSerial() = samplingDevice->serial;
response.setSequence(samplingDevice.sequence); response.setSequence(samplingDevice->sequence);
response.setDirection(tx); response.setDirection(direction);
response.setDeviceNbStreams(samplingDevice.deviceNbItems); response.setDeviceNbStreams(samplingDevice->deviceNbItems);
response.setDeviceStreamIndex(samplingDevice.deviceItemIndex); response.setDeviceStreamIndex(samplingDevice->deviceItemIndex);
response.setDeviceSetIndex(deviceSetIndex); response.setDeviceSetIndex(deviceSetIndex);
response.setIndex(i); response.setIndex(i);

View File

@ -42,12 +42,12 @@ public:
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDevices( virtual int instanceDevices(
bool tx, int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response, SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceChannels( virtual int instanceChannels(
bool tx, int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response, SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
@ -145,7 +145,7 @@ public:
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetPost( virtual int instanceDeviceSetPost(
bool tx, int direction,
SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);