mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
HackRF - final check-in. Changed all tuners to use the low-level API of the usb4java library to resolve limitation in high-level API that constrains maximum sample rate to ~2.0 MHz. Added console logging to logback.
This commit is contained in:
@@ -50,6 +50,13 @@ public class FCDTuner extends MixerTuner
|
||||
mController.addListener( (FrequencyChangeListener)this );
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
//TODO: release the mixer tuner data line as well
|
||||
|
||||
mController.dispose();
|
||||
}
|
||||
|
||||
public FCDTunerController getController()
|
||||
{
|
||||
return mController;
|
||||
@@ -70,7 +77,7 @@ public class FCDTuner extends MixerTuner
|
||||
@Override
|
||||
public String getUniqueID()
|
||||
{
|
||||
return mController.getAddress();
|
||||
return mController.getUSBAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,18 +17,21 @@
|
||||
******************************************************************************/
|
||||
package source.tuner.fcd;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.usb4java.Device;
|
||||
import org.usb4java.DeviceDescriptor;
|
||||
import org.usb4java.DeviceHandle;
|
||||
import org.usb4java.LibUsb;
|
||||
import org.usb4java.LibUsbException;
|
||||
|
||||
import source.SourceException;
|
||||
import source.tuner.TunerClass;
|
||||
@@ -36,7 +39,6 @@ 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
|
||||
@@ -44,57 +46,105 @@ public abstract class FCDTunerController extends TunerController
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( FCDTunerController.class );
|
||||
|
||||
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 FCD_INTERFACE = (byte)0x2;
|
||||
public final static byte FCD_ENDPOINT_IN = (byte)0x82;
|
||||
public final static byte FCD_ENDPOINT_OUT = (byte)0x2;
|
||||
|
||||
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;
|
||||
private Device mDevice;
|
||||
private DeviceDescriptor mDeviceDescriptor;
|
||||
private DeviceHandle mDeviceHandle;
|
||||
|
||||
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();
|
||||
|
||||
public FCDTunerController( USBTunerDevice device,
|
||||
|
||||
/**
|
||||
* Generic FCD tuner controller - contains functionality common across both
|
||||
* funcube dongle tuners
|
||||
*
|
||||
* @param device
|
||||
* @param descriptor
|
||||
* @param minTunableFrequency
|
||||
* @param maxTunableFrequency
|
||||
*/
|
||||
public FCDTunerController( Device device,
|
||||
DeviceDescriptor descriptor,
|
||||
int minTunableFrequency,
|
||||
int maxTunableFrequency ) throws SourceException
|
||||
int maxTunableFrequency )
|
||||
{
|
||||
super( minTunableFrequency, maxTunableFrequency );
|
||||
|
||||
mFuncube = device.getDevice();
|
||||
mUsbConfiguration = mFuncube.getActiveUsbConfiguration();
|
||||
mFuncubeHID = mUsbConfiguration.getUsbInterface( sFCD_INTERFACE );
|
||||
mDevice = device;
|
||||
mDeviceDescriptor = descriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the controller by opening the USB device and claiming the
|
||||
* HID interface.
|
||||
*
|
||||
* Invoke this method after constructing this class to setup the
|
||||
* controller.
|
||||
*
|
||||
* @throws SourceException if cannot open and claim the USB device
|
||||
*/
|
||||
public void init() throws SourceException
|
||||
{
|
||||
mDeviceHandle = new DeviceHandle();
|
||||
|
||||
int result = LibUsb.open( mDevice, mDeviceHandle );
|
||||
|
||||
if( result != LibUsb.SUCCESS )
|
||||
{
|
||||
mDeviceHandle = null;
|
||||
|
||||
throw new SourceException( "libusb couldn't open funcube usb "
|
||||
+ "device [" + LibUsb.errorName( result ) + "]" );
|
||||
}
|
||||
|
||||
claimInterface();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of resources. Closes the USB device and interface.
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if( mDeviceHandle != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
LibUsb.close( mDeviceHandle );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "error while closing device handle", e );
|
||||
}
|
||||
|
||||
mDeviceHandle = null;
|
||||
}
|
||||
|
||||
mDeviceDescriptor = null;
|
||||
mDevice = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample rate of the tuner
|
||||
*/
|
||||
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
|
||||
* 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
|
||||
* Tuner type
|
||||
*/
|
||||
public abstract TunerType getTunerType();
|
||||
|
||||
/**
|
||||
* FCD editor panel
|
||||
* Editor panel (GUI) component.
|
||||
*/
|
||||
public abstract JPanel getEditor( FCDTuner tuner,
|
||||
ResourceManager resourceManager );
|
||||
ResourceManager resourceManager );
|
||||
|
||||
/**
|
||||
* Applies the settings in the tuner configuration
|
||||
@@ -103,17 +153,81 @@ public abstract class FCDTunerController extends TunerController
|
||||
throws SourceException;
|
||||
|
||||
/**
|
||||
* Returns the applied tuner configuration or null if one hasn't yet been
|
||||
* applied
|
||||
* Returns the currently applied tuner configuration or null if one hasn't
|
||||
* yet been applied
|
||||
*/
|
||||
public abstract TunerConfiguration getTunerConfiguration();
|
||||
|
||||
/**
|
||||
* USB address
|
||||
* USB address (bus/port)
|
||||
*/
|
||||
public String getAddress()
|
||||
public String getUSBAddress()
|
||||
{
|
||||
return mFuncube.toString();
|
||||
if( mDevice != null )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( "Bus:" );
|
||||
int bus = LibUsb.getBusNumber( mDevice );
|
||||
sb.append( bus );
|
||||
|
||||
sb.append( " Port:" );
|
||||
int port = LibUsb.getPortNumber( mDevice );
|
||||
sb.append( port );
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
* USB Vendor and Product ID
|
||||
*/
|
||||
public String getUSBID()
|
||||
{
|
||||
if( mDeviceDescriptor != null )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( String.format( "%04X",
|
||||
(int)( mDeviceDescriptor.idVendor() & 0xFFFF ) ) );
|
||||
|
||||
sb.append( ":" );
|
||||
|
||||
sb.append( String.format( "%04X",
|
||||
(int)( mDeviceDescriptor.idProduct() & 0xFFFF ) ) );
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
* USB Port Speed. Should be 2.0 for both types of funcube dongles
|
||||
*/
|
||||
public String getUSBSpeed()
|
||||
{
|
||||
if( mDevice != null )
|
||||
{
|
||||
int speed = LibUsb.getDeviceSpeed( mDevice );
|
||||
|
||||
switch( speed )
|
||||
{
|
||||
case 0:
|
||||
return "1.1 LOW";
|
||||
case 1:
|
||||
return "1.1 FULL";
|
||||
case 2:
|
||||
return "2.0 HIGH";
|
||||
case 3:
|
||||
return "3.0 SUPER";
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,20 +235,17 @@ public abstract class FCDTunerController extends TunerController
|
||||
*/
|
||||
public void setFCDMode( Mode mode ) throws UsbException, UsbClaimException
|
||||
{
|
||||
byte[] response = null;
|
||||
ByteBuffer response = null;
|
||||
|
||||
switch( mode )
|
||||
{
|
||||
case APPLICATION:
|
||||
response = send( FCDCommand.BL_QUERY.getRequestTemplate(),
|
||||
FCDCommand.BL_QUERY.getResponseTemplate() );
|
||||
response = send( FCDCommand.BL_QUERY );
|
||||
break;
|
||||
case BOOTLOADER:
|
||||
response = send( FCDCommand.APP_RESET.getRequestTemplate(),
|
||||
FCDCommand.APP_RESET.getResponseTemplate() );
|
||||
response = send( FCDCommand.APP_RESET );
|
||||
break;
|
||||
case ERROR:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -171,7 +282,11 @@ public abstract class FCDTunerController extends TunerController
|
||||
{
|
||||
try
|
||||
{
|
||||
return send( FCDCommand.APP_GET_FREQUENCY_HZ );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_FREQUENCY_HZ );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
return (int)( buffer.getInt( 2 ) & 0xFFFFFFFF );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
@@ -189,185 +304,206 @@ public abstract class FCDTunerController extends TunerController
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Claims the USB interface. Attempts to detach the active kernel driver if
|
||||
* one is currently attached.
|
||||
*/
|
||||
private boolean claim() throws UsbException, UsbClaimException
|
||||
private void claimInterface() throws SourceException
|
||||
{
|
||||
boolean claimed = false;
|
||||
|
||||
if( !mFuncubeHID.isClaimed() )
|
||||
if( mDeviceHandle != null )
|
||||
{
|
||||
mFuncubeHID.claim( new UsbInterfacePolicy()
|
||||
{
|
||||
@Override
|
||||
public boolean forceClaim( UsbInterface arg0 )
|
||||
{
|
||||
return sFCD_FORCE_CLAIM_HID_INTERFACE;
|
||||
}
|
||||
} );
|
||||
int result = LibUsb.kernelDriverActive( mDeviceHandle, FCD_INTERFACE );
|
||||
|
||||
claimed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.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 )
|
||||
{
|
||||
mLog.error( "Exception thrown while releasing the funcube HID "
|
||||
+ "interface", e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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++ )
|
||||
if( result == 1 )
|
||||
{
|
||||
//Little endian
|
||||
request[ x ] = (byte)( 0xFF &
|
||||
Long.rotateRight( commandArgument, ( x - 1 ) * 8 ) );
|
||||
result = LibUsb.detachKernelDriver( mDeviceHandle,
|
||||
FCD_INTERFACE );
|
||||
|
||||
if( result != LibUsb.SUCCESS )
|
||||
{
|
||||
mLog.error( "failed attempt to detach kernel driver [" +
|
||||
LibUsb.errorName( result ) + "]" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
result = LibUsb.claimInterface( mDeviceHandle, FCD_INTERFACE );
|
||||
|
||||
if( result != LibUsb.SUCCESS )
|
||||
{
|
||||
mPipeOut = endpointOut.getUsbPipe();
|
||||
mPipeOut.open();
|
||||
|
||||
mPipeIn = endpointIn.getUsbPipe();
|
||||
mPipeIn.open();
|
||||
|
||||
setFCDMode( Mode.APPLICATION );
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.error( "FCD Pro Tuner Controller - couldn't gain access " +
|
||||
"to the USB in/out endpoints or pipes." );
|
||||
throw new SourceException( "couldn't claim usb interface [" +
|
||||
LibUsb.errorName( result ) + "]" );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.error( "FCD Pro Tuner Controller - couldn't claim the USB " +
|
||||
"interface. Check to see if another program is using it." );
|
||||
throw new SourceException( "couldn't claim usb hid interface - no "
|
||||
+ "device handle" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an interrupt write to the OUT endpoint.
|
||||
* @param buffer - direct allocated buffer. Must be 64 bytes in length.
|
||||
*
|
||||
* @throws LibUsbException on error
|
||||
*/
|
||||
private void write( ByteBuffer buffer ) throws LibUsbException
|
||||
{
|
||||
if( mDeviceHandle != null )
|
||||
{
|
||||
IntBuffer transferred = IntBuffer.allocate( 1 );
|
||||
|
||||
int result = LibUsb.interruptTransfer( mDeviceHandle,
|
||||
FCD_ENDPOINT_OUT,
|
||||
buffer,
|
||||
transferred,
|
||||
500l );
|
||||
|
||||
if( result != LibUsb.SUCCESS )
|
||||
{
|
||||
throw new LibUsbException( "error writing byte buffer",
|
||||
result );
|
||||
}
|
||||
else if( transferred.get() != buffer.capacity() )
|
||||
{
|
||||
throw new LibUsbException( "transferred bytes [" +
|
||||
transferred.get( 0 ) + "] is not what was expected [" +
|
||||
buffer.capacity() + "]", result );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LibUsbException( "device handle is null",
|
||||
LibUsb.ERROR_NO_DEVICE );
|
||||
}
|
||||
}
|
||||
|
||||
protected void close()
|
||||
/**
|
||||
* Performs an interrupt write to the OUT endpoint for the FCD command.
|
||||
* @param command - no-argument command to write
|
||||
* @throws LibUsbException - on error
|
||||
*/
|
||||
private void write( FCDCommand command ) throws LibUsbException
|
||||
{
|
||||
release();
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect( 64 );
|
||||
|
||||
buffer.put( 0, command.getCommand() );
|
||||
buffer.put( 1, (byte)0x00 );
|
||||
|
||||
write( buffer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience logger for debugging read/write operations
|
||||
*/
|
||||
@SuppressWarnings( "unused" )
|
||||
private void log( String label, ByteBuffer buffer )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( label );
|
||||
|
||||
sb.append( " " );
|
||||
|
||||
sb.append( buffer.get( 0 ) );
|
||||
sb.append( " | " );
|
||||
|
||||
for( int x = 0; x < 64; x++ )
|
||||
{
|
||||
sb.append( String.format( "%02X", (int)( buffer.get( x ) & 0xFF ) ) );
|
||||
sb.append( " " );
|
||||
}
|
||||
|
||||
mLog.debug( sb.toString() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an interrupt write to the OUT endpoint for the FCD command.
|
||||
* @param command - command to write
|
||||
* @param argument - value to write with the command
|
||||
* @throws LibUsbException - on error
|
||||
*/
|
||||
private void write( FCDCommand command, long argument ) throws LibUsbException
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect( 64 );
|
||||
|
||||
/* The FCD expects little-endian formatted values */
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
buffer.put( 0, command.getCommand() );
|
||||
buffer.putLong( 1, argument );
|
||||
|
||||
write( buffer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an interrupt read against the endpoint
|
||||
* @return buffer read from FCD
|
||||
* @throws LibUsbException on error
|
||||
*/
|
||||
private ByteBuffer read() throws LibUsbException
|
||||
{
|
||||
if( mDeviceHandle != null )
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect( 64 );
|
||||
|
||||
IntBuffer transferred = IntBuffer.allocate( 1 );
|
||||
|
||||
|
||||
int result = LibUsb.interruptTransfer( mDeviceHandle,
|
||||
FCD_ENDPOINT_IN,
|
||||
buffer,
|
||||
transferred,
|
||||
500l );
|
||||
|
||||
if( result != LibUsb.SUCCESS )
|
||||
{
|
||||
throw new LibUsbException( "error reading byte buffer",
|
||||
result );
|
||||
}
|
||||
else if( transferred.get( 0 ) != buffer.capacity() )
|
||||
{
|
||||
throw new LibUsbException( "received bytes [" +
|
||||
transferred.get( 0 ) + "] didn't match expected "
|
||||
+ "length [" + buffer.capacity() + "]", result );
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
throw new LibUsbException( "device handle is null",
|
||||
LibUsb.ERROR_NO_DEVICE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the FCD command and argument. Performs a read to complete the
|
||||
* command.
|
||||
*
|
||||
* @param command - command to send
|
||||
* @param argument - command argument to send
|
||||
* @throws LibUsbException - on error
|
||||
*/
|
||||
protected void send( FCDCommand command, long argument ) throws LibUsbException
|
||||
{
|
||||
write( command, argument );
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the no-argument FCD command. Performs a read to complete the
|
||||
* command.
|
||||
*
|
||||
* @param command - command to send
|
||||
* @throws LibUsbException - on error
|
||||
*/
|
||||
protected ByteBuffer send( FCDCommand command ) throws LibUsbException
|
||||
{
|
||||
write( command );
|
||||
return read();
|
||||
}
|
||||
|
||||
/**
|
||||
* FCD configuration string parsing class
|
||||
*/
|
||||
public class FCDConfiguration
|
||||
{
|
||||
private String mConfig;
|
||||
@@ -385,11 +521,20 @@ public abstract class FCDTunerController extends TunerController
|
||||
mMode = Mode.UNKNOWN;
|
||||
}
|
||||
|
||||
public void set( byte[] data )
|
||||
/**
|
||||
* Extracts the configuration string from the buffer
|
||||
*/
|
||||
public void set( ByteBuffer buffer )
|
||||
{
|
||||
if( FCDCommand.checkResponse( FCDCommand.BL_QUERY, data ) ||
|
||||
FCDCommand.checkResponse( FCDCommand.APP_RESET, data ) )
|
||||
if( buffer.capacity() == 64 )
|
||||
{
|
||||
byte[] data = new byte[ 64 ];
|
||||
|
||||
for( int x = 0; x < 64; x++ )
|
||||
{
|
||||
data[ x ] = buffer.get( x );
|
||||
}
|
||||
|
||||
mConfig = new String( data );
|
||||
mMode = Mode.getMode( mConfig );
|
||||
}
|
||||
|
||||
@@ -17,26 +17,27 @@
|
||||
******************************************************************************/
|
||||
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]" ) );
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][][grow]" ) );
|
||||
|
||||
add( new JLabel( "USB ID:" ) );
|
||||
add( new JLabel( controller.getUSBID() ) );
|
||||
|
||||
add( new JLabel( "USB Address:" ) );
|
||||
add( new JLabel( controller.getAddress() ) );
|
||||
add( new JLabel( controller.getUSBAddress() ) );
|
||||
|
||||
add( new JLabel( "USB Speed:" ) );
|
||||
add( new JLabel( controller.getUSBSpeed() ) );
|
||||
|
||||
add( new JLabel( "Cellular Band:" ) );
|
||||
add( new JLabel( controller.getConfiguration().getBandBlocking()
|
||||
|
||||
@@ -511,7 +511,7 @@ public class FCD1TunerConfigurationPanel extends JPanel
|
||||
mResourceManager.getSettingsManager()
|
||||
.setSelectedTunerConfiguration(
|
||||
TunerType.FUNCUBE_DONGLE_PRO,
|
||||
mController.getAddress(), config );
|
||||
mController.getUSBAddress(), config );
|
||||
}
|
||||
catch ( SourceException e1 )
|
||||
{
|
||||
|
||||
@@ -17,12 +17,17 @@
|
||||
******************************************************************************/
|
||||
package source.tuner.fcd.proV1;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.usb.UsbClaimException;
|
||||
import javax.usb.UsbException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.usb4java.Device;
|
||||
import org.usb4java.DeviceDescriptor;
|
||||
|
||||
import source.SourceException;
|
||||
import source.tuner.TunerClass;
|
||||
@@ -31,7 +36,6 @@ 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
|
||||
@@ -53,19 +57,22 @@ public class FCD1TunerController extends FCDTunerController
|
||||
private FCD1TunerConfiguration mTunerConfiguration;
|
||||
private FCD1TunerEditorPanel mEditor;
|
||||
|
||||
public FCD1TunerController( USBTunerDevice device )
|
||||
throws SourceException
|
||||
public FCD1TunerController( Device device, DeviceDescriptor descriptor )
|
||||
{
|
||||
super( device,
|
||||
super( device,
|
||||
descriptor,
|
||||
sMINIMUM_TUNABLE_FREQUENCY,
|
||||
sMAXIMUM_TUNABLE_FREQUENCY );
|
||||
}
|
||||
|
||||
public void init() throws SourceException
|
||||
{
|
||||
super.init();
|
||||
|
||||
mFrequencyController.setSampleRate( sSAMPLE_RATE );
|
||||
|
||||
try
|
||||
{
|
||||
open();
|
||||
|
||||
setFCDMode( Mode.APPLICATION );
|
||||
getPhaseAndGainCorrection();
|
||||
getDCIQCorrection();
|
||||
@@ -73,7 +80,7 @@ public class FCD1TunerController extends FCDTunerController
|
||||
getLNAEnhanceSetting();
|
||||
getMixerGainSetting();
|
||||
|
||||
send( FCDCommand.APP_SET_MIXER_GAIN, 1 );
|
||||
send( FCDCommand.APP_SET_MIXER_GAIN, 1l );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
@@ -156,10 +163,12 @@ public class FCD1TunerController extends FCDTunerController
|
||||
*/
|
||||
private void getLNAGainSetting() throws UsbClaimException, UsbException
|
||||
{
|
||||
int gain = (int)send( FCDCommand.APP_GET_LNA_GAIN );
|
||||
|
||||
mLog.info( "FCD1: lna gain setting is:" + gain );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_LNA_GAIN );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
int gain = buffer.getInt( 2 );
|
||||
|
||||
mLNAGain = LNAGain.valueOf( gain );
|
||||
}
|
||||
|
||||
@@ -286,7 +295,11 @@ public class FCD1TunerController extends FCDTunerController
|
||||
private void getPhaseAndGainCorrection() throws UsbClaimException,
|
||||
UsbException
|
||||
{
|
||||
long correction = send( FCDCommand.APP_GET_IQ_CORRECTION );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_IQ_CORRECTION );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
int correction = buffer.getInt( 2 );
|
||||
|
||||
/**
|
||||
* Gain: mask the upper 16 phase bits and right shift to get the
|
||||
@@ -305,8 +318,6 @@ public class FCD1TunerController extends FCDTunerController
|
||||
short phase = (short)( correction & 0x0000FFFF );
|
||||
|
||||
mPhaseCorrection = ( (double)phase / (double)Short.MAX_VALUE );
|
||||
|
||||
mLog.info( "FCD1: correction:" + correction + " gain:" + gain + " phase:" + phase );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +424,11 @@ public class FCD1TunerController extends FCDTunerController
|
||||
private void getDCIQCorrection() throws UsbClaimException,
|
||||
UsbException
|
||||
{
|
||||
long correction = send( FCDCommand.APP_GET_DC_CORRECTION );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_DC_CORRECTION );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
int correction = buffer.getInt( 2 );
|
||||
|
||||
/**
|
||||
* Quadrature: mask the upper 16 bits and divide by 32768 to get the
|
||||
@@ -443,9 +458,11 @@ public class FCD1TunerController extends FCDTunerController
|
||||
|
||||
private void getLNAEnhanceSetting() throws UsbClaimException, UsbException
|
||||
{
|
||||
int enhance = (int)send( FCDCommand.APP_GET_LNA_ENHANCE );
|
||||
|
||||
mLog.info( "FCD1: lna enhance setting is: " + enhance );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_LNA_ENHANCE );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
int enhance = buffer.getInt( 2 );
|
||||
|
||||
mLNAEnhance = LNAEnhance.valueOf( enhance );
|
||||
}
|
||||
@@ -463,9 +480,11 @@ public class FCD1TunerController extends FCDTunerController
|
||||
|
||||
private void getMixerGainSetting() throws UsbClaimException, UsbException
|
||||
{
|
||||
int gain = (int)send( FCDCommand.APP_GET_MIXER_GAIN );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_MIXER_GAIN );
|
||||
|
||||
mLog.info( "FCD1: mixer gain setting is:" + gain );
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
int gain = buffer.getInt( 2 );
|
||||
|
||||
mMixerGain = MixerGain.valueOf( gain );
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class FCD2TunerConfigurationPanel extends JPanel
|
||||
TunerConfigurationAssignment savedConfig = mResourceManager
|
||||
.getSettingsManager().getSelectedTunerConfiguration(
|
||||
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
|
||||
mController.getAddress() );
|
||||
mController.getUSBAddress() );
|
||||
|
||||
if( savedConfig != null )
|
||||
{
|
||||
@@ -237,7 +237,7 @@ public class FCD2TunerConfigurationPanel extends JPanel
|
||||
mResourceManager.getSettingsManager()
|
||||
.setSelectedTunerConfiguration(
|
||||
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
|
||||
mController.getAddress(), mSelectedConfig );
|
||||
mController.getUSBAddress(), mSelectedConfig );
|
||||
}
|
||||
|
||||
mComboConfigurations.setSelectedItem( mSelectedConfig );
|
||||
@@ -324,7 +324,7 @@ public class FCD2TunerConfigurationPanel extends JPanel
|
||||
|
||||
mResourceManager.getSettingsManager().setSelectedTunerConfiguration(
|
||||
TunerType.FUNCUBE_DONGLE_PRO_PLUS,
|
||||
mController.getAddress(), config );
|
||||
mController.getUSBAddress(), config );
|
||||
}
|
||||
catch ( SourceException e1 )
|
||||
{
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
******************************************************************************/
|
||||
package source.tuner.fcd.proplusV2;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.usb.UsbClaimException;
|
||||
import javax.usb.UsbException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.usb4java.Device;
|
||||
import org.usb4java.DeviceDescriptor;
|
||||
|
||||
import source.SourceException;
|
||||
import source.tuner.TunerClass;
|
||||
@@ -31,7 +34,6 @@ 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
|
||||
@@ -46,25 +48,27 @@ public class FCD2TunerController extends FCDTunerController
|
||||
private FCD2TunerConfiguration mTunerConfiguration;
|
||||
private FCD2TunerEditorPanel mEditor;
|
||||
|
||||
public FCD2TunerController( USBTunerDevice device )
|
||||
throws SourceException
|
||||
public FCD2TunerController( Device device, DeviceDescriptor descriptor )
|
||||
{
|
||||
super( device,
|
||||
descriptor,
|
||||
sMINIMUM_TUNABLE_FREQUENCY,
|
||||
sMAXIMUM_TUNABLE_FREQUENCY );
|
||||
}
|
||||
|
||||
public void init() throws SourceException
|
||||
{
|
||||
super.init();
|
||||
|
||||
mFrequencyController.setSampleRate( sSAMPLE_RATE );
|
||||
|
||||
try
|
||||
{
|
||||
open();
|
||||
|
||||
setFCDMode( Mode.APPLICATION );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new SourceException( "FCDTunerController error " +
|
||||
"during construction", e );
|
||||
throw new SourceException( "error setting Mode to APPLICATION", e );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +113,7 @@ public class FCD2TunerController extends FCDTunerController
|
||||
{
|
||||
if( plusConfig.getGainLNA() )
|
||||
{
|
||||
send( FCDCommand.APP_SET_LNA_GAIN, 1 );
|
||||
send( FCDCommand.APP_SET_LNA_GAIN, 1 );
|
||||
|
||||
}
|
||||
else
|
||||
@@ -117,34 +121,26 @@ public class FCD2TunerController extends FCDTunerController
|
||||
send( FCDCommand.APP_SET_LNA_GAIN, 0 );
|
||||
}
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new SourceException( "Exception while setting LNA Gain", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
throw new SourceException( "Exception while setting LNA Gain", e );
|
||||
throw new SourceException( "error while setting LNA Gain", e );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( plusConfig.getGainMixer() )
|
||||
{
|
||||
send( FCDCommand.APP_SET_MIXER_GAIN, 1 );
|
||||
|
||||
send( FCDCommand.APP_SET_MIXER_GAIN, 1 );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
send( FCDCommand.APP_SET_MIXER_GAIN, 0 );
|
||||
}
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new SourceException( "Exception while setting mixer gain", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
throw new SourceException( "Exception while setting mixer gain", e );
|
||||
throw new SourceException( "error while setting Mixer Gain", e );
|
||||
}
|
||||
|
||||
mTunerConfiguration = plusConfig;
|
||||
@@ -163,17 +159,15 @@ public class FCD2TunerController extends FCDTunerController
|
||||
|
||||
try
|
||||
{
|
||||
dcCorrection = (int)send( FCDCommand.APP_GET_DC_CORRECTION );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_DC_CORRECTION );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
return buffer.getInt( 2 );
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
mLog.error( "FCTTunerController - couldn't claim funcube HID to"
|
||||
+ " get dc correction value", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
mLog.error( "FCTTunerController - error getting dc correction "
|
||||
+ "value", e );
|
||||
mLog.error( "error getting dc correction value", e );
|
||||
}
|
||||
|
||||
return dcCorrection;
|
||||
@@ -183,17 +177,11 @@ public class FCD2TunerController extends FCDTunerController
|
||||
{
|
||||
try
|
||||
{
|
||||
send( FCDCommand.APP_SET_DC_CORRECTION, value );
|
||||
send( FCDCommand.APP_SET_DC_CORRECTION, value );
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
mLog.error( "FCDTunerController - error claiming usb hid while "
|
||||
+ "trying to set dc correction to [" + value + "]", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
mLog.error( "FCDTunerController - error while "
|
||||
+ "trying to set dc correction to [" + value + "]", e );
|
||||
mLog.error( "error setting dc correction to [" + value + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,20 +191,17 @@ public class FCD2TunerController extends FCDTunerController
|
||||
|
||||
try
|
||||
{
|
||||
iqCorrection = (int)send( FCDCommand.APP_GET_IQ_CORRECTION );
|
||||
ByteBuffer buffer = send( FCDCommand.APP_GET_IQ_CORRECTION );
|
||||
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
return buffer.getInt( 2 );
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
mLog.error( "FCTTunerController - couldn't claim funcube HID to"
|
||||
+ " get iq correction value", e );
|
||||
mLog.error( "error reading IQ correction value", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
mLog.error( "FCTTunerController - error getting iq correction "
|
||||
+ "value", e );
|
||||
|
||||
}
|
||||
|
||||
return iqCorrection;
|
||||
}
|
||||
|
||||
@@ -226,15 +211,9 @@ public class FCD2TunerController extends FCDTunerController
|
||||
{
|
||||
send( FCDCommand.APP_SET_IQ_CORRECTION, value );
|
||||
}
|
||||
catch ( UsbClaimException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
mLog.error( "FCDTunerController - error claiming usb hid while "
|
||||
+ "trying to set iq correction to [" + value + "]", e );
|
||||
}
|
||||
catch ( UsbException e )
|
||||
{
|
||||
mLog.error( "FCDTunerController - error while "
|
||||
+ "trying to set iq correction to [" + value + "]", e );
|
||||
mLog.error( "error setting IQ correction to [" + value + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,98 +251,4 @@ public class FCD2TunerController extends FCDTunerController
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user