2017-10-24 12:29:18 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 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:43:33 -04:00
// (at your option) any later version. //
2017-10-24 12:29:18 -04: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/>. //
///////////////////////////////////////////////////////////////////////////////////
# include <QFont>
# include "gui/glspectrum.h"
# include "dsp/spectrumvis.h"
# include "gui/glspectrumgui.h"
# include "gui/channelwindow.h"
# include "gui/samplingdevicecontrol.h"
# include "dsp/dspdevicesourceengine.h"
# include "dsp/dspdevicesinkengine.h"
2017-10-30 17:45:53 -04:00
# include "plugin/plugininstancegui.h"
# include "plugin/pluginapi.h"
# include "plugin/plugininterface.h"
2019-08-01 19:58:59 -04:00
# include "channel/channelutils.h"
2017-10-30 17:45:53 -04:00
# include "settings/preset.h"
2017-10-24 12:29:18 -04:00
# include "deviceuiset.h"
2019-05-16 12:39:13 -04:00
DeviceUISet : : DeviceUISet ( int tabIndex , int deviceType , QTimer & timer )
2017-10-24 12:29:18 -04:00
{
m_spectrum = new GLSpectrum ;
2019-05-16 12:39:13 -04:00
if ( ( deviceType = = 0 ) | | ( deviceType = = 2 ) ) { // Single Rx or MIMO
2018-01-22 08:07:24 -05:00
m_spectrumVis = new SpectrumVis ( SDR_RX_SCALEF , m_spectrum ) ;
2019-05-16 12:39:13 -04:00
} else if ( deviceType = = 1 ) { // Single Tx
2018-01-22 08:07:24 -05:00
m_spectrumVis = new SpectrumVis ( SDR_TX_SCALEF , m_spectrum ) ;
}
2017-10-24 12:29:18 -04:00
m_spectrum - > connectTimer ( timer ) ;
m_spectrumGUI = new GLSpectrumGUI ;
m_spectrumGUI - > setBuddies ( m_spectrumVis - > getInputMessageQueue ( ) , m_spectrumVis , m_spectrum ) ;
m_channelWindow = new ChannelWindow ;
2019-05-16 12:39:13 -04:00
m_samplingDeviceControl = new SamplingDeviceControl ( tabIndex , deviceType ) ;
2019-05-20 10:31:15 -04:00
m_deviceAPI = nullptr ;
m_deviceSourceEngine = nullptr ;
m_deviceSinkEngine = nullptr ;
m_deviceMIMOEngine = nullptr ;
2017-11-01 15:06:33 -04:00
m_deviceTabIndex = tabIndex ;
2019-05-18 09:40:00 -04:00
m_nbAvailableRxChannels = 0 ; // updated at enumeration for UI selector
m_nbAvailableTxChannels = 0 ; // updated at enumeration for UI selector
m_nbAvailableMIMOChannels = 0 ; // updated at enumeration for UI selector
2017-10-24 12:29:18 -04:00
// m_spectrum needs to have its font to be set since it cannot be inherited from the main window
QFont font ;
2018-05-06 11:51:18 -04:00
font . setFamily ( QStringLiteral ( " Liberation Sans " ) ) ;
2017-10-24 12:29:18 -04:00
font . setPointSize ( 9 ) ;
m_spectrum - > setFont ( font ) ;
}
DeviceUISet : : ~ DeviceUISet ( )
{
delete m_samplingDeviceControl ;
delete m_channelWindow ;
delete m_spectrumGUI ;
delete m_spectrumVis ;
delete m_spectrum ;
}
2017-10-30 19:07:55 -04:00
void DeviceUISet : : addChannelMarker ( ChannelMarker * channelMarker )
{
m_spectrum - > addChannelMarker ( channelMarker ) ;
}
void DeviceUISet : : addRollupWidget ( QWidget * widget )
{
m_channelWindow - > addRollupWidget ( widget ) ;
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : registerRxChannelInstance ( const QString & channelName , PluginInstanceGUI * pluginGUI )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
m_rxChannelInstanceRegistrations . append ( ChannelInstanceRegistration ( channelName , pluginGUI ) ) ;
renameRxChannelInstances ( ) ;
2017-10-30 17:45:53 -04:00
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : registerTxChannelInstance ( const QString & channelName , PluginInstanceGUI * pluginGUI )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
m_txChannelInstanceRegistrations . append ( ChannelInstanceRegistration ( channelName , pluginGUI ) ) ;
2017-12-17 17:15:42 -05:00
renameTxChannelInstances ( ) ;
2017-10-31 17:37:57 -04:00
}
void DeviceUISet : : removeRxChannelInstance ( PluginInstanceGUI * pluginGUI )
{
for ( ChannelInstanceRegistrations : : iterator it = m_rxChannelInstanceRegistrations . begin ( ) ; it ! = m_rxChannelInstanceRegistrations . end ( ) ; + + it )
{
if ( it - > m_gui = = pluginGUI )
{
m_rxChannelInstanceRegistrations . erase ( it ) ;
break ;
}
}
renameRxChannelInstances ( ) ;
}
void DeviceUISet : : removeTxChannelInstance ( PluginInstanceGUI * pluginGUI )
{
for ( ChannelInstanceRegistrations : : iterator it = m_txChannelInstanceRegistrations . begin ( ) ; it ! = m_txChannelInstanceRegistrations . end ( ) ; + + it )
2017-10-30 17:45:53 -04:00
{
if ( it - > m_gui = = pluginGUI )
{
2017-10-31 17:37:57 -04:00
m_txChannelInstanceRegistrations . erase ( it ) ;
2017-10-30 17:45:53 -04:00
break ;
}
}
2017-12-17 17:15:42 -05:00
renameTxChannelInstances ( ) ;
2017-10-31 17:37:57 -04:00
}
void DeviceUISet : : freeRxChannels ( )
{
for ( int i = 0 ; i < m_rxChannelInstanceRegistrations . count ( ) ; i + + )
{
qDebug ( " DeviceUISet::freeAll: destroying channel [%s] " , qPrintable ( m_rxChannelInstanceRegistrations [ i ] . m_channelName ) ) ;
m_rxChannelInstanceRegistrations [ i ] . m_gui - > destroy ( ) ;
}
2017-10-30 17:45:53 -04:00
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : freeTxChannels ( )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
for ( int i = 0 ; i < m_txChannelInstanceRegistrations . count ( ) ; i + + )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
qDebug ( " DeviceUISet::freeAll: destroying channel [%s] " , qPrintable ( m_txChannelInstanceRegistrations [ i ] . m_channelName ) ) ;
m_txChannelInstanceRegistrations [ i ] . m_gui - > destroy ( ) ;
2017-10-30 17:45:53 -04:00
}
}
2017-12-23 17:41:37 -05:00
void DeviceUISet : : deleteRxChannel ( int channelIndex )
{
if ( ( channelIndex > = 0 ) & & ( channelIndex < m_rxChannelInstanceRegistrations . count ( ) ) )
{
qDebug ( " DeviceUISet::deleteRxChennel: delete channel [%s] at %d " ,
qPrintable ( m_rxChannelInstanceRegistrations [ channelIndex ] . m_channelName ) ,
channelIndex ) ;
m_rxChannelInstanceRegistrations [ channelIndex ] . m_gui - > destroy ( ) ;
m_rxChannelInstanceRegistrations . removeAt ( channelIndex ) ;
renameRxChannelInstances ( ) ;
}
}
void DeviceUISet : : deleteTxChannel ( int channelIndex )
{
if ( ( channelIndex > = 0 ) & & ( channelIndex < m_txChannelInstanceRegistrations . count ( ) ) )
{
qDebug ( " DeviceUISet::deleteTxChennel: delete channel [%s] at %d " ,
qPrintable ( m_txChannelInstanceRegistrations [ channelIndex ] . m_channelName ) ,
channelIndex ) ;
m_txChannelInstanceRegistrations [ channelIndex ] . m_gui - > destroy ( ) ;
m_txChannelInstanceRegistrations . removeAt ( channelIndex ) ;
renameTxChannelInstances ( ) ;
}
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : loadRxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
2017-10-30 17:45:53 -04:00
{
if ( preset - > isSourcePreset ( ) )
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadRxChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2017-10-30 17:45:53 -04:00
// Available channel plugins
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getRxChannelRegistrations ( ) ;
// copy currently open channels and clear list
2017-10-31 17:37:57 -04:00
ChannelInstanceRegistrations openChannels = m_rxChannelInstanceRegistrations ;
m_rxChannelInstanceRegistrations . clear ( ) ;
2017-10-30 17:45:53 -04:00
2018-03-16 05:13:02 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
{
qDebug ( " DeviceUISet::loadRxChannelSettings: destroying old channel [%s] " , qPrintable ( openChannels [ i ] . m_channelName ) ) ;
openChannels [ i ] . m_gui - > destroy ( ) ; // FIXME: stop channel before
}
2017-10-30 17:45:53 -04:00
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadRxChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
2017-10-30 17:45:53 -04:00
{
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
ChannelInstanceRegistration reg ;
2018-03-16 05:13:02 -04:00
// create channel instance
2017-10-30 17:45:53 -04:00
2018-03-16 05:13:02 -04:00
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
2017-10-30 17:45:53 -04: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-10-30 17:45:53 -04:00
{
2018-05-30 05:49:54 -04:00
qDebug ( " DeviceUISet::loadRxChannelSettings: creating new channel [%s] from config [%s] " ,
qPrintable ( ( * channelRegistrations ) [ i ] . m_channelIdURI ) ,
qPrintable ( channelConfig . m_channelIdURI ) ) ;
2018-03-16 05:13:02 -04:00
BasebandSampleSink * rxChannel =
2019-05-08 16:11:53 -04:00
( * channelRegistrations ) [ i ] . m_plugin - > createRxChannelBS ( m_deviceAPI ) ;
2018-03-16 05:13:02 -04:00
PluginInstanceGUI * rxChannelGUI =
( * channelRegistrations ) [ i ] . m_plugin - > createRxChannelGUI ( this , rxChannel ) ;
reg = ChannelInstanceRegistration ( channelConfig . m_channelIdURI , rxChannelGUI ) ;
2017-10-30 17:45:53 -04:00
break ;
}
}
2018-03-16 05:13:02 -04:00
if ( reg . m_gui ! = 0 )
2017-10-30 17:45:53 -04:00
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadRxChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2017-10-30 17:45:53 -04:00
reg . m_gui - > deserialize ( channelConfig . m_config ) ;
}
}
2017-10-31 17:37:57 -04:00
renameRxChannelInstances ( ) ;
2017-10-30 17:45:53 -04:00
}
else
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadRxChannelSettings: Loading preset [%s | %s] not a source preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2017-10-30 17:45:53 -04:00
}
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : saveRxChannelSettings ( Preset * preset )
2017-10-30 17:45:53 -04:00
{
if ( preset - > isSourcePreset ( ) )
{
2017-10-31 17:37:57 -04:00
qSort ( m_rxChannelInstanceRegistrations . begin ( ) , m_rxChannelInstanceRegistrations . end ( ) ) ; // sort by increasing delta frequency and type
2017-10-30 17:45:53 -04:00
2017-10-31 17:37:57 -04:00
for ( int i = 0 ; i < m_rxChannelInstanceRegistrations . count ( ) ; i + + )
2017-10-30 17:45:53 -04:00
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::saveRxChannelSettings: channel [%s] saved " , qPrintable ( m_rxChannelInstanceRegistrations [ i ] . m_channelName ) ) ;
2017-10-31 17:37:57 -04:00
preset - > addChannel ( m_rxChannelInstanceRegistrations [ i ] . m_channelName , m_rxChannelInstanceRegistrations [ i ] . m_gui - > serialize ( ) ) ;
2017-10-30 17:45:53 -04:00
}
}
else
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::saveRxChannelSettings: not a source preset " ) ;
2017-10-30 17:45:53 -04:00
}
}
2017-10-31 17:37:57 -04:00
void DeviceUISet : : loadTxChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
if ( preset - > isSourcePreset ( ) )
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadTxChannelSettings: Loading preset [%s | %s] not a sink preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2017-10-31 17:37:57 -04:00
}
else
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadTxChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2017-10-31 17:37:57 -04:00
// Available channel plugins
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getTxChannelRegistrations ( ) ;
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_txChannelInstanceRegistrations ;
m_txChannelInstanceRegistrations . clear ( ) ;
2018-03-16 05:13:02 -04:00
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
{
qDebug ( " DeviceUISet::loadTxChannelSettings: destroying old channel [%s] " , qPrintable ( openChannels [ i ] . m_channelName ) ) ;
openChannels [ i ] . m_gui - > destroy ( ) ;
}
qDebug ( " DeviceUISet::loadTxChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
2017-10-31 17:37:57 -04:00
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
{
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
ChannelInstanceRegistration reg ;
2018-03-16 05:13:02 -04:00
// create channel instance
2017-10-31 17:37:57 -04:00
2018-03-16 05:13:02 -04:00
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
2017-10-31 17:37:57 -04:00
{
2018-05-30 05:49:54 -04:00
if ( ( * channelRegistrations ) [ i ] . m_channelIdURI = = channelConfig . m_channelIdURI )
2017-10-31 17:37:57 -04:00
{
2018-05-30 05:49:54 -04:00
qDebug ( " DeviceUISet::loadTxChannelSettings: creating new channel [%s] from config [%s] " ,
qPrintable ( ( * channelRegistrations ) [ i ] . m_channelIdURI ) ,
qPrintable ( channelConfig . m_channelIdURI ) ) ;
2018-03-16 05:13:02 -04:00
BasebandSampleSource * txChannel =
2019-05-08 16:11:53 -04:00
( * channelRegistrations ) [ i ] . m_plugin - > createTxChannelBS ( m_deviceAPI ) ;
2018-03-16 05:13:02 -04:00
PluginInstanceGUI * txChannelGUI =
( * channelRegistrations ) [ i ] . m_plugin - > createTxChannelGUI ( this , txChannel ) ;
reg = ChannelInstanceRegistration ( channelConfig . m_channelIdURI , txChannelGUI ) ;
2017-10-31 17:37:57 -04:00
break ;
}
}
if ( reg . m_gui ! = 0 )
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::loadTxChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channelIdURI ) ) ;
2017-10-31 17:37:57 -04:00
reg . m_gui - > deserialize ( channelConfig . m_config ) ;
}
}
renameTxChannelInstances ( ) ;
}
}
void DeviceUISet : : saveTxChannelSettings ( Preset * preset )
{
if ( preset - > isSourcePreset ( ) )
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::saveTxChannelSettings: not a sink preset " ) ;
2017-10-31 17:37:57 -04:00
}
else
{
qSort ( m_txChannelInstanceRegistrations . begin ( ) , m_txChannelInstanceRegistrations . end ( ) ) ; // sort by increasing delta frequency and type
for ( int i = 0 ; i < m_txChannelInstanceRegistrations . count ( ) ; i + + )
{
2018-03-16 05:13:02 -04:00
qDebug ( " DeviceUISet::saveTxChannelSettings: channel [%s] saved " , qPrintable ( m_txChannelInstanceRegistrations [ i ] . m_channelName ) ) ;
2017-10-31 17:37:57 -04:00
preset - > addChannel ( m_txChannelInstanceRegistrations [ i ] . m_channelName , m_txChannelInstanceRegistrations [ i ] . m_gui - > serialize ( ) ) ;
}
}
}
void DeviceUISet : : renameRxChannelInstances ( )
{
for ( int i = 0 ; i < m_rxChannelInstanceRegistrations . count ( ) ; i + + )
{
m_rxChannelInstanceRegistrations [ i ] . m_gui - > setName ( QString ( " %1:%2 " ) . arg ( m_rxChannelInstanceRegistrations [ i ] . m_channelName ) . arg ( i ) ) ;
}
}
void DeviceUISet : : renameTxChannelInstances ( )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
for ( int i = 0 ; i < m_txChannelInstanceRegistrations . count ( ) ; i + + )
2017-10-30 17:45:53 -04:00
{
2017-10-31 17:37:57 -04:00
m_txChannelInstanceRegistrations [ i ] . m_gui - > setName ( QString ( " %1:%2 " ) . arg ( m_txChannelInstanceRegistrations [ i ] . m_channelName ) . arg ( i ) ) ;
2017-10-30 17:45:53 -04:00
}
}
// sort by increasing delta frequency and type (i.e. name)
bool DeviceUISet : : ChannelInstanceRegistration : : operator < ( const ChannelInstanceRegistration & other ) const
{
if ( m_gui & & other . m_gui )
{
if ( m_gui - > getCenterFrequency ( ) = = other . m_gui - > getCenterFrequency ( ) )
{
return m_gui - > getName ( ) < other . m_gui - > getName ( ) ;
}
else
{
return m_gui - > getCenterFrequency ( ) < other . m_gui - > getCenterFrequency ( ) ;
}
}
else
{
return false ;
}
}
2017-10-24 12:29:18 -04:00