Initial code check in continued

This commit is contained in:
dennis.sheirer
2014-04-26 19:48:24 +00:00
parent 960a6f9952
commit 3dfedcf8d1
474 changed files with 76613 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
/*******************************************************************************
* 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.fcd.proV1;
import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.fcd.proV1.FCD1TunerController.LNAEnhance;
import source.tuner.fcd.proV1.FCD1TunerController.LNAGain;
import source.tuner.fcd.proV1.FCD1TunerController.MixerGain;
public class FCD1TunerConfiguration extends TunerConfiguration
{
private double mFrequencyCorrection = 22.0d;
private double mInphaseDCCorrection = 0.0d;
private double mQuadratureDCCorrection = 0.0d;
private double mPhaseCorrection = 0.0d;
private double mGainCorrection = 0.0d;
private LNAGain mLNAGain = LNAGain.LNA_GAIN_PLUS_20_0;
private LNAEnhance mLNAEnhance = LNAEnhance.LNA_ENHANCE_OFF;
private MixerGain mMixerGain = MixerGain.MIXER_GAIN_PLUS_12_0;
/**
* Default constructor for JAXB
*/
public FCD1TunerConfiguration()
{
this( "Default" );
}
public FCD1TunerConfiguration( String name )
{
super( name );
}
@Override
public TunerType getTunerType()
{
return TunerType.FUNCUBE_DONGLE_PRO;
}
public LNAGain getLNAGain()
{
return mLNAGain;
}
public void setLNAGain( LNAGain gain )
{
mLNAGain = gain;
}
@XmlAttribute( name = "lna_gain" )
public LNAEnhance getLNAEnhance()
{
return mLNAEnhance;
}
public void setLNAEnhance( LNAEnhance enhance )
{
mLNAEnhance = enhance;
}
@XmlAttribute( name = "mixer_gain" )
public MixerGain getMixerGain()
{
return mMixerGain;
}
public void setMixerGain( MixerGain gain )
{
mMixerGain = gain;
}
@XmlAttribute( name = "frequency_correction" )
public double getFrequencyCorrection()
{
return mFrequencyCorrection;
}
public void setFrequencyCorrection( double value )
{
mFrequencyCorrection = value;
}
@XmlAttribute( name = "inphase_dc_correction" )
public double getInphaseDCCorrection()
{
return mInphaseDCCorrection;
}
public void setInphaseDCCorrection( double value )
{
mInphaseDCCorrection = value;
}
@XmlAttribute( name = "quadrature_dc_correction" )
public double getQuadratureDCCorrection()
{
return mQuadratureDCCorrection;
}
public void setQuadratureDCCorrection( double value )
{
mQuadratureDCCorrection = value;
}
@XmlAttribute( name = "phase_correction" )
public double getPhaseCorrection()
{
return mPhaseCorrection;
}
public void setPhaseCorrection( double value )
{
mPhaseCorrection = value;
}
@XmlAttribute( name = "gain_correction" )
public double getGainCorrection()
{
return mGainCorrection;
}
public void setGainCorrection( double value )
{
mGainCorrection = value;
}
}

View File

@@ -0,0 +1,667 @@
/*******************************************************************************
* 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.fcd.proV1;
import java.awt.Color;
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.UsbClaimException;
import javax.usb.UsbException;
import com.jidesoft.swing.JideTabbedPane;
import log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.fcd.proV1.FCD1TunerController.LNAEnhance;
import source.tuner.fcd.proV1.FCD1TunerController.LNAGain;
import source.tuner.fcd.proV1.FCD1TunerController.MixerGain;
import controller.ResourceManager;
public class FCD1TunerConfigurationPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private ResourceManager mResourceManager;
private FCD1TunerController mController;
private FCD1TunerConfiguration mSelectedConfig;
private JButton mNewConfiguration;
private JButton mDeleteConfiguration;
private JComboBox<FCD1TunerConfiguration> mComboConfigurations;
private JComboBox<LNAGain> mComboLNAGain;
private JComboBox<LNAEnhance> mComboLNAEnhance;
private JComboBox<MixerGain> mComboMixerGain;
private JTextField mName;
private JSpinner mCorrectionFrequency;
private CorrectionSpinner mCorrectionDCI;
private CorrectionSpinner mCorrectionDCQ;
private CorrectionSpinner mCorrectionGain;
private CorrectionSpinner mCorrectionPhase;
public FCD1TunerConfigurationPanel( ResourceManager resourceManager,
FCD1TunerController controller )
{
mResourceManager = resourceManager;
mController = controller;
mSelectedConfig = controller.getTunerConfiguration();
init();
}
private void init()
{
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][grow]" ) );
/**
* Tuner configurations combo
*/
mComboConfigurations = new JComboBox<FCD1TunerConfiguration>();
mComboConfigurations.setToolTipText( "Select a tuner configuration. "
+ "Create a separate tuner configuration for each of your "
+ "funcube dongles by using the NEW button and typing a "
+ "descriptive name" );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedItem( mSelectedConfig );
mComboConfigurations.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
FCD1TunerConfiguration selected =
(FCD1TunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
update( selected );
}
}
});
add( new JLabel( "Config:" ) );
add( mComboConfigurations, "growx,push" );
/**
* Tuner Configuration - Name
*/
mName = new JTextField( mSelectedConfig.getName() );
mName.setToolTipText( "Name for the selected tuner configuration" );
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" );
JideTabbedPane tabs = new JideTabbedPane();
tabs.setFont( this.getFont() );
tabs.setForeground( Color.BLACK );
add( tabs, "span,grow,push" );
JPanel gainPanel = new JPanel();
gainPanel.setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) );
/**
* LNA Gain
*/
mComboLNAGain = new JComboBox<LNAGain>( LNAGain.values() );
mComboLNAGain.setToolTipText( "Adjust the low noise amplifier gain "
+ "setting. Default value is 20db" );
mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
mComboLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
LNAGain gain = (LNAGain)mComboLNAGain.getSelectedItem();
mSelectedConfig.setLNAGain( gain );
try
{
mController.setLNAGain( gain );
}
catch ( UsbClaimException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - cannot claim FCD "
+ "Controller to apply LNA gain [" + gain.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - usb claim "
+ "exception while applying LNA gain value [" +
gain.toString() + "] - " +
e1.getLocalizedMessage() );
}
catch ( UsbException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - FCD Controller "
+ "cannot apply LNA gain [" + gain.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - "
+ "exception while applying LNA gain value [" +
gain.toString() + "] - " +
e1.getLocalizedMessage() );
}
save();
}
} );
gainPanel.add( new JLabel( "LNA:" ) );
gainPanel.add( mComboLNAGain, "growx,push" );
/**
* LNA Enhance
*/
mComboLNAEnhance = new JComboBox<LNAEnhance>( LNAEnhance.values() );
mComboLNAEnhance.setToolTipText( "Adjust the LNA enhance setting. "
+ "Default value is OFF" );
mComboLNAEnhance.setSelectedItem( mSelectedConfig.getLNAEnhance() );
mComboLNAEnhance.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
LNAEnhance enhance = (LNAEnhance)mComboLNAEnhance.getSelectedItem();
mSelectedConfig.setLNAEnhance( enhance );
try
{
mController.setLNAEnhance( enhance );
}
catch ( UsbClaimException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - cannot claim FCD "
+ "Controller to apply LNA enhance [" + enhance.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - usb claim "
+ "exception while applying LNA enhance value [" +
enhance.toString() + "] - " +
e1.getLocalizedMessage() );
}
catch ( UsbException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - FCD Controller "
+ "cannot apply LNA enhance [" + enhance.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - "
+ "exception while applying LNA enhance value [" +
enhance.toString() + "] - " +
e1.getLocalizedMessage() );
}
save();
}
} );
gainPanel.add( new JLabel( "LNA Enhance:" ) );
gainPanel.add( mComboLNAEnhance, "growx,push" );
/**
* Mixer Gain
*/
mComboMixerGain = new JComboBox<MixerGain>( MixerGain.values() );
mComboMixerGain.setToolTipText( "Adjust mixer gain setting" );
mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() );
mComboMixerGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent arg0 )
{
MixerGain gain = (MixerGain)mComboMixerGain.getSelectedItem();
mSelectedConfig.setMixerGain( gain );
try
{
mController.setMixerGain( gain );
}
catch ( UsbClaimException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - cannot claim FCD "
+ "Controller to apply Mixer gain [" + gain.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - usb claim "
+ "exception while applying Mixer gain value [" +
gain.toString() + "] - " +
e1.getLocalizedMessage() );
}
catch ( UsbException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - FCD Controller "
+ "cannot apply Mixer gain [" + gain.toString() + "]" );
Log.error( "FuncubeDonglePro Controller - "
+ "exception while applying Mixer gain value [" +
gain.toString() + "] - " +
e1.getLocalizedMessage() );
}
save();
}
} );
gainPanel.add( new JLabel( "Mixer:" ) );
gainPanel.add( mComboMixerGain, "growx,push" );
tabs.add( "Gain", gainPanel );
JPanel correctionPanel = new JPanel();
correctionPanel.setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][][grow]" ) );
/**
* Frequency Correction
*/
SpinnerModel model =
new SpinnerNumberModel( 0.0, -1000.0, 1000.0, 0.1 ); //initial,min,max,step
mCorrectionFrequency = new JSpinner( model );
mCorrectionFrequency.setToolTipText( "Frequency Correction: adjust "
+ "value +/- to align the displayed frequency label with the "
+ "actual signals" );
JSpinner.NumberEditor editor =
(JSpinner.NumberEditor)mCorrectionFrequency.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits( 1 );
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
mCorrectionFrequency.setValue( mSelectedConfig.getFrequencyCorrection() );
mCorrectionFrequency.addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
double value = ((SpinnerNumberModel)mCorrectionFrequency
.getModel()).getNumber().doubleValue();
try
{
mSelectedConfig.setFrequencyCorrection( value );
mController.setFrequencyCorrection( value );
save();
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - couldn't "
+ "apply frequency correction value: " + value +
e1.getLocalizedMessage() );
Log.error( "FuncubeDonglePro Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
}
}
} );
correctionPanel.add( new JLabel( "Frequency PPM:" ) );
correctionPanel.add( mCorrectionFrequency, "growx,push" );
/**
* Inphase DC Correction
*/
mCorrectionDCI = new CorrectionSpinner( Correction.DC_INPHASE,
mSelectedConfig.getInphaseDCCorrection(), 0.00001, 5 );
mCorrectionDCI.setToolTipText( "DC Bias Correction/Inphase "
+ "Component: valid values are -1.0 to 1.0 (default: 0.0)" );
correctionPanel.add( new JLabel( "DC Inphase:" ) );
correctionPanel.add( mCorrectionDCI, "growx,push" );
/**
* Quadrature DC Correction
*/
mCorrectionDCQ = new CorrectionSpinner( Correction.DC_QUADRATURE,
mSelectedConfig.getQuadratureDCCorrection(), 0.00001, 5 );
mCorrectionDCQ.setToolTipText( "DC Bias Correction/Quadrature "
+ "Component: valid values are -1.0 to 1.0 (default: 0.0)" );
correctionPanel.add( new JLabel( "DC Quadrature:" ) );
correctionPanel.add( mCorrectionDCQ, "growx,push" );
/**
* Gain Correction
*/
mCorrectionGain = new CorrectionSpinner( Correction.GAIN,
mSelectedConfig.getGainCorrection(), 0.00001, 5 );
mCorrectionGain.setToolTipText( "Gain Correction: valid values are "
+ "-1.0 to 1.0 (default: 0.0)" );
correctionPanel.add( new JLabel( "Gain:" ) );
correctionPanel.add( mCorrectionGain, "growx,push" );
/**
* Phase Correction
*/
mCorrectionPhase = new CorrectionSpinner( Correction.PHASE,
mSelectedConfig.getPhaseCorrection(), 0.00001, 5 );
mCorrectionPhase.setToolTipText( "Phase Correction: valid values are "
+ "-1.0 to 1.0 (default: 0.0)" );
correctionPanel.add( new JLabel( "Phase:" ) );
correctionPanel.add( mCorrectionPhase, "growx,push" );
tabs.add( "Correction", correctionPanel );
/**
* Create a new configuration
*/
mNewConfiguration = new JButton( "New" );
mNewConfiguration.setToolTipText( "Create a new tuner configuration "
+ "for each of your dongles to keep track of the specific "
+ "settings for each dongle" );
mNewConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
TunerConfiguration config =
mResourceManager.getSettingsManager()
.addNewTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO,
"New Configuration" );
mComboConfigurations.setModel( getModel() );
mComboConfigurations.setSelectedItem( config );
repaint();
}
} );
add( mNewConfiguration, "growx,push" );
/**
* Delete the currently selected configuration
*/
mDeleteConfiguration = new JButton( "Delete" );
mDeleteConfiguration.setToolTipText( "Deletes the currently selected "
+ "tuner configuration. Note: the DEFAULT tuner "
+ "configuration will be recreated if you delete it, "
+ "after you restart the application" );
mDeleteConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
FCD1TunerConfiguration selected =
(FCD1TunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
int n = JOptionPane.showConfirmDialog(
FCD1TunerConfigurationPanel.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" );
}
private void update( FCD1TunerConfiguration config )
{
mSelectedConfig = config;
try
{
mController.apply( config );
mName.setText( config.getName() );
mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
mComboLNAEnhance.setSelectedItem( mSelectedConfig.getLNAEnhance() );
mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() );
mCorrectionFrequency.setValue( config.getFrequencyCorrection() );
mCorrectionDCI.setValue( config.getInphaseDCCorrection() );
mCorrectionDCQ.setValue( config.getQuadratureDCCorrection() );
mCorrectionGain.setValue( config.getGainCorrection() );
mCorrectionPhase.setValue( config.getPhaseCorrection() );
mResourceManager.getSettingsManager()
.setSelectedTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO,
mController.getAddress(), config );
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - couldn't "
+ "apply the tuner configuration settings - " +
e1.getLocalizedMessage() );
Log.error( "FuncubeDonglePro Controller - couldn't apply "
+ "config [" + config.getName() + "] - " +
e1.getLocalizedMessage() );
}
}
private ComboBoxModel<FCD1TunerConfiguration> getModel()
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.FUNCUBE_DONGLE_PRO );
DefaultComboBoxModel<FCD1TunerConfiguration> model =
new DefaultComboBoxModel<FCD1TunerConfiguration>();
for( TunerConfiguration config: configs )
{
model.addElement( (FCD1TunerConfiguration)config );
}
return model;
}
@SuppressWarnings( "unused" )
private FCD1TunerConfiguration getNamedConfiguration( String name )
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.FUNCUBE_DONGLE_PRO );
for( TunerConfiguration config: configs )
{
if( config.getName().contentEquals( name ) )
{
return (FCD1TunerConfiguration)config;
}
}
return null;
}
private void save()
{
mResourceManager.getSettingsManager().save();
}
public enum Correction { GAIN, PHASE, DC_INPHASE, DC_QUADRATURE };
public class CorrectionSpinner extends JSpinner
{
private static final long serialVersionUID = 1L;
private static final double sMIN_VALUE = -1.0d;
private static final double sMAX_VALUE = 1.0d;
private Correction mCorrectionComponent;
public CorrectionSpinner( Correction component,
double initialValue,
double step,
int decimalPlaces )
{
mCorrectionComponent = component;
SpinnerModel model = new SpinnerNumberModel( initialValue,
sMIN_VALUE, sMAX_VALUE, step );
setModel( model );
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits( decimalPlaces );
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
double value =
((SpinnerNumberModel)getModel()).getNumber().doubleValue();
try
{
switch( mCorrectionComponent )
{
case DC_INPHASE:
mSelectedConfig.setInphaseDCCorrection( value );
mController.setDCCorrectionInPhase( value );
break;
case DC_QUADRATURE:
mSelectedConfig.setQuadratureDCCorrection( value );
mController.setDCCorrectionQuadrature( value );
break;
case GAIN:
mSelectedConfig.setGainCorrection( value );
mController.setGainCorrection( value );
break;
case PHASE:
mSelectedConfig.setPhaseCorrection( value );
mController.setPhaseCorrection( value );
break;
}
//Save the change(s) to the selected tuner config
save();
}
catch ( UsbClaimException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - cannot claim FCD "
+ "Controller to apply "
+ mCorrectionComponent.toString() +
" correction value [" + value + "]" );
Log.error( "FuncubeDonglePro Controller - usb claim "
+ "exception while applying "
+ mCorrectionComponent.toString()
+ " correction value [" + value + "] - " +
e1.getLocalizedMessage() );
}
catch ( UsbException e1 )
{
JOptionPane.showMessageDialog(
FCD1TunerConfigurationPanel.this,
"FCD Pro Tuner Controller - USB error from FCD "
+ "Controller while applying "
+ mCorrectionComponent.toString() +
" correction value [" + value + "]" );
Log.error( "FuncubeDonglePro Controller - usb "
+ "exception while applying "
+ mCorrectionComponent.toString()
+ " correction value [" + value + "] - " +
e1.getLocalizedMessage() );
}
}
} );
}
}
}

View File

@@ -0,0 +1,698 @@
/*******************************************************************************
* 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.fcd.proV1;
import javax.swing.JPanel;
import javax.usb.UsbClaimException;
import javax.usb.UsbException;
import log.Log;
import source.SourceException;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.fcd.FCDCommand;
import source.tuner.fcd.FCDTuner;
import source.tuner.fcd.FCDTunerController;
import source.tuner.usb.USBTunerDevice;
import controller.ResourceManager;
public class FCD1TunerController extends FCDTunerController
{
public static final int sMINIMUM_TUNABLE_FREQUENCY = 64000000;
public static final int sMAXIMUM_TUNABLE_FREQUENCY = 1700000000;
public static final int sSAMPLE_RATE = 96000;
private double mDCCorrectionInPhase = 0.0;
private double mDCCorrectionQuadrature = 0.0;
private double mPhaseCorrection = 0.0;
private double mGainCorrection = 0.0;
private LNAGain mLNAGain;
private LNAEnhance mLNAEnhance;
private MixerGain mMixerGain;
private FCD1TunerConfiguration mTunerConfiguration;
private FCD1TunerEditorPanel mEditor;
public FCD1TunerController( USBTunerDevice device )
throws SourceException
{
super( device,
sMINIMUM_TUNABLE_FREQUENCY,
sMAXIMUM_TUNABLE_FREQUENCY );
mFrequencyController.setBandwidth( sSAMPLE_RATE );
try
{
open();
setFCDMode( Mode.APPLICATION );
getPhaseAndGainCorrection();
getDCIQCorrection();
getLNAGainSetting();
getLNAEnhanceSetting();
getMixerGainSetting();
send( FCDCommand.APP_SET_MIXER_GAIN, 1 );
}
catch( Exception e )
{
e.printStackTrace();
throw new SourceException( "FCDTunerController error " +
"during construction", e );
}
}
public int getCurrentSampleRate()
{
return sSAMPLE_RATE;
}
@Override
public TunerClass getTunerClass()
{
return TunerClass.FUNCUBE_DONGLE_PRO;
}
@Override
public TunerType getTunerType()
{
return TunerType.FUNCUBE_DONGLE_PRO;
}
/**
* Get the tuner configuration
*
* @return current config or null if one hasn't been applied yet
*/
public FCD1TunerConfiguration getTunerConfiguration()
{
return mTunerConfiguration;
}
@Override
public void apply( TunerConfiguration tunerConfig )
throws SourceException
{
FCD1TunerConfiguration config = (FCD1TunerConfiguration)tunerConfig;
try
{
setFrequencyCorrection( config.getFrequencyCorrection() );
setLNAGain( config.getLNAGain() );
setLNAEnhance( config.getLNAEnhance() );
setMixerGain( config.getMixerGain() );
setDCCorrectionInPhase( config.getInphaseDCCorrection() );
setDCCorrectionQuadrature( config.getQuadratureDCCorrection() );
setGainCorrection( config.getGainCorrection() );
setPhaseCorrection( config.getPhaseCorrection() );
//If we get to here without exception, store this config
mTunerConfiguration = config;
}
catch( Exception e)
{
//Re-cast any usb exceptions as source exceptions
throw new SourceException( "FCD 1 Controller encountered an "
+ "exception while applying tuner config - " +
e.getLocalizedMessage() );
}
}
@Override
public JPanel getEditor( FCDTuner tuner, ResourceManager resourceManager )
{
if( mEditor == null )
{
mEditor = new FCD1TunerEditorPanel( tuner, resourceManager );
}
return mEditor;
}
/**
* Gets the current LNA Gain value from the controller and stores it
*/
private void getLNAGainSetting() throws UsbClaimException, UsbException
{
int gain = (int)send( FCDCommand.APP_GET_LNA_GAIN );
Log.info( "FCD1: lna gain setting is:" + gain );
mLNAGain = LNAGain.valueOf( gain );
}
/**
* @return - current lna gain setting
*/
public LNAGain getLNAGain()
{
return mLNAGain;
}
/**
* Sets lna gain for the controller
* @param gain
* @throws UsbException
* @throws UsbClaimException
*/
public void setLNAGain( LNAGain gain )
throws UsbException, UsbClaimException
{
send( FCDCommand.APP_SET_LNA_GAIN, gain.getSetting() );
}
/**
* @return - current phase correction setting
*/
public double getPhaseCorrection()
{
return mPhaseCorrection;
}
/**
* Sets the phase correction
* @param value - new phase correction
* @throws IllegalArgumentException for value outside limits (0.0 <> 1.0)
* @throws UsbClaimException - if cannot claim the FCD HID controller
* @throws UsbException - if there was a usb error
*/
public void setPhaseCorrection( double value )
throws UsbClaimException, UsbException
{
if( value < -1.0 || value > 1.0 )
{
throw new IllegalArgumentException( "Phase correction value [" +
value + "] outside limits ( -1.0 <> 1.0 )" );
}
mPhaseCorrection = value;
setPhaseAndGainCorrection();
}
/**
* @return current gain correction setting
*/
public double getGainCorrection()
{
return mGainCorrection;
}
/**
*
* @param value - gain correction value
* @throws IllegalArgumentException for value outside limits (0.0 <> 1.0)
* @throws UsbClaimException - if cannot claim the FCD HID controller
* @throws UsbException - if there was a usb error
*/
public void setGainCorrection( double value )
throws UsbClaimException, UsbException
{
if( value < -1.0 || value > 1.0 )
{
throw new IllegalArgumentException( "Gain correction value [" +
value + "] outside limits ( -1.0 <> 1.0 )" );
}
mGainCorrection = value;
setPhaseAndGainCorrection();
}
/**
* Sends the phase and gain correction values to FCD.
*
* The interface expects an argument with the SIGNED phase value in the first
* 16 bits and the UNSIGNED gain value in the second 16 bits, both in
* big-endian format. Since we're sending the argument in java little endian
* format, we place the phase in the high-order bits and the gain in the
* low-order bits, so that the send(command) function will reorder the bytes
* into big endian format, and place the arguments correctly.
*
* Gain correction values range -1.0 to 0.0 to 1.0 and applied to the dongle
* as values 0 to 65534
*
* Phase correction values range -1.0 to 0.0 to 1.0 and applied to the
* dongle as signed values -32768 to 32767
*/
private void setPhaseAndGainCorrection() throws UsbClaimException,
UsbException
{
//UNSIGNED short gain value - masked into a long to avoid sign-extension
long gain = (long)( ( 1.0 + mGainCorrection ) * Short.MAX_VALUE );
//Left shift gain to place value in upper 16 bits
long longGain = Long.rotateLeft( ( 0xFFFF & gain ), 16 );
//SIGNED short phase value
short phase = (short)( mPhaseCorrection * Short.MAX_VALUE );
//Merge the results
long correction = longGain | phase;
send( FCDCommand.APP_SET_IQ_CORRECTION, correction );
}
/**
* Retrieves the stored phase and gain correction values from the FCD.
*
* Note: testing shows that when the dongle is unplugged, any stored phase
* and gain correction values are reset. Reading the dongle after a fresh
* plugin shows the values reset.
*
* @throws UsbClaimException
* @throws UsbException
*/
private void getPhaseAndGainCorrection() throws UsbClaimException,
UsbException
{
long correction = send( FCDCommand.APP_GET_IQ_CORRECTION );
/**
* Gain: mask the upper 16 phase bits and right shift to get the
* unsigned short value and then divide by 32768 to get the double
* value. We place the unsigned short value in an int to avoid sign
* issues.
*/
int gain = (int)( Long.rotateRight( correction & 0xFFFF0000, 16 ) );
mGainCorrection = ( (double)gain / (double)Short.MAX_VALUE ) - 1.0;
/**
* Phase: mask the lower 16 bits and divide by 32768 to get the double
* value
*/
short phase = (short)( correction & 0x0000FFFF );
mPhaseCorrection = ( (double)phase / (double)Short.MAX_VALUE );
Log.info( "FCD1: correction:" + correction + " gain:" + gain + " phase:" + phase );
}
/**
* @return current DC correction for the I (inphase) component
*/
public double getDCCorrectionInPhase()
{
return mDCCorrectionInPhase;
}
/**
* Sets DC correction for the I (inphase) component and sends the new value
* to the FCD controller
* @param value - new DC correction value for the inphase component
* @throws IllegalArgumentException for values outside limits (-1.0 <> 1.0)
* @throws UsbClaimException - if cannot claim the FCD HID controller
* @throws UsbException - if there was a usb error
*/
public void setDCCorrectionInPhase( double value )
throws UsbClaimException, UsbException
{
if( value < -1.0 || value > 1.0 )
{
throw new IllegalArgumentException( "DC inphase correction value "
+ "[" + value + "] outside limits ( 0.0 <> 1.0 )" );
}
mDCCorrectionInPhase = value;
setDCIQCorrection();
}
/**
* @return current DC correction for the Q (quadrature) component
*/
public double getDCCorrectionQuadrature()
{
return mDCCorrectionQuadrature;
}
/**
* Sets the DC correction for the Q (quadrature) component and send the
* new value to the FCD controller
* @param value - new DC correction value for the quadrature component
* @throws IllegalArgumentException for values outside limits (-1.0 <> 1.0)
* @throws UsbClaimException - if cannot claim the FCD HID controller
* @throws UsbException - if there was a usb error
*/
public void setDCCorrectionQuadrature( double value )
throws UsbClaimException, UsbException
{
if( value < -1.0 || value > 1.0 )
{
throw new IllegalArgumentException( "DC quadrature correction "
+ "value [" + value + "] outside limits ( 0.0 <> 1.0 )" );
}
mDCCorrectionQuadrature = value;
setDCIQCorrection();
}
/**
* Sends the I/Q DC offset correction values to FCD.
*
* The interface expects an argument with the signed inphase value in the
* first 16 bits and the signed quadrature value in the second 16 bits,
* both in big-endian format.
*
* Since we're sending the argument in java little endian format, we place
* the quadrature in the high-order bits and the inphase in the low-order
* bits, so that the send(command) function will reorder the bytes into big
* endian format, and place the arguments correctly.
*
* Both Inphase and Quadrature correction values range -1.0 to 0.0 to 1.0
* and are applied to the dongle as signed short values -32768 to 0 to 32767
*/
private void setDCIQCorrection() throws UsbClaimException, UsbException
{
//I & Q DC offset correction values are signed short values
short inphase = (short)( mDCCorrectionInPhase * Short.MAX_VALUE );
short quadrature = (short)( mDCCorrectionQuadrature * Short.MAX_VALUE );
//Mask the shorts into longs to preserve the sign bit and prepare
//for merging to a single 32-bit value
long maskedInphase = inphase & 0x0000FFFF;
long maskedQuadrature = quadrature & 0x0000FFFF;
//Left shift quadrature to place value in upper 16 bits
long shiftedQuadrature = Long.rotateLeft( maskedQuadrature, 16 );
//Merge the results
long correction = shiftedQuadrature | maskedInphase;
// Log.info( "FCD1: setting iq correction," +
// " inphase:" + inphase +
// " masked inphase:" + maskedInphase +
// " quad:" + quadrature +
// " masked quad:" + maskedQuadrature +
// " shifted quadrature:" + shiftedQuadrature +
// " correction:" + correction );
send( FCDCommand.APP_SET_DC_CORRECTION, correction );
}
private void getDCIQCorrection() throws UsbClaimException,
UsbException
{
long correction = send( FCDCommand.APP_GET_DC_CORRECTION );
/**
* Quadrature: mask the upper 16 bits and divide by 32768 to get the
* stored quadrature value. Cast the 16-bit value to a short to get
* the signed short value
*/
long shiftedQuadrature = correction & 0xFFFF0000;
long quadrature = Long.rotateRight( shiftedQuadrature, 16 );
mDCCorrectionQuadrature = ( (short)quadrature / (double)Short.MAX_VALUE );
/**
* InPhase: mask the lower 16 bits to get the short
* value and then divide by 32768 to get the stored inphase value.
* Cast the 16-bit value to a short to get the signed short value
*/
long inphase = correction & 0x0000FFFF;
mDCCorrectionInPhase = ( (short)inphase / (double)Short.MAX_VALUE );
// Log.info( "FCD1:" +
// " correction:" + correction +
// " Q:" + quadrature +
// " I:" + inphase +
// " QCorr:" + mDCCorrectionQuadrature +
// " ICorr:" + mDCCorrectionInPhase );
}
private void getLNAEnhanceSetting() throws UsbClaimException, UsbException
{
int enhance = (int)send( FCDCommand.APP_GET_LNA_ENHANCE );
Log.info( "FCD1: lna enhance setting is: " + enhance );
mLNAEnhance = LNAEnhance.valueOf( enhance );
}
public LNAEnhance getLNAEnhance()
{
return mLNAEnhance;
}
public void setLNAEnhance( LNAEnhance enhance )
throws UsbClaimException, UsbException
{
send( FCDCommand.APP_SET_LNA_ENHANCE, enhance.getSetting() );
}
private void getMixerGainSetting() throws UsbClaimException, UsbException
{
int gain = (int)send( FCDCommand.APP_GET_MIXER_GAIN );
Log.info( "FCD1: mixer gain setting is:" + gain );
mMixerGain = MixerGain.valueOf( gain );
}
public MixerGain getMixerGain()
{
return mMixerGain;
}
public void setMixerGain( MixerGain gain ) throws UsbClaimException, UsbException
{
send( FCDCommand.APP_SET_MIXER_GAIN, gain.getSetting() );
}
public enum Block
{
CELLULAR_BAND_BLOCKED( "Blocked" ),
NO_BAND_BLOCK( "Unblocked" ),
UNKNOWN( "Unknown" );
private String mLabel;
private Block( String label )
{
mLabel = label;
}
public String getLabel()
{
return mLabel;
}
public static Block getBlock( String block )
{
Block retVal = UNKNOWN;
if( block.equalsIgnoreCase( "No blk" ) )
{
retVal = NO_BAND_BLOCK;
}
else if( block.equalsIgnoreCase( "Cell blk" ) )
{
retVal = CELLULAR_BAND_BLOCKED;
}
return retVal;
}
}
/**
* LNA Gain values suppported by the FCD Pro 1.0
*/
public enum LNAGain
{
LNA_GAIN_MINUS_5_0( 0, "-5.0 dB" ),
LNA_GAIN_MINUS_2_5( 1, "-2.5 dB" ),
LNA_GAIN_PLUS_0_0( 4, "0.0 dB" ),
LNA_GAIN_PLUS_2_5( 5, "2.5 dB" ),
LNA_GAIN_PLUS_5_0( 6, "5.0 dB" ),
LNA_GAIN_PLUS_7_5( 7, "7.5 dB" ),
LNA_GAIN_PLUS_10_0( 8, "10.0 dB" ),
LNA_GAIN_PLUS_12_5( 9, "12.5 dB" ),
LNA_GAIN_PLUS_15_0( 10, "15.0 dB" ),
LNA_GAIN_PLUS_17_5( 11, "17.5 dB" ),
LNA_GAIN_PLUS_20_0( 12, "20.0 dB" ),
LNA_GAIN_PLUS_25_0( 13, "25.0 dB" ),
LNA_GAIN_PLUS_30_0( 14, "30.0 dB" );
private int mSetting;
private String mLabel;
private LNAGain( int setting, String label )
{
mSetting = setting;
mLabel = label;
}
public static LNAGain valueOf( int setting )
{
switch( setting )
{
case 0:
return LNA_GAIN_MINUS_5_0;
case 1:
return LNA_GAIN_MINUS_2_5;
case 4:
return LNA_GAIN_PLUS_0_0;
case 5:
return LNA_GAIN_PLUS_2_5;
case 6:
return LNA_GAIN_PLUS_5_0;
case 7:
return LNA_GAIN_PLUS_7_5;
case 8:
return LNA_GAIN_PLUS_10_0;
case 9:
return LNA_GAIN_PLUS_12_5;
case 10:
return LNA_GAIN_PLUS_15_0;
case 11:
return LNA_GAIN_PLUS_17_5;
case 12:
return LNA_GAIN_PLUS_20_0;
case 13:
return LNA_GAIN_PLUS_25_0;
case 14:
return LNA_GAIN_PLUS_30_0;
default:
throw new IllegalArgumentException( "FCD 1.0 Tuner "
+ "Controller - unrecognized LNA gain setting "
+ "value [" + setting + "]" );
}
}
public int getSetting()
{
return mSetting;
}
public String getLabel()
{
return mLabel;
}
public String toString()
{
return getLabel();
}
}
/**
* LNA Enhance values suppported by the FCD Pro 1.0
*/
public enum LNAEnhance
{
LNA_ENHANCE_OFF( 0, "Off" ),
LNA_ENHANCE_0( 1, "0" ),
LNA_ENHANCE_1( 3, "1" ),
LNA_ENHANCE_2( 5, "2" ),
LNA_ENHANCE_3( 7, "3" );
private int mSetting;
private String mLabel;
private LNAEnhance( int setting, String label )
{
mSetting = setting;
mLabel = label;
}
public static LNAEnhance valueOf( int setting )
{
switch( setting )
{
case 0:
return LNA_ENHANCE_OFF;
case 1:
return LNA_ENHANCE_0;
case 3:
return LNA_ENHANCE_1;
case 5:
return LNA_ENHANCE_2;
case 7:
return LNA_ENHANCE_3;
default:
throw new IllegalArgumentException( "FCD 1.0 Tuner "
+ "Controller - unrecognized LNA enhance setting "
+ "value [" + setting + "]" );
}
}
public int getSetting()
{
return mSetting;
}
public String getLabel()
{
return mLabel;
}
public String toString()
{
return getLabel();
}
}
/**
* Mixer Gain values suppported by the FCD Pro 1.0
*/
public enum MixerGain
{
MIXER_GAIN_PLUS_4_0( 0, "4.0 dB" ),
MIXER_GAIN_PLUS_12_0( 1, "12.0 dB" );
private int mSetting;
private String mLabel;
private MixerGain( int setting, String label )
{
mSetting = setting;
mLabel = label;
}
public static MixerGain valueOf( int setting )
{
switch( setting )
{
case 0:
return MIXER_GAIN_PLUS_4_0;
case 1:
return MIXER_GAIN_PLUS_12_0;
default:
throw new IllegalArgumentException( "FCD 1.0 Tuner "
+ "Controller - unrecognized mixer gain setting "
+ "value [" + setting + "]" );
}
}
public int getSetting()
{
return mSetting;
}
public String getLabel()
{
return mLabel;
}
public String toString()
{
return getLabel();
}
}
}

View File

@@ -0,0 +1,102 @@
/*******************************************************************************
* 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.fcd.proV1;
import java.awt.Color;
import gui.control.JFrequencyControl;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.jidesoft.swing.JideTabbedPane;
import log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.FrequencyChangeListener;
import source.tuner.fcd.FCDTuner;
import source.tuner.fcd.FCDTunerDetailsPanel;
import controller.ResourceManager;
public class FCD1TunerEditorPanel extends JPanel implements FrequencyChangeListener
{
private static final long serialVersionUID = 1L;
private FCDTuner mTuner;
private FCD1TunerController mController;
private ResourceManager mResourceManager;
private JFrequencyControl mFrequencyControl;
public FCD1TunerEditorPanel( FCDTuner tuner, ResourceManager resourceManager )
{
mTuner = tuner;
mController = (FCD1TunerController)mTuner.getController();
mResourceManager = resourceManager;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2", "[grow,right][grow]", "[][][grow]" ) );
add( new JLabel( "Funcube Dongle Pro Tuner" ), "span, align center" );
mFrequencyControl = new JFrequencyControl();
mFrequencyControl.addListener( this );
/* Add frequency control as listener to tuner to get frequency changes
* that are invoked elsewhere, to keep the control in sync with the
* frequency */
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 );
tabs.add( "Configuration", new FCD1TunerConfigurationPanel(
mResourceManager, mController ) );
tabs.add( "Info", new FCDTunerDetailsPanel( mController ) );
add( tabs, "span,push,grow" );
}
@Override
public void frequencyChanged( int frequency, int bandwidth )
{
//Disregard the bandwidth value, which shouldn't be changing
try
{
mController.setFrequency( frequency );
}
catch ( SourceException e )
{
Log.error( "FCTProController - error setting frequency [" +
frequency + "] - " + e.getLocalizedMessage() );
}
}
}