mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
WIP #34 - more work on tuner model and view. Includes new tuner
configuration and tuner configuration assignment editors. Beginning of tuner editor panel rework. Removes most of the remaining JTree configuration pieces. Updates the settings manager to load and save tuners and refactors all of the tuner configuration management out into the tuner configuration model.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 Dennis Sheirer
|
||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
||||
*
|
||||
* 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
|
||||
@@ -17,15 +17,7 @@
|
||||
******************************************************************************/
|
||||
package source.tuner;
|
||||
|
||||
import gui.editor.EmptyEditor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -34,15 +26,10 @@ import org.usb4java.DeviceDescriptor;
|
||||
import org.usb4java.DeviceList;
|
||||
import org.usb4java.LibUsb;
|
||||
|
||||
import settings.SettingsManager;
|
||||
import source.Source;
|
||||
import source.SourceException;
|
||||
import source.config.SourceConfigTuner;
|
||||
import source.config.SourceConfiguration;
|
||||
import source.mixer.MixerManager;
|
||||
import source.tuner.airspy.AirspyTuner;
|
||||
import source.tuner.airspy.AirspyTunerController;
|
||||
import source.tuner.airspy.AirspyTunerEditorPanel;
|
||||
import source.tuner.fcd.FCDTuner;
|
||||
import source.tuner.fcd.proV1.FCD1TunerController;
|
||||
import source.tuner.fcd.proplusV2.FCD2TunerController;
|
||||
@@ -51,7 +38,6 @@ import source.tuner.hackrf.HackRFTunerController;
|
||||
import source.tuner.rtl.RTL2832Tuner;
|
||||
import source.tuner.rtl.RTL2832TunerController;
|
||||
import source.tuner.rtl.e4k.E4KTunerController;
|
||||
import source.tuner.rtl.e4k.E4KTunerEditorPanel;
|
||||
import source.tuner.rtl.r820t.R820TTunerController;
|
||||
import controller.ThreadPoolManager;
|
||||
|
||||
@@ -60,17 +46,15 @@ public class TunerManager
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( TunerManager.class );
|
||||
|
||||
private ArrayList<Tuner> mTuners = new ArrayList<Tuner>();
|
||||
|
||||
private MixerManager mMixerManager;
|
||||
private SettingsManager mSettingsManager;
|
||||
private TunerModel mTunerModel;
|
||||
private ThreadPoolManager mThreadPoolManager;
|
||||
|
||||
public TunerManager( MixerManager mixerManager,
|
||||
SettingsManager settingsManager,
|
||||
TunerModel tunerModel,
|
||||
ThreadPoolManager threadPoolManager )
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
mTunerModel = tunerModel;
|
||||
mThreadPoolManager = threadPoolManager;
|
||||
|
||||
initTuners();
|
||||
@@ -84,57 +68,6 @@ public class TunerManager
|
||||
LibUsb.exit( null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates current tuners to get a tuner channel source for the frequency
|
||||
* specified in the channel config's source config object
|
||||
*/
|
||||
public Source getSource( SourceConfiguration config, int bandwidth )
|
||||
{
|
||||
TunerChannelSource retVal = null;
|
||||
|
||||
if( config instanceof SourceConfigTuner )
|
||||
{
|
||||
SourceConfigTuner tunerConfig = (SourceConfigTuner)config;
|
||||
|
||||
TunerChannel tunerChannel = tunerConfig.getTunerChannel();
|
||||
|
||||
tunerChannel.setBandwidth( bandwidth );
|
||||
|
||||
Iterator<Tuner> it = mTuners.iterator();
|
||||
|
||||
Tuner tuner;
|
||||
|
||||
while( it.hasNext() && retVal == null )
|
||||
{
|
||||
tuner = it.next();
|
||||
|
||||
try
|
||||
{
|
||||
retVal = tuner.getChannel( tunerChannel );
|
||||
}
|
||||
catch ( RejectedExecutionException ree )
|
||||
{
|
||||
mLog.error( "couldn't provide tuner channel source", ree );
|
||||
}
|
||||
catch ( SourceException e )
|
||||
{
|
||||
mLog.error( "error obtaining channel from tuner [" +
|
||||
tuner.getName() + "]", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of current tuners
|
||||
*/
|
||||
public List<Tuner> getTuners()
|
||||
{
|
||||
return mTuners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all USB tuners and USB/Mixer tuner devices
|
||||
*/
|
||||
@@ -192,9 +125,19 @@ public class TunerManager
|
||||
if( status.isLoaded() )
|
||||
{
|
||||
Tuner tuner = status.getTuner();
|
||||
sb.append( "] LOADED: " );
|
||||
sb.append( tuner.toString() );
|
||||
mTuners.add( tuner );
|
||||
|
||||
try
|
||||
{
|
||||
mTunerModel.addTuner( tuner );
|
||||
sb.append( "] LOADED: " );
|
||||
sb.append( tuner.toString() );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
sb.append( "] NOT LOADED: " );
|
||||
sb.append( status.getInfo() );
|
||||
sb.append( " Error:" + e.getMessage() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -276,13 +219,6 @@ public class TunerManager
|
||||
|
||||
AirspyTuner tuner = new AirspyTuner( airspyController );
|
||||
|
||||
TunerConfiguration config = getTunerConfiguration( tuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
tuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( tuner, "LOADED" );
|
||||
}
|
||||
catch( SourceException se )
|
||||
@@ -301,11 +237,6 @@ public class TunerManager
|
||||
{
|
||||
return new TunerInitStatus( null, "Ettus B100 tuner not currently "
|
||||
+ "supported" );
|
||||
// case ETTUS_USRP_B100:
|
||||
// mTuners.add( new B100Tuner( device ) );
|
||||
// status = sLOADED;
|
||||
// reason = null;
|
||||
// break;
|
||||
}
|
||||
|
||||
private TunerInitStatus initFuncubeProTuner( Device device,
|
||||
@@ -328,13 +259,6 @@ public class TunerManager
|
||||
FCDTuner tuner =
|
||||
new FCDTuner( dataline, controller );
|
||||
|
||||
TunerConfiguration config = getTunerConfiguration( tuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
tuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( tuner, "LOADED" );
|
||||
}
|
||||
catch ( SourceException e )
|
||||
@@ -373,13 +297,6 @@ public class TunerManager
|
||||
FCDTuner tuner =
|
||||
new FCDTuner( dataline, controller );
|
||||
|
||||
TunerConfiguration config = getTunerConfiguration( tuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
tuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( tuner, "LOADED" );
|
||||
}
|
||||
catch ( SourceException e )
|
||||
@@ -412,13 +329,6 @@ public class TunerManager
|
||||
|
||||
HackRFTuner tuner = new HackRFTuner( hackRFController );
|
||||
|
||||
TunerConfiguration config = getTunerConfiguration( tuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
tuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( tuner, "LOADED" );
|
||||
}
|
||||
catch( SourceException se )
|
||||
@@ -465,14 +375,6 @@ public class TunerManager
|
||||
RTL2832Tuner rtlTuner =
|
||||
new RTL2832Tuner( tunerClass, controller );
|
||||
|
||||
TunerConfiguration config =
|
||||
getTunerConfiguration( rtlTuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
rtlTuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( rtlTuner, "LOADED" );
|
||||
}
|
||||
catch( SourceException se )
|
||||
@@ -492,14 +394,6 @@ public class TunerManager
|
||||
RTL2832Tuner rtlTuner =
|
||||
new RTL2832Tuner( tunerClass, controller );
|
||||
|
||||
TunerConfiguration config =
|
||||
getTunerConfiguration( rtlTuner );
|
||||
|
||||
if( config != null )
|
||||
{
|
||||
rtlTuner.apply( config );
|
||||
}
|
||||
|
||||
return new TunerInitStatus( rtlTuner, "LOADED" );
|
||||
}
|
||||
catch( SourceException se )
|
||||
@@ -522,54 +416,6 @@ public class TunerManager
|
||||
|
||||
return new TunerInitStatus( null, reason );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stored tuner configuration or create a default tuner configuration
|
||||
* for the tuner type, connected at the address.
|
||||
*
|
||||
* Note: a named tuner configuration will be stored for for each tuner type
|
||||
* and address combination.
|
||||
* @param type - tuner type
|
||||
* @param address - current usb address/port
|
||||
* @return - stored tuner configuration or default configuration
|
||||
*/
|
||||
private TunerConfiguration getTunerConfiguration( Tuner tuner )
|
||||
{
|
||||
TunerConfigurationAssignment selected = mSettingsManager
|
||||
.getSelectedTunerConfiguration( tuner.getTunerType(), tuner.getUniqueID() );
|
||||
|
||||
ArrayList<TunerConfiguration> configs = mSettingsManager
|
||||
.getTunerConfigurations( tuner.getTunerType() );
|
||||
|
||||
TunerConfiguration config = null;
|
||||
|
||||
if( selected != null )
|
||||
{
|
||||
for( TunerConfiguration tunerConfig: configs )
|
||||
{
|
||||
if( tunerConfig.getName().contentEquals( selected.getTunerConfigurationName() ) )
|
||||
{
|
||||
config = tunerConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If we're still null at this point, create a default config
|
||||
if( config == null )
|
||||
{
|
||||
String name = "Default-" + tuner.getUniqueID();
|
||||
|
||||
config = mSettingsManager.addNewTunerConfiguration(
|
||||
tuner.getTunerType(), name );
|
||||
}
|
||||
|
||||
//Persist the config as the selected tuner configuration. The method
|
||||
//auto-saves the setting
|
||||
mSettingsManager.setSelectedTunerConfiguration(
|
||||
tuner.getTunerType(), tuner.getUniqueID(), config );
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first tuner mixer dataline that corresponds to the tuner class.
|
||||
@@ -625,15 +471,4 @@ public class TunerManager
|
||||
}
|
||||
}
|
||||
|
||||
public static JPanel getEditor( SettingsManager settingsManager, Tuner tuner )
|
||||
{
|
||||
JPanel editor = tuner.getEditor( settingsManager );
|
||||
|
||||
if( editor != null )
|
||||
{
|
||||
return editor;
|
||||
}
|
||||
|
||||
return new EmptyEditor<Tuner>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user