Merges #34 Major redesign of Tuner, Channel and Alias management.

Changes to model, view and controller components and updates all gui
editors.  Removes the configuration panel and tree and replaces with 3
new panels.  Updates playlist.xml to a new playlist_v2.xml format.
This commit is contained in:
denny
2016-04-01 08:23:49 -04:00
450 changed files with 19560 additions and 22805 deletions

View File

@@ -1,104 +0,0 @@
package source.tuner.hackrf;
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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
* the Free Software Foundation, either 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 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/>
******************************************************************************/
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import source.tuner.hackrf.HackRFTunerController.Serial;
public class HackRFInformationPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private final static Logger mLog =
LoggerFactory.getLogger( HackRFInformationPanel.class );
private HackRFTunerController mController;
/**
* Displays HackRF firmware, serial number and part identifier
*/
public HackRFInformationPanel( HackRFTunerController controller )
{
mController = controller;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2",
"[right,grow][grow]",
"[][][][grow]" ) );
Serial serial = null;
try
{
serial = mController.getSerial();
}
catch( Exception e )
{
mLog.error( "couldn't read HackRF serial number", e );
}
if( serial != null )
{
add( new JLabel( "Serial:" ) );
add( new JLabel( serial.getSerialNumber() ) );
add( new JLabel( "Part:" ) );
add( new JLabel( serial.getPartID() ) );
}
else
{
add( new JLabel( "Serial:" ) );
add( new JLabel( "Unknown" ) );
add( new JLabel( "Part:" ) );
add( new JLabel( "Unknown" ) );
}
String firmware = null;
try
{
firmware = mController.getFirmwareVersion();
}
catch( Exception e )
{
mLog.error( "couldn't read HackRF firmware version", e );
}
add( new JLabel( "Firmware:" ) );
if( firmware != null )
{
add( new JLabel( firmware ) );
}
else
{
add( new JLabel( "Unknown" ) );
}
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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
@@ -19,8 +19,6 @@ package source.tuner.hackrf;
import java.util.concurrent.RejectedExecutionException;
import javax.swing.JPanel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,26 +29,22 @@ import source.tuner.Tuner;
import source.tuner.TunerChannel;
import source.tuner.TunerChannelSource;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerEvent;
import source.tuner.TunerType;
import source.tuner.hackrf.HackRFTunerController.BoardID;
import controller.ResourceManager;
import controller.ThreadPoolManager;
public class HackRFTuner extends Tuner
{
private final static Logger mLog = LoggerFactory.getLogger( HackRFTuner.class );
private HackRFTunerController mController;
public HackRFTuner( HackRFTunerController controller ) throws SourceException
{
super( "HackRF" );
mController = controller;
/* Register for frequency/sample rate changes */
mController.addListener( this );
super( "HackRF", controller );
}
public HackRFTunerController getController()
{
return (HackRFTunerController)getTunerController();
}
public void dispose()
@@ -58,11 +52,6 @@ public class HackRFTuner extends Tuner
//TODO: dispose of something here
}
public HackRFTunerController getController()
{
return mController;
}
@Override
public TunerClass getTunerClass()
{
@@ -75,41 +64,24 @@ public class HackRFTuner extends Tuner
return TunerType.HACKRF;
}
@Override
public JPanel getEditor( ResourceManager resourceManager )
{
return new HackRFTunerEditorPanel( this, resourceManager );
}
@Override
public void apply( TunerConfiguration config ) throws SourceException
{
mController.apply( config );
}
@Override
public int getSampleRate()
{
return mController.getSampleRate();
}
@Override
public double getSampleSize()
{
return 11.0;
}
@Override
public long getFrequency() throws SourceException
{
return mController.getFrequency();
}
@Override
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException
{
return mController.getChannel( this, channel );
TunerChannelSource source = getController().getChannel( this, channel );
if( source != null )
{
broadcast( new TunerEvent( this, TunerEvent.Event.CHANNEL_COUNT ) );
}
return source;
}
@Override
@@ -121,7 +93,7 @@ public class HackRFTuner extends Tuner
/* Tell the controller to release the channel and cleanup */
if( source != null )
{
mController.releaseChannel( source );
getController().releaseChannel( source );
}
}
@@ -130,7 +102,7 @@ public class HackRFTuner extends Tuner
{
try
{
return mController.getSerial().getSerialNumber();
return getController().getSerial().getSerialNumber();
}
catch( Exception e )
{
@@ -143,12 +115,12 @@ public class HackRFTuner extends Tuner
@Override
public void addListener( Listener<ComplexBuffer> listener )
{
mController.addListener( listener );
getController().addListener( listener );
}
@Override
public void removeListener( Listener<ComplexBuffer> listener )
{
mController.removeListener( listener );
getController().removeListener( listener );
}
}

View File

@@ -20,8 +20,8 @@ package source.tuner.hackrf;
import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.configuration.TunerConfiguration;
import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain;
import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate;
import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain;
@@ -39,12 +39,11 @@ public class HackRFTunerConfiguration extends TunerConfiguration
*/
public HackRFTunerConfiguration()
{
this( "Default" );
}
public HackRFTunerConfiguration( String name )
public HackRFTunerConfiguration( String uniqueID, String name )
{
super( name );
super( uniqueID, name );
}
@Override

View File

@@ -1,562 +0,0 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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
* the Free Software Foundation, either 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 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/>
******************************************************************************/
package source.tuner.hackrf;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.DecimalFormat;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.usb.UsbException;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerConfigurationAssignment;
import source.tuner.TunerType;
import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain;
import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate;
import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain;
import controller.ResourceManager;
public class HackRFTunerConfigurationPanel extends JPanel
{
private final static Logger mLog =
LoggerFactory.getLogger( HackRFTunerConfigurationPanel.class );
private static final long serialVersionUID = 1L;
private ResourceManager mResourceManager;
private HackRFTunerController mController;
private HackRFTunerConfiguration mSelectedConfig;
private JButton mNewConfiguration;
private JButton mDeleteConfiguration;
private JComboBox<HackRFTunerConfiguration> mComboConfigurations;
private JTextField mName;
private JSpinner mFrequencyCorrection;
private JToggleButton mAmplifier;
private JComboBox<HackRFLNAGain> mComboLNAGain;
private JComboBox<HackRFVGAGain> mComboVGAGain;
private JComboBox<HackRFSampleRate> mComboSampleRate;
public HackRFTunerConfigurationPanel( ResourceManager resourceManager,
HackRFTunerController controller )
{
mResourceManager = resourceManager;
mController = controller;
init();
}
/**
* Initializes the gui components
*/
private void init()
{
setLayout( new MigLayout( "fill,wrap 2", "[grow,right][grow]", "[][][][][][][grow]" ) );
/**
* Tuner configuration selector
*/
mComboConfigurations = new JComboBox<HackRFTunerConfiguration>();
mComboConfigurations.setModel( getModel() );
/* Determine which tuner configuration should be selected/displayed */
TunerConfigurationAssignment savedConfig = null;
String serial = null;
try
{
serial = mController.getSerial().getSerialNumber();
}
catch ( UsbException e2 )
{
mLog.error( "couldn't read hackrf serial number", e2 );
}
if( serial != null )
{
savedConfig = mResourceManager
.getSettingsManager().getSelectedTunerConfiguration(
TunerType.HACKRF, serial );
}
if( savedConfig != null )
{
mSelectedConfig = getNamedConfiguration(
savedConfig.getTunerConfigurationName() );
}
/* If we couldn't determine the saved/selected config, use the first one */
if( mSelectedConfig == null )
{
mSelectedConfig = mComboConfigurations.getItemAt( 0 );
//Store this config as the default for this tuner at this address
if( serial != null )
{
mResourceManager.getSettingsManager()
.setSelectedTunerConfiguration( TunerType.HACKRF,
serial, mSelectedConfig );
}
}
mComboConfigurations.setSelectedItem( mSelectedConfig );
mComboConfigurations.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
HackRFTunerConfiguration selected =
(HackRFTunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
update( selected );
}
}
});
add( new JLabel( "Config:" ) );
add( mComboConfigurations, "growx,push" );
/**
* Tuner Configuration Name
*/
mName = new JTextField();
mName.setText( mSelectedConfig.getName() );
mName.addFocusListener( new FocusListener()
{
@Override
public void focusLost( FocusEvent e )
{
mSelectedConfig.setName( mName.getText() );
save();
}
@Override
public void focusGained( FocusEvent e ) {}
} );
add( new JLabel( "Name:" ) );
add( mName, "growx,push" );
/**
* Frequency Correction
*/
SpinnerModel model =
new SpinnerNumberModel( 0.0, //initial value
-1000.0, //min
1000.0, //max
0.1 ); //step
mFrequencyCorrection = new JSpinner( model );
JSpinner.NumberEditor editor =
(JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits( 1 );
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
mFrequencyCorrection.setValue( mSelectedConfig.getFrequencyCorrection() );
mFrequencyCorrection.addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
final double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
EventQueue.invokeLater( new Runnable()
{
@Override
public void run()
{
try
{
mController.setFrequencyCorrection( value );
mSelectedConfig.setFrequencyCorrection( value );
save();
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"HackRF Tuner Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply "
+ "frequency correction value: " + value, e1 );
}
}
} );
}
} );
add( new JLabel( "Correction PPM:" ) );
add( mFrequencyCorrection, "growx,push" );
/**
* Sample Rate
*/
mComboSampleRate = new JComboBox<>( HackRFSampleRate.values() );
mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() );
mComboSampleRate.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
HackRFSampleRate sampleRate =
(HackRFSampleRate)mComboSampleRate.getSelectedItem();
try
{
mController.setSampleRate( sampleRate );
mSelectedConfig.setSampleRate( sampleRate );
save();
}
catch ( UsbException e2 )
{
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"HackRF Tuner Controller - couldn't apply the sample "
+ "rate setting [" + sampleRate.getLabel() + "] " +
e2.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply sample "
+ "rate setting [" + sampleRate.getLabel() + "]", e );
}
}
} );
add( new JLabel( "Sample Rate:" ) );
add( mComboSampleRate, "growx,push" );
/**
* Gain Controls
*/
JPanel gainPanel = new JPanel();
gainPanel.setLayout( new MigLayout( "",
"[][right][grow,fill][right][grow,fill]", "[grow,fill]" ) );
gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) );
/* Amplifier */
mAmplifier = new JToggleButton( "Amp" );
mAmplifier.setSelected( mSelectedConfig.getAmplifierEnabled() );
mAmplifier.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
mController.setAmplifierEnabled( mAmplifier.isSelected() );
mSelectedConfig.setAmplifierEnabled( mAmplifier.isSelected() );
save();
}
catch ( UsbException e )
{
mLog.error( "couldn't enable/disable amplifier", e );
mAmplifier.setEnabled( !mAmplifier.isSelected() );
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"Couldn't change amplifier setting",
"Error changing amplifier setting",
JOptionPane.ERROR_MESSAGE );
}
}
} );
gainPanel.add( mAmplifier );
/* LNA Gain Control */
mComboLNAGain = new JComboBox<HackRFLNAGain>( HackRFLNAGain.values() );
mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
mComboLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
HackRFLNAGain lnaGain =
(HackRFLNAGain)mComboLNAGain.getSelectedItem();
if ( lnaGain == null )
{
lnaGain = HackRFLNAGain.GAIN_0;
}
if( mComboLNAGain.isEnabled() )
{
mController.setLNAGain( lnaGain );
}
mSelectedConfig.setLNAGain( lnaGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"HackRF Tuner Controller - couldn't apply the LNA "
+ "gain setting - " + e.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply LNA "
+ "gain setting - ", e );
}
}
} );
mComboLNAGain.setToolTipText( "<html>LNA Gain. Adjust to set "
+ "the IF gain</html>" );
gainPanel.add( new JLabel( "LNA" ) );
gainPanel.add( mComboLNAGain );
/* VGA Gain Control */
mComboVGAGain = new JComboBox<HackRFVGAGain>( HackRFVGAGain.values() );
mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() );
mComboVGAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem();
if( vgaGain == null )
{
vgaGain = HackRFVGAGain.GAIN_4;
}
if( mComboVGAGain.isEnabled() )
{
mController.setVGAGain( vgaGain );
}
mSelectedConfig.setVGAGain( vgaGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"HackRF Tuner Controller - couldn't apply the VGA "
+ "gain setting - " + e.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply VGA "
+ "gain setting", e );
}
}
} );
mComboVGAGain.setToolTipText( "<html>VGA Gain. Adjust to set the "
+ "baseband gain</html>" );
gainPanel.add( new JLabel( "VGA" ) );
gainPanel.add( mComboVGAGain, "wrap" );
add( gainPanel, "span,growx" );
/**
* Create a new configuration
*/
mNewConfiguration = new JButton( "New" );
mNewConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
TunerConfiguration config =
mResourceManager.getSettingsManager()
.addNewTunerConfiguration(
TunerType.HACKRF,
"New Configuration" );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedItem( config );
repaint();
}
} );
add( mNewConfiguration, "growx,push" );
/**
* Delete the currently selected configuration
*/
mDeleteConfiguration = new JButton( "Delete" );
mDeleteConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
HackRFTunerConfiguration selected =
(HackRFTunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
int n = JOptionPane.showConfirmDialog(
HackRFTunerConfigurationPanel.this,
"Are you sure you want to delete '"
+ selected.getName() + "'?",
"Are you sure?",
JOptionPane.YES_NO_OPTION );
if( n == JOptionPane.YES_OPTION )
{
mResourceManager.getSettingsManager()
.deleteTunerConfiguration( selected );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedIndex( 0 );
repaint();
}
}
}
} );
add( mDeleteConfiguration, "growx,push,wrap" );
}
/**
* Updates gui controls with the values from the tuner configuration
* @param config - tuner configuration
*/
private void update( HackRFTunerConfiguration config )
{
mSelectedConfig = config;
try
{
mController.apply( config );
mName.setText( config.getName() );
mFrequencyCorrection.setValue( config.getFrequencyCorrection() );
mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() );
mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() );
mResourceManager.getSettingsManager().setSelectedTunerConfiguration(
TunerType.HACKRF, mController.getSerial().getSerialNumber(), config );
}
catch ( UsbException | SourceException e1 )
{
JOptionPane.showMessageDialog(
HackRFTunerConfigurationPanel.this,
"HackRF Tuner Controller - couldn't "
+ "apply the tuner configuration settings - " +
e1.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply "
+ "config [" + config.getName() + "]", e1 );
}
}
/**
* Constructs a combo box model for the tuner configuration combo component
* by assembling a list of the tuner configurations appropriate for this
* specific tuner
*/
private ComboBoxModel<HackRFTunerConfiguration> getModel()
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.HACKRF );
DefaultComboBoxModel<HackRFTunerConfiguration> model =
new DefaultComboBoxModel<HackRFTunerConfiguration>();
for( TunerConfiguration config: configs )
{
model.addElement( (HackRFTunerConfiguration)config );
}
return model;
}
/**
* Retrieves a specific (named) tuner configuration
*/
private HackRFTunerConfiguration getNamedConfiguration( String name )
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.HACKRF );
for( TunerConfiguration config: configs )
{
if( config.getName().contentEquals( name ) )
{
return (HackRFTunerConfiguration)config;
}
}
return null;
}
/**
* Saves current tuner configuration settings
*/
private void save()
{
mResourceManager.getSettingsManager().save();
}
}

View File

@@ -1,4 +1,3 @@
package source.tuner.hackrf;
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
@@ -52,12 +51,13 @@ package source.tuner.hackrf;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package source.tuner.hackrf;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -81,8 +81,8 @@ import sample.Listener;
import sample.adapter.ByteSampleAdapter;
import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerController;
import source.tuner.configuration.TunerConfiguration;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
@@ -92,7 +92,7 @@ public class HackRFTunerController extends TunerController
private final static Logger mLog =
LoggerFactory.getLogger( HackRFTunerController.class );
public final static long USB_TIMEOUT_MS = 1000000l; //uSeconds
public final static long USB_TIMEOUT_US = 1000000l; //uSeconds
public static final byte USB_ENDPOINT = (byte)0x81;
public static final byte USB_INTERFACE = (byte)0x0;
@@ -395,7 +395,7 @@ public class HackRFTunerController extends TunerController
(short)value,
(short)index,
buffer,
USB_TIMEOUT_MS );
USB_TIMEOUT_US );
if( transferred < 0 )
{
@@ -468,7 +468,7 @@ public class HackRFTunerController extends TunerController
(short)value,
(short)index,
buffer,
USB_TIMEOUT_MS );
USB_TIMEOUT_US );
if( transferred < 0 )
{
@@ -887,8 +887,8 @@ public class HackRFTunerController extends TunerController
*/
public void addListener( Listener<ComplexBuffer> listener )
{
synchronized( mComplexBufferBroadcaster )
{
synchronized ( mComplexBufferBroadcaster )
{
mComplexBufferBroadcaster.addListener( listener );
if( mBufferProcessor == null || !mBufferProcessor.isRunning() )
@@ -901,7 +901,7 @@ public class HackRFTunerController extends TunerController
thread.start();
}
}
}
}
/**
@@ -910,15 +910,15 @@ public class HackRFTunerController extends TunerController
*/
public void removeListener( Listener<ComplexBuffer> listener )
{
synchronized( mComplexBufferBroadcaster )
{
synchronized ( mComplexBufferBroadcaster )
{
mComplexBufferBroadcaster.removeListener( listener );
if( !mComplexBufferBroadcaster.hasListeners() )
{
mBufferProcessor.stop();
}
}
}
}
/**
@@ -928,12 +928,12 @@ public class HackRFTunerController extends TunerController
public class BufferProcessor implements Runnable, TransferCallback
{
private ScheduledFuture<?> mSampleDispatcherTask;
private AtomicBoolean mRunning = new AtomicBoolean();
private LinkedTransferQueue<Transfer> mAvailableTransfers;
private LinkedTransferQueue<Transfer> mTransfersInProgress = new LinkedTransferQueue<>();
private AtomicBoolean mRunning = new AtomicBoolean();
private ByteBuffer mLibUsbHandlerStatus;
private boolean mCancel = false;
@Override
public void run()
{
@@ -955,23 +955,23 @@ public class HackRFTunerController extends TunerController
{
mAvailableTransfers.drainTo( transfers );
for( Transfer transfer: transfers )
{
int result = LibUsb.submitTransfer( transfer );
if( result == LibUsb.SUCCESS )
{
mTransfersInProgress.add( transfer );
}
else
{
mLog.error( "error submitting transfer [" +
LibUsb.errorName( result ) + "]" );
}
}
for( Transfer transfer: transfers )
{
int result = LibUsb.submitTransfer( transfer );
if( result == LibUsb.SUCCESS )
{
mTransfersInProgress.add( transfer );
}
else
{
mLog.error( "error submitting transfer [" +
LibUsb.errorName( result ) + "]" );
}
}
int result = LibUsb.handleEventsTimeoutCompleted(
null, USB_TIMEOUT_MS, mLibUsbHandlerStatus.asIntBuffer() );
null, USB_TIMEOUT_US, mLibUsbHandlerStatus.asIntBuffer() );
if( result != LibUsb.SUCCESS )
{
@@ -990,16 +990,16 @@ public class HackRFTunerController extends TunerController
LibUsb.cancelTransfer( transfer );
}
int result = LibUsb.handleEventsTimeoutCompleted(
null, USB_TIMEOUT_MS, mLibUsbHandlerStatus.asIntBuffer() );
int result = LibUsb.handleEventsTimeoutCompleted( null,
USB_TIMEOUT_US, mLibUsbHandlerStatus.asIntBuffer() );
if( result != LibUsb.SUCCESS )
{
mLog.error( "error cancelling transfers in progress" );
}
mLibUsbHandlerStatus.rewind();
}
{
mLog.error( "error cancelling transfers in progress" );
}
mLibUsbHandlerStatus.rewind();
}
}
}
@@ -1089,7 +1089,7 @@ public class HackRFTunerController extends TunerController
ByteBuffer.allocateDirect( mBufferSize );
LibUsb.fillBulkTransfer( transfer, mDeviceHandle,USB_ENDPOINT,
buffer, BufferProcessor.this, "Buffer", USB_TIMEOUT_MS );
buffer, BufferProcessor.this, "Buffer", USB_TIMEOUT_US );
mAvailableTransfers.add( transfer );
}

View File

@@ -0,0 +1,464 @@
/*******************************************************************************
* SDR Trunk
* 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
* the Free Software Foundation, either 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 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/>
******************************************************************************/
package source.tuner.hackrf;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.usb.UsbException;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import source.SourceException;
import source.tuner.configuration.TunerConfiguration;
import source.tuner.configuration.TunerConfigurationEditor;
import source.tuner.configuration.TunerConfigurationEvent;
import source.tuner.configuration.TunerConfigurationEvent.Event;
import source.tuner.configuration.TunerConfigurationModel;
import source.tuner.hackrf.HackRFTunerController.BoardID;
import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain;
import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate;
import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain;
import source.tuner.hackrf.HackRFTunerController.Serial;
public class HackRFTunerEditor extends TunerConfigurationEditor
{
private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger( HackRFTunerEditor.class );
private JTextField mConfigurationName;
private JButton mTunerInfo;
private JComboBox<HackRFSampleRate> mComboSampleRate;
private JSpinner mFrequencyCorrection;
private JToggleButton mAmplifier;
private JComboBox<HackRFLNAGain> mComboLNAGain;
private JComboBox<HackRFVGAGain> mComboVGAGain;
private boolean mLoading;
private HackRFTunerController mController;
public HackRFTunerEditor( TunerConfigurationModel tunerConfigurationModel, HackRFTuner tuner )
{
super( tunerConfigurationModel );
mController = tuner.getController();
init();
}
private HackRFTunerConfiguration getConfiguration()
{
if( hasItem() )
{
return (HackRFTunerConfiguration)getItem();
}
return null;
}
private void init()
{
setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]",
"[][][][][][][grow]" ) );
add( new JLabel( "HackRF Tuner Configuration" ), "span,align center" );
mConfigurationName = new JTextField();
mConfigurationName.setEnabled( false );
mConfigurationName.addFocusListener( new FocusListener()
{
@Override
public void focusLost( FocusEvent e )
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
} );
add( new JLabel( "Name:" ) );
add( mConfigurationName, "span 2" );
mTunerInfo = new JButton( "Tuner Info" );
mTunerInfo.setEnabled( false );
mTunerInfo.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
JOptionPane.showMessageDialog( HackRFTunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE );
}
} );
add( mTunerInfo );
mComboSampleRate = new JComboBox<>( HackRFSampleRate.values() );
mComboSampleRate.setEnabled( false );
mComboSampleRate.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
HackRFSampleRate sampleRate =
(HackRFSampleRate)mComboSampleRate.getSelectedItem();
try
{
mController.setSampleRate( sampleRate );
save();
}
catch ( UsbException e2 )
{
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the sample rate setting [" + sampleRate.getLabel() +
"] " + e2.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply sample rate setting [" +
sampleRate.getLabel() + "]", e );
}
}
} );
add( new JLabel( "Sample Rate:" ) );
add( mComboSampleRate );
SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value
-1000.0, //min
1000.0, //max
0.1 ); //step
mFrequencyCorrection = new JSpinner( model );
mFrequencyCorrection.setEnabled( false );
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits( 1 );
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
mFrequencyCorrection.addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
final double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
try
{
mController.setFrequencyCorrection( value );
save();
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply frequency correction value: " + value +
e1.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply frequency correction "
+ "value: " + value, e1 );
}
}
} );
add( new JLabel( "PPM:" ) );
add( mFrequencyCorrection );
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" );
add( new JLabel( "Gain" ) );
add( new JLabel( "" ), "span 2" ); //filler
mAmplifier = new JToggleButton( "Amplifier" );
mAmplifier.setEnabled( false );
mAmplifier.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
mController.setAmplifierEnabled( mAmplifier.isSelected() );
save();
}
catch ( UsbException e )
{
mLog.error( "couldn't enable/disable amplifier", e );
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "Couldn't change amplifier setting",
"Error changing amplifier setting", JOptionPane.ERROR_MESSAGE );
}
}
} );
add( mAmplifier );
mComboLNAGain = new JComboBox<HackRFLNAGain>( HackRFLNAGain.values() );
mComboLNAGain.setEnabled( false );
mComboLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
HackRFLNAGain lnaGain = (HackRFLNAGain)mComboLNAGain.getSelectedItem();
if ( lnaGain == null )
{
lnaGain = HackRFLNAGain.GAIN_0;
}
mController.setLNAGain( lnaGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the LNA gain setting - " + e.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply LNA gain setting - ", e );
}
}
} );
mComboLNAGain.setToolTipText( "<html>LNA Gain. Adjust to set the IF gain</html>" );
add( new JLabel( "LNA:" ) );
add( mComboLNAGain );
mComboVGAGain = new JComboBox<HackRFVGAGain>( HackRFVGAGain.values() );
mComboVGAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
try
{
HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem();
if( vgaGain == null )
{
vgaGain = HackRFVGAGain.GAIN_4;
}
mController.setVGAGain( vgaGain );
save();
}
catch ( UsbException e )
{
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the VGA gain setting - " + e.getLocalizedMessage() );
mLog.error( "HackRF Tuner Controller - couldn't apply VGA gain setting", e );
}
}
} );
mComboVGAGain.setToolTipText( "<html>VGA Gain. Adjust to set the baseband gain</html>" );
add( new JLabel( "VGA:" ) );
add( mComboVGAGain );
}
/**
* Sets each of the tuner configuration controls to the enabled argument state
*/
private void setControlsEnabled( boolean enabled )
{
if( mConfigurationName.isEnabled() != enabled )
{
mConfigurationName.setEnabled( enabled );
}
if( mTunerInfo.isEnabled() != enabled )
{
mTunerInfo.setEnabled( enabled );
}
if( mFrequencyCorrection.isEnabled() != enabled )
{
mFrequencyCorrection.setEnabled( enabled );
}
if( mComboSampleRate.isEnabled() != enabled )
{
mComboSampleRate.setEnabled( enabled );
}
if( mAmplifier.isEnabled() != enabled )
{
mAmplifier.setEnabled( enabled );
}
if( mComboLNAGain.isEnabled() != enabled )
{
mComboLNAGain.setEnabled( enabled );
}
if( mComboVGAGain.isEnabled() != enabled )
{
mComboVGAGain.setEnabled( enabled );
}
}
private String getTunerInfo()
{
BoardID board = BoardID.INVALID;
try
{
board = mController.getBoardID();
}
catch ( UsbException e )
{
mLog.error( "couldn't read HackRF board identifier", e );
}
StringBuilder sb = new StringBuilder();
sb.append( "<html><h3>HackRF Tuner</h3>" );
sb.append( "<b>Board: </b>" );
sb.append( board.getLabel() );
sb.append( "<br>" );
Serial serial = null;
try
{
serial = mController.getSerial();
}
catch( Exception e )
{
mLog.error( "couldn't read HackRF serial number", e );
}
if( serial != null )
{
sb.append( "<b>Serial: </b>" );
sb.append( serial.getSerialNumber() );
sb.append( "<br>" );
sb.append( "<b>Part: </b>" );
sb.append( serial.getPartID() );
sb.append( "<br>" );
}
else
{
sb.append( "<b>Serial: Unknown</b><br>" );
sb.append( "<b>Part: Unknown</b><br>" );
}
String firmware = null;
try
{
firmware = mController.getFirmwareVersion();
}
catch( Exception e )
{
mLog.error( "couldn't read HackRF firmware version", e );
}
if( firmware != null )
{
sb.append( "<b>Firmware: </b>" );
sb.append( firmware );
sb.append( "<br>" );
}
else
{
sb.append( "<b>Firmware: Unknown</b><br>" );
}
return sb.toString();
}
@Override
public void setItem( TunerConfiguration tunerConfiguration )
{
super.setItem( tunerConfiguration );
//Toggle loading so that we don't fire a change event and schedule a settings file save
mLoading = true;
if( hasItem() )
{
HackRFTunerConfiguration config = getConfiguration();
if( tunerConfiguration.isAssigned() )
{
setControlsEnabled( true );
mConfigurationName.setText( config.getName() );
mComboSampleRate.setSelectedItem( config.getSampleRate() );
mFrequencyCorrection.setValue( config.getFrequencyCorrection() );
mAmplifier.setSelected( config.getAmplifierEnabled() );
mComboLNAGain.setSelectedItem( config.getLNAGain() );
mComboVGAGain.setSelectedItem( config.getVGAGain() );
}
else
{
setControlsEnabled( false );
mConfigurationName.setText( config.getName() );
}
}
else
{
setControlsEnabled( false );
mConfigurationName.setText( "" );
}
mLoading = false;
}
@Override
public void save()
{
if( hasItem() && !mLoading )
{
HackRFTunerConfiguration config = getConfiguration();
config.setName( mConfigurationName.getText() );
double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
config.setFrequencyCorrection( value );
config.setSampleRate( (HackRFSampleRate)mComboSampleRate.getSelectedItem() );
config.setAmplifierEnabled( mAmplifier.isSelected() );
config.setLNAGain( (HackRFLNAGain)mComboLNAGain.getSelectedItem() );
config.setVGAGain( (HackRFVGAGain)mComboVGAGain.getSelectedItem() );
getTunerConfigurationModel().broadcast(
new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) );
}
}
}

View File

@@ -1,125 +0,0 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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
* the Free Software Foundation, either 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 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/>
******************************************************************************/
package source.tuner.hackrf;
import gui.control.JFrequencyControl;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.usb.UsbException;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import source.SourceException;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.FrequencyChangeListener;
import source.tuner.frequency.FrequencyChangeEvent.Event;
import source.tuner.hackrf.HackRFTunerController.BoardID;
import com.jidesoft.swing.JideTabbedPane;
import controller.ResourceManager;
public class HackRFTunerEditorPanel extends JPanel
implements FrequencyChangeListener
{
private static final long serialVersionUID = 1L;
private final static Logger mLog =
LoggerFactory.getLogger( HackRFTunerEditorPanel.class );
private JFrequencyControl mFrequencyControl;
private HackRFTuner mTuner;
private HackRFTunerController mController;
private ResourceManager mResourceManager;
public HackRFTunerEditorPanel( HackRFTuner tuner,
ResourceManager resourceManager )
{
mTuner = tuner;
mController = mTuner.getController();
mResourceManager = resourceManager;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2",
"[right,grow][grow]",
"[][][][][][grow]" ) );
BoardID board = BoardID.INVALID;
try
{
board = mTuner.getController().getBoardID();
}
catch ( UsbException e )
{
mLog.error( "couldn't read HackRF board identifier", e );
}
add( new JLabel( board.getLabel() ), "span,align center" );
mFrequencyControl = new JFrequencyControl();
mFrequencyControl.addListener( this );
/* Add frequency control as frequency change listener. This creates a
* feedback loop, so the control does not rebroadcast the event */
mTuner.addListener( mFrequencyControl );
mFrequencyControl.setFrequency( mController.getFrequency(), false );
add( mFrequencyControl, "span,align center" );
JideTabbedPane tabs = new JideTabbedPane();
tabs.setFont( this.getFont() );
tabs.setForeground( Color.BLACK );
add( tabs, "span,grow,push" );
tabs.add( "Config", new HackRFTunerConfigurationPanel(
mResourceManager, mTuner.getController() ) );
tabs.add( "Info", new HackRFInformationPanel( mTuner.getController() ) );
}
@Override
public void frequencyChanged( FrequencyChangeEvent event )
{
if( event.getEvent() == Event.FREQUENCY_CHANGE_NOTIFICATION )
{
try
{
mController.setFrequency( event.getValue().longValue() );
}
catch ( SourceException e )
{
mLog.error( "error setting frequency [" + event.getValue().longValue() + "]", e );
}
}
}
}