[WIP] Adds locking mechanism to tuner controllers so that the

polyphase channel manager can block users from changing frequency and/or
sample rate when polyphase channels are allocated.
This commit is contained in:
Denny
2018-02-04 06:30:25 -05:00
parent 85691edacb
commit 96d9d6f750
14 changed files with 3271 additions and 3031 deletions

View File

@@ -147,6 +147,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
mChannelCalculator.getChannelSampleRate()); mChannelCalculator.getChannelSampleRate());
mChannelSources.add(channelSource); mChannelSources.add(channelSource);
mSourceEventBroadcaster.broadcast(SourceEvent.channelCountChange(getTunerChannelCount()));
} }
} }
catch(IllegalArgumentException iae) catch(IllegalArgumentException iae)
@@ -225,7 +226,6 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
synchronized(mBufferProcessor) synchronized(mBufferProcessor)
{ {
mPolyphaseChannelizer.addChannel(channelSource); mPolyphaseChannelizer.addChannel(channelSource);
mSourceEventBroadcaster.broadcast(SourceEvent.channelCountChange(getTunerChannelCount()));
if(mPolyphaseChannelizer.getRegisteredChannelCount() == 1) if(mPolyphaseChannelizer.getRegisteredChannelCount() == 1)
{ {

View File

@@ -20,7 +20,6 @@ package io.github.dsheirer.gui.control;
import io.github.dsheirer.source.ISourceEventProcessor; import io.github.dsheirer.source.ISourceEventProcessor;
import io.github.dsheirer.source.InvalidFrequencyException; import io.github.dsheirer.source.InvalidFrequencyException;
import io.github.dsheirer.source.SourceEvent; import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.SourceEvent.Event;
import io.github.dsheirer.source.SourceException; import io.github.dsheirer.source.SourceException;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -32,6 +31,7 @@ import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Font; import java.awt.Font;
import java.awt.Image; import java.awt.Image;
import java.awt.Point; import java.awt.Point;
@@ -146,9 +146,38 @@ public class JFrequencyControl extends JPanel implements ISourceEventProcessor
@Override @Override
public void process(SourceEvent event) public void process(SourceEvent event)
{ {
if(event.getEvent() == Event.NOTIFICATION_FREQUENCY_CHANGE) switch(event.getEvent())
{ {
setFrequency(event.getValue().longValue(), false); case NOTIFICATION_FREQUENCY_CHANGE:
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
setFrequency(event.getValue().longValue(), false);
}
});
break;
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED:
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
setEnabled(false);
}
});
break;
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED:
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
setEnabled(true);
}
});
break;
} }
} }

View File

@@ -27,6 +27,8 @@ public class SourceEvent
NOTIFICATION_CHANNEL_COUNT_CHANGE, NOTIFICATION_CHANNEL_COUNT_CHANGE,
NOTIFICATION_CHANNEL_FREQUENCY_CORRECTION_CHANGE, NOTIFICATION_CHANNEL_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_CHANNEL_SAMPLE_RATE_CHANGE, NOTIFICATION_CHANNEL_SAMPLE_RATE_CHANGE,
NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED,
NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED,
NOTIFICATION_FREQUENCY_CHANGE, NOTIFICATION_FREQUENCY_CHANGE,
NOTIFICATION_FREQUENCY_CORRECTION_CHANGE, NOTIFICATION_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_SAMPLE_RATE_CHANGE, NOTIFICATION_SAMPLE_RATE_CHANGE,
@@ -119,6 +121,22 @@ public class SourceEvent
return mSource != null; return mSource != null;
} }
/**
* Creates a new locked state change event
*/
public static SourceEvent lockedState()
{
return new SourceEvent(Event.NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED, 1);
}
/**
* Creates a new unlocked state change event
*/
public static SourceEvent unlockedState()
{
return new SourceEvent(Event.NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED, 0);
}
/** /**
* Creates a new frequency change event * Creates a new frequency change event
* *

View File

@@ -104,6 +104,37 @@ public abstract class TunerController implements Tunable, ISourceEventProcessor,
} }
} }
/**
* Indicates if the frequency and sample rate controls are locked by another process. User interface controls
* should monitor source events and check the locked state via this method to correctly render the enabled state
* of the frequency and sample rate controls.
*
* @return true if the tuner controller is locked.
*/
public boolean isLocked()
{
return mFrequencyController.isLocked();
}
/**
* Sets the frequency and sample rate locked state to the locked argument value. This should only be changed
* by a downstream consumer of samples to prevent users or other processes from modifying the center frequency
* and/or sample rate of the tuner while processing samples.
*
* @param locked true to indicate the tuner controller is in a locked state, otherwise false.
*/
public void setLocked(boolean locked)
{
try
{
mFrequencyController.setLocked(locked);
}
catch(SourceException se)
{
mLog.error("Couldn't set frequency controller locked state to: " + locked);
}
}
public int getBandwidth() public int getBandwidth()
{ {
return mFrequencyController.getBandwidth(); return mFrequencyController.getBandwidth();

View File

@@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
* sdr-trunk * sdr-trunk
* Copyright (C) 2014-2017 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * 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 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
@@ -44,306 +44,305 @@ import java.awt.event.ActionListener;
public class TunerEditor extends Editor<Tuner> public class TunerEditor extends Editor<Tuner>
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger( TunerEditor.class ); private final static Logger mLog = LoggerFactory.getLogger(TunerEditor.class);
private TunerConfigurationModel mTunerConfigurationModel; private TunerConfigurationModel mTunerConfigurationModel;
private JTable mTunerConfigurationTable; private JTable mTunerConfigurationTable;
private TableRowSorter<TunerConfigurationModel> mRowSorter; private TableRowSorter<TunerConfigurationModel> mRowSorter;
private JFrequencyControl mFrequencyControl = new JFrequencyControl(); private JFrequencyControl mFrequencyControl = new JFrequencyControl();
private JLabel mSelectedTunerType = new JLabel( "No Tuner Selected" ); private JLabel mSelectedTunerType = new JLabel("No Tuner Selected");
private JButton mNewConfigurationButton = new JButton( "New" ); private JButton mNewConfigurationButton = new JButton("New");
private JButton mDeleteConfigurationButton = new JButton( "Delete" ); private JButton mDeleteConfigurationButton = new JButton("Delete");
private JButton mAssignConfigurationButton = new JButton( "Assign" ); private JButton mAssignConfigurationButton = new JButton("Assign");
private JScrollPane mEditorScroller; private JScrollPane mEditorScroller;
private Editor<TunerConfiguration> mEditor = new EmptyEditor<>( "a tuner" ); private Editor<TunerConfiguration> mEditor = new EmptyEditor<>("a tuner");
private JideSplitPane mEditorSplitPane = new JideSplitPane(); private JideSplitPane mEditorSplitPane = new JideSplitPane();
public TunerEditor( TunerConfigurationModel tunerConfigurationModel ) public TunerEditor(TunerConfigurationModel tunerConfigurationModel)
{ {
mTunerConfigurationModel = tunerConfigurationModel; mTunerConfigurationModel = tunerConfigurationModel;
init(); init();
} }
public void init() public void init()
{ {
setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]" ) ); setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]"));
JPanel listPanel = new JPanel(); JPanel listPanel = new JPanel();
listPanel.setLayout( new MigLayout( "fill,wrap 3", "[grow,fill]", "[][][][grow,fill][]" ) ); listPanel.setLayout(new MigLayout("fill,wrap 3", "[grow,fill]", "[][][][grow,fill][]"));
listPanel.add( mSelectedTunerType, "span" ); listPanel.add(mSelectedTunerType, "span");
mFrequencyControl.setEnabled( false ); mFrequencyControl.setEnabled(false);
listPanel.add( mFrequencyControl, "span" ); listPanel.add(mFrequencyControl, "span");
mRowSorter = new TableRowSorter<>( mTunerConfigurationModel ); mRowSorter = new TableRowSorter<>(mTunerConfigurationModel);
mTunerConfigurationTable = new JTable( mTunerConfigurationModel ); mTunerConfigurationTable = new JTable(mTunerConfigurationModel);
mTunerConfigurationTable.setRowSorter( mRowSorter ); mTunerConfigurationTable.setRowSorter(mRowSorter);
mTunerConfigurationTable.setEnabled( false ); mTunerConfigurationTable.setEnabled(false);
mTunerConfigurationTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() mTunerConfigurationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{ {
@Override @Override
public void valueChanged( ListSelectionEvent event ) public void valueChanged(ListSelectionEvent event)
{ {
if( !event.getValueIsAdjusting() ) if(!event.getValueIsAdjusting())
{ {
int row = mTunerConfigurationTable.getSelectedRow(); int row = mTunerConfigurationTable.getSelectedRow();
if( row >= 0 ) if(row >= 0)
{ {
int modelRow = mTunerConfigurationTable.convertRowIndexToModel( row ); int modelRow = mTunerConfigurationTable.convertRowIndexToModel(row);
if( modelRow >= 0 ) if(modelRow >= 0)
{ {
setTunerConfiguration( mTunerConfigurationModel.getTunerConfiguration( modelRow ) ); setTunerConfiguration(mTunerConfigurationModel.getTunerConfiguration(modelRow));
} }
} }
} }
} }
} ); });
JScrollPane tableScroller = new JScrollPane( mTunerConfigurationTable ); JScrollPane tableScroller = new JScrollPane(mTunerConfigurationTable);
tableScroller.setHorizontalScrollBarPolicy( tableScroller.setHorizontalScrollBarPolicy(
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
listPanel.add( new JLabel( "Tuner Configurations" ), "span" ); listPanel.add(new JLabel("Tuner Configurations"), "span");
listPanel.add( tableScroller, "span" ); listPanel.add(tableScroller, "span");
mNewConfigurationButton.setEnabled( false ); mNewConfigurationButton.setEnabled(false);
mNewConfigurationButton.setToolTipText( "Create a new configuration for the currently selected tuner" ); mNewConfigurationButton.setToolTipText("Create a new configuration for the currently selected tuner");
mNewConfigurationButton.addActionListener( new ActionListener() mNewConfigurationButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent e ) public void actionPerformed(ActionEvent e)
{ {
Tuner tuner = getItem(); Tuner tuner = getItem();
String name = mTunerConfigurationModel String name = mTunerConfigurationModel
.getDistinctName( tuner.getTunerType(), tuner.getUniqueID() ); .getDistinctName(tuner.getTunerType(), tuner.getUniqueID());
TunerConfiguration config = TunerConfigurationFactory TunerConfiguration config = TunerConfigurationFactory
.getTunerConfiguration( tuner.getTunerType(), .getTunerConfiguration(tuner.getTunerType(),
tuner.getUniqueID(), name ); tuner.getUniqueID(), name);
mTunerConfigurationModel.addTunerConfiguration( config ); mTunerConfigurationModel.addTunerConfiguration(config);
} }
} ); });
listPanel.add( mNewConfigurationButton ); listPanel.add(mNewConfigurationButton);
mDeleteConfigurationButton.setEnabled( false ); mDeleteConfigurationButton.setEnabled(false);
mDeleteConfigurationButton.setToolTipText( "Deletes the currently selected tuner" ); mDeleteConfigurationButton.setToolTipText("Deletes the currently selected tuner");
mDeleteConfigurationButton.addActionListener( new ActionListener() mDeleteConfigurationButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent e ) public void actionPerformed(ActionEvent e)
{ {
int choice = JOptionPane.showConfirmDialog( TunerEditor.this, int choice = JOptionPane.showConfirmDialog(TunerEditor.this,
"Do you want to delete this tuner configuration?", "Do you want to delete this tuner configuration?",
"Delete Tuner Configuration?", JOptionPane.YES_NO_OPTION ); "Delete Tuner Configuration?", JOptionPane.YES_NO_OPTION);
if( choice == JOptionPane.YES_OPTION ) if(choice == JOptionPane.YES_OPTION)
{ {
TunerConfiguration selected = getSelectedTunerConfiguration(); TunerConfiguration selected = getSelectedTunerConfiguration();
mTunerConfigurationModel.removeTunerConfiguration( selected ); mTunerConfigurationModel.removeTunerConfiguration(selected);
mTunerConfigurationTable.setRowSelectionInterval( 0, 0 ); mTunerConfigurationTable.setRowSelectionInterval(0, 0);
} }
} }
} ); });
listPanel.add( mDeleteConfigurationButton ); listPanel.add(mDeleteConfigurationButton);
mAssignConfigurationButton.setEnabled( false ); mAssignConfigurationButton.setEnabled(false);
mAssignConfigurationButton.setToolTipText( "Assigns to the currently selected tuner configuration to the selected tuner" ); mAssignConfigurationButton.setToolTipText("Assigns to the currently selected tuner configuration to the selected tuner");
mAssignConfigurationButton.addActionListener( new ActionListener() mAssignConfigurationButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent e ) public void actionPerformed(ActionEvent e)
{ {
TunerConfiguration selected = getSelectedTunerConfiguration(); TunerConfiguration selected = getSelectedTunerConfiguration();
mTunerConfigurationModel.assignTunerConfiguration( selected ); mTunerConfigurationModel.assignTunerConfiguration(selected);
setTunerConfiguration( getSelectedTunerConfiguration() ); setTunerConfiguration(getSelectedTunerConfiguration());
} }
} ); });
listPanel.add( mAssignConfigurationButton ); listPanel.add(mAssignConfigurationButton);
//Set preferred size on both scrollers to same width, so they split the space //Set preferred size on both scrollers to same width, so they split the space
listPanel.setPreferredSize( new Dimension( 100, 80 ) ); listPanel.setPreferredSize(new Dimension(100, 80));
JScrollPane listScroller = new JScrollPane( listPanel ); JScrollPane listScroller = new JScrollPane(listPanel);
listScroller.setPreferredSize( new Dimension( 100, 80 ) ); listScroller.setPreferredSize(new Dimension(100, 80));
mEditorScroller = new JScrollPane( mEditor ); mEditorScroller = new JScrollPane(mEditor);
mEditorScroller.setPreferredSize( new Dimension( 100, 80 ) ); mEditorScroller.setPreferredSize(new Dimension(100, 80));
mEditorSplitPane = new JideSplitPane( JideSplitPane.HORIZONTAL_SPLIT ); mEditorSplitPane = new JideSplitPane(JideSplitPane.HORIZONTAL_SPLIT);
mEditorSplitPane.add( listScroller ); mEditorSplitPane.add(listScroller);
mEditorSplitPane.add( mEditorScroller ); mEditorSplitPane.add(mEditorScroller);
add( mEditorSplitPane ); add(mEditorSplitPane);
} }
private TunerConfiguration getSelectedTunerConfiguration() private TunerConfiguration getSelectedTunerConfiguration()
{ {
int tableRow = mTunerConfigurationTable.getSelectedRow(); int tableRow = mTunerConfigurationTable.getSelectedRow();
if( tableRow >= 0 ) if(tableRow >= 0)
{ {
int modelRow = mTunerConfigurationTable.convertRowIndexToModel( tableRow ); int modelRow = mTunerConfigurationTable.convertRowIndexToModel(tableRow);
if( modelRow >= 0 ) if(modelRow >= 0)
{ {
return mTunerConfigurationModel.getTunerConfiguration( modelRow ); return mTunerConfigurationModel.getTunerConfiguration(modelRow);
} }
} }
return null; return null;
} }
@Override @Override
public void save() public void save()
{ {
//Unused //Unused
} }
@Override @Override
public void setItem( Tuner tuner ) public void setItem(Tuner tuner)
{ {
//Cleanup previously selected tuner //Cleanup previously selected tuner
if( hasItem() ) if(hasItem())
{ {
Tuner previous = getItem(); Tuner previous = getItem();
previous.getTunerController().removeListener( mFrequencyControl ); previous.getTunerController().removeListener(mFrequencyControl);
mFrequencyControl.removeListener( previous.getTunerController() ); mFrequencyControl.removeListener(previous.getTunerController());
} }
super.setItem( tuner ); super.setItem(tuner);
if( hasItem() ) if(hasItem())
{ {
mSelectedTunerType.setText( tuner.getName() ); mSelectedTunerType.setText(tuner.getName());
mFrequencyControl.setEnabled( true ); mTunerConfigurationTable.setEnabled(true);
mTunerConfigurationTable.setEnabled( true ); mNewConfigurationButton.setEnabled(true);
mNewConfigurationButton.setEnabled( true );
//Change to an editor for this config's tuner type //Change to an editor for this config's tuner type
mEditor = TunerConfigurationFactory.getEditor( getItem(), mTunerConfigurationModel ); mEditor = TunerConfigurationFactory.getEditor(getItem(), mTunerConfigurationModel);
mRowSorter.setRowFilter( new ConfigurationRowFilter( tuner.getTunerType(), mRowSorter.setRowFilter(new ConfigurationRowFilter(tuner.getTunerType(),
tuner.getUniqueID() ) ); tuner.getUniqueID()));
TunerConfiguration assigned = mTunerConfigurationModel TunerConfiguration assigned = mTunerConfigurationModel
.getTunerConfiguration( tuner.getTunerType(), tuner.getUniqueID() ); .getTunerConfiguration(tuner.getTunerType(), tuner.getUniqueID());
int modelIndex = mTunerConfigurationModel.getRowIndex( assigned ); int modelIndex = mTunerConfigurationModel.getRowIndex(assigned);
if( modelIndex >= 0 ) if(modelIndex >= 0)
{ {
int viewIndex = mTunerConfigurationTable int viewIndex = mTunerConfigurationTable
.convertRowIndexToView( modelIndex ); .convertRowIndexToView(modelIndex);
if( viewIndex >= 0 ) if(viewIndex >= 0)
{ {
mTunerConfigurationTable mTunerConfigurationTable
.setRowSelectionInterval( viewIndex, viewIndex ); .setRowSelectionInterval(viewIndex, viewIndex);
} }
} }
//Link frequency control to the tuner //Link frequency control to the tuner and set enabled state
mFrequencyControl.addListener( tuner.getTunerController() ); mFrequencyControl.addListener(tuner.getTunerController());
mFrequencyControl.setEnabled(!tuner.getTunerController().isLocked());
//Link tuner to frequency control //Link tuner to frequency control
tuner.getTunerController().addListener( mFrequencyControl ); tuner.getTunerController().addListener(mFrequencyControl);
//Set the displayed frequency without adjusting the tuner's frequency //Set the displayed frequency without adjusting the tuner's frequency
mFrequencyControl.setFrequency( mFrequencyControl.setFrequency(tuner.getTunerController().getFrequency(), false);
tuner.getTunerController().getFrequency(), false ); }
} else
else {
{ mSelectedTunerType.setText("No Tuner Selected");
mSelectedTunerType.setText( "No Tuner Selected" ); mFrequencyControl.setEnabled(false);
mFrequencyControl.setEnabled( false ); mTunerConfigurationTable.setEnabled(false);
mTunerConfigurationTable.setEnabled( false ); mNewConfigurationButton.setEnabled(false);
mNewConfigurationButton.setEnabled( false ); mRowSorter.setRowFilter(null);
mRowSorter.setRowFilter( null ); mEditor = new EmptyEditor<TunerConfiguration>();
mEditor = new EmptyEditor<TunerConfiguration>(); }
}
//Swap out the editor //Swap out the editor
int split = mEditorSplitPane.getDividerLocation( 0 ); int split = mEditorSplitPane.getDividerLocation(0);
mEditorSplitPane.remove( mEditorScroller ); mEditorSplitPane.remove(mEditorScroller);
mEditorScroller = new JScrollPane( mEditor ); mEditorScroller = new JScrollPane(mEditor);
mEditorSplitPane.add( mEditorScroller ); mEditorSplitPane.add(mEditorScroller);
mEditorSplitPane.setDividerLocation( 0, split ); mEditorSplitPane.setDividerLocation(0, split);
} }
private void setTunerConfiguration( TunerConfiguration config ) private void setTunerConfiguration(TunerConfiguration config)
{ {
if( config != null ) if(config != null)
{ {
if( !config.isAssigned() ) if(!config.isAssigned())
{ {
if( !mAssignConfigurationButton.isEnabled() ) if(!mAssignConfigurationButton.isEnabled())
{ {
mAssignConfigurationButton.setEnabled( true ); mAssignConfigurationButton.setEnabled(true);
} }
if( !mDeleteConfigurationButton.isEnabled() ) if(!mDeleteConfigurationButton.isEnabled())
{ {
mDeleteConfigurationButton.setEnabled( true ); mDeleteConfigurationButton.setEnabled(true);
} }
} }
else else
{ {
if( mAssignConfigurationButton.isEnabled() ) if(mAssignConfigurationButton.isEnabled())
{ {
mAssignConfigurationButton.setEnabled( false ); mAssignConfigurationButton.setEnabled(false);
} }
if( mDeleteConfigurationButton.isEnabled() ) if(mDeleteConfigurationButton.isEnabled())
{ {
mDeleteConfigurationButton.setEnabled( false ); mDeleteConfigurationButton.setEnabled(false);
} }
} }
} }
else else
{ {
if( mDeleteConfigurationButton.isEnabled() ) if(mDeleteConfigurationButton.isEnabled())
{ {
mDeleteConfigurationButton.setEnabled( false ); mDeleteConfigurationButton.setEnabled(false);
} }
if( mAssignConfigurationButton.isEnabled() ) if(mAssignConfigurationButton.isEnabled())
{ {
mAssignConfigurationButton.setEnabled( false ); mAssignConfigurationButton.setEnabled(false);
} }
} }
mEditor.setItem( config ); mEditor.setItem(config);
} }
public class ConfigurationRowFilter extends RowFilter<TunerConfigurationModel,Integer> public class ConfigurationRowFilter extends RowFilter<TunerConfigurationModel,Integer>
{ {
private TunerType mTunerType; private TunerType mTunerType;
private String mUniqueID; private String mUniqueID;
public ConfigurationRowFilter( TunerType type, String uniqueID ) public ConfigurationRowFilter(TunerType type, String uniqueID)
{ {
mTunerType = type; mTunerType = type;
mUniqueID = uniqueID; mUniqueID = uniqueID;
} }
@Override @Override
public boolean include( javax.swing.RowFilter.Entry<? extends TunerConfigurationModel, public boolean include(javax.swing.RowFilter.Entry<? extends TunerConfigurationModel,
? extends Integer> entry ) ? extends Integer> entry)
{ {
TunerConfiguration config = entry.getModel() TunerConfiguration config = entry.getModel()
.getTunerConfiguration( entry.getIdentifier() ); .getTunerConfiguration(entry.getIdentifier());
return config != null && return config != null &&
config.getTunerType() == mTunerType && config.getTunerType() == mTunerType &&
config.getUniqueID() != null && config.getUniqueID() != null &&
config.getUniqueID().contentEquals( mUniqueID ); config.getUniqueID().contentEquals(mUniqueID);
} }
} }
} }

View File

@@ -1,20 +1,43 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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 io.github.dsheirer.source.tuner.configuration; package io.github.dsheirer.source.tuner.configuration;
import io.github.dsheirer.gui.editor.Editor; import io.github.dsheirer.gui.editor.Editor;
public abstract class TunerConfigurationEditor extends Editor<TunerConfiguration> public abstract class TunerConfigurationEditor extends Editor<TunerConfiguration>
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private TunerConfigurationModel mTunerConfigurationModel; private TunerConfigurationModel mTunerConfigurationModel;
public TunerConfigurationEditor( TunerConfigurationModel model ) public TunerConfigurationEditor(TunerConfigurationModel model)
{ {
mTunerConfigurationModel = model; mTunerConfigurationModel = model;
} }
public TunerConfigurationModel getTunerConfigurationModel() public TunerConfigurationModel getTunerConfigurationModel()
{ {
return mTunerConfigurationModel; return mTunerConfigurationModel;
} }
/**
* Sets the state of the sample rate editor control. When enabled, users are allowed to change the sample rate
* of the tuner. When disabled, user controls should NOT allow sample rate changes.
*
* @param enabled state for the sample rate control
*/
public abstract void setSampleRateControl(boolean enabled);
} }

View File

@@ -1,17 +1,17 @@
/******************************************************************************* /*******************************************************************************
* SDR Trunk * SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer * Copyright (C) 2014-2016 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/ ******************************************************************************/
@@ -51,475 +51,489 @@ import java.text.DecimalFormat;
public class FCD1TunerEditor extends TunerConfigurationEditor public class FCD1TunerEditor extends TunerConfigurationEditor
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger( FCD1TunerEditor.class ); private final static Logger mLog = LoggerFactory.getLogger(FCD1TunerEditor.class);
private JTextField mConfigurationName; private JTextField mConfigurationName;
private JButton mTunerInfo; private JButton mTunerInfo;
private JSpinner mFrequencyCorrection; private JSpinner mFrequencyCorrection;
private JComboBox<LNAGain> mComboLNAGain; private JComboBox<LNAGain> mComboLNAGain;
private JComboBox<LNAEnhance> mComboLNAEnhance; private JComboBox<LNAEnhance> mComboLNAEnhance;
private JComboBox<MixerGain> mComboMixerGain; private JComboBox<MixerGain> mComboMixerGain;
private CorrectionSpinner mCorrectionDCI; private CorrectionSpinner mCorrectionDCI;
private CorrectionSpinner mCorrectionDCQ; private CorrectionSpinner mCorrectionDCQ;
private CorrectionSpinner mCorrectionGain; private CorrectionSpinner mCorrectionGain;
private CorrectionSpinner mCorrectionPhase; private CorrectionSpinner mCorrectionPhase;
private boolean mLoading; private boolean mLoading;
private FCD1TunerController mController; private FCD1TunerController mController;
public FCD1TunerEditor( TunerConfigurationModel tunerConfigurationModel, FCDTuner tuner ) public FCD1TunerEditor(TunerConfigurationModel tunerConfigurationModel, FCDTuner tuner)
{ {
super( tunerConfigurationModel ); super(tunerConfigurationModel);
mController = (FCD1TunerController)tuner.getController(); mController = (FCD1TunerController)tuner.getController();
init(); init();
} }
private FCD1TunerConfiguration getConfiguration() private FCD1TunerConfiguration getConfiguration()
{ {
if( hasItem() ) if(hasItem())
{ {
return (FCD1TunerConfiguration)getItem(); return (FCD1TunerConfiguration)getItem();
} }
return null; return null;
} }
private void init() @Override
{ public void setSampleRateControl(boolean enabled)
setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", {
"[][][][][][][][][][][][grow]" ) ); //no-op
}
add( new JLabel( "FCD Pro Tuner Configuration" ), "span,align center" );
private void init()
mConfigurationName = new JTextField(); {
mConfigurationName.setEnabled( false ); setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
mConfigurationName.addFocusListener( new FocusListener() "[][][][][][][][][][][][grow]"));
{
@Override add(new JLabel("FCD Pro Tuner Configuration"), "span,align center");
public void focusLost( FocusEvent e )
{ mConfigurationName = new JTextField();
save(); mConfigurationName.setEnabled(false);
} mConfigurationName.addFocusListener(new FocusListener()
@Override {
public void focusGained( FocusEvent e ) {} @Override
} ); public void focusLost(FocusEvent e)
{
add( new JLabel( "Name:" ) ); save();
add( mConfigurationName, "span 2" ); }
mTunerInfo = new JButton( "Tuner Info" ); @Override
mTunerInfo.setEnabled( false ); public void focusGained(FocusEvent e)
mTunerInfo.addActionListener( new ActionListener() {
{ }
@Override });
public void actionPerformed( ActionEvent e )
{ add(new JLabel("Name:"));
JOptionPane.showMessageDialog( FCD1TunerEditor.this, getTunerInfo(), add(mConfigurationName, "span 2");
"Tuner Info", JOptionPane.INFORMATION_MESSAGE );
} mTunerInfo = new JButton("Tuner Info");
} ); mTunerInfo.setEnabled(false);
add( mTunerInfo ); mTunerInfo.addActionListener(new ActionListener()
{
SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value @Override
-1000.0, //min public void actionPerformed(ActionEvent e)
1000.0, //max {
0.1 ); //step JOptionPane.showMessageDialog(FCD1TunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE);
mFrequencyCorrection = new JSpinner( model ); }
mFrequencyCorrection.setEnabled( false ); });
JSpinner.NumberEditor editor = add(mTunerInfo);
(JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
SpinnerModel model = new SpinnerNumberModel(0.0, //initial value
DecimalFormat format = editor.getFormat(); -1000.0, //min
format.setMinimumFractionDigits( 1 ); 1000.0, //max
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); 0.1); //step
mFrequencyCorrection.addChangeListener( new ChangeListener() mFrequencyCorrection = new JSpinner(model);
{ mFrequencyCorrection.setEnabled(false);
@Override JSpinner.NumberEditor editor =
public void stateChanged( ChangeEvent e ) (JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
{
double value = ((SpinnerNumberModel)mFrequencyCorrection DecimalFormat format = editor.getFormat();
.getModel()).getNumber().doubleValue(); format.setMinimumFractionDigits(1);
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
try
{ mFrequencyCorrection.addChangeListener(new ChangeListener()
mController.setFrequencyCorrection( value ); {
save(); @Override
} public void stateChanged(ChangeEvent e)
catch ( SourceException e1 ) {
{ double value = ((SpinnerNumberModel)mFrequencyCorrection
JOptionPane.showMessageDialog( FCD1TunerEditor.this, "FCD Pro Tuner " .getModel()).getNumber().doubleValue();
+ "Controller - couldn't apply frequency correction value: " + value +
e1.getLocalizedMessage() ); try
{
mLog.error( "FuncubeDonglePro Controller - couldn't apply " mController.setFrequencyCorrection(value);
+ "frequency correction value: " + value, e1 ); save();
} }
} catch(SourceException e1)
} ); {
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCD Pro Tuner "
add( new JLabel( "PPM:" ) ); + "Controller - couldn't apply frequency correction value: " + value +
add( mFrequencyCorrection, "wrap" ); e1.getLocalizedMessage());
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); mLog.error("FuncubeDonglePro Controller - couldn't apply "
add( new JLabel( "Gain" ), "span,align center" ); + "frequency correction value: " + value, e1);
}
mComboLNAGain = new JComboBox<LNAGain>( LNAGain.values() ); }
mComboLNAGain.setEnabled( false ); });
mComboLNAGain.setToolTipText( "Adjust the low noise amplifier gain setting." );
mComboLNAGain.addActionListener( new ActionListener() add(new JLabel("PPM:"));
{ add(mFrequencyCorrection, "wrap");
@Override
public void actionPerformed( ActionEvent arg0 ) add(new JSeparator(JSeparator.HORIZONTAL), "span,grow");
{ add(new JLabel("Gain"), "span,align center");
LNAGain gain = (LNAGain)mComboLNAGain.getSelectedItem();
mComboLNAGain = new JComboBox<LNAGain>(LNAGain.values());
mComboLNAGain.setEnabled(false);
try mComboLNAGain.setToolTipText("Adjust the low noise amplifier gain setting.");
{ mComboLNAGain.addActionListener(new ActionListener()
mController.setLNAGain( gain ); {
save(); @Override
} public void actionPerformed(ActionEvent arg0)
catch ( Exception e ) {
{ LNAGain gain = (LNAGain)mComboLNAGain.getSelectedItem();
JOptionPane.showMessageDialog( FCD1TunerEditor.this, "FCD Pro Tuner Controller"
+ " - error setting LNA gain [" + gain.toString() + "]" );
try
mLog.error( "FuncubeDonglePro Controller - error setting gain [" + gain.toString() + "]", e ); {
} mController.setLNAGain(gain);
} save();
} ); }
catch(Exception e)
add( new JLabel( "LNA:" ) ); {
add( mComboLNAGain ); JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCD Pro Tuner Controller"
+ " - error setting LNA gain [" + gain.toString() + "]");
/**
* LNA Enhance mLog.error("FuncubeDonglePro Controller - error setting gain [" + gain.toString() + "]", e);
*/ }
mComboLNAEnhance = new JComboBox<LNAEnhance>( LNAEnhance.values() ); }
mComboLNAEnhance.setToolTipText( "Adjust the LNA enhance setting. Default value is OFF" ); });
mComboLNAEnhance.addActionListener( new ActionListener() add(new JLabel("LNA:"));
{ add(mComboLNAGain);
@Override
public void actionPerformed( ActionEvent arg0 ) /**
{ * LNA Enhance
LNAEnhance enhance = (LNAEnhance)mComboLNAEnhance.getSelectedItem(); */
mComboLNAEnhance = new JComboBox<LNAEnhance>(LNAEnhance.values());
try mComboLNAEnhance.setToolTipText("Adjust the LNA enhance setting. Default value is OFF");
{
mController.setLNAEnhance( enhance ); mComboLNAEnhance.addActionListener(new ActionListener()
save(); {
} @Override
catch ( Exception e1 ) public void actionPerformed(ActionEvent arg0)
{ {
JOptionPane.showMessageDialog( FCD1TunerEditor.this, "FCD Pro Tuner" LNAEnhance enhance = (LNAEnhance)mComboLNAEnhance.getSelectedItem();
+ " error setting LNA enhance gain [" + enhance.toString() + "]" );
try
mLog.error( "FCDPro - error setting LNA enhance [" + enhance.toString() + "]", e1 ); {
} mController.setLNAEnhance(enhance);
} save();
} ); }
catch(Exception e1)
add( new JLabel( "Enhance:" ) ); {
add( mComboLNAEnhance ); JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCD Pro Tuner"
+ " error setting LNA enhance gain [" + enhance.toString() + "]");
/**
* Mixer Gain mLog.error("FCDPro - error setting LNA enhance [" + enhance.toString() + "]", e1);
*/ }
mComboMixerGain = new JComboBox<MixerGain>( MixerGain.values() ); }
mComboMixerGain.setToolTipText( "Adjust mixer gain setting" ); });
add(new JLabel("Enhance:"));
mComboMixerGain.addActionListener( new ActionListener() add(mComboLNAEnhance);
{
@Override /**
public void actionPerformed( ActionEvent arg0 ) * Mixer Gain
{ */
MixerGain gain = (MixerGain)mComboMixerGain.getSelectedItem(); mComboMixerGain = new JComboBox<MixerGain>(MixerGain.values());
mComboMixerGain.setToolTipText("Adjust mixer gain setting");
try
{
mController.setMixerGain( gain ); mComboMixerGain.addActionListener(new ActionListener()
save(); {
} @Override
catch ( Exception e1 ) public void actionPerformed(ActionEvent arg0)
{ {
JOptionPane.showMessageDialog( FCD1TunerEditor.this, "FCDPro - error setting" MixerGain gain = (MixerGain)mComboMixerGain.getSelectedItem();
+ " mixer gain [" + gain.toString() + "]" );
try
mLog.error( "FCDPro - error setting mixer gain [" + gain.toString() + "]", e1 ); {
} mController.setMixerGain(gain);
} save();
} ); }
catch(Exception e1)
add( new JLabel( "Mixer:" ) ); {
add( mComboMixerGain, "wrap" ); JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCDPro - error setting"
+ " mixer gain [" + gain.toString() + "]");
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" );
add( new JLabel( "Correction" ), "span,align center" ); mLog.error("FCDPro - error setting mixer gain [" + gain.toString() + "]", e1);
}
/** }
* Inphase DC Correction });
*/
mCorrectionDCI = new CorrectionSpinner( Correction.DC_INPHASE, 0.0, 0.00001, 5 ); add(new JLabel("Mixer:"));
mCorrectionDCI.setEnabled( false ); add(mComboMixerGain, "wrap");
mCorrectionDCI.setToolTipText( "DC Bias Correction/Inphase "
+ "Component: valid values are -1.0 to 1.0 (default: 0.0)" ); add(new JSeparator(JSeparator.HORIZONTAL), "span,grow");
add( new JLabel( "DC Inphase:" ) ); add(new JLabel("Correction"), "span,align center");
add( mCorrectionDCI );
/**
/** * Inphase DC Correction
* Quadrature DC Correction */
*/ mCorrectionDCI = new CorrectionSpinner(Correction.DC_INPHASE, 0.0, 0.00001, 5);
mCorrectionDCQ = new CorrectionSpinner( Correction.DC_QUADRATURE, 0.0, 0.00001, 5 ); mCorrectionDCI.setEnabled(false);
mCorrectionDCQ.setToolTipText( "DC Bias Correction/Quadrature " mCorrectionDCI.setToolTipText("DC Bias Correction/Inphase "
+ "Component: valid values are -1.0 to 1.0 (default: 0.0)" ); + "Component: valid values are -1.0 to 1.0 (default: 0.0)");
add( new JLabel( "DC Quadrature:" ) ); add(new JLabel("DC Inphase:"));
add( mCorrectionDCQ ); add(mCorrectionDCI);
/** /**
* Gain Correction * Quadrature DC Correction
*/ */
mCorrectionGain = new CorrectionSpinner( Correction.GAIN, 0.0, 0.00001, 5 ); mCorrectionDCQ = new CorrectionSpinner(Correction.DC_QUADRATURE, 0.0, 0.00001, 5);
mCorrectionGain.setToolTipText( "Gain Correction: valid values are " mCorrectionDCQ.setToolTipText("DC Bias Correction/Quadrature "
+ "-1.0 to 1.0 (default: 0.0)" ); + "Component: valid values are -1.0 to 1.0 (default: 0.0)");
add( new JLabel( "Gain:" ) ); add(new JLabel("DC Quadrature:"));
add( mCorrectionGain ); add(mCorrectionDCQ);
/** /**
* Phase Correction * Gain Correction
*/ */
mCorrectionPhase = new CorrectionSpinner( Correction.PHASE, 0.0, 0.00001, 5 ); mCorrectionGain = new CorrectionSpinner(Correction.GAIN, 0.0, 0.00001, 5);
mCorrectionPhase.setToolTipText( "Phase Correction: valid values are " mCorrectionGain.setToolTipText("Gain Correction: valid values are "
+ "-1.0 to 1.0 (default: 0.0)" ); + "-1.0 to 1.0 (default: 0.0)");
add( new JLabel( "Phase:" ) ); add(new JLabel("Gain:"));
add( mCorrectionPhase ); add(mCorrectionGain);
}
/**
/** * Phase Correction
* Sets each of the tuner configuration controls to the enabled argument state */
*/ mCorrectionPhase = new CorrectionSpinner(Correction.PHASE, 0.0, 0.00001, 5);
private void setControlsEnabled( boolean enabled ) mCorrectionPhase.setToolTipText("Phase Correction: valid values are "
{ + "-1.0 to 1.0 (default: 0.0)");
if( mConfigurationName.isEnabled() != enabled ) add(new JLabel("Phase:"));
{ add(mCorrectionPhase);
mConfigurationName.setEnabled( enabled ); }
}
/**
if( mTunerInfo.isEnabled() != enabled ) * Sets each of the tuner configuration controls to the enabled argument state
{ */
mTunerInfo.setEnabled( enabled ); private void setControlsEnabled(boolean enabled)
} {
if(mConfigurationName.isEnabled() != enabled)
if( mFrequencyCorrection.isEnabled() != enabled ) {
{ mConfigurationName.setEnabled(enabled);
mFrequencyCorrection.setEnabled( enabled ); }
}
if(mTunerInfo.isEnabled() != enabled)
if( mComboLNAEnhance.isEnabled() != enabled ) {
{ mTunerInfo.setEnabled(enabled);
mComboLNAEnhance.setEnabled( enabled ); }
}
if(mFrequencyCorrection.isEnabled() != enabled)
if( mComboLNAGain.isEnabled() != enabled ) {
{ mFrequencyCorrection.setEnabled(enabled);
mComboLNAGain.setEnabled( enabled ); }
}
if(mComboLNAEnhance.isEnabled() != enabled)
if( mComboMixerGain.isEnabled() != enabled ) {
{ mComboLNAEnhance.setEnabled(enabled);
mComboMixerGain.setEnabled( enabled ); }
}
if(mComboLNAGain.isEnabled() != enabled)
if( mCorrectionDCI.isEnabled() != enabled ) {
{ mComboLNAGain.setEnabled(enabled);
mCorrectionDCI.setEnabled( enabled ); }
}
if(mComboMixerGain.isEnabled() != enabled)
if( mCorrectionDCQ.isEnabled() != enabled ) {
{ mComboMixerGain.setEnabled(enabled);
mCorrectionDCQ.setEnabled( enabled ); }
}
if(mCorrectionDCI.isEnabled() != enabled)
if( mCorrectionGain.isEnabled() != enabled ) {
{ mCorrectionDCI.setEnabled(enabled);
mCorrectionGain.setEnabled( enabled ); }
}
if(mCorrectionDCQ.isEnabled() != enabled)
if( mCorrectionPhase.isEnabled() != enabled ) {
{ mCorrectionDCQ.setEnabled(enabled);
mCorrectionPhase.setEnabled( enabled ); }
}
} if(mCorrectionGain.isEnabled() != enabled)
{
private String getTunerInfo() mCorrectionGain.setEnabled(enabled);
{ }
StringBuilder sb = new StringBuilder();
if(mCorrectionPhase.isEnabled() != enabled)
sb.append( "<html><h3>Funcube Dongle Pro Tuner</h3>" ); {
mCorrectionPhase.setEnabled(enabled);
sb.append( "<b>USB ID: </b>" ); }
sb.append( mController.getUSBID() ); }
sb.append( "<br>" );
private String getTunerInfo()
sb.append( "<b>USB Address: </b>" ); {
sb.append( mController.getUSBAddress() ); StringBuilder sb = new StringBuilder();
sb.append( "<br>" );
sb.append("<html><h3>Funcube Dongle Pro Tuner</h3>");
sb.append( "<b>USB Speed: </b>" );
sb.append( mController.getUSBSpeed() ); sb.append("<b>USB ID: </b>");
sb.append( "<br>" ); sb.append(mController.getUSBID());
sb.append("<br>");
sb.append( "<b>Cellular Band: </b>" );
sb.append( mController.getConfiguration().getBandBlocking() ); sb.append("<b>USB Address: </b>");
sb.append( "<br>" ); sb.append(mController.getUSBAddress());
sb.append("<br>");
sb.append( "<b>Firmware: </b>" );
sb.append( mController.getConfiguration().getFirmware() ); sb.append("<b>USB Speed: </b>");
sb.append( "<br>" ); sb.append(mController.getUSBSpeed());
sb.append("<br>");
return sb.toString();
} sb.append("<b>Cellular Band: </b>");
sb.append(mController.getConfiguration().getBandBlocking());
@Override sb.append("<br>");
public void save()
{ sb.append("<b>Firmware: </b>");
if( hasItem() && !mLoading ) sb.append(mController.getConfiguration().getFirmware());
{ sb.append("<br>");
FCD1TunerConfiguration config = getConfiguration();
return sb.toString();
config.setName( mConfigurationName.getText() ); }
double value = ((SpinnerNumberModel)mFrequencyCorrection @Override
.getModel()).getNumber().doubleValue(); public void save()
config.setFrequencyCorrection( value ); {
config.setLNAEnhance( (LNAEnhance)mComboLNAEnhance.getSelectedItem() ); if(hasItem() && !mLoading)
config.setLNAGain( (LNAGain)mComboLNAGain.getSelectedItem() ); {
config.setMixerGain( (MixerGain)mComboMixerGain.getSelectedItem() ); FCD1TunerConfiguration config = getConfiguration();
double dci = ((SpinnerNumberModel)mCorrectionDCI.getModel()).getNumber().doubleValue(); config.setName(mConfigurationName.getText());
config.setInphaseDCCorrection( dci );
double value = ((SpinnerNumberModel)mFrequencyCorrection
double dcq = ((SpinnerNumberModel)mCorrectionDCQ.getModel()).getNumber().doubleValue(); .getModel()).getNumber().doubleValue();
config.setQuadratureDCCorrection( dcq ); config.setFrequencyCorrection(value);
config.setLNAEnhance((LNAEnhance)mComboLNAEnhance.getSelectedItem());
double gain = ((SpinnerNumberModel)mCorrectionGain.getModel()).getNumber().doubleValue(); config.setLNAGain((LNAGain)mComboLNAGain.getSelectedItem());
config.setGainCorrection( gain ); config.setMixerGain((MixerGain)mComboMixerGain.getSelectedItem());
double phase = ((SpinnerNumberModel)mCorrectionPhase.getModel()).getNumber().doubleValue(); double dci = ((SpinnerNumberModel)mCorrectionDCI.getModel()).getNumber().doubleValue();
config.setPhaseCorrection( phase ); config.setInphaseDCCorrection(dci);
getTunerConfigurationModel().broadcast( new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); double dcq = ((SpinnerNumberModel)mCorrectionDCQ.getModel()).getNumber().doubleValue();
} config.setQuadratureDCCorrection(dcq);
}
double gain = ((SpinnerNumberModel)mCorrectionGain.getModel()).getNumber().doubleValue();
@Override config.setGainCorrection(gain);
public void setItem( TunerConfiguration tunerConfiguration )
{ double phase = ((SpinnerNumberModel)mCorrectionPhase.getModel()).getNumber().doubleValue();
super.setItem( tunerConfiguration ); config.setPhaseCorrection(phase);
//Toggle loading so that we don't fire a change event and schedule a settings file save getTunerConfigurationModel().broadcast(new TunerConfigurationEvent(getConfiguration(), Event.CHANGE));
mLoading = true; }
}
if( hasItem() )
{ @Override
FCD1TunerConfiguration config = getConfiguration(); public void setItem(TunerConfiguration tunerConfiguration)
{
if( tunerConfiguration.isAssigned() ) super.setItem(tunerConfiguration);
{
setControlsEnabled( true ); //Toggle loading so that we don't fire a change event and schedule a settings file save
mConfigurationName.setText( config.getName() ); mLoading = true;
mFrequencyCorrection.setValue( config.getFrequencyCorrection() );
mComboLNAEnhance.setSelectedItem( config.getLNAEnhance() ); if(hasItem())
mComboLNAGain.setSelectedItem( config.getLNAGain() ); {
mComboMixerGain.setSelectedItem( config.getMixerGain() ); FCD1TunerConfiguration config = getConfiguration();
mCorrectionDCI.setValue( config.getInphaseDCCorrection() );
mCorrectionDCQ.setValue( config.getQuadratureDCCorrection() ); if(tunerConfiguration.isAssigned())
mCorrectionGain.setValue( config.getGainCorrection() ); {
mCorrectionPhase.setValue( config.getPhaseCorrection() ); setControlsEnabled(true);
} mConfigurationName.setText(config.getName());
else mFrequencyCorrection.setValue(config.getFrequencyCorrection());
{ mComboLNAEnhance.setSelectedItem(config.getLNAEnhance());
setControlsEnabled( false ); mComboLNAGain.setSelectedItem(config.getLNAGain());
mConfigurationName.setText( config.getName() ); mComboMixerGain.setSelectedItem(config.getMixerGain());
} mCorrectionDCI.setValue(config.getInphaseDCCorrection());
} mCorrectionDCQ.setValue(config.getQuadratureDCCorrection());
else mCorrectionGain.setValue(config.getGainCorrection());
{ mCorrectionPhase.setValue(config.getPhaseCorrection());
setControlsEnabled( false ); }
mConfigurationName.setText( "" ); else
} {
setControlsEnabled(false);
mLoading = false; mConfigurationName.setText(config.getName());
} }
}
public enum Correction { GAIN, PHASE, DC_INPHASE, DC_QUADRATURE }; else
{
public class CorrectionSpinner extends JSpinner setControlsEnabled(false);
{ mConfigurationName.setText("");
private static final long serialVersionUID = 1L; }
private static final double MIN_VALUE = -1.0d;
private static final double MAX_VALUE = 1.0d; mLoading = false;
}
private Correction mCorrectionComponent;
public enum Correction
public CorrectionSpinner( Correction component, double initialValue, double step, int decimalPlaces ) {
{ GAIN, PHASE, DC_INPHASE, DC_QUADRATURE
mCorrectionComponent = component; }
SpinnerModel model = new SpinnerNumberModel( initialValue, MIN_VALUE, MAX_VALUE, step ); ;
setModel( model );
public class CorrectionSpinner extends JSpinner
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)getEditor(); {
private static final long serialVersionUID = 1L;
DecimalFormat format = editor.getFormat(); private static final double MIN_VALUE = -1.0d;
format.setMinimumFractionDigits( decimalPlaces ); private static final double MAX_VALUE = 1.0d;
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); private Correction mCorrectionComponent;
addChangeListener( new ChangeListener() public CorrectionSpinner(Correction component, double initialValue, double step, int decimalPlaces)
{ {
@Override mCorrectionComponent = component;
public void stateChanged( ChangeEvent e )
{ SpinnerModel model = new SpinnerNumberModel(initialValue, MIN_VALUE, MAX_VALUE, step);
double value = setModel(model);
((SpinnerNumberModel)getModel()).getNumber().doubleValue();
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)getEditor();
try
{ DecimalFormat format = editor.getFormat();
switch( mCorrectionComponent ) format.setMinimumFractionDigits(decimalPlaces);
{
case DC_INPHASE: editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
mController.setDCCorrectionInPhase( value );
break; addChangeListener(new ChangeListener()
case DC_QUADRATURE: {
mController.setDCCorrectionQuadrature( value ); @Override
break; public void stateChanged(ChangeEvent e)
case GAIN: {
mController.setGainCorrection( value ); double value =
break; ((SpinnerNumberModel)getModel()).getNumber().doubleValue();
case PHASE:
mController.setPhaseCorrection( value ); try
break; {
} switch(mCorrectionComponent)
{
save(); case DC_INPHASE:
} mController.setDCCorrectionInPhase(value);
catch ( Exception e1 ) break;
{ case DC_QUADRATURE:
JOptionPane.showMessageDialog( FCD1TunerEditor.this, "FCDPro - error " mController.setDCCorrectionQuadrature(value);
+ "applying " + mCorrectionComponent.toString() + " correction value [" break;
+ value + "]" ); case GAIN:
mController.setGainCorrection(value);
mLog.error( "FCDPro - error applying "+ mCorrectionComponent.toString() break;
+ " correction value [" + value + "]", e1 ); case PHASE:
} mController.setPhaseCorrection(value);
} break;
} ); }
}
} save();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCDPro - error "
+ "applying " + mCorrectionComponent.toString() + " correction value ["
+ value + "]");
mLog.error("FCDPro - error applying " + mCorrectionComponent.toString()
+ " correction value [" + value + "]", e1);
}
}
});
}
}
} }

View File

@@ -1,19 +1,17 @@
/******************************************************************************* /*******************************************************************************
* SDR Trunk * sdr-trunk
* Copyright (C) 2014-2016 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* it under the terms of the GNU General Public License as published by * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* the Free Software Foundation, either version 3 of the License, or * later version.
* (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
* This program is distributed in the hope that it will be useful, * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * You should have received a copy of the GNU General Public License along with this program.
* GNU General Public License for more details. * If not, see <http://www.gnu.org/licenses/>
* *
* 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 io.github.dsheirer.source.tuner.fcd.proplusV2; package io.github.dsheirer.source.tuner.fcd.proplusV2;
@@ -48,278 +46,287 @@ import java.text.DecimalFormat;
public class FCD2TunerEditor extends TunerConfigurationEditor public class FCD2TunerEditor extends TunerConfigurationEditor
{ {
private final static Logger mLog = LoggerFactory.getLogger( FCD2TunerEditor.class ); private final static Logger mLog = LoggerFactory.getLogger(FCD2TunerEditor.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JTextField mConfigurationName; private JTextField mConfigurationName;
private JButton mTunerInfo; private JButton mTunerInfo;
private JSpinner mFrequencyCorrection; private JSpinner mFrequencyCorrection;
private JCheckBox mLNAGain; private JCheckBox mLNAGain;
private JCheckBox mMixerGain; private JCheckBox mMixerGain;
private boolean mLoading; private boolean mLoading;
private FCD2TunerController mController; private FCD2TunerController mController;
public FCD2TunerEditor( TunerConfigurationModel tunerConfigurationModel, FCDTuner tuner ) public FCD2TunerEditor(TunerConfigurationModel tunerConfigurationModel, FCDTuner tuner)
{ {
super( tunerConfigurationModel ); super(tunerConfigurationModel);
mController = (FCD2TunerController)tuner.getController(); mController = (FCD2TunerController)tuner.getController();
init(); init();
} }
private FCD2TunerConfiguration getConfiguration() private FCD2TunerConfiguration getConfiguration()
{ {
if( hasItem() ) if(hasItem())
{ {
return (FCD2TunerConfiguration)getItem(); return (FCD2TunerConfiguration)getItem();
} }
return null; return null;
} }
private void init() @Override
{ public void setSampleRateControl(boolean enabled)
setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", {
"[][][][][][grow]" ) ); //no-op
}
add( new JLabel( "FCD Pro+ Tuner Configuration" ), "span,align center" ); private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
"[][][][][][grow]"));
mConfigurationName = new JTextField(); add(new JLabel("FCD Pro+ Tuner Configuration"), "span,align center");
mConfigurationName.setEnabled( false );
mConfigurationName.addFocusListener( new FocusListener()
{
@Override
public void focusLost( FocusEvent e )
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
} );
add( new JLabel( "Name:" ) ); mConfigurationName = new JTextField();
add( mConfigurationName, "span 2" ); mConfigurationName.setEnabled(false);
mConfigurationName.addFocusListener(new FocusListener()
{
@Override
public void focusLost(FocusEvent e)
{
save();
}
mTunerInfo = new JButton( "Tuner Info" ); @Override
mTunerInfo.setEnabled( false ); public void focusGained(FocusEvent e)
mTunerInfo.addActionListener( new ActionListener() {
{ }
@Override });
public void actionPerformed( ActionEvent e )
{
JOptionPane.showMessageDialog( FCD2TunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE );
}
} );
add( mTunerInfo );
SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value add(new JLabel("Name:"));
-1000.0, //min add(mConfigurationName, "span 2");
1000.0, //max
0.1 ); //step
mFrequencyCorrection = new JSpinner( model ); mTunerInfo = new JButton("Tuner Info");
mFrequencyCorrection.setEnabled( false ); mTunerInfo.setEnabled(false);
JSpinner.NumberEditor editor = mTunerInfo.addActionListener(new ActionListener()
(JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); {
@Override
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(FCD2TunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE);
}
});
add(mTunerInfo);
DecimalFormat format = editor.getFormat(); SpinnerModel model = new SpinnerNumberModel(0.0, //initial value
format.setMinimumFractionDigits( 1 ); -1000.0, //min
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); 1000.0, //max
0.1); //step
mFrequencyCorrection.addChangeListener( new ChangeListener() mFrequencyCorrection = new JSpinner(model);
{ mFrequencyCorrection.setEnabled(false);
@Override JSpinner.NumberEditor editor =
public void stateChanged( ChangeEvent e ) (JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
{
double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
try DecimalFormat format = editor.getFormat();
{ format.setMinimumFractionDigits(1);
mController.setFrequencyCorrection( value ); editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
save();
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog( FCD2TunerEditor.this, "FCD Pro Plus Tuner "
+ "Controller - couldn't apply frequency correction value: " + value +
e1.getLocalizedMessage() );
mLog.error( "FuncubeDongleProPlus Controller - couldn't apply " mFrequencyCorrection.addChangeListener(new ChangeListener()
+ "frequency correction value: " + value, e1 ); {
} @Override
} public void stateChanged(ChangeEvent e)
} ); {
double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue();
add( new JLabel( "PPM:" ) ); try
add( mFrequencyCorrection, "wrap" ); {
mController.setFrequencyCorrection(value);
save();
}
catch(SourceException e1)
{
JOptionPane.showMessageDialog(FCD2TunerEditor.this, "FCD Pro Plus Tuner "
+ "Controller - couldn't apply frequency correction value: " + value +
e1.getLocalizedMessage());
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); mLog.error("FuncubeDongleProPlus Controller - couldn't apply "
+ "frequency correction value: " + value, e1);
}
}
});
mLNAGain = new JCheckBox( "LNA Gain" ); add(new JLabel("PPM:"));
mLNAGain.setEnabled( false ); add(mFrequencyCorrection, "wrap");
mLNAGain.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent event )
{
try
{
mController.setLNAGain( mLNAGain.isSelected() );
save();
}
catch( SourceException e )
{
mLog.error( "Couldn't set LNA gain for FCD2", e );
}
}
} );
add( new JLabel( "" ) ); add(new JSeparator(JSeparator.HORIZONTAL), "span,grow");
add( mLNAGain );
/** mLNAGain = new JCheckBox("LNA Gain");
* Mixer Gain mLNAGain.setEnabled(false);
*/ mLNAGain.addActionListener(new ActionListener()
mMixerGain = new JCheckBox( "Mixer Gain" ); {
@Override
public void actionPerformed(ActionEvent event)
{
try
{
mController.setLNAGain(mLNAGain.isSelected());
save();
}
catch(SourceException e)
{
mLog.error("Couldn't set LNA gain for FCD2", e);
}
}
});
mMixerGain.addActionListener( new ActionListener() add(new JLabel(""));
{ add(mLNAGain);
@Override
public void actionPerformed( ActionEvent event )
{
try
{
mController.setMixerGain( mMixerGain.isSelected() );
save();
}
catch( SourceException e )
{
mLog.error( "Couldn't set mixer gain for FCD2", e );
}
}
} );
add( new JLabel( "" ) ); /**
add( mMixerGain ); * Mixer Gain
} */
mMixerGain = new JCheckBox("Mixer Gain");
/** mMixerGain.addActionListener(new ActionListener()
* Sets each of the tuner configuration controls to the enabled argument state {
*/ @Override
private void setControlsEnabled( boolean enabled ) public void actionPerformed(ActionEvent event)
{ {
if( mConfigurationName.isEnabled() != enabled ) try
{ {
mConfigurationName.setEnabled( enabled ); mController.setMixerGain(mMixerGain.isSelected());
} save();
}
catch(SourceException e)
{
mLog.error("Couldn't set mixer gain for FCD2", e);
}
}
});
if( mTunerInfo.isEnabled() != enabled ) add(new JLabel(""));
{ add(mMixerGain);
mTunerInfo.setEnabled( enabled ); }
}
if( mFrequencyCorrection.isEnabled() != enabled ) /**
{ * Sets each of the tuner configuration controls to the enabled argument state
mFrequencyCorrection.setEnabled( enabled ); */
} private void setControlsEnabled(boolean enabled)
{
if(mConfigurationName.isEnabled() != enabled)
{
mConfigurationName.setEnabled(enabled);
}
if( mLNAGain.isEnabled() != enabled ) if(mTunerInfo.isEnabled() != enabled)
{ {
mLNAGain.setEnabled( enabled ); mTunerInfo.setEnabled(enabled);
} }
if( mMixerGain.isEnabled() != enabled ) if(mFrequencyCorrection.isEnabled() != enabled)
{ {
mMixerGain.setEnabled( enabled ); mFrequencyCorrection.setEnabled(enabled);
} }
}
private String getTunerInfo() if(mLNAGain.isEnabled() != enabled)
{ {
StringBuilder sb = new StringBuilder(); mLNAGain.setEnabled(enabled);
}
sb.append( "<html><h3>Funcube Dongle Pro Plus Tuner</h3>" ); if(mMixerGain.isEnabled() != enabled)
{
mMixerGain.setEnabled(enabled);
}
}
sb.append( "<b>USB ID: </b>" ); private String getTunerInfo()
sb.append( mController.getUSBID() ); {
sb.append( "<br>" ); StringBuilder sb = new StringBuilder();
sb.append( "<b>USB Address: </b>" ); sb.append("<html><h3>Funcube Dongle Pro Plus Tuner</h3>");
sb.append( mController.getUSBAddress() );
sb.append( "<br>" );
sb.append( "<b>USB Speed: </b>" ); sb.append("<b>USB ID: </b>");
sb.append( mController.getUSBSpeed() ); sb.append(mController.getUSBID());
sb.append( "<br>" ); sb.append("<br>");
sb.append( "<b>Cellular Band: </b>" ); sb.append("<b>USB Address: </b>");
sb.append( mController.getConfiguration().getBandBlocking() ); sb.append(mController.getUSBAddress());
sb.append( "<br>" ); sb.append("<br>");
sb.append( "<b>Firmware: </b>" ); sb.append("<b>USB Speed: </b>");
sb.append( mController.getConfiguration().getFirmware() ); sb.append(mController.getUSBSpeed());
sb.append( "<br>" ); sb.append("<br>");
return sb.toString(); sb.append("<b>Cellular Band: </b>");
} sb.append(mController.getConfiguration().getBandBlocking());
sb.append("<br>");
@Override sb.append("<b>Firmware: </b>");
public void save() sb.append(mController.getConfiguration().getFirmware());
{ sb.append("<br>");
if( hasItem() && !mLoading )
{
FCD2TunerConfiguration config = getConfiguration();
config.setName( mConfigurationName.getText() ); return sb.toString();
}
double value = ((SpinnerNumberModel)mFrequencyCorrection @Override
.getModel()).getNumber().doubleValue(); public void save()
config.setFrequencyCorrection( value ); {
if(hasItem() && !mLoading)
{
FCD2TunerConfiguration config = getConfiguration();
config.setGainLNA( mLNAGain.isSelected() ); config.setName(mConfigurationName.getText());
config.setGainMixer( mMixerGain.isSelected() );
getTunerConfigurationModel().broadcast( double value = ((SpinnerNumberModel)mFrequencyCorrection
new TunerConfigurationEvent( getConfiguration(), Event.CHANGE ) ); .getModel()).getNumber().doubleValue();
} config.setFrequencyCorrection(value);
}
@Override config.setGainLNA(mLNAGain.isSelected());
public void setItem( TunerConfiguration tunerConfiguration ) config.setGainMixer(mMixerGain.isSelected());
{
super.setItem( tunerConfiguration );
//Toggle loading so that we don't fire a change event and schedule a settings file save getTunerConfigurationModel().broadcast(
mLoading = true; new TunerConfigurationEvent(getConfiguration(), Event.CHANGE));
}
}
if( hasItem() ) @Override
{ public void setItem(TunerConfiguration tunerConfiguration)
FCD2TunerConfiguration config = getConfiguration(); {
super.setItem(tunerConfiguration);
//Toggle loading so that we don't fire a change event and schedule a settings file save
mLoading = true;
if(hasItem())
{
FCD2TunerConfiguration config = getConfiguration();
if( tunerConfiguration.isAssigned() ) if(tunerConfiguration.isAssigned())
{ {
setControlsEnabled( true ); setControlsEnabled(true);
mConfigurationName.setText( config.getName() ); mConfigurationName.setText(config.getName());
mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); mFrequencyCorrection.setValue(config.getFrequencyCorrection());
mLNAGain.setSelected( config.getGainLNA() ); mLNAGain.setSelected(config.getGainLNA());
mMixerGain.setSelected( config.getGainMixer() ); mMixerGain.setSelected(config.getGainMixer());
} }
else else
{ {
setControlsEnabled( false ); setControlsEnabled(false);
mConfigurationName.setText( config.getName() ); mConfigurationName.setText(config.getName());
} }
} }
else else
{ {
setControlsEnabled( false ); setControlsEnabled(false);
mConfigurationName.setText( "" ); mConfigurationName.setText("");
} }
mLoading = false; mLoading = false;
} }
} }

View File

@@ -1,7 +1,6 @@
/******************************************************************************* /*******************************************************************************
* *********************************************************************************************************************
* sdr-trunk * sdr-trunk
* Copyright (C) 2014-2017 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * 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 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
@@ -12,7 +11,7 @@
* *
* You should have received a copy of the GNU General Public License along with this program. * You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/> * If not, see <http://www.gnu.org/licenses/>
* ********************************************************************************************************************* *
******************************************************************************/ ******************************************************************************/
package io.github.dsheirer.source.tuner.frequency; package io.github.dsheirer.source.tuner.frequency;
@@ -28,248 +27,284 @@ import java.util.List;
public class FrequencyController public class FrequencyController
{ {
private final static Logger mLog = LoggerFactory.getLogger(FrequencyController.class); private final static Logger mLog = LoggerFactory.getLogger(FrequencyController.class);
private Tunable mTunable; private Tunable mTunable;
private long mFrequency = 101100000; private long mFrequency = 101100000;
private long mTunedFrequency = 101100000; private long mTunedFrequency = 101100000;
private long mMinimumFrequency; private long mMinimumFrequency;
private long mMaximumFrequency; private long mMaximumFrequency;
private double mFrequencyCorrection = 0.0d; private double mFrequencyCorrection = 0.0d;
private double mSampleRate = 0.0d; private double mSampleRate = 0.0d;
private boolean mLocked = false;
private List<ISourceEventProcessor> mProcessors = new ArrayList<>(); private List<ISourceEventProcessor> mProcessors = new ArrayList<>();
public FrequencyController(Tunable tunable, long minFrequency, long maxFrequency, double frequencyCorrection) public FrequencyController(Tunable tunable, long minFrequency, long maxFrequency, double frequencyCorrection)
{ {
mTunable = tunable; mTunable = tunable;
mMinimumFrequency = minFrequency; mMinimumFrequency = minFrequency;
mMaximumFrequency = maxFrequency; mMaximumFrequency = maxFrequency;
mFrequencyCorrection = frequencyCorrection; mFrequencyCorrection = frequencyCorrection;
} }
/** /**
* Get bandwidth in hertz * Indicates if this frequency controller is locked by a remote process. A locked state indicates that neither
*/ * the frequency nor the sample rate should be changed. The remote process will typically be a downstream
public int getBandwidth() * consumer of the data produced by the device being controlled (ie polyphase channelizer) that does not want
{ * the sample rate or frequency to be changed while processing is ongoing.
return (int)mSampleRate; *
} * @return true if locked or false if not locked.
*/
public boolean isLocked()
{
return mLocked;
}
/** /**
* Set sample rate in hertz * Sets the lock state for this frequency controller. Set to true when a consumer process requires that the
*/ * frequency and sample rate controls be locked so that only the singular consumer process makes changes. This
public void setSampleRate(int sampleRate) throws SourceException * is primarily to lock down user interface controls when the polyphase channelizer is producing channels.
{ *
mSampleRate = sampleRate; * @param locked state
*/
public void setLocked(boolean locked) throws SourceException
{
mLocked = locked;
broadcastSampleRateChange(); if(mLocked)
} {
broadcast(SourceEvent.lockedState());
}
else
{
broadcast(SourceEvent.unlockedState());
}
}
/** /**
* Get sample rate in hertz * Get bandwidth in hertz
*/ */
public double getSampleRate() public int getBandwidth()
{ {
return mSampleRate; return (int)mSampleRate;
} }
/** /**
* Get frequency in hertz * Set sample rate in hertz
*/ */
public long getFrequency() public void setSampleRate(int sampleRate) throws SourceException
{ {
return mFrequency; mSampleRate = sampleRate;
}
/** broadcastSampleRateChange();
* Set frequency }
*
* @param frequency in hertz
* @throws SourceException if tunable doesn't support tuning a corrected
* version of the requested frequency
*/
public void setFrequency(long frequency) throws SourceException
{
setFrequency(frequency, true);
}
/** /**
* Indicates if the specified frequency can be tuned (ie is within min/max frequency) by this controller. * Get sample rate in hertz
* @param frequency to evaluate */
* @return true if the frequency falls within the tuning range of this controller public double getSampleRate()
*/ {
public boolean canTune(long frequency) return mSampleRate;
{ }
return getMinimumFrequency() <= frequency && frequency <= getMaximumFrequency();
}
/** /**
* Set frequency with optional broadcast of frequency change event. This * Get frequency in hertz
* method supports changing the frequency correction value without */
* broadcasting a frequency change event. public long getFrequency()
*/ {
private void setFrequency(long frequency, boolean broadcastChange) throws SourceException return mFrequency;
{ }
long tunedFrequency = getTunedFrequency(frequency);
if(tunedFrequency < mMinimumFrequency) /**
{ * Set frequency
throw new InvalidFrequencyException("Requested frequency not valid", frequency, mMinimumFrequency); *
} * @param frequency in hertz
* @throws SourceException if tunable doesn't support tuning a corrected
* version of the requested frequency
*/
public void setFrequency(long frequency) throws SourceException
{
setFrequency(frequency, true);
}
if(tunedFrequency > mMaximumFrequency) /**
{ * Indicates if the specified frequency can be tuned (ie is within min/max frequency) by this controller.
throw new InvalidFrequencyException("Requested frequency not valid", frequency, mMaximumFrequency); *
} * @param frequency to evaluate
* @return true if the frequency falls within the tuning range of this controller
*/
public boolean canTune(long frequency)
{
return getMinimumFrequency() <= frequency && frequency <= getMaximumFrequency();
}
mFrequency = frequency; /**
* Set frequency with optional broadcast of frequency change event. This
* method supports changing the frequency correction value without
* broadcasting a frequency change event.
*/
private void setFrequency(long frequency, boolean broadcastChange) throws SourceException
{
long tunedFrequency = getTunedFrequency(frequency);
mTunedFrequency = tunedFrequency; if(tunedFrequency < mMinimumFrequency)
{
throw new InvalidFrequencyException("Requested frequency not valid", frequency, mMinimumFrequency);
}
if(mTunable != null) if(tunedFrequency > mMaximumFrequency)
{ {
mTunable.setTunedFrequency(mTunedFrequency); throw new InvalidFrequencyException("Requested frequency not valid", frequency, mMaximumFrequency);
} }
/* Broadcast to all listeners that the frequency has changed */ mFrequency = frequency;
if(broadcastChange)
{
broadcastFrequencyChange();
}
}
public long getTunedFrequency() mTunedFrequency = tunedFrequency;
{
return mTunedFrequency;
}
public long getMinimumFrequency() if(mTunable != null)
{ {
return mMinimumFrequency; mTunable.setTunedFrequency(mTunedFrequency);
} }
public long getMaximumFrequency() /* Broadcast to all listeners that the frequency has changed */
{ if(broadcastChange)
return mMaximumFrequency; {
} broadcastFrequencyChange();
}
}
/** public long getTunedFrequency()
* Calculate the tuned frequency by adding frequency correction to the {
* corrected frequency. return mTunedFrequency;
* }
* @param correctedFrequency
*/
private long getTunedFrequency(long correctedFrequency)
{
return (long)((double)correctedFrequency /
(1.0 + (mFrequencyCorrection / 1000000.0)));
}
/** public long getMinimumFrequency()
* Calculate the corrected frequency by subtracting frequency correction {
* from the tuned frequency. return mMinimumFrequency;
* }
* @param tunedFrequency
*/
@SuppressWarnings("unused")
private long getCorrectedFrequency(long tunedFrequency)
{
return (long)((double)tunedFrequency /
(1.0 - (mFrequencyCorrection / 1000000.0)));
}
public double getFrequencyCorrection() public long getMaximumFrequency()
{ {
return mFrequencyCorrection; return mMaximumFrequency;
} }
public void setFrequencyCorrection(double correction) throws SourceException /**
{ * Calculate the tuned frequency by adding frequency correction to the
mFrequencyCorrection = correction; * corrected frequency.
*
* @param correctedFrequency
*/
private long getTunedFrequency(long correctedFrequency)
{
return (long)((double)correctedFrequency /
(1.0 + (mFrequencyCorrection / 1000000.0)));
}
if(mFrequency > 0) /**
{ * Calculate the corrected frequency by subtracting frequency correction
setFrequency(mFrequency, true); * from the tuned frequency.
} *
* @param tunedFrequency
*/
@SuppressWarnings("unused")
private long getCorrectedFrequency(long tunedFrequency)
{
return (long)((double)tunedFrequency /
(1.0 - (mFrequencyCorrection / 1000000.0)));
}
broadcastFrequencyCorrectionChange(); public double getFrequencyCorrection()
} {
return mFrequencyCorrection;
}
/** public void setFrequencyCorrection(double correction) throws SourceException
* Adds listener to receive frequency change events {
*/ mFrequencyCorrection = correction;
public void addListener(ISourceEventProcessor processor)
{
if(!mProcessors.contains(processor))
{
mProcessors.add(processor);
}
}
/** if(mFrequency > 0)
* Removes listener from receiving frequency change events {
*/ setFrequency(mFrequency, true);
public void removeFrequencyChangeProcessor(ISourceEventProcessor processor) }
{
mProcessors.remove(processor); broadcastFrequencyCorrectionChange();
} }
/**
* Adds listener to receive frequency change events
*/
public void addListener(ISourceEventProcessor processor)
{
if(!mProcessors.contains(processor))
{
mProcessors.add(processor);
}
}
/**
* Removes listener from receiving frequency change events
*/
public void removeFrequencyChangeProcessor(ISourceEventProcessor processor)
{
mProcessors.remove(processor);
}
/** /**
* Broadcasts a change/update to the current (uncorrected) frequency or the * Broadcasts a change/update to the current (uncorrected) frequency or the
* bandwidth/sample rate value. * bandwidth/sample rate value.
*/ */
protected void broadcastFrequencyChange() throws SourceException protected void broadcastFrequencyChange() throws SourceException
{ {
broadcast(SourceEvent.frequencyChange(mFrequency)); broadcast(SourceEvent.frequencyChange(mFrequency));
} }
/** /**
* Broadcast a frequency error/correction value change * Broadcast a frequency error/correction value change
*/ */
protected void broadcastFrequencyCorrectionChange() throws SourceException protected void broadcastFrequencyCorrectionChange() throws SourceException
{ {
broadcast(SourceEvent.frequencyCorrectionChange((int)mFrequencyCorrection)); broadcast(SourceEvent.frequencyCorrectionChange((int)mFrequencyCorrection));
} }
/** /**
* Broadcasts a sample rate change * Broadcasts a sample rate change
*/ */
protected void broadcastSampleRateChange() throws SourceException protected void broadcastSampleRateChange() throws SourceException
{ {
broadcast(SourceEvent.sampleRateChange(mSampleRate)); broadcast(SourceEvent.sampleRateChange(mSampleRate));
} }
public void broadcast(SourceEvent event) throws SourceException public void broadcast(SourceEvent event) throws SourceException
{ {
for(ISourceEventProcessor processor : mProcessors) for(ISourceEventProcessor processor : mProcessors)
{ {
processor.process(event); processor.process(event);
} }
} }
public interface Tunable public interface Tunable
{ {
/** /**
* Gets the tuned frequency of the device * Gets the tuned frequency of the device
*/ */
public long getTunedFrequency() throws SourceException; public long getTunedFrequency() throws SourceException;
/** /**
* Sets the tuned frequency of the device * Sets the tuned frequency of the device
*/ */
public void setTunedFrequency(long frequency) throws SourceException; public void setTunedFrequency(long frequency) throws SourceException;
/** /**
* Gets the current bandwidth setting of the device * Gets the current bandwidth setting of the device
*/ */
public double getCurrentSampleRate() throws SourceException; public double getCurrentSampleRate() throws SourceException;
/** /**
* Indicates if this tunable can tune the frequency * Indicates if this tunable can tune the frequency
*/ */
public boolean canTune(long frequency); public boolean canTune(long frequency);
} }
} }

View File

@@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
* sdr-trunk * sdr-trunk
* Copyright (C) 2014-2017 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * 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 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
@@ -41,6 +41,7 @@ import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.usb.UsbException; import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
@@ -51,7 +52,7 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger( HackRFTunerEditor.class ); private final static Logger mLog = LoggerFactory.getLogger(HackRFTunerEditor.class);
private JTextField mConfigurationName; private JTextField mConfigurationName;
private JButton mTunerInfo; private JButton mTunerInfo;
@@ -64,9 +65,9 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
private HackRFTunerController mController; private HackRFTunerController mController;
public HackRFTunerEditor( TunerConfigurationModel tunerConfigurationModel, HackRFTuner tuner ) public HackRFTunerEditor(TunerConfigurationModel tunerConfigurationModel, HackRFTuner tuner)
{ {
super( tunerConfigurationModel ); super(tunerConfigurationModel);
mController = tuner.getController(); mController = tuner.getController();
@@ -75,7 +76,7 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
private HackRFTunerConfiguration getConfiguration() private HackRFTunerConfiguration getConfiguration()
{ {
if( hasItem() ) if(hasItem())
{ {
return (HackRFTunerConfiguration)getItem(); return (HackRFTunerConfiguration)getItem();
} }
@@ -83,241 +84,257 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
return null; return null;
} }
private void init() @Override
public void setSampleRateControl(boolean enabled)
{ {
setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", EventQueue.invokeLater(new Runnable()
"[][][][][][][grow]" ) );
add( new JLabel( "HackRF Tuner Configuration" ), "span,align center" );
mConfigurationName = new JTextField();
mConfigurationName.setEnabled( false );
mConfigurationName.addFocusListener( new FocusListener()
{ {
@Override @Override
public void focusLost( FocusEvent e ) public void run()
{
mComboSampleRate.setEnabled(enabled);
}
});
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
"[][][][][][][grow]"));
add(new JLabel("HackRF Tuner Configuration"), "span,align center");
mConfigurationName = new JTextField();
mConfigurationName.setEnabled(false);
mConfigurationName.addFocusListener(new FocusListener()
{
@Override
public void focusLost(FocusEvent e)
{ {
save(); save();
} }
@Override
public void focusGained( FocusEvent e ) {}
} );
add( new JLabel( "Name:" ) );
add( mConfigurationName, "span 2" );
mTunerInfo = new JButton( "Tuner Info" );
mTunerInfo.setEnabled( false );
mTunerInfo.addActionListener( new ActionListener()
{
@Override @Override
public void actionPerformed( ActionEvent e ) public void focusGained(FocusEvent e)
{ {
JOptionPane.showMessageDialog( HackRFTunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE );
} }
} ); });
add( mTunerInfo );
mComboSampleRate = new JComboBox<>( HackRFSampleRate.values() ); add(new JLabel("Name:"));
mComboSampleRate.setEnabled( false ); add(mConfigurationName, "span 2");
mComboSampleRate.addActionListener( new ActionListener()
mTunerInfo = new JButton("Tuner Info");
mTunerInfo.setEnabled(false);
mTunerInfo.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent e ) public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(HackRFTunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE);
}
});
add(mTunerInfo);
mComboSampleRate = new JComboBox<>(HackRFSampleRate.values());
mComboSampleRate.setEnabled(false);
mComboSampleRate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{ {
HackRFSampleRate sampleRate = HackRFSampleRate sampleRate =
(HackRFSampleRate)mComboSampleRate.getSelectedItem(); (HackRFSampleRate)mComboSampleRate.getSelectedItem();
try try
{ {
mController.setSampleRate( sampleRate ); mController.setSampleRate(sampleRate);
save(); save();
} }
catch ( SourceException|UsbException e2 ) catch(SourceException | UsbException e2)
{ {
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the sample rate setting [" + sampleRate.getLabel() + + " - couldn't apply the sample rate setting [" + sampleRate.getLabel() +
"] " + e2.getLocalizedMessage() ); "] " + e2.getLocalizedMessage());
mLog.error( "HackRF Tuner Controller - couldn't apply sample rate setting [" + mLog.error("HackRF Tuner Controller - couldn't apply sample rate setting [" +
sampleRate.getLabel() + "]", e ); sampleRate.getLabel() + "]", e);
} }
} }
} ); });
add( new JLabel( "Sample Rate:" ) ); add(new JLabel("Sample Rate:"));
add( mComboSampleRate ); add(mComboSampleRate);
SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value SpinnerModel model = new SpinnerNumberModel(0.0, //initial value
-1000.0, //min -1000.0, //min
1000.0, //max 1000.0, //max
0.1 ); //step 0.1); //step
mFrequencyCorrection = new JSpinner( model ); mFrequencyCorrection = new JSpinner(model);
mFrequencyCorrection.setEnabled( false ); mFrequencyCorrection.setEnabled(false);
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); JSpinner.NumberEditor editor = (JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
DecimalFormat format = editor.getFormat(); DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits( 1 ); format.setMinimumFractionDigits(1);
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
mFrequencyCorrection.addChangeListener( new ChangeListener() mFrequencyCorrection.addChangeListener(new ChangeListener()
{ {
@Override @Override
public void stateChanged( ChangeEvent e ) public void stateChanged(ChangeEvent e)
{ {
final double value = ((SpinnerNumberModel)mFrequencyCorrection final double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue(); .getModel()).getNumber().doubleValue();
try try
{ {
mController.setFrequencyCorrection( value ); mController.setFrequencyCorrection(value);
save(); save();
} }
catch ( SourceException e1 ) catch(SourceException e1)
{ {
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply frequency correction value: " + value + + " - couldn't apply frequency correction value: " + value +
e1.getLocalizedMessage() ); e1.getLocalizedMessage());
mLog.error( "HackRF Tuner Controller - couldn't apply frequency correction " mLog.error("HackRF Tuner Controller - couldn't apply frequency correction "
+ "value: " + value, e1 ); + "value: " + value, e1);
} }
} }
} ); });
add( new JLabel( "PPM:" ) ); add(new JLabel("PPM:"));
add( mFrequencyCorrection ); add(mFrequencyCorrection);
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); add(new JSeparator(JSeparator.HORIZONTAL), "span,grow");
add( new JLabel( "Gain" ) ); add(new JLabel("Gain"));
add( new JLabel( "" ), "span 2" ); //filler add(new JLabel(""), "span 2"); //filler
mAmplifier = new JToggleButton( "Amplifier" ); mAmplifier = new JToggleButton("Amplifier");
mAmplifier.setEnabled( false ); mAmplifier.setEnabled(false);
mAmplifier.addActionListener( new ActionListener() mAmplifier.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent arg0 ) public void actionPerformed(ActionEvent arg0)
{ {
try try
{ {
mController.setAmplifierEnabled( mAmplifier.isSelected() ); mController.setAmplifierEnabled(mAmplifier.isSelected());
save(); save();
} }
catch ( UsbException e ) catch(UsbException e)
{ {
mLog.error( "couldn't enable/disable amplifier", e ); mLog.error("couldn't enable/disable amplifier", e);
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "Couldn't change amplifier setting", JOptionPane.showMessageDialog(HackRFTunerEditor.this, "Couldn't change amplifier setting",
"Error changing amplifier setting", JOptionPane.ERROR_MESSAGE ); "Error changing amplifier setting", JOptionPane.ERROR_MESSAGE);
} }
} }
} ); });
add( mAmplifier ); add(mAmplifier);
mComboLNAGain = new JComboBox<HackRFLNAGain>( HackRFLNAGain.values() ); mComboLNAGain = new JComboBox<HackRFLNAGain>(HackRFLNAGain.values());
mComboLNAGain.setEnabled( false ); mComboLNAGain.setEnabled(false);
mComboLNAGain.addActionListener( new ActionListener() mComboLNAGain.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent arg0 ) public void actionPerformed(ActionEvent arg0)
{ {
try try
{ {
HackRFLNAGain lnaGain = (HackRFLNAGain)mComboLNAGain.getSelectedItem(); HackRFLNAGain lnaGain = (HackRFLNAGain)mComboLNAGain.getSelectedItem();
if ( lnaGain == null ) if(lnaGain == null)
{ {
lnaGain = HackRFLNAGain.GAIN_0; lnaGain = HackRFLNAGain.GAIN_0;
} }
mController.setLNAGain( lnaGain ); mController.setLNAGain(lnaGain);
save(); save();
} }
catch ( UsbException e ) catch(UsbException e)
{ {
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the LNA gain setting - " + e.getLocalizedMessage() ); + " - couldn't apply the LNA gain setting - " + e.getLocalizedMessage());
mLog.error( "HackRF Tuner Controller - couldn't apply LNA gain setting - ", e ); mLog.error("HackRF Tuner Controller - couldn't apply LNA gain setting - ", e);
} }
} }
} ); });
mComboLNAGain.setToolTipText( "<html>LNA Gain. Adjust to set the IF gain</html>" ); mComboLNAGain.setToolTipText("<html>LNA Gain. Adjust to set the IF gain</html>");
add( new JLabel( "LNA:" ) ); add(new JLabel("LNA:"));
add( mComboLNAGain ); add(mComboLNAGain);
mComboVGAGain = new JComboBox<HackRFVGAGain>( HackRFVGAGain.values() ); mComboVGAGain = new JComboBox<HackRFVGAGain>(HackRFVGAGain.values());
mComboVGAGain.addActionListener( new ActionListener() mComboVGAGain.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed( ActionEvent arg0 ) public void actionPerformed(ActionEvent arg0)
{ {
try try
{ {
HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem(); HackRFVGAGain vgaGain = (HackRFVGAGain)mComboVGAGain.getSelectedItem();
if( vgaGain == null ) if(vgaGain == null)
{ {
vgaGain = HackRFVGAGain.GAIN_4; vgaGain = HackRFVGAGain.GAIN_4;
} }
mController.setVGAGain( vgaGain ); mController.setVGAGain(vgaGain);
save(); save();
} }
catch ( UsbException e ) catch(UsbException e)
{ {
JOptionPane.showMessageDialog( HackRFTunerEditor.this, "HackRF Tuner Controller" JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
+ " - couldn't apply the VGA gain setting - " + e.getLocalizedMessage() ); + " - couldn't apply the VGA gain setting - " + e.getLocalizedMessage());
mLog.error( "HackRF Tuner Controller - couldn't apply VGA gain setting", e ); mLog.error("HackRF Tuner Controller - couldn't apply VGA gain setting", e);
} }
} }
} ); });
mComboVGAGain.setToolTipText( "<html>VGA Gain. Adjust to set the baseband gain</html>" ); mComboVGAGain.setToolTipText("<html>VGA Gain. Adjust to set the baseband gain</html>");
add( new JLabel( "VGA:" ) ); add(new JLabel("VGA:"));
add( mComboVGAGain ); add(mComboVGAGain);
} }
/** /**
* Sets each of the tuner configuration controls to the enabled argument state * Sets each of the tuner configuration controls to the enabled argument state
*/ */
private void setControlsEnabled( boolean enabled ) private void setControlsEnabled(boolean enabled)
{ {
if( mConfigurationName.isEnabled() != enabled ) if(mConfigurationName.isEnabled() != enabled)
{ {
mConfigurationName.setEnabled( enabled ); mConfigurationName.setEnabled(enabled);
} }
if( mTunerInfo.isEnabled() != enabled ) if(mTunerInfo.isEnabled() != enabled)
{ {
mTunerInfo.setEnabled( enabled ); mTunerInfo.setEnabled(enabled);
} }
if( mFrequencyCorrection.isEnabled() != enabled ) if(mFrequencyCorrection.isEnabled() != enabled)
{ {
mFrequencyCorrection.setEnabled( enabled ); mFrequencyCorrection.setEnabled(enabled);
} }
if( mComboSampleRate.isEnabled() != enabled ) if(mComboSampleRate.isEnabled() != enabled)
{ {
mComboSampleRate.setEnabled( enabled ); mComboSampleRate.setEnabled(enabled);
} }
if( mAmplifier.isEnabled() != enabled ) if(mAmplifier.isEnabled() != enabled)
{ {
mAmplifier.setEnabled( enabled ); mAmplifier.setEnabled(enabled);
} }
if( mComboLNAGain.isEnabled() != enabled ) if(mComboLNAGain.isEnabled() != enabled)
{ {
mComboLNAGain.setEnabled( enabled ); mComboLNAGain.setEnabled(enabled);
} }
if( mComboVGAGain.isEnabled() != enabled ) if(mComboVGAGain.isEnabled() != enabled)
{ {
mComboVGAGain.setEnabled( enabled ); mComboVGAGain.setEnabled(enabled);
} }
} }
@@ -329,18 +346,18 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
{ {
board = mController.getBoardID(); board = mController.getBoardID();
} }
catch ( UsbException e ) catch(UsbException e)
{ {
mLog.error( "couldn't read HackRF board identifier", e ); mLog.error("couldn't read HackRF board identifier", e);
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( "<html><h3>HackRF Tuner</h3>" ); sb.append("<html><h3>HackRF Tuner</h3>");
sb.append( "<b>Board: </b>" ); sb.append("<b>Board: </b>");
sb.append( board.getLabel() ); sb.append(board.getLabel());
sb.append( "<br>" ); sb.append("<br>");
HackRFTunerController.Serial serial = null; HackRFTunerController.Serial serial = null;
@@ -348,25 +365,25 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
{ {
serial = mController.getSerial(); serial = mController.getSerial();
} }
catch( Exception e ) catch(Exception e)
{ {
mLog.error( "couldn't read HackRF serial number", e ); mLog.error("couldn't read HackRF serial number", e);
} }
if( serial != null ) if(serial != null)
{ {
sb.append( "<b>Serial: </b>" ); sb.append("<b>Serial: </b>");
sb.append( serial.getSerialNumber() ); sb.append(serial.getSerialNumber());
sb.append( "<br>" ); sb.append("<br>");
sb.append( "<b>Part: </b>" ); sb.append("<b>Part: </b>");
sb.append( serial.getPartID() ); sb.append(serial.getPartID());
sb.append( "<br>" ); sb.append("<br>");
} }
else else
{ {
sb.append( "<b>Serial: Unknown</b><br>" ); sb.append("<b>Serial: Unknown</b><br>");
sb.append( "<b>Part: Unknown</b><br>" ); sb.append("<b>Part: Unknown</b><br>");
} }
String firmware = null; String firmware = null;
@@ -375,58 +392,61 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
{ {
firmware = mController.getFirmwareVersion(); firmware = mController.getFirmwareVersion();
} }
catch( Exception e ) catch(Exception e)
{ {
mLog.error( "couldn't read HackRF firmware version", e ); mLog.error("couldn't read HackRF firmware version", e);
} }
if( firmware != null ) if(firmware != null)
{ {
sb.append( "<b>Firmware: </b>" ); sb.append("<b>Firmware: </b>");
sb.append( firmware ); sb.append(firmware);
sb.append( "<br>" ); sb.append("<br>");
} }
else else
{ {
sb.append( "<b>Firmware: Unknown</b><br>" ); sb.append("<b>Firmware: Unknown</b><br>");
} }
return sb.toString(); return sb.toString();
} }
@Override @Override
public void setItem( TunerConfiguration tunerConfiguration ) public void setItem(TunerConfiguration tunerConfiguration)
{ {
super.setItem( tunerConfiguration ); super.setItem(tunerConfiguration);
//Toggle loading so that we don't fire a change event and schedule a settings file save //Toggle loading so that we don't fire a change event and schedule a settings file save
mLoading = true; mLoading = true;
if( hasItem() ) if(hasItem())
{ {
HackRFTunerConfiguration config = getConfiguration(); HackRFTunerConfiguration config = getConfiguration();
if( tunerConfiguration.isAssigned() ) if(tunerConfiguration.isAssigned())
{ {
setControlsEnabled( true ); setControlsEnabled(true);
mConfigurationName.setText( config.getName() ); mConfigurationName.setText(config.getName());
mComboSampleRate.setSelectedItem( config.getSampleRate() ); mComboSampleRate.setSelectedItem(config.getSampleRate());
mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); mFrequencyCorrection.setValue(config.getFrequencyCorrection());
mAmplifier.setSelected( config.getAmplifierEnabled() ); mAmplifier.setSelected(config.getAmplifierEnabled());
mComboLNAGain.setSelectedItem( config.getLNAGain() ); mComboLNAGain.setSelectedItem(config.getLNAGain());
mComboVGAGain.setSelectedItem( config.getVGAGain() ); mComboVGAGain.setSelectedItem(config.getVGAGain());
//Update enabled state to reflect when frequency and sample rate controls are locked
mComboSampleRate.setEnabled(!mController.isLocked());
} }
else else
{ {
setControlsEnabled( false ); setControlsEnabled(false);
mConfigurationName.setText( config.getName() ); mConfigurationName.setText(config.getName());
} }
} }
else else
{ {
setControlsEnabled( false ); setControlsEnabled(false);
mConfigurationName.setText( "" ); mConfigurationName.setText("");
} }
mLoading = false; mLoading = false;
@@ -435,22 +455,22 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
@Override @Override
public void save() public void save()
{ {
if( hasItem() && !mLoading ) if(hasItem() && !mLoading)
{ {
HackRFTunerConfiguration config = getConfiguration(); HackRFTunerConfiguration config = getConfiguration();
config.setName( mConfigurationName.getText() ); config.setName(mConfigurationName.getText());
double value = ((SpinnerNumberModel)mFrequencyCorrection double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue(); .getModel()).getNumber().doubleValue();
config.setFrequencyCorrection( value ); config.setFrequencyCorrection(value);
config.setSampleRate( (HackRFSampleRate)mComboSampleRate.getSelectedItem() ); config.setSampleRate((HackRFSampleRate)mComboSampleRate.getSelectedItem());
config.setAmplifierEnabled( mAmplifier.isSelected() ); config.setAmplifierEnabled(mAmplifier.isSelected());
config.setLNAGain( (HackRFLNAGain)mComboLNAGain.getSelectedItem() ); config.setLNAGain((HackRFLNAGain)mComboLNAGain.getSelectedItem());
config.setVGAGain( (HackRFVGAGain)mComboVGAGain.getSelectedItem() ); config.setVGAGain((HackRFVGAGain)mComboVGAGain.getSelectedItem());
getTunerConfigurationModel().broadcast( getTunerConfigurationModel().broadcast(
new TunerConfigurationEvent( getConfiguration(), TunerConfigurationEvent.Event.CHANGE ) ); new TunerConfigurationEvent(getConfiguration(), TunerConfigurationEvent.Event.CHANGE));
} }
} }
} }

View File

@@ -433,6 +433,9 @@ public class TunerChannelSourceManager extends ChannelSourceManager
case NOTIFICATION_CHANNEL_COUNT_CHANGE: case NOTIFICATION_CHANNEL_COUNT_CHANGE:
//Rebroadcast this event to any registered listeners (ie tuner and tuner controller) //Rebroadcast this event to any registered listeners (ie tuner and tuner controller)
broadcast(sourceEvent); broadcast(sourceEvent);
//Lock the frequency and sample rate controls on the tuner controller so users can't change them
//when the polyphase manager has channels allocated
mTunerController.setLocked(getTunerChannelCount() > 0);
break; break;
default: default:
mLog.info("Unrecognized source event: " + sourceEvent); mLog.info("Unrecognized source event: " + sourceEvent);

View File

@@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
* sdr-trunk * sdr-trunk
* Copyright (C) 2014-2017 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * 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 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
@@ -45,6 +45,7 @@ import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.usb.UsbException; import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
@@ -53,442 +54,461 @@ import java.text.DecimalFormat;
public class E4KTunerEditor extends TunerConfigurationEditor public class E4KTunerEditor extends TunerConfigurationEditor
{ {
private final static Logger mLog = LoggerFactory.getLogger( E4KTunerEditor.class ); private final static Logger mLog = LoggerFactory.getLogger(E4KTunerEditor.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JTextField mConfigurationName; private JTextField mConfigurationName;
private JButton mTunerInfo; private JButton mTunerInfo;
private JComboBox<SampleRate> mComboSampleRate; private JComboBox<SampleRate> mComboSampleRate;
private JSpinner mFrequencyCorrection; private JSpinner mFrequencyCorrection;
private JComboBox<E4KGain> mComboMasterGain; private JComboBox<E4KGain> mComboMasterGain;
private JComboBox<E4KMixerGain> mComboMixerGain; private JComboBox<E4KMixerGain> mComboMixerGain;
private JComboBox<E4KLNAGain> mComboLNAGain; private JComboBox<E4KLNAGain> mComboLNAGain;
private JComboBox<E4KEnhanceGain> mComboEnhanceGain; private JComboBox<E4KEnhanceGain> mComboEnhanceGain;
private E4KTunerController mController; private E4KTunerController mController;
private boolean mLoading; private boolean mLoading;
public E4KTunerEditor( TunerConfigurationModel tunerConfigurationModel, RTL2832Tuner tuner ) public E4KTunerEditor(TunerConfigurationModel tunerConfigurationModel, RTL2832Tuner tuner)
{ {
super( tunerConfigurationModel ); super(tunerConfigurationModel);
mController = (E4KTunerController)tuner.getController(); mController = (E4KTunerController)tuner.getController();
init(); init();
} }
private E4KTunerConfiguration getConfiguration() private E4KTunerConfiguration getConfiguration()
{ {
if( hasItem() ) if(hasItem())
{ {
return (E4KTunerConfiguration)getItem(); return (E4KTunerConfiguration)getItem();
} }
return null; return null;
} }
private void init() @Override
{ public void setSampleRateControl(boolean enabled)
setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", {
"[][][][][][][][grow]" ) ); EventQueue.invokeLater(new Runnable()
{
add( new JLabel( "E4000 Tuner Configuration" ), "span,align center" ); @Override
public void run()
/** {
* Tuner Configuration Name mComboSampleRate.setEnabled(enabled);
*/ }
add( new JLabel( "Name:" ) ); });
mConfigurationName = new JTextField(); }
mConfigurationName.setEnabled( false );
mConfigurationName.addFocusListener( new FocusListener() private void init()
{ {
@Override setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
public void focusLost( FocusEvent e ) "[][][][][][][][grow]"));
{
save(); add(new JLabel("E4000 Tuner Configuration"), "span,align center");
}
@Override /**
public void focusGained( FocusEvent e ) {} * Tuner Configuration Name
} ); */
add(new JLabel("Name:"));
add( mConfigurationName, "span 2" ); mConfigurationName = new JTextField();
mConfigurationName.setEnabled(false);
mTunerInfo = new JButton( "Tuner Info" ); mConfigurationName.addFocusListener(new FocusListener()
mTunerInfo.setEnabled( false ); {
mTunerInfo.addActionListener( new ActionListener() @Override
{ public void focusLost(FocusEvent e)
@Override {
public void actionPerformed( ActionEvent e ) save();
{ }
JOptionPane.showMessageDialog( E4KTunerEditor.this, getTunerInfo(),
"Tuner Info", JOptionPane.INFORMATION_MESSAGE ); @Override
} public void focusGained(FocusEvent e)
} ); {
add( mTunerInfo ); }
});
mComboSampleRate = new JComboBox<>( SampleRate.values() );
mComboSampleRate.setEnabled( false ); add(mConfigurationName, "span 2");
mComboSampleRate.addActionListener( new ActionListener()
{ mTunerInfo = new JButton("Tuner Info");
@Override mTunerInfo.setEnabled(false);
public void actionPerformed( ActionEvent e ) mTunerInfo.addActionListener(new ActionListener()
{ {
SampleRate sampleRate = (SampleRate)mComboSampleRate.getSelectedItem(); @Override
public void actionPerformed(ActionEvent e)
try {
{ JOptionPane.showMessageDialog(E4KTunerEditor.this, getTunerInfo(),
mController.setSampleRate( sampleRate ); "Tuner Info", JOptionPane.INFORMATION_MESSAGE);
save(); }
} });
catch ( SourceException | LibUsbException eSampleRate ) add(mTunerInfo);
{
JOptionPane.showMessageDialog( E4KTunerEditor.this, mComboSampleRate = new JComboBox<>(SampleRate.values());
"E4K Tuner Controller - couldn't apply the sample rate setting [" + mComboSampleRate.setEnabled(false);
sampleRate.getLabel() + "] " + eSampleRate.getLocalizedMessage() ); mComboSampleRate.addActionListener(new ActionListener()
{
mLog.error( "E4K Tuner Controller - couldn't apply sample rate setting [" + @Override
sampleRate.getLabel() + "]", eSampleRate ); public void actionPerformed(ActionEvent e)
} {
} SampleRate sampleRate = (SampleRate)mComboSampleRate.getSelectedItem();
} );
add( new JLabel( "Sample Rate:" ) ); try
add( mComboSampleRate ); {
mController.setSampleRate(sampleRate);
SpinnerModel model = new SpinnerNumberModel( 0.0, //initial value save();
-1000.0, //min }
1000.0, //max catch(SourceException | LibUsbException eSampleRate)
0.1 ); //step {
JOptionPane.showMessageDialog(E4KTunerEditor.this,
mFrequencyCorrection = new JSpinner( model ); "E4K Tuner Controller - couldn't apply the sample rate setting [" +
mFrequencyCorrection.setEnabled( false ); sampleRate.getLabel() + "] " + eSampleRate.getLocalizedMessage());
JSpinner.NumberEditor editor = mLog.error("E4K Tuner Controller - couldn't apply sample rate setting [" +
(JSpinner.NumberEditor)mFrequencyCorrection.getEditor(); sampleRate.getLabel() + "]", eSampleRate);
}
DecimalFormat format = editor.getFormat(); }
format.setMinimumFractionDigits( 1 ); });
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER ); add(new JLabel("Sample Rate:"));
add(mComboSampleRate);
mFrequencyCorrection.addChangeListener( new ChangeListener()
{ SpinnerModel model = new SpinnerNumberModel(0.0, //initial value
@Override -1000.0, //min
public void stateChanged( ChangeEvent e ) 1000.0, //max
{ 0.1); //step
final double value = ((SpinnerNumberModel)mFrequencyCorrection
.getModel()).getNumber().doubleValue(); mFrequencyCorrection = new JSpinner(model);
mFrequencyCorrection.setEnabled(false);
try
{ JSpinner.NumberEditor editor =
mController.setFrequencyCorrection( value ); (JSpinner.NumberEditor)mFrequencyCorrection.getEditor();
save();
} DecimalFormat format = editor.getFormat();
catch ( SourceException e1 ) format.setMinimumFractionDigits(1);
{ editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
JOptionPane.showMessageDialog( E4KTunerEditor.this, "E4K Tuner Controller - "
+ "couldn't apply frequency correction value: " + value + e1.getLocalizedMessage() ); mFrequencyCorrection.addChangeListener(new ChangeListener()
{
mLog.error( "E4K Tuner Controller - couldn't apply frequency correction value:" @Override
+ value, e1 ); public void stateChanged(ChangeEvent e)
} {
} final double value = ((SpinnerNumberModel)mFrequencyCorrection
} ); .getModel()).getNumber().doubleValue();
add( new JLabel( "PPM:" ) ); try
add( mFrequencyCorrection ); {
mController.setFrequencyCorrection(value);
add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); save();
add( new JLabel( "Gain" ), "wrap" ); }
catch(SourceException e1)
mComboMasterGain = new JComboBox<E4KGain>( E4KGain.values() ); {
mComboMasterGain.setEnabled( false ); JOptionPane.showMessageDialog(E4KTunerEditor.this, "E4K Tuner Controller - "
mComboMasterGain.addActionListener( new ActionListener() + "couldn't apply frequency correction value: " + value + e1.getLocalizedMessage());
{
@Override mLog.error("E4K Tuner Controller - couldn't apply frequency correction value:"
public void actionPerformed( ActionEvent arg0 ) + value, e1);
{ }
try }
{ });
E4KGain gain = (E4KGain)mComboMasterGain.getSelectedItem();
add(new JLabel("PPM:"));
mController.setGain( (E4KGain)mComboMasterGain.getSelectedItem(), true ); add(mFrequencyCorrection);
if( gain == E4KGain.MANUAL ) add(new JSeparator(JSeparator.HORIZONTAL), "span,grow");
{ add(new JLabel("Gain"), "wrap");
mComboMixerGain.setSelectedItem( mController.getMixerGain( true ) );
mComboMixerGain.setEnabled( true ); mComboMasterGain = new JComboBox<E4KGain>(E4KGain.values());
mComboMasterGain.setEnabled(false);
mComboLNAGain.setSelectedItem( mController.getLNAGain( true ) ); mComboMasterGain.addActionListener(new ActionListener()
mComboLNAGain.setEnabled( true ); {
@Override
mComboEnhanceGain.setSelectedItem( mController.getEnhanceGain( true ) ); public void actionPerformed(ActionEvent arg0)
mComboEnhanceGain.setEnabled( true ); {
} try
else {
{ E4KGain gain = (E4KGain)mComboMasterGain.getSelectedItem();
mComboMixerGain.setEnabled( false );
mComboMixerGain.setSelectedItem( gain.getMixerGain() ); mController.setGain((E4KGain)mComboMasterGain.getSelectedItem(), true);
mComboLNAGain.setEnabled( false ); if(gain == E4KGain.MANUAL)
mComboLNAGain.setSelectedItem( gain.getLNAGain() ); {
mComboMixerGain.setSelectedItem(mController.getMixerGain(true));
mComboEnhanceGain.setEnabled( false ); mComboMixerGain.setEnabled(true);
mComboEnhanceGain.setSelectedItem( gain.getEnhanceGain() );
} mComboLNAGain.setSelectedItem(mController.getLNAGain(true));
mComboLNAGain.setEnabled(true);
save();
} mComboEnhanceGain.setSelectedItem(mController.getEnhanceGain(true));
catch ( UsbException e ) mComboEnhanceGain.setEnabled(true);
{ }
JOptionPane.showMessageDialog( E4KTunerEditor.this, "E4K Tuner Controller - " else
+ "couldn't apply the gain setting - " + e.getLocalizedMessage() ); {
mComboMixerGain.setEnabled(false);
mLog.error( "E4K Tuner Controller - couldn't apply gain setting", e ); mComboMixerGain.setSelectedItem(gain.getMixerGain());
}
} mComboLNAGain.setEnabled(false);
} ); mComboLNAGain.setSelectedItem(gain.getLNAGain());
mComboMasterGain.setToolTipText( "<html>Select <b>AUTOMATIC</b> for auto " mComboEnhanceGain.setEnabled(false);
+ "gain, <b>MANUAL</b> to enable<br> independent control of " mComboEnhanceGain.setSelectedItem(gain.getEnhanceGain());
+ "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>" }
+ "settings, or one of the individual gain settings for<br>"
+ "semi-manual gain control</html>" ); save();
add( new JLabel( "Master:" ) ); }
add( mComboMasterGain ); catch(UsbException e)
{
mComboMixerGain = new JComboBox<E4KMixerGain>( E4KMixerGain.values() ); JOptionPane.showMessageDialog(E4KTunerEditor.this, "E4K Tuner Controller - "
mComboMixerGain.addActionListener( new ActionListener() + "couldn't apply the gain setting - " + e.getLocalizedMessage());
{
@Override mLog.error("E4K Tuner Controller - couldn't apply gain setting", e);
public void actionPerformed( ActionEvent arg0 ) }
{ }
try });
{
E4KMixerGain mixerGain = (E4KMixerGain)mComboMixerGain.getSelectedItem(); mComboMasterGain.setToolTipText("<html>Select <b>AUTOMATIC</b> for auto "
mController.setMixerGain( mixerGain, true ); + "gain, <b>MANUAL</b> to enable<br> independent control of "
save(); + "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>"
} + "settings, or one of the individual gain settings for<br>"
catch ( UsbException e ) + "semi-manual gain control</html>");
{ add(new JLabel("Master:"));
JOptionPane.showMessageDialog( E4KTunerEditor.this, "E4K Tuner Controller - " add(mComboMasterGain);
+ "couldn't apply the mixer gain setting - " + e.getLocalizedMessage() );
mComboMixerGain = new JComboBox<E4KMixerGain>(E4KMixerGain.values());
mLog.error( "E4K Tuner Controller - couldn't apply mixer gain setting", e ); mComboMixerGain.addActionListener(new ActionListener()
} {
} @Override
} ); public void actionPerformed(ActionEvent arg0)
mComboMixerGain.setToolTipText( "<html>Mixer Gain. Set master gain " {
+ "to <b>MASTER</b> to enable adjustment</html>" ); try
mComboMixerGain.setEnabled( false ); {
add( new JLabel( "Mixer:" ) ); E4KMixerGain mixerGain = (E4KMixerGain)mComboMixerGain.getSelectedItem();
add( mComboMixerGain ); mController.setMixerGain(mixerGain, true);
save();
mComboLNAGain = new JComboBox<E4KLNAGain>( E4KLNAGain.values() ); }
mComboLNAGain.addActionListener( new ActionListener() catch(UsbException e)
{ {
@Override JOptionPane.showMessageDialog(E4KTunerEditor.this, "E4K Tuner Controller - "
public void actionPerformed( ActionEvent arg0 ) + "couldn't apply the mixer gain setting - " + e.getLocalizedMessage());
{
try mLog.error("E4K Tuner Controller - couldn't apply mixer gain setting", e);
{ }
E4KLNAGain lnaGain = (E4KLNAGain)mComboLNAGain.getSelectedItem(); }
mController.setLNAGain( lnaGain, true ); });
save(); mComboMixerGain.setToolTipText("<html>Mixer Gain. Set master gain "
} + "to <b>MASTER</b> to enable adjustment</html>");
catch ( UsbException e ) mComboMixerGain.setEnabled(false);
{ add(new JLabel("Mixer:"));
JOptionPane.showMessageDialog( E4KTunerEditor.this, "E4K Tuner Controller - " add(mComboMixerGain);
+ "couldn't apply the LNA gain setting - " + e.getLocalizedMessage() );
mComboLNAGain = new JComboBox<E4KLNAGain>(E4KLNAGain.values());
mLog.error( "E4K Tuner Controller - couldn't apply LNA gain setting - ", e ); mComboLNAGain.addActionListener(new ActionListener()
} {
} @Override
} ); public void actionPerformed(ActionEvent arg0)
mComboLNAGain.setToolTipText( "<html>LNA Gain. Set master gain " {
+ "to <b>MANUAL</b> to enable adjustment</html>" ); try
mComboLNAGain.setEnabled( false ); {
add( new JLabel( "LNA:" ) ); E4KLNAGain lnaGain = (E4KLNAGain)mComboLNAGain.getSelectedItem();
add( mComboLNAGain ); mController.setLNAGain(lnaGain, true);
save();
mComboEnhanceGain = new JComboBox<E4KEnhanceGain>( E4KEnhanceGain.values() ); }
mComboEnhanceGain.addActionListener( new ActionListener() catch(UsbException e)
{ {
@Override JOptionPane.showMessageDialog(E4KTunerEditor.this, "E4K Tuner Controller - "
public void actionPerformed( ActionEvent arg0 ) + "couldn't apply the LNA gain setting - " + e.getLocalizedMessage());
{
try mLog.error("E4K Tuner Controller - couldn't apply LNA gain setting - ", e);
{ }
E4KEnhanceGain enhance = (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem(); }
mController.setEnhanceGain( enhance, true ); });
save(); mComboLNAGain.setToolTipText("<html>LNA Gain. Set master gain "
} + "to <b>MANUAL</b> to enable adjustment</html>");
catch ( UsbException e ) mComboLNAGain.setEnabled(false);
{ add(new JLabel("LNA:"));
JOptionPane.showMessageDialog( E4KTunerEditor.this, "E4K Tuner Controller - " add(mComboLNAGain);
+ "couldn't apply the enhance gain setting - " + e.getLocalizedMessage() );
mComboEnhanceGain = new JComboBox<E4KEnhanceGain>(E4KEnhanceGain.values());
mLog.error( "E4K Tuner Controller - couldn't apply enhance gain setting", e ); mComboEnhanceGain.addActionListener(new ActionListener()
} {
} @Override
} ); public void actionPerformed(ActionEvent arg0)
mComboEnhanceGain.setToolTipText( "<html>Enhance Gain. Set master gain " {
+ "to <b>MANUAL</b> to enable adjustment</html>" ); try
mComboEnhanceGain.setEnabled( false ); {
add( new JLabel( "Enhance:" ) ); E4KEnhanceGain enhance = (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem();
add( mComboEnhanceGain ); mController.setEnhanceGain(enhance, true);
} save();
}
/** catch(UsbException e)
* Sets each of the tuner configuration controls to the enabled argument state {
*/ JOptionPane.showMessageDialog(E4KTunerEditor.this, "E4K Tuner Controller - "
private void setControlsEnabled( boolean enabled ) + "couldn't apply the enhance gain setting - " + e.getLocalizedMessage());
{
if( mConfigurationName.isEnabled() != enabled ) mLog.error("E4K Tuner Controller - couldn't apply enhance gain setting", e);
{ }
mConfigurationName.setEnabled( enabled ); }
} });
mComboEnhanceGain.setToolTipText("<html>Enhance Gain. Set master gain "
if( mTunerInfo.isEnabled() != enabled ) + "to <b>MANUAL</b> to enable adjustment</html>");
{ mComboEnhanceGain.setEnabled(false);
mTunerInfo.setEnabled( enabled ); add(new JLabel("Enhance:"));
} add(mComboEnhanceGain);
}
if( mFrequencyCorrection.isEnabled() != enabled )
{ /**
mFrequencyCorrection.setEnabled( enabled ); * Sets each of the tuner configuration controls to the enabled argument state
} */
private void setControlsEnabled(boolean enabled)
if( mComboSampleRate.isEnabled() != enabled ) {
{ if(mConfigurationName.isEnabled() != enabled)
mComboSampleRate.setEnabled( enabled ); {
} mConfigurationName.setEnabled(enabled);
}
if( mComboMasterGain.isEnabled() != enabled )
{ if(mTunerInfo.isEnabled() != enabled)
mComboMasterGain.setEnabled( enabled ); {
} mTunerInfo.setEnabled(enabled);
}
if( mComboMixerGain.isEnabled() != enabled )
{ if(mFrequencyCorrection.isEnabled() != enabled)
mComboMixerGain.setEnabled( enabled ); {
} mFrequencyCorrection.setEnabled(enabled);
}
if( mComboLNAGain.isEnabled() != enabled )
{ if(mComboSampleRate.isEnabled() != enabled)
mComboLNAGain.setEnabled( enabled ); {
} mComboSampleRate.setEnabled(enabled);
}
if( mComboEnhanceGain.isEnabled() != enabled )
{ if(mComboMasterGain.isEnabled() != enabled)
mComboEnhanceGain.setEnabled( enabled ); {
} mComboMasterGain.setEnabled(enabled);
} }
private String getTunerInfo() if(mComboMixerGain.isEnabled() != enabled)
{ {
StringBuilder sb = new StringBuilder(); mComboMixerGain.setEnabled(enabled);
}
RTL2832TunerController.Descriptor descriptor = mController.getDescriptor();
if(mComboLNAGain.isEnabled() != enabled)
sb.append( "<html><h3>RTL-2832 with E4000 Tuner</h3>" ); {
mComboLNAGain.setEnabled(enabled);
if( descriptor == null ) }
{
sb.append( "No EEPROM Descriptor Available" ); if(mComboEnhanceGain.isEnabled() != enabled)
} {
else mComboEnhanceGain.setEnabled(enabled);
{ }
sb.append( "<b>USB ID: </b>" ); }
sb.append( descriptor.getVendorID() );
sb.append( ":" ); private String getTunerInfo()
sb.append( descriptor.getProductID() ); {
sb.append( "<br>" ); StringBuilder sb = new StringBuilder();
sb.append( "<b>Vendor: </b>" ); RTL2832TunerController.Descriptor descriptor = mController.getDescriptor();
sb.append( descriptor.getVendorLabel() );
sb.append( "<br>" ); sb.append("<html><h3>RTL-2832 with E4000 Tuner</h3>");
sb.append( "<b>Product: </b>" ); if(descriptor == null)
sb.append( descriptor.getProductLabel() ); {
sb.append( "<br>" ); sb.append("No EEPROM Descriptor Available");
}
sb.append( "<b>Serial: </b>" ); else
sb.append( descriptor.getSerial() ); {
sb.append( "<br>" ); sb.append("<b>USB ID: </b>");
sb.append(descriptor.getVendorID());
sb.append( "<b>IR Enabled: </b>" ); sb.append(":");
sb.append( descriptor.irEnabled() ); sb.append(descriptor.getProductID());
sb.append( "<br>" ); sb.append("<br>");
sb.append( "<b>Remote Wake: </b>" ); sb.append("<b>Vendor: </b>");
sb.append( descriptor.remoteWakeupEnabled() ); sb.append(descriptor.getVendorLabel());
sb.append( "<br>" ); sb.append("<br>");
}
sb.append("<b>Product: </b>");
return sb.toString(); sb.append(descriptor.getProductLabel());
} sb.append("<br>");
@Override sb.append("<b>Serial: </b>");
public void save() sb.append(descriptor.getSerial());
{ sb.append("<br>");
if( hasItem() && !mLoading )
{ sb.append("<b>IR Enabled: </b>");
E4KTunerConfiguration config = getConfiguration(); sb.append(descriptor.irEnabled());
sb.append("<br>");
config.setName( mConfigurationName.getText() );
sb.append("<b>Remote Wake: </b>");
config.setSampleRate( (SampleRate)mComboSampleRate.getSelectedItem() ); sb.append(descriptor.remoteWakeupEnabled());
sb.append("<br>");
double value = ((SpinnerNumberModel)mFrequencyCorrection }
.getModel()).getNumber().doubleValue();
config.setFrequencyCorrection( value ); return sb.toString();
}
config.setMasterGain( (E4KGain)mComboMasterGain.getSelectedItem() );
config.setMixerGain( (E4KMixerGain)mComboMixerGain.getSelectedItem() ); @Override
config.setLNAGain( (E4KLNAGain)mComboLNAGain.getSelectedItem() ); public void save()
config.setEnhanceGain( (E4KEnhanceGain)mComboEnhanceGain.getSelectedItem() ); {
if(hasItem() && !mLoading)
getTunerConfigurationModel().broadcast( new TunerConfigurationEvent( {
getConfiguration(), TunerConfigurationEvent.Event.CHANGE ) ); E4KTunerConfiguration config = getConfiguration();
}
config.setName(mConfigurationName.getText());
}
config.setSampleRate((SampleRate)mComboSampleRate.getSelectedItem());
@Override
public void setItem( TunerConfiguration tunerConfiguration ) double value = ((SpinnerNumberModel)mFrequencyCorrection
{ .getModel()).getNumber().doubleValue();
super.setItem( tunerConfiguration ); config.setFrequencyCorrection(value);
//Toggle loading so that we don't fire a change event and schedule a settings file save config.setMasterGain((E4KGain)mComboMasterGain.getSelectedItem());
mLoading = true; config.setMixerGain((E4KMixerGain)mComboMixerGain.getSelectedItem());
config.setLNAGain((E4KLNAGain)mComboLNAGain.getSelectedItem());
if( hasItem() ) config.setEnhanceGain((E4KEnhanceGain)mComboEnhanceGain.getSelectedItem());
{
E4KTunerConfiguration config = getConfiguration(); getTunerConfigurationModel().broadcast(new TunerConfigurationEvent(
getConfiguration(), TunerConfigurationEvent.Event.CHANGE));
if( tunerConfiguration.isAssigned() ) }
{
setControlsEnabled( true ); }
mConfigurationName.setText( config.getName() ); @Override
mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); public void setItem(TunerConfiguration tunerConfiguration)
mComboSampleRate.setSelectedItem( config.getSampleRate() ); {
mComboMasterGain.setSelectedItem( config.getMasterGain() ); super.setItem(tunerConfiguration);
mComboMixerGain.setSelectedItem( config.getMixerGain() );
mComboLNAGain.setSelectedItem( config.getLNAGain() ); //Toggle loading so that we don't fire a change event and schedule a settings file save
mComboEnhanceGain.setSelectedItem( config.getEnhanceGain() ); mLoading = true;
}
else if(hasItem())
{ {
setControlsEnabled( false ); E4KTunerConfiguration config = getConfiguration();
mConfigurationName.setText( config.getName() );
} if(tunerConfiguration.isAssigned())
} {
else setControlsEnabled(true);
{
setControlsEnabled( false ); mConfigurationName.setText(config.getName());
mConfigurationName.setText( "" ); mFrequencyCorrection.setValue(config.getFrequencyCorrection());
} mComboSampleRate.setSelectedItem(config.getSampleRate());
mComboMasterGain.setSelectedItem(config.getMasterGain());
mLoading = false; mComboMixerGain.setSelectedItem(config.getMixerGain());
} mComboLNAGain.setSelectedItem(config.getLNAGain());
mComboEnhanceGain.setSelectedItem(config.getEnhanceGain());
//Update enabled state to reflect when frequency and sample rate controls are locked
mComboSampleRate.setEnabled(!mController.isLocked());
}
else
{
setControlsEnabled(false);
mConfigurationName.setText(config.getName());
}
}
else
{
setControlsEnabled(false);
mConfigurationName.setText("");
}
mLoading = false;
}
} }