2017-12-17 17:15:42 -05:00
///////////////////////////////////////////////////////////////////////////////////
// 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 //
2019-04-11 08:44:23 -04:00
// (at your option) any later version. //
2017-12-17 17:15:42 -05:00
// //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
2020-04-19 00:13:32 -04:00
# include <algorithm>
2017-12-17 17:15:42 -05:00
# include "dsp/dspdevicesourceengine.h"
# include "dsp/dspdevicesinkengine.h"
2020-11-11 19:22:48 -05:00
# include "dsp/spectrumvis.h"
2017-12-17 17:15:42 -05:00
# include "plugin/pluginapi.h"
# include "plugin/plugininterface.h"
# include "settings/preset.h"
2019-05-09 11:27:12 -04:00
# include "channel/channelapi.h"
2019-08-01 19:58:59 -04:00
# include "channel/channelutils.h"
2017-12-17 17:15:42 -05:00
# include "settings/preset.h"
2020-10-16 02:35:06 -04:00
# include "maincore.h"
2017-12-17 17:15:42 -05:00
# include "deviceset.h"
2020-10-11 03:36:27 -04:00
DeviceSet : : DeviceSet ( int tabIndex , int deviceType )
2017-12-17 17:15:42 -05:00
{
2019-05-20 10:31:15 -04:00
m_deviceAPI = nullptr ;
m_deviceSourceEngine = nullptr ;
m_deviceSinkEngine = nullptr ;
m_deviceMIMOEngine = nullptr ;
2017-12-17 17:15:42 -05:00
m_deviceTabIndex = tabIndex ;
2020-11-11 19:22:48 -05:00
if ( ( deviceType = = 0 ) | | ( deviceType = = 2 ) ) { // Single Rx or MIMO
m_spectrumVis = new SpectrumVis ( SDR_RX_SCALEF ) ;
} else if ( deviceType = = 1 ) { // Single Tx
m_spectrumVis = new SpectrumVis ( SDR_TX_SCALEF ) ;
}
2017-12-17 17:15:42 -05:00
}
DeviceSet : : ~ DeviceSet ( )
{
2020-11-11 19:22:48 -05:00
delete m_spectrumVis ;
2017-12-17 17:15:42 -05:00
}
2019-09-07 18:44:56 -04:00
void DeviceSet : : freeChannels ( )
2017-12-23 16:33:30 -05:00
{
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
2017-12-23 16:33:30 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::freeChannels: destroying channel [%s] " , qPrintable ( m_channelInstanceRegistrations [ i ] - > getURI ( ) ) ) ;
m_channelInstanceRegistrations [ i ] - > destroy ( ) ;
2017-12-23 16:33:30 -05:00
}
2020-10-16 02:35:06 -04:00
MainCore : : instance ( ) - > clearChannels ( this ) ;
2017-12-23 16:33:30 -05:00
}
2020-10-13 02:15:21 -04:00
const ChannelAPI * DeviceSet : : getChannelAt ( int channelIndex ) const
{
if ( ( channelIndex > = 0 ) & & ( channelIndex < m_channelInstanceRegistrations . size ( ) ) ) {
2020-10-14 20:24:29 -04:00
return m_channelInstanceRegistrations [ channelIndex ] ;
2020-10-13 02:15:21 -04:00
} else {
return nullptr ;
}
}
ChannelAPI * DeviceSet : : getChannelAt ( int channelIndex )
{
if ( ( channelIndex > = 0 ) & & ( channelIndex < m_channelInstanceRegistrations . size ( ) ) ) {
2020-10-14 20:24:29 -04:00
return m_channelInstanceRegistrations [ channelIndex ] ;
2020-10-13 02:15:21 -04:00
} else {
return nullptr ;
}
}
2019-09-07 18:44:56 -04:00
void DeviceSet : : deleteChannel ( int channelIndex )
2017-12-23 16:33:30 -05:00
{
2019-09-07 18:44:56 -04:00
if ( channelIndex < m_channelInstanceRegistrations . count ( ) )
2017-12-23 16:33:30 -05:00
{
2020-10-14 20:24:29 -04:00
m_channelInstanceRegistrations [ channelIndex ] - > destroy ( ) ;
2019-09-07 18:44:56 -04:00
m_channelInstanceRegistrations . removeAt ( channelIndex ) ;
2020-10-16 02:35:06 -04:00
MainCore : : instance ( ) - > removeChannelInstanceAt ( this , channelIndex ) ;
2019-09-07 18:44:56 -04:00
renameChannelInstances ( ) ;
2017-12-23 16:33:30 -05:00
}
}
2017-12-22 23:56:40 -05:00
void DeviceSet : : addRxChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
{
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getRxChannelRegistrations ( ) ; // Available channel plugins
2020-10-01 16:47:30 -04:00
ChannelAPI * rxChannel ;
( * channelRegistrations ) [ selectedChannelIndex ] . m_plugin - > createRxChannel ( m_deviceAPI , nullptr , & rxChannel ) ;
2020-10-16 02:35:06 -04:00
ChannelAPI * channelAPI = rxChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
MainCore : : instance ( ) - > addChannelInstance ( this , channelAPI ) ;
renameChannelInstances ( ) ;
2017-12-22 23:56:40 -05:00
qDebug ( " DeviceSet::addRxChannel: %s " , qPrintable ( rxChannel - > getName ( ) ) ) ;
}
void DeviceSet : : addTxChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
{
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getTxChannelRegistrations ( ) ; // Available channel plugins
2020-10-01 16:47:30 -04:00
ChannelAPI * txChannel ;
( * channelRegistrations ) [ selectedChannelIndex ] . m_plugin - > createTxChannel ( m_deviceAPI , nullptr , & txChannel ) ;
2020-10-16 02:35:06 -04:00
ChannelAPI * channelAPI = txChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
MainCore : : instance ( ) - > addChannelInstance ( this , channelAPI ) ;
renameChannelInstances ( ) ;
2017-12-22 23:56:40 -05:00
qDebug ( " DeviceSet::addTxChannel: %s " , qPrintable ( txChannel - > getName ( ) ) ) ;
}
2019-09-07 18:44:56 -04:00
void DeviceSet : : addMIMOChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
{
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getMIMOChannelRegistrations ( ) ; // Available channel plugins
2020-10-01 16:47:30 -04:00
ChannelAPI * mimoChannel ;
( * channelRegistrations ) [ selectedChannelIndex ] . m_plugin - > createMIMOChannel ( m_deviceAPI , nullptr , & mimoChannel ) ;
2020-10-16 02:35:06 -04:00
ChannelAPI * channelAPI = mimoChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
MainCore : : instance ( ) - > addChannelInstance ( this , channelAPI ) ;
renameChannelInstances ( ) ;
2019-09-07 18:44:56 -04:00
qDebug ( " DeviceSet::addMIMOChannel: %s " , qPrintable ( mimoChannel - > getName ( ) ) ) ;
}
2017-12-17 17:15:42 -05:00
void DeviceSet : : loadRxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
if ( preset - > isSourcePreset ( ) )
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2017-12-17 17:15:42 -05:00
qDebug ( " DeviceSet::loadChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
// Available channel plugins
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getRxChannelRegistrations ( ) ;
// copy currently open channels and clear list
2019-09-07 18:44:56 -04:00
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations ;
m_channelInstanceRegistrations . clear ( ) ;
2020-10-16 02:35:06 -04:00
mainCore - > clearChannels ( this ) ;
2017-12-17 17:15:42 -05:00
qDebug ( " DeviceSet::loadChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
2018-05-30 05:49:54 -04:00
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
2021-09-26 05:51:03 -04:00
ChannelAPI * channelAPI = nullptr ;
2017-12-17 17:15:42 -05:00
// if we have one instance available already, use it
2018-05-30 05:49:54 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadChannelSettings: channels compare [%s] vs [%s] " ,
qPrintable ( openChannels [ i ] - > getURI ( ) ) , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2017-12-17 17:15:42 -05:00
2018-05-30 05:49:54 -04:00
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
2020-10-14 20:24:29 -04:00
if ( ChannelUtils : : compareChannelURIs ( openChannels [ i ] - > getURI ( ) , channelConfig . m_channelIdURI ) )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadChannelSettings: channel [%s] found " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
channelAPI = openChannels . takeAt ( i ) ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2017-12-17 17:15:42 -05:00
break ;
}
}
// if we haven't one already, create one
2020-10-14 20:24:29 -04:00
if ( ! channelAPI )
2017-12-17 17:15:42 -05:00
{
2018-05-30 05:49:54 -04:00
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2018-05-30 05:49:54 -04:00
//if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
2019-08-04 14:24:44 -04:00
if ( ChannelUtils : : compareChannelURIs ( ( * channelRegistrations ) [ i ] . m_channelIdURI , channelConfig . m_channelIdURI ) )
2017-12-17 17:15:42 -05:00
{
2018-05-30 05:49:54 -04:00
qDebug ( " DeviceSet::loadChannelSettings: creating new channel [%s] from config [%s] " ,
qPrintable ( ( * channelRegistrations ) [ i ] . m_channelIdURI ) ,
qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-01 16:47:30 -04:00
ChannelAPI * rxChannel ;
( * channelRegistrations ) [ i ] . m_plugin - > createRxChannel ( m_deviceAPI , nullptr , & rxChannel ) ;
2020-10-14 20:24:29 -04:00
channelAPI = rxChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2017-12-17 17:15:42 -05:00
break ;
}
}
}
2020-10-14 20:24:29 -04:00
if ( channelAPI )
2017-12-17 17:15:42 -05:00
{
qDebug ( " DeviceSet::loadChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-14 20:24:29 -04:00
channelAPI - > deserialize ( channelConfig . m_config ) ;
2017-12-17 17:15:42 -05:00
}
}
// everything, that is still "available" is not needed anymore
2018-05-30 05:49:54 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadChannelSettings: destroying spare channel [%s] " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
openChannels [ i ] - > destroy ( ) ;
2017-12-17 17:15:42 -05:00
}
2019-09-07 18:44:56 -04:00
renameChannelInstances ( ) ;
2017-12-17 17:15:42 -05:00
}
else
{
qDebug ( " DeviceSet::loadChannelSettings: Loading preset [%s | %s] not a source preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
}
}
void DeviceSet : : saveRxChannelSettings ( Preset * preset )
{
if ( preset - > isSourcePreset ( ) )
{
2020-10-14 20:24:29 -04:00
// sort by increasing delta frequency and type
std : : sort ( m_channelInstanceRegistrations . begin ( ) , m_channelInstanceRegistrations . end ( ) , compareChannels ) ;
2017-12-17 17:15:42 -05:00
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::saveChannelSettings: channel [%s] saved " , qPrintable ( m_channelInstanceRegistrations [ i ] - > getURI ( ) ) ) ;
preset - > addChannel ( m_channelInstanceRegistrations [ i ] - > getURI ( ) , m_channelInstanceRegistrations [ i ] - > serialize ( ) ) ;
2017-12-17 17:15:42 -05:00
}
}
else
{
qDebug ( " DeviceSet::saveChannelSettings: not a source preset " ) ;
}
}
void DeviceSet : : loadTxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
2019-09-13 07:40:31 -04:00
if ( preset - > isSinkPreset ( ) )
2017-12-17 17:15:42 -05:00
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2017-12-17 17:15:42 -05:00
// Available channel plugins
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getTxChannelRegistrations ( ) ;
// copy currently open channels and clear list
2019-09-07 18:44:56 -04:00
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations ;
m_channelInstanceRegistrations . clear ( ) ;
2020-10-16 02:35:06 -04:00
mainCore - > clearChannels ( this ) ;
2017-12-17 17:15:42 -05:00
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
2017-12-17 17:15:42 -05:00
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
2020-10-14 20:24:29 -04:00
ChannelAPI * channelAPI ;
2017-12-17 17:15:42 -05:00
// if we have one instance available already, use it
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: channels compare [%s] vs [%s] " ,
qPrintable ( openChannels [ i ] - > getURI ( ) ) , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2017-12-17 17:15:42 -05:00
2020-10-14 20:24:29 -04:00
if ( openChannels [ i ] - > getURI ( ) = = channelConfig . m_channelIdURI )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: channel [%s] found " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
channelAPI = openChannels . takeAt ( i ) ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2017-12-17 17:15:42 -05:00
break ;
}
}
// if we haven't one already, create one
2020-10-14 20:24:29 -04:00
if ( ! channelAPI )
2017-12-17 17:15:42 -05:00
{
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2019-09-07 18:44:56 -04:00
if ( ( * channelRegistrations ) [ i ] . m_channelIdURI = = channelConfig . m_channelIdURI )
2017-12-17 17:15:42 -05:00
{
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: creating new channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-01 16:47:30 -04:00
ChannelAPI * txChannel ;
( * channelRegistrations ) [ i ] . m_plugin - > createTxChannel ( m_deviceAPI , nullptr , & txChannel ) ;
2020-10-14 20:24:29 -04:00
channelAPI = txChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2017-12-17 17:15:42 -05:00
break ;
}
}
}
2020-10-14 20:24:29 -04:00
if ( channelAPI )
2017-12-17 17:15:42 -05:00
{
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-14 20:24:29 -04:00
channelAPI - > deserialize ( channelConfig . m_config ) ;
2017-12-17 17:15:42 -05:00
}
}
// everything, that is still "available" is not needed anymore
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: destroying spare channel [%s] " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
openChannels [ i ] - > destroy ( ) ;
2017-12-17 17:15:42 -05:00
}
2019-09-07 18:44:56 -04:00
renameChannelInstances ( ) ;
2017-12-17 17:15:42 -05:00
}
2019-09-13 07:40:31 -04:00
else
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadTxChannelSettings: Loading preset [%s | %s] not a sink preset " ,
qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2019-09-13 07:40:31 -04:00
}
2017-12-17 17:15:42 -05:00
}
void DeviceSet : : saveTxChannelSettings ( Preset * preset )
{
2019-09-13 07:40:31 -04:00
if ( preset - > isSinkPreset ( ) )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
// sort by increasing delta frequency and type
std : : sort ( m_channelInstanceRegistrations . begin ( ) , m_channelInstanceRegistrations . end ( ) , compareChannels ) ;
2019-09-13 07:40:31 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::saveTxChannelSettings: channel [%s] saved " , qPrintable ( m_channelInstanceRegistrations [ i ] - > getURI ( ) ) ) ;
preset - > addChannel ( m_channelInstanceRegistrations [ i ] - > getURI ( ) , m_channelInstanceRegistrations [ i ] - > serialize ( ) ) ;
2019-09-13 07:40:31 -04:00
}
2017-12-17 17:15:42 -05:00
}
else
2019-09-13 07:40:31 -04:00
{
qDebug ( " DeviceSet::saveTxChannelSettings: not a sink preset " ) ;
}
}
void DeviceSet : : loadMIMOChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
if ( preset - > isMIMOPreset ( ) )
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadMIMOChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
// Available channel plugins
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getMIMOChannelRegistrations ( ) ;
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations ;
m_channelInstanceRegistrations . clear ( ) ;
2020-10-16 02:35:06 -04:00
mainCore - > clearChannels ( this ) ;
2019-09-13 07:40:31 -04:00
qDebug ( " DeviceSet::loadMIMOChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
{
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
2020-10-14 20:24:29 -04:00
ChannelAPI * channelAPI ;
2019-09-13 07:40:31 -04:00
// if we have one instance available already, use it
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadMIMOChannelSettings: channels compare [%s] vs [%s] " ,
qPrintable ( openChannels [ i ] - > getURI ( ) ) , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2019-09-13 07:40:31 -04:00
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
2020-10-14 20:24:29 -04:00
if ( ChannelUtils : : compareChannelURIs ( openChannels [ i ] - > getURI ( ) , channelConfig . m_channelIdURI ) )
2019-09-13 07:40:31 -04:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadMIMOChannelSettings: channel [%s] found " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
channelAPI = openChannels . takeAt ( i ) ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2019-09-13 07:40:31 -04:00
break ;
}
}
// if we haven't one already, create one
2020-10-14 20:24:29 -04:00
if ( ! channelAPI )
2019-09-13 07:40:31 -04:00
{
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
{
//if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
if ( ChannelUtils : : compareChannelURIs ( ( * channelRegistrations ) [ i ] . m_channelIdURI , channelConfig . m_channelIdURI ) )
{
qDebug ( " DeviceSet::loadMIMOChannelSettings: creating new channel [%s] from config [%s] " ,
qPrintable ( ( * channelRegistrations ) [ i ] . m_channelIdURI ) ,
qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-01 16:47:30 -04:00
ChannelAPI * mimoChannel ;
( * channelRegistrations ) [ i ] . m_plugin - > createMIMOChannel ( m_deviceAPI , nullptr , & mimoChannel ) ;
2020-10-14 20:24:29 -04:00
channelAPI = mimoChannel ;
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
2019-09-13 07:40:31 -04:00
break ;
}
}
}
2020-10-14 20:24:29 -04:00
if ( channelAPI )
2019-09-13 07:40:31 -04:00
{
qDebug ( " DeviceSet::loadMIMOChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2020-10-14 20:24:29 -04:00
channelAPI - > deserialize ( channelConfig . m_config ) ;
2019-09-13 07:40:31 -04:00
}
}
// everything, that is still "available" is not needed anymore
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::loadMIMOChannelSettings: destroying spare channel [%s] " , qPrintable ( openChannels [ i ] - > getURI ( ) ) ) ;
openChannels [ i ] - > destroy ( ) ;
2019-09-13 07:40:31 -04:00
}
renameChannelInstances ( ) ;
}
else
{
qDebug ( " DeviceSet::loadChannelSettings: Loading preset [%s | %s] not a MIMO preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
}
}
void DeviceSet : : saveMIMOChannelSettings ( Preset * preset )
{
if ( preset - > isMIMOPreset ( ) )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
// sort by increasing delta frequency and type
std : : sort ( m_channelInstanceRegistrations . begin ( ) , m_channelInstanceRegistrations . end ( ) , compareChannels ) ;
2017-12-17 17:15:42 -05:00
2019-09-07 18:44:56 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
qDebug ( " DeviceSet::saveMIMOChannelSettings: channel [%s] saved " , qPrintable ( m_channelInstanceRegistrations [ i ] - > getURI ( ) ) ) ;
preset - > addChannel ( m_channelInstanceRegistrations [ i ] - > getURI ( ) , m_channelInstanceRegistrations [ i ] - > serialize ( ) ) ;
2017-12-17 17:15:42 -05:00
}
}
2019-09-13 07:40:31 -04:00
else
{
qDebug ( " DeviceSet::saveMIMOChannelSettings: not a MIMO preset " ) ;
}
2017-12-17 17:15:42 -05:00
}
2019-09-07 18:44:56 -04:00
void DeviceSet : : renameChannelInstances ( )
2017-12-17 17:15:42 -05:00
{
2020-10-16 02:35:06 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
2020-10-14 20:24:29 -04:00
m_channelInstanceRegistrations [ i ] - > setName ( QString ( " %1:%2 " ) . arg ( m_channelInstanceRegistrations [ i ] - > getURI ( ) ) . arg ( i ) ) ;
2020-10-16 02:35:06 -04:00
m_channelInstanceRegistrations [ i ] - > setIndexInDeviceSet ( i ) ;
2017-12-17 17:15:42 -05:00
}
}
// sort by increasing delta frequency and type (i.e. name)
2020-10-14 20:24:29 -04:00
bool DeviceSet : : compareChannels ( const ChannelAPI * channelA , const ChannelAPI * channelB )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
if ( channelA & & channelB )
2017-12-17 17:15:42 -05:00
{
2020-10-14 20:24:29 -04:00
if ( channelA - > getCenterFrequency ( ) = = channelB - > getCenterFrequency ( ) ) {
return channelA - > getName ( ) < channelB - > getName ( ) ;
} else {
return channelA - > getCenterFrequency ( ) < channelB - > getCenterFrequency ( ) ;
2017-12-17 17:15:42 -05:00
}
}
else
{
return false ;
}
}
2020-11-11 19:22:48 -05:00
int DeviceSet : : webapiSpectrumSettingsGet ( SWGSDRangel : : SWGGLSpectrum & response , QString & errorMessage ) const
{
return m_spectrumVis - > webapiSpectrumSettingsGet ( response , errorMessage ) ;
}
int DeviceSet : : webapiSpectrumSettingsPutPatch (
bool force ,
const QStringList & spectrumSettingsKeys ,
SWGSDRangel : : SWGGLSpectrum & response , // query + response
QString & errorMessage )
{
return m_spectrumVis - > webapiSpectrumSettingsPutPatch ( force , spectrumSettingsKeys , response , errorMessage ) ;
}
int DeviceSet : : webapiSpectrumServerGet ( SWGSDRangel : : SWGSpectrumServer & response , QString & errorMessage ) const
{
return m_spectrumVis - > webapiSpectrumServerGet ( response , errorMessage ) ;
}
int DeviceSet : : webapiSpectrumServerPost ( SWGSDRangel : : SWGSuccessResponse & response , QString & errorMessage )
{
return m_spectrumVis - > webapiSpectrumServerPost ( response , errorMessage ) ;
}
int DeviceSet : : webapiSpectrumServerDelete ( SWGSDRangel : : SWGSuccessResponse & response , QString & errorMessage )
{
return m_spectrumVis - > webapiSpectrumServerDelete ( response , errorMessage ) ;
}
2020-10-15 02:52:30 -04:00
void DeviceSet : : addChannelInstance ( ChannelAPI * channelAPI )
2020-10-11 03:36:27 -04:00
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2020-10-14 20:24:29 -04:00
m_channelInstanceRegistrations . append ( channelAPI ) ;
2020-10-16 02:35:06 -04:00
mainCore - > addChannelInstance ( this , channelAPI ) ;
renameChannelInstances ( ) ;
2020-10-11 03:36:27 -04:00
}
void DeviceSet : : removeChannelInstanceAt ( int index )
{
2020-10-16 02:35:06 -04:00
if ( index < m_channelInstanceRegistrations . size ( ) )
{
MainCore * mainCore = MainCore : : instance ( ) ;
2020-10-11 03:36:27 -04:00
m_channelInstanceRegistrations . removeAt ( index ) ;
2020-10-16 02:35:06 -04:00
mainCore - > removeChannelInstanceAt ( this , index ) ;
renameChannelInstances ( ) ;
2020-10-11 03:36:27 -04:00
}
}
void DeviceSet : : removeChannelInstance ( ChannelAPI * channelAPI )
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2020-10-11 03:36:27 -04:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
2020-10-14 20:24:29 -04:00
if ( m_channelInstanceRegistrations . at ( i ) = = channelAPI )
2020-10-11 03:36:27 -04:00
{
m_channelInstanceRegistrations . removeAt ( i ) ;
2020-10-16 02:35:06 -04:00
mainCore - > removeChannelInstance ( channelAPI ) ;
2020-10-11 03:36:27 -04:00
break ;
}
}
2020-10-16 02:35:06 -04:00
renameChannelInstances ( ) ;
2020-10-11 03:36:27 -04:00
}
void DeviceSet : : clearChannels ( )
{
2020-10-16 02:35:06 -04:00
MainCore * mainCore = MainCore : : instance ( ) ;
2020-10-11 03:36:27 -04:00
m_channelInstanceRegistrations . clear ( ) ;
2020-10-16 02:35:06 -04:00
mainCore - > clearChannels ( this ) ;
2020-10-11 03:36:27 -04:00
}