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,163 @@
/*******************************************************************************
* 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;
public enum FCDCommand
{
/**
* Note: the javaxUSB and usb4Java libraries are slightly different than
* the signal9 HID libraries used in C, so you will see variations in the
* byte array length and indexes, when comparing this setup to the qthid
* source code.
*/
//Bootloader Mode Commands
BL_QUERY( (byte) 0x01, 64 ), //01 Decimal
BL_RESET( (byte) 0x08, 2 ), //08
BL_ERASE( (byte) 0x19, 2 ), //24
BL_SET_BYTE_ADDR( (byte) 0x1A, 6 ), //25
BL_GET_BYTE_ADDR_RANGE( (byte) 0x1B, 6 ), //26
BL_WRITE_FLASH_BLOCK( (byte) 0x1C, 52 ), //27
BL_READ_FLASH_BLOCK( (byte) 0x1D, 48 ), //28
//Application Mode Commands
APP_SET_FREQUENCY_KHZ( (byte)0x64, 5 ), //100
APP_SET_FREQUENCY_HZ( (byte)0x65, 6 ), //101
APP_GET_FREQUENCY_HZ( (byte)0x66, 6 ), //102
APP_GET_IF_RSSI( (byte) 0x68, 3 ), //104
APP_GET_PLL_LOCKED( (byte) 0x69, 3 ), //105
APP_SET_DC_CORRECTION( (byte) 0x6A, 5 ), //106
APP_GET_DC_CORRECTION( (byte) 0x6B, 6 ), //107
APP_SET_IQ_CORRECTION( (byte) 0x6C, 5 ), //108
APP_GET_IQ_CORRECTION( (byte) 0x6D, 6 ), //109
APP_SET_LNA_GAIN( (byte)0x6E, 2 ), //110
APP_SET_LNA_ENHANCE( (byte)0x6F, 2 ), //111
APP_SET_BAND( (byte)0x70, 2 ), //112
APP_SET_RF_FILTER( (byte)0x71, 2 ), //113
APP_SET_MIXER_GAIN( (byte)0x72, 2 ), //114
APP_SET_BIAS_CURRENT( (byte)0x73, 2 ), //115
APP_SET_MIXER_FILTER( (byte)0x74, 2 ), //116
APP_SET_IF_GAIN1( (byte)0x75, 2 ), //117
APP_SET_IF_GAIN_MODE( (byte)0x76, 2 ), //118
APP_SET_IF_RC_FILTER( (byte)0x77, 2 ), //119
APP_SET_IF_GAIN2( (byte)0x78, 2 ), //120
APP_SET_IF_GAIN3( (byte)0x79, 2 ), //121
APP_SET_IF_FILTER( (byte)0x7A, 2 ), //122
APP_SET_IF_GAIN4( (byte)0x7B, 2 ), //123
APP_SET_IF_GAIN5( (byte)0x7C, 2 ), //124
APP_SET_IF_GAIN6( (byte)0x7D, 2 ), //125
APP_SET_BIAS_TEE( (byte)0x7E, 2 ), //126
APP_GET_LNA_GAIN( (byte)0x96, 3 ), //150
APP_GET_LNA_ENHANCE( (byte)0x97, 3 ), //151
APP_GET_BAND( (byte)0x98, 3 ), //152
APP_GET_RF_FILTER( (byte)0x99, 3 ), //153
APP_GET_MIXER_GAIN( (byte)0x9A, 3 ), //154
APP_GET_BIAS_CURRENT( (byte)0x9B, 3 ), //155
APP_GET_MIXER_FILTER( (byte)0x9C, 3 ), //156
APP_GET_IF_GAIN1( (byte)0x9D, 3 ), //157
APP_GET_IF_GAIN_MODE( (byte)0x9E, 3 ), //158
APP_GET_IF_RC_FILTER( (byte)0x9F, 3 ), //159
APP_GET_IF_GAIN2( (byte)0xA0, 3 ), //160
APP_GET_IF_GAIN3( (byte)0xA1, 3 ), //161
APP_GET_IF_FILTER( (byte)0xA2, 3 ), //162
APP_GET_IF_GAIN4( (byte)0xA3, 3 ), //163
APP_GET_IF_GAIN5( (byte)0xA4, 3 ), //164
APP_GET_IF_GAIN6( (byte)0xA5, 3 ), //165
APP_GET_BIAS_TEE( (byte)0xA6, 3 ), //166
APP_SEND_I2C_BYTE( (byte)0xC8, 2 ), //200
APP_RECV_I2C_BYTE( (byte)0xC9, 3 ), //201
APP_RESET( (byte)0xFF, 1 ); //255
/**
* Single-byte value to use for the command
*/
private byte mCommandByte;
/**
* Required array length
*/
private int mArrayLength;
private FCDCommand( byte value, int responseLength )
{
mCommandByte = value;
mArrayLength = responseLength;
}
/**
* Returns a byte array of the specified length with the command byte value
* set in index position zero. Fill in additional command arguments prior
* to sending to the device
*/
public byte[] getRequestTemplate()
{
byte[] retVal = new byte[ 64 ];
retVal[ 0 ] = mCommandByte;
retVal[ 1 ] = (byte)0x0;
return retVal;
}
/**
* Returns an empty byte array of the correct length to receive the response
* from the associated command
*/
public byte[] getResponseTemplate()
{
return new byte[ 64 ];
}
/**
* Byte value of the command
*/
public byte getCommand()
{
return mCommandByte;
}
/**
* Total array length required to send the command or receive the response.
*
* Index 0: command is echoed back
* Index 1: 0-fail, 1-success
*/
public int getArrayLength()
{
return mArrayLength;
}
/**
* Checks the response array to verify the pass/fail value that is placed
* in array index position 1, in responses from the device
*/
public static boolean checkResponse( FCDCommand command, byte[] response )
{
boolean valid = false;
if( command != null && response != null )
{
valid = response[ 0 ] == command.getCommand() &&
response[ 1 ] == 1;
}
return valid;
}
}

View File

@@ -0,0 +1,53 @@
/*******************************************************************************
* 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;
public enum FCDModel
{
FUNCUBE_DONGLE_PRO( "FunCube Dongle Pro" ),
FUNCUBE_DONGLE_PRO_PLUS( "FunCube Dongle Pro Plus"),
FUNCUBE_UNKNOWN( "Unknown" );
private String mLabel;
private FCDModel( String label )
{
mLabel = label;
}
public String getLabel()
{
return mLabel;
}
public static FCDModel getFCD( String board )
{
FCDModel retVal = FUNCUBE_UNKNOWN;
if( board.equalsIgnoreCase( "Brd 1.1" ) )
{
retVal = FUNCUBE_DONGLE_PRO;
}
else if( board.equalsIgnoreCase( "Brd 2.0" ) )
{
retVal = FUNCUBE_DONGLE_PRO_PLUS;
}
return retVal;
}
}

View 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.fcd;
import java.util.concurrent.RejectedExecutionException;
import javax.swing.JPanel;
import sample.Listener;
import source.SourceException;
import source.mixer.ShortAdapter;
import source.tuner.FrequencyChangeListener;
import source.tuner.MixerTuner;
import source.tuner.MixerTunerDataLine;
import source.tuner.TunerChannel;
import source.tuner.TunerChannelSource;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import controller.ResourceManager;
import controller.ThreadPoolManager;
public class FCDTuner extends MixerTuner
{
private FCDTunerController mController;
public FCDTuner( MixerTunerDataLine mixerTDL,
FCDTunerController controller )
{
super( controller.getConfiguration().toString(),
mixerTDL,
new ShortAdapter() );
mController = controller;
mController.addListener( (FrequencyChangeListener)this );
}
public FCDTunerController getController()
{
return mController;
}
@Override
public TunerClass getTunerClass()
{
return mController.getTunerClass();
}
@Override
public TunerType getTunerType()
{
return mController.getTunerType();
}
@Override
public String getUniqueID()
{
return mController.getAddress();
}
@Override
public JPanel getEditor( ResourceManager resourceManager )
{
return mController.getEditor( this, resourceManager );
}
@Override
public void apply( TunerConfiguration config )throws SourceException
{
mController.apply( config );
}
@Override
public int getSampleRate()
{
return (int)mMixerTunerType.getAudioFormat().getSampleRate();
}
@Override
public int getFrequency() throws SourceException
{
return mController.getFrequency();
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel tunerChannel ) throws RejectedExecutionException,
SourceException
{
return mController.getChannel( threadPoolManager, this, tunerChannel );
}
/**
* Releases the tuned channel so that the tuner controller can tune to
* other frequencies as needed.
*/
@Override
public void releaseChannel( TunerChannelSource source )
{
if( source != null )
{
/* Unregister for receiving samples */
removeListener( (Listener<Float[]>)source );
/* Tell the controller to release the channel and cleanup */
/* This will release the channel as a frequency change listener */
mController.releaseChannel( source );
}
}
}

View File

@@ -0,0 +1,497 @@
/*******************************************************************************
* 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;
import javax.swing.JPanel;
import javax.usb.UsbClaimException;
import javax.usb.UsbConfiguration;
import javax.usb.UsbDevice;
import javax.usb.UsbEndpoint;
import javax.usb.UsbException;
import javax.usb.UsbInterface;
import javax.usb.UsbInterfacePolicy;
import javax.usb.UsbPipe;
import log.Log;
import source.SourceException;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerController;
import source.tuner.TunerType;
import source.tuner.fcd.proV1.FCD1TunerController.Block;
import source.tuner.usb.USBTunerDevice;
import controller.ResourceManager;
public abstract class FCDTunerController extends TunerController
{
public final static int sINT_NULL_VALUE = -1;
public final static long sLONG_NULL_VALUE = -1l;
public final static double sDOUBLE_NULL_VALUE = -1.0D;
public final static byte sFCD_INTERFACE = (byte)0x2;
public final static byte sFCD_ENDPOINT_IN = (byte)0x82;
public final static byte sFCD_ENDPOINT_OUT = (byte)0x2;
public final static boolean sFCD_FORCE_CLAIM_HID_INTERFACE = true;
private UsbDevice mFuncube;
private UsbConfiguration mUsbConfiguration;
private UsbInterface mFuncubeHID;
private UsbPipe mPipeIn;
private UsbPipe mPipeOut;
private FCDConfiguration mConfiguration = new FCDConfiguration();
private int mSampleRate;
public FCDTunerController( USBTunerDevice device,
int minTunableFrequency,
int maxTunableFrequency ) throws SourceException
{
super( minTunableFrequency, maxTunableFrequency );
mFuncube = device.getDevice();
mUsbConfiguration = mFuncube.getActiveUsbConfiguration();
mFuncubeHID = mUsbConfiguration.getUsbInterface( sFCD_INTERFACE );
}
public abstract int getCurrentSampleRate() throws SourceException;
/**
* Returns the tuner class. Since this is a generic container for both
* types of funcube, we let the controller self identify the class and type
*
* @return - tuner class
*/
public abstract TunerClass getTunerClass();
/**
* Returns the tuner type. Since this is a generic container for both
* types of funcube, we let the controller self identify the class and type
*
* @return - tuner type
*/
public abstract TunerType getTunerType();
/**
* FCD editor panel
*/
public abstract JPanel getEditor( FCDTuner tuner,
ResourceManager resourceManager );
/**
* Applies the settings in the tuner configuration
*/
public abstract void apply( TunerConfiguration config )
throws SourceException;
/**
* Returns the applied tuner configuration or null if one hasn't yet been
* applied
*/
public abstract TunerConfiguration getTunerConfiguration();
/**
* USB address
*/
public String getAddress()
{
return mFuncube.toString();
}
/**
* Set fcd interface mode
*/
public void setFCDMode( Mode mode ) throws UsbException, UsbClaimException
{
byte[] response = null;
switch( mode )
{
case APPLICATION:
response = send( FCDCommand.BL_QUERY.getRequestTemplate(),
FCDCommand.BL_QUERY.getResponseTemplate() );
break;
case BOOTLOADER:
response = send( FCDCommand.APP_RESET.getRequestTemplate(),
FCDCommand.APP_RESET.getResponseTemplate() );
break;
case ERROR:
case UNKNOWN:
break;
}
if( response != null )
{
mConfiguration.set( response );
}
else
{
mConfiguration.setModeUnknown();
}
}
/**
* Sets the actual (uncorrected) device frequency
*/
public void setTunedFrequency( int frequency ) throws SourceException
{
try
{
send( FCDCommand.APP_SET_FREQUENCY_HZ, frequency );
}
catch( Exception e )
{
throw new SourceException( "Couldn't set FCD Local " +
"Oscillator Frequency [" + frequency + "]", e );
}
}
/**
* Gets the actual (uncorrected) device frequency
*/
public int getTunedFrequency() throws SourceException
{
try
{
return (int)send( FCDCommand.APP_GET_FREQUENCY_HZ );
}
catch( Exception e )
{
throw new SourceException( "FCDTunerController - "
+ "couldn't get LO frequency", e );
}
}
/**
* Returns the FCD device configuration
*/
public FCDConfiguration getConfiguration()
{
return mConfiguration;
}
/**
* Claims the FCD USB HID interface. If another application currently has
* the interface claimed, the sFCD_FORCE_CLAIM_HID_INTERFACE setting
* will dictate if the interface is forcibly claimed from the other
* application
*/
private boolean claim() throws UsbException, UsbClaimException
{
boolean claimed = false;
if( !mFuncubeHID.isClaimed() )
{
mFuncubeHID.claim( new UsbInterfacePolicy()
{
@Override
public boolean forceClaim( UsbInterface arg0 )
{
return sFCD_FORCE_CLAIM_HID_INTERFACE;
}
} );
claimed = true;
}
else
{
Log.info( "Attempted to claim the Funcube HID interface, but it's in use by another program" );
}
return claimed;
}
/**
* Releases the claimed USB (FCD) interface
*/
private void release()
{
mPipeIn = null;
mPipeOut = null;
try
{
mFuncubeHID.release();
}
catch ( Exception e )
{
Log.error( "Exception thrown while releasing the funcube HID interface" + e.getLocalizedMessage() );
}
}
/**
* Convenience wrapper for commands that don't take arguments
*/
public long send( FCDCommand command ) throws UsbException, UsbClaimException
{
return send( command, sLONG_NULL_VALUE );
}
/**
* Sends the command, optionally placing the argument value parsed into
* little endian bytes in the request array. Returns any integer value that
* part of the response, or sINT_NULL_VALUE (-1) if it fails.
*
* Note: we use a long return value to avoid any issues with the MSB of a
* 32-bit response value being misinterpreted as the integer sign bit.
*
* @param command
* @param commandArgument - command argument. Use -1 for no-argument commands
* @return - response long value, or -1 if fails
* @throws UsbException
* @throws UsbClaimException
*/
public long send( FCDCommand command, long commandArgument ) throws UsbException,
UsbClaimException
{
long retVal = sLONG_NULL_VALUE;
byte[] request = command.getRequestTemplate();
if( commandArgument != sLONG_NULL_VALUE )
{
//Parse the value argument into the request byte indices, according to command length
for( int x = 1; x < command.getArrayLength(); x++ )
{
//Little endian
request[ x ] = (byte)( 0xFF &
Long.rotateRight( commandArgument, ( x - 1 ) * 8 ) );
}
}
byte[] response = send( request, command.getResponseTemplate() );
if( response != null )
{
retVal = parseResponse( command, response );
}
return retVal;
}
/**
* Sends the request byte array to the device and returns the response array
* filled with the response bytes from the device, or returns null if
* something failed along the way
*/
private byte[] send( byte[] request, byte[] response )
throws UsbException, UsbClaimException
{
byte[] retVal = null;
if( mPipeIn != null && mPipeOut != null )
{
mPipeOut.syncSubmit( request );
mPipeIn.syncSubmit( response );
retVal = response;
}
return retVal;
}
/**
* Parses a multi-byte integer response value from a byte array that is
* 2 or more bytes long
*/
private long parseResponse( FCDCommand command, byte[] response )
{
long retVal = 0;
//Parse the value argument into the request byte indices, according to command length
for( int x = 2; x < command.getArrayLength(); x++ )
{
retVal += Long.rotateLeft( ( response[ x ] & 0xFF ), ( x - 2 ) * 8 );
}
return retVal;
}
protected void open() throws UsbException, UsbClaimException
{
if( claim() )
{
//Get the USB endpoints
UsbEndpoint endpointIn =
mFuncubeHID.getUsbEndpoint( sFCD_ENDPOINT_IN );
UsbEndpoint endpointOut =
mFuncubeHID.getUsbEndpoint( sFCD_ENDPOINT_OUT );
//Setup the pipes
if( endpointIn != null && endpointOut != null )
{
mPipeOut = endpointOut.getUsbPipe();
mPipeOut.open();
mPipeIn = endpointIn.getUsbPipe();
mPipeIn.open();
setFCDMode( Mode.APPLICATION );
}
else
{
Log.error( "FCD Pro Tuner Controller - couldn't gain access " +
"to the USB in/out endpoints or pipes." );
}
}
else
{
Log.error( "FCD Pro Tuner Controller - couldn't claim the USB " +
"interface. Check to see if another program is using it." );
}
}
protected void close()
{
release();
}
public class FCDConfiguration
{
private String mConfig;
private Mode mMode;
public FCDConfiguration()
{
mConfig = null;
mMode = Mode.UNKNOWN;
}
private void setModeUnknown()
{
mConfig = null;
mMode = Mode.UNKNOWN;
}
public void set( byte[] data )
{
if( FCDCommand.checkResponse( FCDCommand.BL_QUERY, data ) ||
FCDCommand.checkResponse( FCDCommand.APP_RESET, data ) )
{
mConfig = new String( data );
mMode = Mode.getMode( mConfig );
}
else
{
mConfig = null;
mMode = Mode.ERROR;
}
}
public Mode getMode()
{
return mMode;
}
public FCDModel getModel()
{
FCDModel retVal = FCDModel.FUNCUBE_UNKNOWN;
switch( mMode )
{
case APPLICATION:
retVal = FCDModel.getFCD( mConfig.substring( 15, 22 ) );
break;
case BOOTLOADER:
case UNKNOWN:
case ERROR:
break;
}
return retVal;
}
public Block getBandBlocking()
{
Block retVal = Block.UNKNOWN;
switch( mMode )
{
case APPLICATION:
retVal = Block.getBlock( mConfig.substring( 23, 33 ).trim() );
break;
case BOOTLOADER:
case UNKNOWN:
case ERROR:
break;
}
return retVal;
}
public String getFirmware()
{
String retVal = null;
switch( mMode )
{
case APPLICATION:
retVal = mConfig.substring( 9, 14 );
break;
case BOOTLOADER:
case UNKNOWN:
case ERROR:
break;
}
return retVal;
}
public String toString()
{
return getModel().getLabel();
}
}
public enum Mode
{
APPLICATION,
BOOTLOADER,
ERROR,
UNKNOWN;
public static Mode getMode( String config )
{
Mode retVal = UNKNOWN;
if( config == null )
{
retVal = ERROR;
}
else
{
if( config.length() >= 8 )
{
String mode = config.substring( 2, 8 ).trim();
if( mode.equalsIgnoreCase( "FCDAPP" ) )
{
retVal = APPLICATION;
}
else if( mode.equalsIgnoreCase( "FCDBL" ) )
{
retVal = BOOTLOADER;
}
}
}
return retVal;
}
}
}

View File

@@ -0,0 +1,48 @@
/*******************************************************************************
* 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;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import source.tuner.rtl.RTL2832TunerController.Descriptor;
import net.miginfocom.swing.MigLayout;
public class FCDTunerDetailsPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private JLabel mAddress;
private JLabel mCellBlock;
private JLabel mFirmware;
public FCDTunerDetailsPanel( FCDTunerController controller )
{
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) );
add( new JLabel( "USB Address:" ) );
add( new JLabel( controller.getAddress() ) );
add( new JLabel( "Cellular Band:" ) );
add( new JLabel( controller.getConfiguration().getBandBlocking()
.getLabel() ) );
add( new JLabel( "Firmware:" ) );
add( new JLabel( controller.getConfiguration().getFirmware() ) );
}
}

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() );
}
}
}

View File

@@ -0,0 +1,82 @@
/*******************************************************************************
* 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.proplusV2;
import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
public class FCD2TunerConfiguration extends TunerConfiguration
{
private boolean mGainLNA = true;
private boolean mGainMixer = true;
private double mFrequencyCorrection = -2.2d;
/**
* Default constructor for JAXB
*/
public FCD2TunerConfiguration()
{
this( "Default" );
}
public FCD2TunerConfiguration( String name )
{
super( name );
}
@Override
public TunerType getTunerType()
{
return TunerType.FUNCUBE_DONGLE_PRO_PLUS;
}
@XmlAttribute( name = "lna_gain" )
public boolean getGainLNA()
{
return mGainLNA;
}
public void setGainLNA( boolean gain )
{
mGainLNA = gain;
}
@XmlAttribute( name = "mixer_gain" )
public boolean getGainMixer()
{
return mGainMixer;
}
public void setGainMixer( boolean gain )
{
mGainMixer = gain;
}
@XmlAttribute( name = "frequency_correction" )
public double getFrequencyCorrection()
{
return mFrequencyCorrection;
}
public void setFrequencyCorrection( double value )
{
mFrequencyCorrection = value;
}
}

View File

@@ -0,0 +1,377 @@
/*******************************************************************************
* 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.proplusV2;
import java.awt.ComponentOrientation;
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.JCheckBox;
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 log.Log;
import net.miginfocom.swing.MigLayout;
import source.SourceException;
import source.tuner.TunerConfiguration;
import source.tuner.TunerConfigurationAssignment;
import source.tuner.TunerType;
import controller.ResourceManager;
public class FCD2TunerConfigurationPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private ResourceManager mResourceManager;
private FCD2TunerController mController;
private FCD2TunerConfiguration mSelectedConfig;
private JButton mNewConfiguration;
private JButton mDeleteConfiguration;
private JComboBox<FCD2TunerConfiguration> mComboConfigurations;
private JTextField mName;
private JCheckBox mLNAGain;
private JCheckBox mMixerGain;
private JSpinner mFrequencyCorrection;
public FCD2TunerConfigurationPanel( ResourceManager resourceManager,
FCD2TunerController controller )
{
mResourceManager = resourceManager;
mController = controller;
init();
}
private void init()
{
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][][grow]" ) );
mComboConfigurations = new JComboBox<FCD2TunerConfiguration>();
mComboConfigurations.setModel( getModel() );
mComboConfigurations.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
FCD2TunerConfiguration selected =
(FCD2TunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
update( selected );
}
}
});
add( new JLabel( "Config:" ) );
add( mComboConfigurations, "growx,push" );
mName = new JTextField();
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.addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
try
{
mController.setFrequencyCorrection( value );
mSelectedConfig.setFrequencyCorrection( value );
save();
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
FCD2TunerConfigurationPanel.this,
"FCD Pro Plus Tuner Controller - couldn't "
+ "apply frequency correction value: " + value +
e1.getLocalizedMessage() );
Log.error( "FuncubeDongleProPlus Controller - couldn't apply "
+ "frequency correction value: " + value +
e1.getLocalizedMessage() );
}
}
} );
add( new JLabel( "Correction PPM:" ) );
add( mFrequencyCorrection, "growx,push" );
/**
* LNA Gain
*/
mLNAGain = new JCheckBox( "LNA Gain:" );
mLNAGain.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT );
mLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
mSelectedConfig.setGainLNA( mLNAGain.isSelected() );
save();
update( mSelectedConfig );
}
} );
add( mLNAGain );
/**
* Mixer Gain
*/
mMixerGain = new JCheckBox( "Mixer Gain:" );
mMixerGain.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT );
mMixerGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
mSelectedConfig.setGainMixer( mMixerGain.isSelected() );
save();
update( mSelectedConfig );
}
} );
add( mMixerGain );
/**
* Lookup the save config and apply that config to update all of the
* controls
*/
TunerConfigurationAssignment savedConfig = mResourceManager
.getSettingsManager().getSelectedTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
mController.getAddress() );
if( savedConfig != null )
{
mSelectedConfig = getNamedConfiguration(
savedConfig.getTunerConfigurationName() );
}
if( mSelectedConfig == null )
{
mSelectedConfig = mComboConfigurations.getItemAt( 0 );
//Store this config as the default for this tuner at this address
mResourceManager.getSettingsManager()
.setSelectedTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
mController.getAddress(), mSelectedConfig );
}
mComboConfigurations.setSelectedItem( mSelectedConfig );
/**
* Create a new configuration
*/
mNewConfiguration = new JButton( "New" );
mNewConfiguration.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
TunerConfiguration config =
mResourceManager.getSettingsManager()
.addNewTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
"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 )
{
FCD2TunerConfiguration selected =
(FCD2TunerConfiguration)mComboConfigurations
.getItemAt( mComboConfigurations.getSelectedIndex() );
if( selected != null )
{
int n = JOptionPane.showConfirmDialog(
FCD2TunerConfigurationPanel.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( FCD2TunerConfiguration config )
{
mSelectedConfig = config;
try
{
mController.apply( config );
mName.setText( config.getName() );
mLNAGain.setSelected( config.getGainLNA() );
mMixerGain.setSelected( config.getGainMixer() );
mFrequencyCorrection.setValue( config.getFrequencyCorrection() );
mResourceManager.getSettingsManager().setSelectedTunerConfiguration(
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
mController.getAddress(), config );
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
FCD2TunerConfigurationPanel.this,
"FCD Pro Plus Tuner Controller - couldn't "
+ "apply the tuner configuration settings - " +
e1.getLocalizedMessage() );
Log.error( "FuncubeDongleProPlus Controller - couldn't apply "
+ "config [" + config.getName() + "] - " +
e1.getLocalizedMessage() );
}
}
private ComboBoxModel<FCD2TunerConfiguration> getModel()
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.FUNCUBE_DONGLE_PRO_PLUS );
DefaultComboBoxModel<FCD2TunerConfiguration> model =
new DefaultComboBoxModel<FCD2TunerConfiguration>();
for( TunerConfiguration config: configs )
{
model.addElement( (FCD2TunerConfiguration)config );
}
return model;
}
private FCD2TunerConfiguration getNamedConfiguration( String name )
{
ArrayList<TunerConfiguration> configs =
mResourceManager.getSettingsManager()
.getTunerConfigurations( TunerType.FUNCUBE_DONGLE_PRO_PLUS );
for( TunerConfiguration config: configs )
{
if( config.getName().contentEquals( name ) )
{
return (FCD2TunerConfiguration)config;
}
}
return null;
}
private void save()
{
mResourceManager.getSettingsManager().save();
}
}

View File

@@ -0,0 +1,367 @@
/*******************************************************************************
* 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.proplusV2;
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 FCD2TunerController extends FCDTunerController
{
public static final int sMINIMUM_TUNABLE_FREQUENCY = 150000;
public static final int sMAXIMUM_TUNABLE_FREQUENCY = 2050000000;
public static final int sSAMPLE_RATE = 192000;
private FCD2TunerConfiguration mTunerConfiguration;
private FCD2TunerEditorPanel mEditor;
public FCD2TunerController( USBTunerDevice device )
throws SourceException
{
super( device,
sMINIMUM_TUNABLE_FREQUENCY,
sMAXIMUM_TUNABLE_FREQUENCY );
mFrequencyController.setBandwidth( sSAMPLE_RATE );
try
{
open();
setFCDMode( Mode.APPLICATION );
}
catch( Exception e )
{
throw new SourceException( "FCDTunerController error " +
"during construction", e );
}
}
public int getCurrentSampleRate()
{
return sSAMPLE_RATE;
}
@Override
public TunerClass getTunerClass()
{
return TunerClass.FUNCUBE_DONGLE_PRO_PLUS;
}
@Override
public TunerType getTunerType()
{
return TunerType.FUNCUBE_DONGLE_PRO_PLUS;
}
public JPanel getEditor( FCDTuner tuner, ResourceManager resourceManager )
{
if( mEditor == null )
{
mEditor = new FCD2TunerEditorPanel( tuner, resourceManager );
}
return mEditor;
}
@Override
public void apply( TunerConfiguration config ) throws SourceException
{
if( config instanceof FCD2TunerConfiguration )
{
FCD2TunerConfiguration plusConfig =
(FCD2TunerConfiguration)config;
setFrequencyCorrection( plusConfig.getFrequencyCorrection() );
try
{
if( plusConfig.getGainLNA() )
{
send( FCDCommand.APP_SET_LNA_GAIN, 1 );
}
else
{
send( FCDCommand.APP_SET_LNA_GAIN, 0 );
}
}
catch ( UsbClaimException e )
{
throw new SourceException( "Exception while setting LNA Gain", e );
}
catch ( UsbException e )
{
throw new SourceException( "Exception while setting LNA Gain", e );
}
try
{
if( plusConfig.getGainMixer() )
{
send( FCDCommand.APP_SET_MIXER_GAIN, 1 );
}
else
{
send( FCDCommand.APP_SET_MIXER_GAIN, 0 );
}
}
catch ( UsbClaimException e )
{
throw new SourceException( "Exception while setting mixer gain", e );
}
catch ( UsbException e )
{
throw new SourceException( "Exception while setting mixer gain", e );
}
mTunerConfiguration = plusConfig;
}
}
@Override
public TunerConfiguration getTunerConfiguration()
{
return mTunerConfiguration;
}
public int getDCCorrection()
{
int dcCorrection = -999;
try
{
dcCorrection = (int)send( FCDCommand.APP_GET_DC_CORRECTION );
}
catch ( UsbClaimException e )
{
Log.error( "FCTTunerController - couldn't claim funcube HID to"
+ " get dc correction value" );
}
catch ( UsbException e )
{
Log.error( "FCTTunerController - error getting dc correction "
+ "value - " + e.getLocalizedMessage() );
}
return dcCorrection;
}
public void setDCCorrection( int value )
{
try
{
send( FCDCommand.APP_SET_DC_CORRECTION, value );
}
catch ( UsbClaimException e )
{
Log.error( "FCDTunerController - error claiming usb hid while "
+ "trying to set dc correction to [" + value + "]" );
}
catch ( UsbException e )
{
Log.error( "FCDTunerController - error while "
+ "trying to set dc correction to [" + value + "] - " +
e.getLocalizedMessage() );
}
}
public int getIQCorrection()
{
int iqCorrection = -999;
try
{
iqCorrection = (int)send( FCDCommand.APP_GET_IQ_CORRECTION );
}
catch ( UsbClaimException e )
{
Log.error( "FCTTunerController - couldn't claim funcube HID to"
+ " get iq correction value" );
}
catch ( UsbException e )
{
Log.error( "FCTTunerController - error getting iq correction "
+ "value - " + e.getLocalizedMessage() );
}
return iqCorrection;
}
public void setIQCorrection( int value )
{
try
{
send( FCDCommand.APP_SET_IQ_CORRECTION, value );
}
catch ( UsbClaimException e )
{
Log.error( "FCDTunerController - error claiming usb hid while "
+ "trying to set iq correction to [" + value + "]" );
}
catch ( UsbException e )
{
Log.error( "FCDTunerController - error while "
+ "trying to set iq correction to [" + value + "] - " +
e.getLocalizedMessage() );
}
}
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;
}
}
public enum TunerRFFilter
{
TRF_0_4,
TRF_4_8,
TRF_8_16,
TRF_16_32,
TRF_32_75,
TRF_75_125,
TRF_125_250,
TRF_145,
TRF_410_875,
TRF_435,
TRF_875_2000,
UNKNOWN;
public static TunerRFFilter get( int value )
{
TunerRFFilter retVal = UNKNOWN;
if( 0 <= value && value <= 10 )
{
retVal = values()[ value ];
}
return retVal;
}
}
public enum TunerIFFilter
{
TIF_200KHZ,
TIF_300KHZ,
TIF_600KHZ,
TIF_1536KHZ,
TIF_5MHZ,
TIF_6MHZ,
TIF_7MHZ,
TIF_8MHZ,
UNKNOWN;
public static TunerIFFilter get( int value )
{
TunerIFFilter retVal = UNKNOWN;
if( 0 <= value && value <= 7 )
{
retVal = values()[ value ];
}
return retVal;
}
}
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 int getSetting()
{
return mSetting;
}
public String getLabel()
{
return mLabel;
}
public String toString()
{
return getLabel();
}
}
}

View File

@@ -0,0 +1,101 @@
/*******************************************************************************
* 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.proplusV2;
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 FCD2TunerEditorPanel extends JPanel implements FrequencyChangeListener
{
private static final long serialVersionUID = 1L;
private FCDTuner mTuner;
private FCD2TunerController mController;
private ResourceManager mResourceManager;
private JFrequencyControl mFrequencyControl;
public FCD2TunerEditorPanel( FCDTuner tuner, ResourceManager resourceManager )
{
mTuner = tuner;
mController = (FCD2TunerController)mTuner.getController();
mResourceManager = resourceManager;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2", "[right,grow][grow]", "[][][grow]" ) );
add( new JLabel( "Funcube Dongle Pro Plus Tuner" ), "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 );
tabs.add( "Configuration", new FCD2TunerConfigurationPanel(
mResourceManager, mController ) );
tabs.add( "Info", new FCDTunerDetailsPanel( mController ) );
add( tabs, "span,grow,push" );
}
@Override
public void frequencyChanged( int frequency, int bandwidth )
{
//Disregard the bandwidth, which shouldn't be changing
try
{
mController.setFrequency( frequency );
}
catch ( SourceException e )
{
Log.error( "FCTProController - error setting frequency [" +
frequency + "] - " + e.getLocalizedMessage() );
}
}
}