mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
HackRF - partial check-in of code. HackRF is commented out in the TunerManager, since it's not yet ready for use.
This commit is contained in:
@@ -48,6 +48,11 @@ public abstract class Tuner implements FrequencyChangeBroadcaster,
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an editor panel for the tuner
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@ public enum TunerClass
|
||||
FUNCUBE_DONGLE_PRO_PLUS( TunerType.FUNCUBE_DONGLE_PRO_PLUS, "04D8", "FB31", "Hamlincrest", "Funcube Dongle Pro Plus" ),
|
||||
GIGABYTE_GTU7300( TunerType.FITIPOWER_FC0012, "1B80", "D393", "Gigabyte", "GT-U7300" ),
|
||||
GTEK_T803( TunerType.FITIPOWER_FC0012, "1F4D", "B803", "GTek", "T803" ),
|
||||
HACKRF_ONE( TunerType.HACKRF, "1D50", "6089", "Great Scott Gadgets", "HackRF One" ),
|
||||
LIFEVIEW_LV5T_DELUXE( TunerType.FITIPOWER_FC0012, "1F4D", "C803", "Liveview", "LV5T Deluxe" ),
|
||||
MYGICA_TD312( TunerType.FITIPOWER_FC0012, "1F4D", "D286", "MyGica", "TD312" ),
|
||||
PEAK_102569AGPK( TunerType.FITIPOWER_FC0012, "1B80", "D395", "Peak", "102569AGPK" ),
|
||||
@@ -174,6 +175,12 @@ public enum TunerClass
|
||||
retVal = DEXATEK_5217_DVBT;
|
||||
}
|
||||
break;
|
||||
case 7504: //1D50
|
||||
if( productID == 24713 ) //6089
|
||||
{
|
||||
retVal = HACKRF_ONE;
|
||||
}
|
||||
break;
|
||||
case 8013: //1F4D
|
||||
if( productID == 47107 ) //B803
|
||||
{
|
||||
|
||||
@@ -40,6 +40,8 @@ import source.tuner.ettus.B100Tuner;
|
||||
import source.tuner.fcd.FCDTuner;
|
||||
import source.tuner.fcd.proV1.FCD1TunerController;
|
||||
import source.tuner.fcd.proplusV2.FCD2TunerController;
|
||||
import source.tuner.hackrf.HackRFTuner;
|
||||
import source.tuner.hackrf.HackRFTunerController;
|
||||
import source.tuner.rtl.RTL2832Tuner;
|
||||
import source.tuner.rtl.RTL2832TunerController;
|
||||
import source.tuner.rtl.e4k.E4KTunerController;
|
||||
@@ -361,6 +363,29 @@ public class TunerManager
|
||||
status = sLOADED;
|
||||
reason = null;
|
||||
break;
|
||||
case HACKRF_ONE:
|
||||
// try
|
||||
// {
|
||||
// HackRFTunerController hackRFController =
|
||||
// new HackRFTunerController( device );
|
||||
//
|
||||
// hackRFController.init();
|
||||
//
|
||||
// HackRFTuner hackRFTuner =
|
||||
// new HackRFTuner( hackRFController );
|
||||
//
|
||||
// mTuners.add( hackRFTuner );
|
||||
// name = hackRFTuner.getName();
|
||||
// status = sLOADED;
|
||||
// reason = null;
|
||||
// }
|
||||
// catch( SourceException se )
|
||||
// {
|
||||
// status = sNOT_LOADED;
|
||||
// reason = "Error constructing HackRF tuner "
|
||||
// + "controller - " + se.getLocalizedMessage();
|
||||
// }
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -134,6 +134,7 @@ public class TunerNode extends BaseNode implements FrequencyChangeListener
|
||||
mFrequency = frequency;
|
||||
getModel().nodeChanged( TunerNode.this );
|
||||
}
|
||||
break;
|
||||
case SAMPLE_RATE:
|
||||
int sampleRate = (int)event.getValue();
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ public enum TunerType
|
||||
FITIPOWER_FC0013( "FC0013" ),
|
||||
FUNCUBE_DONGLE_PRO( "Funcube Dongle Pro" ),
|
||||
FUNCUBE_DONGLE_PRO_PLUS( "Funcube Dongle Pro Plus" ),
|
||||
HACKRF( "HackRF" ),
|
||||
RAFAELMICRO_R820T( "R820T" ),
|
||||
RAFAELMICRO_R828D( "R828D" ),
|
||||
RTL2832_VARIOUS( "Generic" ),
|
||||
|
||||
86
src/source/tuner/hackrf/HackRFInformationPanel.java
Normal file
86
src/source/tuner/hackrf/HackRFInformationPanel.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package source.tuner.hackrf;
|
||||
|
||||
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" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
161
src/source/tuner/hackrf/HackRFTuner.java
Normal file
161
src/source/tuner/hackrf/HackRFTuner.java
Normal file
@@ -0,0 +1,161 @@
|
||||
/*******************************************************************************
|
||||
* 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.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.usb.UsbException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sample.Listener;
|
||||
import source.SourceException;
|
||||
import source.tuner.Tuner;
|
||||
import source.tuner.TunerChannel;
|
||||
import source.tuner.TunerChannelSource;
|
||||
import source.tuner.TunerClass;
|
||||
import source.tuner.TunerConfiguration;
|
||||
import source.tuner.TunerType;
|
||||
import source.tuner.hackrf.HackRFTunerController.BoardID;
|
||||
import source.tuner.hackrf.HackRFTunerController.Serial;
|
||||
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 );
|
||||
|
||||
try
|
||||
{
|
||||
BoardID id = mController.getBoardID();
|
||||
super.setName( id.getLabel() );
|
||||
|
||||
String version = mController.getFirmwareVersion();
|
||||
mLog.info( "HackRF firmware: " + version );
|
||||
|
||||
Serial serial = mController.getSerial();
|
||||
mLog.info( "HackRF Part ID: " + serial.getPartID() );
|
||||
mLog.info( "HackRF Serial Number: " + serial.getSerialNumber() );
|
||||
}
|
||||
catch( UsbException e )
|
||||
{
|
||||
mLog.error( "couldn't read HackRF board id", e );
|
||||
}
|
||||
}
|
||||
|
||||
public HackRFTunerController getController()
|
||||
{
|
||||
return mController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunerClass getTunerClass()
|
||||
{
|
||||
return TunerClass.HACKRF_ONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunerType getTunerType()
|
||||
{
|
||||
return TunerType.HACKRF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JPanel getEditor( ResourceManager resourceManager )
|
||||
{
|
||||
return new HackRFTunerEditorPanel( this, resourceManager );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply( TunerConfiguration config ) throws SourceException
|
||||
{
|
||||
mLog.error( "B100 Tuner - can't apply tuner configuration" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSampleRate()
|
||||
{
|
||||
return mController.getSampleRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFrequency() throws SourceException
|
||||
{
|
||||
return mController.getFrequency();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
|
||||
TunerChannel channel ) throws RejectedExecutionException, SourceException
|
||||
{
|
||||
return mController.getChannel( threadPoolManager, this, channel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseChannel( TunerChannelSource source )
|
||||
{
|
||||
/* Unregister for receiving samples */
|
||||
removeListener( (Listener<Float[]>)source );
|
||||
|
||||
/* Tell the controller to release the channel and cleanup */
|
||||
if( source != null )
|
||||
{
|
||||
mController.releaseChannel( source );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueID()
|
||||
{
|
||||
try
|
||||
{
|
||||
return mController.getSerial().getSerialNumber();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "error gettting serial number", e );
|
||||
}
|
||||
|
||||
return BoardID.HACKRF_ONE.getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( Listener<Float[]> listener )
|
||||
{
|
||||
mController.addListener( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( Listener<Float[]> listener )
|
||||
{
|
||||
mController.removeListener( listener );
|
||||
}
|
||||
}
|
||||
98
src/source/tuner/hackrf/HackRFTunerConfiguration.java
Normal file
98
src/source/tuner/hackrf/HackRFTunerConfiguration.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*******************************************************************************
|
||||
* 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 javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import source.tuner.TunerConfiguration;
|
||||
import source.tuner.TunerType;
|
||||
import source.tuner.hackrf.HackRFTunerController.HackRFLNAGain;
|
||||
import source.tuner.hackrf.HackRFTunerController.HackRFSampleRate;
|
||||
import source.tuner.hackrf.HackRFTunerController.HackRFVGAGain;
|
||||
|
||||
public class HackRFTunerConfiguration extends TunerConfiguration
|
||||
{
|
||||
private HackRFSampleRate mSampleRate = HackRFSampleRate.RATE2_016MHZ;
|
||||
private HackRFLNAGain mLNAGain = HackRFLNAGain.GAIN_0;
|
||||
private HackRFVGAGain mVGAGain = HackRFVGAGain.GAIN_10;
|
||||
private double mFrequencyCorrection = 0.0d;
|
||||
|
||||
/**
|
||||
* Default constructor for JAXB
|
||||
*/
|
||||
public HackRFTunerConfiguration()
|
||||
{
|
||||
this( "Default" );
|
||||
}
|
||||
|
||||
public HackRFTunerConfiguration( String name )
|
||||
{
|
||||
super( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunerType getTunerType()
|
||||
{
|
||||
return TunerType.HACKRF;
|
||||
}
|
||||
|
||||
@XmlAttribute( name = "lna_gain" )
|
||||
public HackRFLNAGain getLNAGain()
|
||||
{
|
||||
return mLNAGain;
|
||||
}
|
||||
|
||||
public void setLNAGain( HackRFLNAGain lnaGain )
|
||||
{
|
||||
mLNAGain = lnaGain;
|
||||
}
|
||||
|
||||
@XmlAttribute( name = "vga_gain" )
|
||||
public HackRFVGAGain getVGAGain()
|
||||
{
|
||||
return mVGAGain;
|
||||
}
|
||||
|
||||
public void setVGAGain( HackRFVGAGain vgaGain )
|
||||
{
|
||||
mVGAGain = vgaGain;
|
||||
}
|
||||
|
||||
@XmlAttribute( name = "frequency_correction" )
|
||||
public double getFrequencyCorrection()
|
||||
{
|
||||
return mFrequencyCorrection;
|
||||
}
|
||||
|
||||
public void setFrequencyCorrection( double value )
|
||||
{
|
||||
mFrequencyCorrection = value;
|
||||
}
|
||||
|
||||
@XmlAttribute( name = "sample_rate" )
|
||||
public HackRFSampleRate getSampleRate()
|
||||
{
|
||||
return mSampleRate;
|
||||
}
|
||||
|
||||
public void setSampleRate( HackRFSampleRate sampleRate )
|
||||
{
|
||||
mSampleRate = sampleRate;
|
||||
}
|
||||
}
|
||||
529
src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java
Normal file
529
src/source/tuner/hackrf/HackRFTunerConfigurationPanel.java
Normal file
@@ -0,0 +1,529 @@
|
||||
/*******************************************************************************
|
||||
* 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.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 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( "", "[grow,fill]", "[grow,fill]" ) );
|
||||
gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) );
|
||||
|
||||
/* 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. Set master gain "
|
||||
+ "to <b>MANUAL</b> to enable adjustment</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. Set master gain "
|
||||
+ "to <b>MANUAL</b> to enable adjustment</html>" );
|
||||
gainPanel.add( new JLabel( "VGA" ) );
|
||||
gainPanel.add( mComboVGAGain, "wrap" );
|
||||
|
||||
add( gainPanel, "span" );
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
1071
src/source/tuner/hackrf/HackRFTunerController.java
Normal file
1071
src/source/tuner/hackrf/HackRFTunerController.java
Normal file
File diff suppressed because it is too large
Load Diff
125
src/source/tuner/hackrf/HackRFTunerEditorPanel.java
Normal file
125
src/source/tuner/hackrf/HackRFTunerEditorPanel.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*******************************************************************************
|
||||
* 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.FrequencyChangeEvent;
|
||||
import source.tuner.FrequencyChangeEvent.Attribute;
|
||||
import source.tuner.FrequencyChangeListener;
|
||||
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.getAttribute() == Attribute.FREQUENCY )
|
||||
{
|
||||
try
|
||||
{
|
||||
mController.setFrequency( event.getValue() );
|
||||
}
|
||||
catch ( SourceException e )
|
||||
{
|
||||
mLog.error( "error setting frequency [" + event.getValue() + "]", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ package source.tuner.rtl;
|
||||
|
||||
import source.mixer.SampleAdapter;
|
||||
|
||||
public class RTL2832SampleAdapter extends SampleAdapter
|
||||
public class ByteSampleAdapter extends SampleAdapter
|
||||
{
|
||||
private final static float[] mLOOKUP_VALUES;
|
||||
private final static float[] LOOKUP_VALUES;
|
||||
|
||||
/**
|
||||
* Creates a static lookup table that converts the 8-bit valued range
|
||||
@@ -29,14 +29,14 @@ public class RTL2832SampleAdapter extends SampleAdapter
|
||||
*/
|
||||
static
|
||||
{
|
||||
mLOOKUP_VALUES = new float[ 256 ];
|
||||
LOOKUP_VALUES = new float[ 256 ];
|
||||
|
||||
for( int x = 0; x < 256; x++ )
|
||||
{
|
||||
mLOOKUP_VALUES[ x ] = (float)( x - 128 ) * 256.0f;
|
||||
LOOKUP_VALUES[ x ] = (float)( x - 128 ) * 256.0f;
|
||||
}
|
||||
|
||||
mLOOKUP_VALUES[ 128 ] = 0.0000001f;
|
||||
LOOKUP_VALUES[ 128 ] = 0.0000001f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +48,7 @@ public class RTL2832SampleAdapter extends SampleAdapter
|
||||
for( byte sample: samples )
|
||||
{
|
||||
/* Convert byte value into float from the lookup table */
|
||||
convertedSamples[ pointer++ ] = mLOOKUP_VALUES[ ( sample & 0xFF ) ];
|
||||
convertedSamples[ pointer++ ] = LOOKUP_VALUES[ ( sample & 0xFF ) ];
|
||||
}
|
||||
|
||||
return convertedSamples;
|
||||
@@ -155,7 +155,7 @@ public abstract class RTL2832TunerController extends TunerController
|
||||
|
||||
private BufferProcessor mBufferProcessor = new BufferProcessor();
|
||||
|
||||
private RTL2832SampleAdapter mSampleAdapter = new RTL2832SampleAdapter();
|
||||
private ByteSampleAdapter mSampleAdapter = new ByteSampleAdapter();
|
||||
|
||||
private CopyOnWriteArrayList<Listener<Float[]>> mSampleListeners =
|
||||
new CopyOnWriteArrayList<Listener<Float[]>>();
|
||||
|
||||
Reference in New Issue
Block a user