[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());
mChannelSources.add(channelSource);
mSourceEventBroadcaster.broadcast(SourceEvent.channelCountChange(getTunerChannelCount()));
}
}
catch(IllegalArgumentException iae)
@@ -225,7 +226,6 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
synchronized(mBufferProcessor)
{
mPolyphaseChannelizer.addChannel(channelSource);
mSourceEventBroadcaster.broadcast(SourceEvent.channelCountChange(getTunerChannelCount()));
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.InvalidFrequencyException;
import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.SourceEvent.Event;
import io.github.dsheirer.source.SourceException;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
@@ -32,6 +31,7 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
@@ -146,10 +146,39 @@ public class JFrequencyControl extends JPanel implements ISourceEventProcessor
@Override
public void process(SourceEvent event)
{
if(event.getEvent() == Event.NOTIFICATION_FREQUENCY_CHANGE)
switch(event.getEvent())
{
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_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_CHANNEL_SAMPLE_RATE_CHANGE,
NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED,
NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED,
NOTIFICATION_FREQUENCY_CHANGE,
NOTIFICATION_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_SAMPLE_RATE_CHANGE,
@@ -119,6 +121,22 @@ public class SourceEvent
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
*

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()
{
return mFrequencyController.getBandwidth();

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* 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
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
@@ -222,7 +222,6 @@ public class TunerEditor extends Editor<Tuner>
if(hasItem())
{
mSelectedTunerType.setText(tuner.getName());
mFrequencyControl.setEnabled( true );
mTunerConfigurationTable.setEnabled(true);
mNewConfigurationButton.setEnabled(true);
@@ -249,15 +248,15 @@ public class TunerEditor extends Editor<Tuner>
}
}
//Link frequency control to the tuner
//Link frequency control to the tuner and set enabled state
mFrequencyControl.addListener(tuner.getTunerController());
mFrequencyControl.setEnabled(!tuner.getTunerController().isLocked());
//Link tuner to frequency control
tuner.getTunerController().addListener(mFrequencyControl);
//Set the displayed frequency without adjusting the tuner's frequency
mFrequencyControl.setFrequency(
tuner.getTunerController().getFrequency(), false );
mFrequencyControl.setFrequency(tuner.getTunerController().getFrequency(), false);
}
else
{

View File

@@ -1,19 +1,17 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2015-2016 Dennis Sheirer
* 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 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.
* 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/>
*
* 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.airspy;
@@ -45,6 +43,7 @@ import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -104,6 +103,24 @@ public class AirspyTunerEditor extends TunerConfigurationEditor
return null;
}
/**
* Updates the enabled state of the sample rate combo control.
*
* @param enabled state for the sample rate control
*/
@Override
public void setSampleRateControl(boolean enabled)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mSampleRateCombo.setEnabled(enabled);
}
});
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -120,8 +137,11 @@ public class AirspyTunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(new JLabel("Name:"));
@@ -683,6 +703,9 @@ public class AirspyTunerEditor extends TunerConfigurationEditor
mSampleRateCombo.setSelectedItem(rate);
}
//Update enabled state to reflect when frequency and sample rate controls are locked
mSampleRateCombo.setEnabled(!mController.isLocked());
mFrequencyCorrection.setValue(airspy.getFrequencyCorrection());
GainMode mode = Gain.getGainMode(airspy.getGain());

View File

@@ -1,3 +1,18 @@
/*******************************************************************************
* 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;
import io.github.dsheirer.gui.editor.Editor;
@@ -17,4 +32,12 @@ public abstract class TunerConfigurationEditor extends Editor<TunerConfiguration
{
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

@@ -86,6 +86,12 @@ public class FCD1TunerEditor extends TunerConfigurationEditor
return null;
}
@Override
public void setSampleRateControl(boolean enabled)
{
//no-op
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -102,8 +108,11 @@ public class FCD1TunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(new JLabel("Name:"));
@@ -457,7 +466,12 @@ public class FCD1TunerEditor extends TunerConfigurationEditor
mLoading = false;
}
public enum Correction { GAIN, PHASE, DC_INPHASE, DC_QUADRATURE };
public enum Correction
{
GAIN, PHASE, DC_INPHASE, DC_QUADRATURE
}
;
public class CorrectionSpinner extends JSpinner
{

View File

@@ -1,19 +1,17 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* 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 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.
* 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/>
*
* 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;
@@ -78,6 +76,12 @@ public class FCD2TunerEditor extends TunerConfigurationEditor
return null;
}
@Override
public void setSampleRateControl(boolean enabled)
{
//no-op
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -94,8 +98,11 @@ public class FCD2TunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(new JLabel("Name:"));

View File

@@ -1,7 +1,6 @@
/*******************************************************************************
* *********************************************************************************************************************
* 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
* 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.
* If not, see <http://www.gnu.org/licenses/>
* *********************************************************************************************************************
*
******************************************************************************/
package io.github.dsheirer.source.tuner.frequency;
@@ -37,6 +36,7 @@ public class FrequencyController
private long mMaximumFrequency;
private double mFrequencyCorrection = 0.0d;
private double mSampleRate = 0.0d;
private boolean mLocked = false;
private List<ISourceEventProcessor> mProcessors = new ArrayList<>();
@@ -48,6 +48,40 @@ public class FrequencyController
mFrequencyCorrection = frequencyCorrection;
}
/**
* 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
* 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 true if locked or false if not locked.
*/
public boolean isLocked()
{
return mLocked;
}
/**
* 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
* is primarily to lock down user interface controls when the polyphase channelizer is producing channels.
*
* @param locked state
*/
public void setLocked(boolean locked) throws SourceException
{
mLocked = locked;
if(mLocked)
{
broadcast(SourceEvent.lockedState());
}
else
{
broadcast(SourceEvent.unlockedState());
}
}
/**
* Get bandwidth in hertz
*/
@@ -96,6 +130,7 @@ public class FrequencyController
/**
* Indicates if the specified frequency can be tuned (ie is within min/max frequency) by this controller.
*
* @param frequency to evaluate
* @return true if the frequency falls within the tuning range of this controller
*/

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* 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
* 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.ChangeListener;
import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -83,6 +84,19 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
return null;
}
@Override
public void setSampleRateControl(boolean enabled)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mComboSampleRate.setEnabled(enabled);
}
});
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -99,8 +113,11 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(new JLabel("Name:"));
@@ -416,6 +433,9 @@ public class HackRFTunerEditor extends TunerConfigurationEditor
mAmplifier.setSelected(config.getAmplifierEnabled());
mComboLNAGain.setSelectedItem(config.getLNAGain());
mComboVGAGain.setSelectedItem(config.getVGAGain());
//Update enabled state to reflect when frequency and sample rate controls are locked
mComboSampleRate.setEnabled(!mController.isLocked());
}
else
{

View File

@@ -433,6 +433,9 @@ public class TunerChannelSourceManager extends ChannelSourceManager
case NOTIFICATION_CHANNEL_COUNT_CHANGE:
//Rebroadcast this event to any registered listeners (ie tuner and tuner controller)
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;
default:
mLog.info("Unrecognized source event: " + sourceEvent);

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* 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
* 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.ChangeListener;
import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -87,6 +88,19 @@ public class E4KTunerEditor extends TunerConfigurationEditor
return null;
}
@Override
public void setSampleRateControl(boolean enabled)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mComboSampleRate.setEnabled(enabled);
}
});
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -107,8 +121,11 @@ public class E4KTunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(mConfigurationName, "span 2");
@@ -476,6 +493,9 @@ public class E4KTunerEditor extends TunerConfigurationEditor
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
{

View File

@@ -1,19 +1,17 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* 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 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.
* 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/>
*
* 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.rtl.r820t;
@@ -47,6 +45,7 @@ import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.usb.UsbException;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -90,6 +89,19 @@ public class R820TTunerEditor extends TunerConfigurationEditor
return null;
}
@Override
public void setSampleRateControl(boolean enabled)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mComboSampleRate.setEnabled(enabled);
}
});
}
private void init()
{
setLayout(new MigLayout("fill,wrap 4", "[right][grow,fill][right][grow,fill]",
@@ -106,8 +118,11 @@ public class R820TTunerEditor extends TunerConfigurationEditor
{
save();
}
@Override
public void focusGained( FocusEvent e ) {}
public void focusGained(FocusEvent e)
{
}
});
add(new JLabel("Name:"));
@@ -537,6 +552,9 @@ public class R820TTunerEditor extends TunerConfigurationEditor
mComboMixerGain.setSelectedItem(config.getMixerGain());
mComboLNAGain.setSelectedItem(config.getLNAGain());
mComboVGAGain.setSelectedItem(config.getVGAGain());
//Update enabled state to reflect when frequency and sample rate controls are locked
mComboSampleRate.setEnabled(!mController.isLocked());
}
else
{