2017-12-17 23:15:42 +01:00
///////////////////////////////////////////////////////////////////////////////////
2023-11-19 06:43:20 +01:00
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// Copyright (C) 2015-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
2017-12-17 23:15:42 +01:00
// //
// 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 14:44:23 +02:00
// (at your option) any later version. //
2017-12-17 23:15:42 +01: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 06:13:32 +02:00
#include <algorithm>
2017-12-17 23:15:42 +01:00
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspdevicesinkengine.h"
2020-11-12 01:22:48 +01:00
#include "dsp/spectrumvis.h"
2017-12-17 23:15:42 +01:00
#include "plugin/pluginapi.h"
#include "plugin/plugininterface.h"
#include "settings/preset.h"
2019-05-09 17:27:12 +02:00
#include "channel/channelapi.h"
2019-08-02 01:58:59 +02:00
#include "channel/channelutils.h"
2017-12-17 23:15:42 +01:00
#include "settings/preset.h"
2020-10-16 08:35:06 +02:00
#include "maincore.h"
2017-12-17 23:15:42 +01:00
#include "deviceset.h"
2020-10-11 09:36:27 +02:00
DeviceSet :: DeviceSet ( int tabIndex , int deviceType )
2017-12-17 23:15:42 +01:00
{
2019-05-20 16:31:15 +02:00
m_deviceAPI = nullptr ;
m_deviceSourceEngine = nullptr ;
m_deviceSinkEngine = nullptr ;
m_deviceMIMOEngine = nullptr ;
2017-12-17 23:15:42 +01:00
m_deviceTabIndex = tabIndex ;
2020-11-12 01:22:48 +01: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 23:15:42 +01:00
}
DeviceSet ::~ DeviceSet ()
{
2020-11-12 01:22:48 +01:00
delete m_spectrumVis ;
2017-12-17 23:15:42 +01:00
}
2019-09-08 00:44:56 +02:00
void DeviceSet :: freeChannels ()
2017-12-23 22:33:30 +01:00
{
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
2017-12-23 22:33:30 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::freeChannels: destroying channel [%s]" , qPrintable ( m_channelInstanceRegistrations [ i ] -> getURI ()));
2024-08-19 00:31:55 +02:00
delete m_channelInstanceRegistrations [ i ];
2017-12-23 22:33:30 +01:00
}
2020-10-16 08:35:06 +02:00
MainCore :: instance () -> clearChannels ( this );
2017-12-23 22:33:30 +01:00
}
2020-10-13 08:15:21 +02:00
const ChannelAPI * DeviceSet :: getChannelAt ( int channelIndex ) const
{
if (( channelIndex >= 0 ) && ( channelIndex < m_channelInstanceRegistrations . size ())) {
2020-10-15 02:24:29 +02:00
return m_channelInstanceRegistrations [ channelIndex ];
2020-10-13 08:15:21 +02:00
} else {
return nullptr ;
}
}
ChannelAPI * DeviceSet :: getChannelAt ( int channelIndex )
{
if (( channelIndex >= 0 ) && ( channelIndex < m_channelInstanceRegistrations . size ())) {
2020-10-15 02:24:29 +02:00
return m_channelInstanceRegistrations [ channelIndex ];
2020-10-13 08:15:21 +02:00
} else {
return nullptr ;
}
}
2019-09-08 00:44:56 +02:00
void DeviceSet :: deleteChannel ( int channelIndex )
2017-12-23 22:33:30 +01:00
{
2019-09-08 00:44:56 +02:00
if ( channelIndex < m_channelInstanceRegistrations . count ())
2017-12-23 22:33:30 +01:00
{
2024-08-19 00:31:55 +02:00
delete m_channelInstanceRegistrations [ channelIndex ];
2019-09-08 00:44:56 +02:00
m_channelInstanceRegistrations . removeAt ( channelIndex );
2020-10-16 08:35:06 +02:00
MainCore :: instance () -> removeChannelInstanceAt ( this , channelIndex );
2019-09-08 00:44:56 +02:00
renameChannelInstances ();
2017-12-23 22:33:30 +01:00
}
}
2022-03-23 05:53:12 +01:00
ChannelAPI * DeviceSet :: addRxChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
2017-12-23 05:56:40 +01:00
{
PluginAPI :: ChannelRegistrations * channelRegistrations = pluginAPI -> getRxChannelRegistrations (); // Available channel plugins
2020-10-01 22:47:30 +02:00
ChannelAPI * rxChannel ;
( * channelRegistrations )[ selectedChannelIndex ]. m_plugin -> createRxChannel ( m_deviceAPI , nullptr , & rxChannel );
2022-03-23 05:53:12 +01:00
m_channelInstanceRegistrations . append ( rxChannel );
MainCore :: instance () -> addChannelInstance ( this , rxChannel );
2020-10-16 08:35:06 +02:00
renameChannelInstances ();
2017-12-23 05:56:40 +01:00
qDebug ( "DeviceSet::addRxChannel: %s" , qPrintable ( rxChannel -> getName ()));
2022-03-23 05:53:12 +01:00
return rxChannel ;
2017-12-23 05:56:40 +01:00
}
2022-03-23 05:53:12 +01:00
ChannelAPI * DeviceSet :: addTxChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
2017-12-23 05:56:40 +01:00
{
PluginAPI :: ChannelRegistrations * channelRegistrations = pluginAPI -> getTxChannelRegistrations (); // Available channel plugins
2020-10-01 22:47:30 +02:00
ChannelAPI * txChannel ;
( * channelRegistrations )[ selectedChannelIndex ]. m_plugin -> createTxChannel ( m_deviceAPI , nullptr , & txChannel );
2022-03-23 05:53:12 +01:00
m_channelInstanceRegistrations . append ( txChannel );
MainCore :: instance () -> addChannelInstance ( this , txChannel );
2020-10-16 08:35:06 +02:00
renameChannelInstances ();
2017-12-23 05:56:40 +01:00
qDebug ( "DeviceSet::addTxChannel: %s" , qPrintable ( txChannel -> getName ()));
2022-03-23 05:53:12 +01:00
return txChannel ;
2017-12-23 05:56:40 +01:00
}
2022-03-23 05:53:12 +01:00
ChannelAPI * DeviceSet :: addMIMOChannel ( int selectedChannelIndex , PluginAPI * pluginAPI )
2019-09-08 00:44:56 +02:00
{
PluginAPI :: ChannelRegistrations * channelRegistrations = pluginAPI -> getMIMOChannelRegistrations (); // Available channel plugins
2020-10-01 22:47:30 +02:00
ChannelAPI * mimoChannel ;
( * channelRegistrations )[ selectedChannelIndex ]. m_plugin -> createMIMOChannel ( m_deviceAPI , nullptr , & mimoChannel );
2022-03-23 05:53:12 +01:00
m_channelInstanceRegistrations . append ( mimoChannel );
MainCore :: instance () -> addChannelInstance ( this , mimoChannel );
2020-10-16 08:35:06 +02:00
renameChannelInstances ();
2019-09-08 00:44:56 +02:00
qDebug ( "DeviceSet::addMIMOChannel: %s" , qPrintable ( mimoChannel -> getName ()));
2022-03-23 05:53:12 +01:00
return mimoChannel ;
2019-09-08 00:44:56 +02:00
}
2017-12-17 23:15:42 +01:00
void DeviceSet :: loadRxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
if ( preset -> isSourcePreset ())
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2017-12-17 23:15:42 +01: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
2024-08-19 00:31:55 +02:00
QList < ChannelAPI *> openChannels = m_channelInstanceRegistrations ;
2019-09-08 00:44:56 +02:00
m_channelInstanceRegistrations . clear ();
2020-10-16 08:35:06 +02:00
mainCore -> clearChannels ( this );
2017-12-17 23:15:42 +01:00
qDebug ( "DeviceSet::loadChannelSettings: %d channel(s) in preset" , preset -> getChannelCount ());
2018-05-30 11:49:54 +02:00
for ( int i = 0 ; i < preset -> getChannelCount (); i ++ )
2017-12-17 23:15:42 +01:00
{
const Preset :: ChannelConfig & channelConfig = preset -> getChannelConfig ( i );
2021-09-26 11:51:03 +02:00
ChannelAPI * channelAPI = nullptr ;
2017-12-17 23:15:42 +01:00
// if we have one instance available already, use it
2018-05-30 11:49:54 +02:00
for ( int i = 0 ; i < openChannels . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadChannelSettings: channels compare [%s] vs [%s]" ,
qPrintable ( openChannels [ i ] -> getURI ()), qPrintable ( channelConfig . m_channelIdURI ));
2017-12-17 23:15:42 +01:00
2018-05-30 11:49:54 +02:00
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
2020-10-15 02:24:29 +02:00
if ( ChannelUtils :: compareChannelURIs ( openChannels [ i ] -> getURI (), channelConfig . m_channelIdURI ))
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadChannelSettings: channel [%s] found" , qPrintable ( openChannels [ i ] -> getURI ()));
channelAPI = openChannels . takeAt ( i );
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2017-12-17 23:15:42 +01:00
break ;
}
}
// if we haven't one already, create one
2020-10-15 02:24:29 +02:00
if ( ! channelAPI )
2017-12-17 23:15:42 +01:00
{
2018-05-30 11:49:54 +02:00
for ( int i = 0 ; i < channelRegistrations -> count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2018-05-30 11:49:54 +02:00
//if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
2019-08-04 20:24:44 +02:00
if ( ChannelUtils :: compareChannelURIs (( * channelRegistrations )[ i ]. m_channelIdURI , channelConfig . m_channelIdURI ))
2017-12-17 23:15:42 +01:00
{
2018-05-30 11:49:54 +02:00
qDebug ( "DeviceSet::loadChannelSettings: creating new channel [%s] from config [%s]" ,
qPrintable (( * channelRegistrations )[ i ]. m_channelIdURI ),
qPrintable ( channelConfig . m_channelIdURI ));
2020-10-01 22:47:30 +02:00
ChannelAPI * rxChannel ;
( * channelRegistrations )[ i ]. m_plugin -> createRxChannel ( m_deviceAPI , nullptr , & rxChannel );
2020-10-15 02:24:29 +02:00
channelAPI = rxChannel ;
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2017-12-17 23:15:42 +01:00
break ;
}
}
}
2020-10-15 02:24:29 +02:00
if ( channelAPI )
2017-12-17 23:15:42 +01:00
{
qDebug ( "DeviceSet::loadChannelSettings: deserializing channel [%s]" , qPrintable ( channelConfig . m_channelIdURI ));
2020-10-15 02:24:29 +02:00
channelAPI -> deserialize ( channelConfig . m_config );
2017-12-17 23:15:42 +01:00
}
}
// everything, that is still "available" is not needed anymore
2018-05-30 11:49:54 +02:00
for ( int i = 0 ; i < openChannels . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadChannelSettings: destroying spare channel [%s]" , qPrintable ( openChannels [ i ] -> getURI ()));
openChannels [ i ] -> destroy ();
2017-12-17 23:15:42 +01:00
}
2019-09-08 00:44:56 +02:00
renameChannelInstances ();
2017-12-17 23:15:42 +01: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 ())
{
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02: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 23:15:42 +01:00
}
}
else
{
qDebug ( "DeviceSet::saveChannelSettings: not a source preset" );
}
}
void DeviceSet :: loadTxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
2019-09-13 13:40:31 +02:00
if ( preset -> isSinkPreset ())
2017-12-17 23:15:42 +01:00
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2019-09-13 13:40:31 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: Loading preset [%s | %s]" , qPrintable ( preset -> getGroup ()), qPrintable ( preset -> getDescription ()));
2017-12-17 23:15:42 +01:00
// Available channel plugins
PluginAPI :: ChannelRegistrations * channelRegistrations = pluginAPI -> getTxChannelRegistrations ();
// copy currently open channels and clear list
2024-08-19 00:31:55 +02:00
QList < ChannelAPI *> openChannels = m_channelInstanceRegistrations ;
2019-09-08 00:44:56 +02:00
m_channelInstanceRegistrations . clear ();
2020-10-16 08:35:06 +02:00
mainCore -> clearChannels ( this );
2017-12-17 23:15:42 +01:00
2019-09-13 13:40:31 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: %d channel(s) in preset" , preset -> getChannelCount ());
2017-12-17 23:15:42 +01:00
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < preset -> getChannelCount (); i ++ )
2017-12-17 23:15:42 +01:00
{
const Preset :: ChannelConfig & channelConfig = preset -> getChannelConfig ( i );
2022-07-24 21:48:02 +02:00
ChannelAPI * channelAPI = nullptr ;
2017-12-17 23:15:42 +01:00
// if we have one instance available already, use it
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < openChannels . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: channels compare [%s] vs [%s]" ,
qPrintable ( openChannels [ i ] -> getURI ()), qPrintable ( channelConfig . m_channelIdURI ));
2017-12-17 23:15:42 +01:00
2020-10-15 02:24:29 +02:00
if ( openChannels [ i ] -> getURI () == channelConfig . m_channelIdURI )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: channel [%s] found" , qPrintable ( openChannels [ i ] -> getURI ()));
channelAPI = openChannels . takeAt ( i );
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2017-12-17 23:15:42 +01:00
break ;
}
}
// if we haven't one already, create one
2020-10-15 02:24:29 +02:00
if ( ! channelAPI )
2017-12-17 23:15:42 +01:00
{
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < channelRegistrations -> count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2019-09-08 00:44:56 +02:00
if (( * channelRegistrations )[ i ]. m_channelIdURI == channelConfig . m_channelIdURI )
2017-12-17 23:15:42 +01:00
{
2019-09-13 13:40:31 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: creating new channel [%s]" , qPrintable ( channelConfig . m_channelIdURI ));
2020-10-01 22:47:30 +02:00
ChannelAPI * txChannel ;
( * channelRegistrations )[ i ]. m_plugin -> createTxChannel ( m_deviceAPI , nullptr , & txChannel );
2020-10-15 02:24:29 +02:00
channelAPI = txChannel ;
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2017-12-17 23:15:42 +01:00
break ;
}
}
}
2020-10-15 02:24:29 +02:00
if ( channelAPI )
2017-12-17 23:15:42 +01:00
{
2019-09-13 13:40:31 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: deserializing channel [%s]" , qPrintable ( channelConfig . m_channelIdURI ));
2020-10-15 02:24:29 +02:00
channelAPI -> deserialize ( channelConfig . m_config );
2017-12-17 23:15:42 +01:00
}
}
// everything, that is still "available" is not needed anymore
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < openChannels . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: destroying spare channel [%s]" , qPrintable ( openChannels [ i ] -> getURI ()));
openChannels [ i ] -> destroy ();
2017-12-17 23:15:42 +01:00
}
2019-09-08 00:44:56 +02:00
renameChannelInstances ();
2017-12-17 23:15:42 +01:00
}
2019-09-13 13:40:31 +02:00
else
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadTxChannelSettings: Loading preset [%s | %s] not a sink preset" ,
qPrintable ( preset -> getGroup ()), qPrintable ( preset -> getDescription ()));
2019-09-13 13:40:31 +02:00
}
2017-12-17 23:15:42 +01:00
}
void DeviceSet :: saveTxChannelSettings ( Preset * preset )
{
2019-09-13 13:40:31 +02:00
if ( preset -> isSinkPreset ())
2017-12-17 23:15:42 +01:00
{
2019-09-13 13:40:31 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
{
2020-10-15 02:24:29 +02: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 13:40:31 +02:00
}
2017-12-17 23:15:42 +01:00
}
else
2019-09-13 13:40:31 +02:00
{
qDebug ( "DeviceSet::saveTxChannelSettings: not a sink preset" );
}
}
void DeviceSet :: loadMIMOChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
if ( preset -> isMIMOPreset ())
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2019-09-13 13:40:31 +02: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
2024-08-19 00:31:55 +02:00
QList < ChannelAPI *> openChannels = m_channelInstanceRegistrations ;
2019-09-13 13:40:31 +02:00
m_channelInstanceRegistrations . clear ();
2020-10-16 08:35:06 +02:00
mainCore -> clearChannels ( this );
2019-09-13 13:40:31 +02: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 );
2022-07-24 21:48:02 +02:00
ChannelAPI * channelAPI = nullptr ;
2019-09-13 13:40:31 +02:00
// if we have one instance available already, use it
for ( int i = 0 ; i < openChannels . count (); i ++ )
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadMIMOChannelSettings: channels compare [%s] vs [%s]" ,
qPrintable ( openChannels [ i ] -> getURI ()), qPrintable ( channelConfig . m_channelIdURI ));
2019-09-13 13:40:31 +02:00
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
2020-10-15 02:24:29 +02:00
if ( ChannelUtils :: compareChannelURIs ( openChannels [ i ] -> getURI (), channelConfig . m_channelIdURI ))
2019-09-13 13:40:31 +02:00
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadMIMOChannelSettings: channel [%s] found" , qPrintable ( openChannels [ i ] -> getURI ()));
channelAPI = openChannels . takeAt ( i );
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2019-09-13 13:40:31 +02:00
break ;
}
}
// if we haven't one already, create one
2020-10-15 02:24:29 +02:00
if ( ! channelAPI )
2019-09-13 13:40:31 +02: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 22:47:30 +02:00
ChannelAPI * mimoChannel ;
( * channelRegistrations )[ i ]. m_plugin -> createMIMOChannel ( m_deviceAPI , nullptr , & mimoChannel );
2020-10-15 02:24:29 +02:00
channelAPI = mimoChannel ;
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
2019-09-13 13:40:31 +02:00
break ;
}
}
}
2020-10-15 02:24:29 +02:00
if ( channelAPI )
2019-09-13 13:40:31 +02:00
{
qDebug ( "DeviceSet::loadMIMOChannelSettings: deserializing channel [%s]" , qPrintable ( channelConfig . m_channelIdURI ));
2020-10-15 02:24:29 +02:00
channelAPI -> deserialize ( channelConfig . m_config );
2019-09-13 13:40:31 +02:00
}
}
// everything, that is still "available" is not needed anymore
for ( int i = 0 ; i < openChannels . count (); i ++ )
{
2020-10-15 02:24:29 +02:00
qDebug ( "DeviceSet::loadMIMOChannelSettings: destroying spare channel [%s]" , qPrintable ( openChannels [ i ] -> getURI ()));
openChannels [ i ] -> destroy ();
2019-09-13 13:40:31 +02: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 23:15:42 +01:00
{
2019-09-08 00:44:56 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02: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 23:15:42 +01:00
}
}
2019-09-13 13:40:31 +02:00
else
{
qDebug ( "DeviceSet::saveMIMOChannelSettings: not a MIMO preset" );
}
2017-12-17 23:15:42 +01:00
}
2019-09-08 00:44:56 +02:00
void DeviceSet :: renameChannelInstances ()
2017-12-17 23:15:42 +01:00
{
2020-10-16 08:35:06 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
{
2020-10-15 02:24:29 +02:00
m_channelInstanceRegistrations [ i ] -> setName ( QString ( "%1:%2" ). arg ( m_channelInstanceRegistrations [ i ] -> getURI ()). arg ( i ));
2020-10-16 08:35:06 +02:00
m_channelInstanceRegistrations [ i ] -> setIndexInDeviceSet ( i );
2017-12-17 23:15:42 +01:00
}
}
// sort by increasing delta frequency and type (i.e. name)
2020-10-15 02:24:29 +02:00
bool DeviceSet :: compareChannels ( const ChannelAPI * channelA , const ChannelAPI * channelB )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
if ( channelA && channelB )
2017-12-17 23:15:42 +01:00
{
2020-10-15 02:24:29 +02:00
if ( channelA -> getCenterFrequency () == channelB -> getCenterFrequency ()) {
return channelA -> getName () < channelB -> getName ();
} else {
return channelA -> getCenterFrequency () < channelB -> getCenterFrequency ();
2017-12-17 23:15:42 +01:00
}
}
else
{
return false ;
}
}
2020-11-12 01:22:48 +01: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 08:52:30 +02:00
void DeviceSet :: addChannelInstance ( ChannelAPI * channelAPI )
2020-10-11 09:36:27 +02:00
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2020-10-15 02:24:29 +02:00
m_channelInstanceRegistrations . append ( channelAPI );
2020-10-16 08:35:06 +02:00
mainCore -> addChannelInstance ( this , channelAPI );
renameChannelInstances ();
2020-10-11 09:36:27 +02:00
}
void DeviceSet :: removeChannelInstanceAt ( int index )
{
2020-10-16 08:35:06 +02:00
if ( index < m_channelInstanceRegistrations . size ())
{
MainCore * mainCore = MainCore :: instance ();
2020-10-11 09:36:27 +02:00
m_channelInstanceRegistrations . removeAt ( index );
2020-10-16 08:35:06 +02:00
mainCore -> removeChannelInstanceAt ( this , index );
renameChannelInstances ();
2020-10-11 09:36:27 +02:00
}
}
void DeviceSet :: removeChannelInstance ( ChannelAPI * channelAPI )
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2020-10-11 09:36:27 +02:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count (); i ++ )
{
2020-10-15 02:24:29 +02:00
if ( m_channelInstanceRegistrations . at ( i ) == channelAPI )
2020-10-11 09:36:27 +02:00
{
m_channelInstanceRegistrations . removeAt ( i );
2020-10-16 08:35:06 +02:00
mainCore -> removeChannelInstance ( channelAPI );
2020-10-11 09:36:27 +02:00
break ;
}
}
2020-10-16 08:35:06 +02:00
renameChannelInstances ();
2020-10-11 09:36:27 +02:00
}
void DeviceSet :: clearChannels ()
{
2020-10-16 08:35:06 +02:00
MainCore * mainCore = MainCore :: instance ();
2020-10-11 09:36:27 +02:00
m_channelInstanceRegistrations . clear ();
2020-10-16 08:35:06 +02:00
mainCore -> clearChannels ( this );
2020-10-11 09:36:27 +02:00
}