diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index a060e46b2..6bc041d6a 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -54,6 +54,7 @@ set(sdrbase_SOURCES audio/audioresampler.cpp channel/channelapi.cpp + channel/channelutils.cpp channel/remotedataqueue.cpp channel/remotedatareadqueue.cpp @@ -160,6 +161,7 @@ set(sdrbase_HEADERS audio/audioresampler.h channel/channelapi.h + channel/channelutils.h channel/remotedataqueue.h channel/remotedatareadqueue.h channel/remotedatablock.h diff --git a/sdrbase/channel/channelutils.cpp b/sdrbase/channel/channelutils.cpp new file mode 100644 index 000000000..b10c0a5a5 --- /dev/null +++ b/sdrbase/channel/channelutils.cpp @@ -0,0 +1,40 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "channelutils.h" + +bool ChannelUtils::compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI) +{ + return registerdChannelURI == getRegisteredChannelURI(xChannelURI); +} + +QString ChannelUtils::getRegisteredChannelURI(const QString& xChannelURI) +{ + if (xChannelURI == "sdrangel.channel.chanalyzerng") { + return "sdrangel.channel.chanalyzer"; + } else if (xChannelURI == "de.maintech.sdrangelove.channel.am") { + return "sdrangel.channel.amdemod"; + } else if (xChannelURI == "de.maintech.sdrangelove.channel.nfm") { + return "sdrangel.channel.nfmdemod"; + } else if (xChannelURI == "de.maintech.sdrangelove.channel.ssb") { + return "sdrangel.channel.ssbdemod"; + } else if (xChannelURI == "de.maintech.sdrangelove.channel.wfm") { + return "sdrangel.channel.wfmdemod"; + } else { + return xChannelURI; + } +} \ No newline at end of file diff --git a/sdrbase/channel/channelutils.h b/sdrbase/channel/channelutils.h new file mode 100644 index 000000000..9711fbcb8 --- /dev/null +++ b/sdrbase/channel/channelutils.h @@ -0,0 +1,30 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRBASE_CHANNEL_CHANNELUTILS_H_ +#define SDRBASE_CHANNEL_CHANNELUTILS_H_ + +#include + +class ChannelUtils +{ +public: + static bool compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI); + static QString getRegisteredChannelURI(const QString& xChannelURI); +}; + +#endif // SDRBASE_CHANNEL_CHANNELUTILS_H_ \ No newline at end of file diff --git a/sdrbase/webapi/webapiadapterbase.cpp b/sdrbase/webapi/webapiadapterbase.cpp index 8f0718a61..afc058e8d 100644 --- a/sdrbase/webapi/webapiadapterbase.cpp +++ b/sdrbase/webapi/webapiadapterbase.cpp @@ -19,6 +19,7 @@ #include "plugin/pluginmanager.h" #include "channel/channelapi.h" +#include "channel/channelutils.h" #include "webapiadapterbase.h" WebAPIAdapterBase::WebAPIAdapterBase() @@ -67,6 +68,7 @@ void WebAPIAdapterBase::webapiFormatPreset( const Preset::ChannelConfig& channelConfig = preset.getChannelConfig(i); QList *swgChannelConfigs = apiPreset->getChannelConfigs(); swgChannelConfigs->append(new SWGSDRangel::SWGChannelConfig); + swgChannelConfigs->back()->init(); swgChannelConfigs->back()->setChannelIdUri(new QString(channelConfig.m_channelIdURI)); const QByteArray& channelSettings = channelConfig.m_config; SWGSDRangel::SWGChannelSettings *swgChannelSettings = swgChannelConfigs->back()->getConfig(); @@ -87,12 +89,13 @@ void WebAPIAdapterBase::webapiFormatPreset( const Preset::DeviceConfig& deviceConfig = preset.getDeviceConfig(i); QList *swgdeviceConfigs = apiPreset->getDeviceConfigs(); swgdeviceConfigs->append(new SWGSDRangel::SWGDeviceConfig); + swgdeviceConfigs->back()->init(); swgdeviceConfigs->back()->setDeviceId(new QString(deviceConfig.m_deviceId)); swgdeviceConfigs->back()->setDeviceSerial(new QString(deviceConfig.m_deviceSerial)); swgdeviceConfigs->back()->setDeviceSequence(deviceConfig.m_deviceSequence); - const QByteArray& deviceSettings = deviceConfig.m_config; - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = swgdeviceConfigs->back()->getConfig(); - swgDeviceSettings->init(); + // const QByteArray& deviceSettings = deviceConfig.m_config; + // SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = swgdeviceConfigs->back()->getConfig(); + // swgDeviceSettings->init(); } } @@ -114,13 +117,24 @@ void WebAPIAdapterBase::webapiFormatCommand( ChannelAPI *WebAPIAdapterBase::WebAPIChannelAdapters::getChannelAPI(const QString& channelURI, const PluginManager *pluginManager) { - QMap::iterator it = m_webAPIChannelAdapters.find(channelURI); + QString registeredChannelURI = ChannelUtils::getRegisteredChannelURI(channelURI); + QMap::iterator it = m_webAPIChannelAdapters.find(registeredChannelURI); if (it == m_webAPIChannelAdapters.end()) { - ChannelAPI *channelAPI = pluginManager->getChannelPluginInterface(channelURI)->createChannelWebAPIAdapter(); - m_webAPIChannelAdapters.insert(channelURI, channelAPI); - return channelAPI; + const PluginInterface *pluginInterface = pluginManager->getChannelPluginInterface(registeredChannelURI); + + if (pluginInterface) + { + ChannelAPI *channelAPI = pluginInterface->createChannelWebAPIAdapter(); + m_webAPIChannelAdapters.insert(registeredChannelURI, channelAPI); + return channelAPI; + } + else + { + m_webAPIChannelAdapters.insert(registeredChannelURI, nullptr); + return nullptr; + } } else { diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index ac1084235..2ab0a34e6 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -27,6 +27,7 @@ #include "plugin/plugininstancegui.h" #include "plugin/pluginapi.h" #include "plugin/plugininterface.h" +#include "channel/channelutils.h" #include "settings/preset.h" #include "deviceuiset.h" @@ -194,7 +195,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA for(int i = 0; i < channelRegistrations->count(); i++) { //if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI) - if (compareRxChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI)) + if (ChannelUtils::compareRxChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI)) { qDebug("DeviceUISet::loadRxChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), @@ -354,19 +355,3 @@ bool DeviceUISet::ChannelInstanceRegistration::operator<(const ChannelInstanceRe } } -bool DeviceUISet::compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI) -{ - if ((xChannelURI == "sdrangel.channel.chanalyzerng") || (xChannelURI == "sdrangel.channel.chanalyzer")) { // renamed ChanalyzerNG to Chanalyzer in 4.0.0 - return registerdChannelURI == "sdrangel.channel.chanalyzer"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.am") || (xChannelURI == "sdrangel.channel.amdemod")) { - return registerdChannelURI == "sdrangel.channel.amdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.nfm") || (xChannelURI == "sdrangel.channel.nfmdemod")) { - return registerdChannelURI == "sdrangel.channel.nfmdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.ssb") || (xChannelURI == "sdrangel.channel.ssbdemod")) { - return registerdChannelURI == "sdrangel.channel.ssbdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.wfm") || (xChannelURI == "sdrangel.channel.wfmdemod")) { - return registerdChannelURI == "sdrangel.channel.wfmdemod"; - } else { - return registerdChannelURI == xChannelURI; - } -} diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index cff2da450..9ae2b786d 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -111,8 +111,6 @@ private: void renameRxChannelInstances(); void renameTxChannelInstances(); - /** Use this function to support possible older identifiers in presets */ - bool compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI); }; diff --git a/sdrsrv/device/deviceset.cpp b/sdrsrv/device/deviceset.cpp index d4c58a52b..39ea9ef2c 100644 --- a/sdrsrv/device/deviceset.cpp +++ b/sdrsrv/device/deviceset.cpp @@ -21,6 +21,7 @@ #include "plugin/plugininterface.h" #include "settings/preset.h" #include "channel/channelapi.h" +#include "channel/channelutils.h" #include "settings/preset.h" #include "deviceset.h" @@ -184,7 +185,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI qDebug("DeviceSet::loadChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channelIdURI)); //if(openChannels[i].m_channelName == channelConfig.m_channelIdURI) - if (compareRxChannelURIs(openChannels[i].m_channelName, channelConfig.m_channelIdURI)) + if (ChannelUtils::compareRxChannelURIs(openChannels[i].m_channelName, channelConfig.m_channelIdURI)) { qDebug("DeviceSet::loadChannelSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); reg = openChannels.takeAt(i); @@ -200,7 +201,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI for (int i = 0; i < channelRegistrations->count(); i++) { //if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI) - if (compareRxChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI)) + if (ChannelUtils::compareRxChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI)) { qDebug("DeviceSet::loadChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), @@ -392,19 +393,3 @@ bool DeviceSet::ChannelInstanceRegistration::operator<(const ChannelInstanceRegi } } -bool DeviceSet::compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI) -{ - if ((xChannelURI == "sdrangel.channel.chanalyzerng") || (xChannelURI == "sdrangel.channel.chanalyzer")) { // renamed ChanalyzerNG to Chanalyzer in 4.0.0 - return registerdChannelURI == "sdrangel.channel.chanalyzer"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.am") || (xChannelURI == "sdrangel.channel.amdemod")) { - return registerdChannelURI == "sdrangel.channel.amdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.nfm") || (xChannelURI == "sdrangel.channel.nfmdemod")) { - return registerdChannelURI == "sdrangel.channel.nfmdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.ssb") || (xChannelURI == "sdrangel.channel.ssbdemod")) { - return registerdChannelURI == "sdrangel.channel.ssbdemod"; - } else if ((xChannelURI == "de.maintech.sdrangelove.channel.wfm") || (xChannelURI == "sdrangel.channel.wfmdemod")) { - return registerdChannelURI == "sdrangel.channel.wfmdemod"; - } else { - return registerdChannelURI == xChannelURI; - } -} diff --git a/sdrsrv/device/deviceset.h b/sdrsrv/device/deviceset.h index c253ce5db..dab2524e8 100644 --- a/sdrsrv/device/deviceset.h +++ b/sdrsrv/device/deviceset.h @@ -82,8 +82,6 @@ private: void renameRxChannelInstances(); void renameTxChannelInstances(); - /** Use this function to support possible older identifiers in presets */ - bool compareRxChannelURIs(const QString& registerdChannelURI, const QString& xChannelURI); }; #endif /* SDRSRV_DEVICE_DEVICESET_H_ */