mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 17:17:29 -05:00
Frequency limit for Automatic Frequency Control to prevent the controller from walking too far.
Defaults to a maximum of 3kHz, but can be set to as high as 15 kHz.
This commit is contained in:
@@ -376,7 +376,11 @@ public class ProcessingChain implements Listener<Message>
|
||||
{
|
||||
TunerChannelSource tcs = (TunerChannelSource)mSource;
|
||||
|
||||
mAFC = new AutomaticFrequencyControl( tcs );
|
||||
int maximumCorrection = mChannel
|
||||
.getDecodeConfiguration().getAFCMaximumCorrection();
|
||||
|
||||
mAFC = new AutomaticFrequencyControl( tcs,
|
||||
maximumCorrection );
|
||||
|
||||
/* Register AFC to receive frequency change events */
|
||||
tcs.addListener( mAFC );
|
||||
|
||||
@@ -21,6 +21,13 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import controller.Editor;
|
||||
import decode.config.DecodeConfiguration;
|
||||
@@ -32,6 +39,7 @@ public class DecodeEditor extends Editor
|
||||
protected DecodeConfiguration mConfig;
|
||||
|
||||
protected JCheckBox mAFC;
|
||||
protected JSpinner mAFCMaximumCorrection;
|
||||
|
||||
public DecodeEditor( DecodeConfiguration config )
|
||||
{
|
||||
@@ -49,8 +57,42 @@ public class DecodeEditor extends Editor
|
||||
mConfig.setAFC( mAFC.isSelected() );
|
||||
}
|
||||
} );
|
||||
|
||||
mAFC.setToolTipText( "AFC automatically adjusts the center "
|
||||
+ "frequency of the channel to correct/compensate for "
|
||||
+ "inaccuracies and frequency drift in the tuner" );
|
||||
|
||||
add( mAFC, "wrap" );
|
||||
add( mAFC, "span" );
|
||||
|
||||
int initial = mConfig.getAFCMaximumCorrection();
|
||||
|
||||
SpinnerModel model = new SpinnerNumberModel( initial, 0, 15000, 1 );
|
||||
|
||||
mAFCMaximumCorrection = new JSpinner( model );
|
||||
|
||||
JSpinner.NumberEditor editor =
|
||||
(JSpinner.NumberEditor)mAFCMaximumCorrection.getEditor();
|
||||
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
|
||||
|
||||
mAFCMaximumCorrection.setToolTipText( "Sets the maximum frequency "
|
||||
+ "correction value in hertz, 0 - 15kHz" );
|
||||
|
||||
mAFCMaximumCorrection.addChangeListener( new ChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged( ChangeEvent e )
|
||||
{
|
||||
int value = ((SpinnerNumberModel)mAFCMaximumCorrection
|
||||
.getModel()).getNumber().intValue();
|
||||
|
||||
mConfig.setAFCMaximumCorrection( value );
|
||||
|
||||
save();
|
||||
}
|
||||
} );
|
||||
|
||||
add( mAFCMaximumCorrection );
|
||||
add( new JLabel( "Correction Limit Hz" ), "growx, push" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +104,12 @@ public class DecodeEditor extends Editor
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public abstract class DecodeConfiguration extends Configuration
|
||||
{
|
||||
private DecoderType mDecoderType = DecoderType.NBFM;
|
||||
private boolean mAFCEnabled = true;
|
||||
private int mAFCMaxCorrection = 3000;
|
||||
|
||||
public DecodeConfiguration()
|
||||
{
|
||||
@@ -67,6 +68,16 @@ public abstract class DecodeConfiguration extends Configuration
|
||||
mAFCEnabled = enabled;
|
||||
}
|
||||
|
||||
public int getAFCMaximumCorrection()
|
||||
{
|
||||
return mAFCMaxCorrection;
|
||||
}
|
||||
|
||||
public void setAFCMaximumCorrection( int max )
|
||||
{
|
||||
mAFCMaxCorrection = max;
|
||||
}
|
||||
|
||||
public boolean supportsAFC()
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -24,6 +24,7 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
|
||||
private int mSkipThreshold = 4;
|
||||
private int mErrorCorrection = 0;
|
||||
private long mCurrentFrequency;
|
||||
private int mMaximumCorrection;
|
||||
private FrequencyChangeListener mListener;
|
||||
|
||||
public enum Mode
|
||||
@@ -31,9 +32,11 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
|
||||
NORMAL,FAST;
|
||||
}
|
||||
|
||||
public AutomaticFrequencyControl( FrequencyChangeListener listener )
|
||||
public AutomaticFrequencyControl( FrequencyChangeListener listener,
|
||||
int maximumCorrection )
|
||||
{
|
||||
mListener = listener;
|
||||
mMaximumCorrection = maximumCorrection;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
@@ -150,6 +153,14 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
|
||||
if( correction != 0 )
|
||||
{
|
||||
mErrorCorrection -= correction;
|
||||
|
||||
if( Math.abs( mErrorCorrection ) > mMaximumCorrection )
|
||||
{
|
||||
mErrorCorrection = ( mErrorCorrection < 0 ) ?
|
||||
-mMaximumCorrection :
|
||||
mMaximumCorrection;
|
||||
}
|
||||
|
||||
dispatch();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -135,10 +135,6 @@ public abstract class TunerController implements Tunable
|
||||
long maxLockedFrequency = mTunedChannels
|
||||
.get( mTunedChannels.size() - 1 ).getMaxFrequency();
|
||||
|
||||
mLog.debug( "Tuner Controller min [" + minLockedFrequency +
|
||||
"] max [" + maxLockedFrequency +
|
||||
"] bw [" + getBandwidth() + "]" );
|
||||
|
||||
//Requested channel is higher than min locked frequency
|
||||
if( minLockedFrequency <= channel.getMinFrequency() &&
|
||||
( channel.getMaxFrequency() - minLockedFrequency ) <= getBandwidth() )
|
||||
|
||||
Reference in New Issue
Block a user