Merge pull request #420 from DSheirer/419-heterdyne-channelizer-center-frequency-tuning

419 Heterodyne Channelizer Center Frequency Calculations
This commit is contained in:
Denny Sheirer
2018-09-16 06:04:09 -04:00
committed by GitHub
3 changed files with 139 additions and 43 deletions

View File

@@ -26,12 +26,15 @@ import io.github.dsheirer.source.ISourceEventProcessor;
import io.github.dsheirer.source.SourceEvent; import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.SourceEventListenerToProcessorAdapter; import io.github.dsheirer.source.SourceEventListenerToProcessorAdapter;
import io.github.dsheirer.source.SourceException; import io.github.dsheirer.source.SourceException;
import io.github.dsheirer.source.tuner.channel.TunerChannel;
import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration;
import io.github.dsheirer.source.tuner.frequency.FrequencyController; import io.github.dsheirer.source.tuner.frequency.FrequencyController;
import io.github.dsheirer.source.tuner.frequency.FrequencyController.Tunable; import io.github.dsheirer.source.tuner.frequency.FrequencyController.Tunable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.SortedSet;
public abstract class TunerController implements Tunable, ISourceEventProcessor, ISourceEventListener, public abstract class TunerController implements Tunable, ISourceEventProcessor, ISourceEventListener,
IReusableComplexBufferProvider, Listener<ReusableComplexBuffer> IReusableComplexBufferProvider, Listener<ReusableComplexBuffer>
{ {
@@ -361,4 +364,85 @@ public abstract class TunerController implements Tunable, ISourceEventProcessor,
{ {
broadcast(complexBuffer); broadcast(complexBuffer);
} }
/**
* Indicates if the current center frequency and bandwidth is correct to source the tuner channel
*
* @param tunerChannel to test
* @return true if the current center frequency and bandwidth is correct for the channel
*/
public boolean isTunedFor(TunerChannel tunerChannel)
{
try
{
if(tunerChannel.getMinFrequency() < getMinTunedFrequency())
{
return false;
}
if(tunerChannel.getMaxFrequency() > getMaxTunedFrequency())
{
return false;
}
if(hasMiddleUnusableBandwidth())
{
long minAvoid = getFrequency() - getMiddleUnusableHalfBandwidth();
long maxAvoid = getFrequency() + getMiddleUnusableHalfBandwidth();
if(tunerChannel.overlaps(minAvoid, maxAvoid))
{
return false;
}
}
}
catch(SourceException se)
{
return false;
}
return true;
}
/**
* Indicates if the current center frequency and bandwidth is correct to source the tuner channel set
*
* @param tunerChannels to test
* @return true if the current center frequency and bandwidth is correct for the channel set
*/
public boolean isTunedFor(SortedSet<TunerChannel> tunerChannels)
{
try
{
if(tunerChannels.first().getMinFrequency() < getMinTunedFrequency())
{
return false;
}
if(tunerChannels.last().getMaxFrequency() > getMaxTunedFrequency())
{
return false;
}
if(hasMiddleUnusableBandwidth())
{
long minAvoid = getFrequency() - getMiddleUnusableHalfBandwidth();
long maxAvoid = getFrequency() + getMiddleUnusableHalfBandwidth();
for(TunerChannel tunerChannel: tunerChannels)
{
if(tunerChannel.overlaps(minAvoid, maxAvoid))
{
return false;
}
}
}
}
catch(SourceException se)
{
return false;
}
return true;
}
} }

View File

@@ -54,6 +54,13 @@ public class CenterFrequencyCalculator
//Start by placing the highest frequency channel at the high end of the spectrum //Start by placing the highest frequency channel at the high end of the spectrum
candidateFrequency = maxChannelFrequency - (tunerController.getUsableBandwidth() / 2); candidateFrequency = maxChannelFrequency - (tunerController.getUsableBandwidth() / 2);
if(maxChannelFrequency - minChannelFrequency <= tunerController.getUsableHalfBandwidth())
{
candidateFrequency = minChannelFrequency - tunerController.getMiddleUnusableHalfBandwidth();
isValidCandidateFrequency = true;
}
else
{
//Iterate the channels and make sure that none of them overlap the center DC spike buffer, if one exists //Iterate the channels and make sure that none of them overlap the center DC spike buffer, if one exists
if(tunerController.getMiddleUnusableHalfBandwidth() > 0) if(tunerController.getMiddleUnusableHalfBandwidth() > 0)
{ {
@@ -98,6 +105,8 @@ public class CenterFrequencyCalculator
} }
} }
}
if(isValidCandidateFrequency) if(isValidCandidateFrequency)
{ {
return candidateFrequency; return candidateFrequency;

View File

@@ -107,6 +107,8 @@ public class HeterodyneChannelSourceManager extends ChannelSourceManager
* Calculates a new center frequency and updates the tuner center frequency * Calculates a new center frequency and updates the tuner center frequency
*/ */
private void updateTunerFrequency() private void updateTunerFrequency()
{
if(!mTunerController.isTunedFor(getTunerChannels()))
{ {
long centerFrequency = CenterFrequencyCalculator.getCenterFrequency(mTunerController, getTunerChannels()); long centerFrequency = CenterFrequencyCalculator.getCenterFrequency(mTunerController, getTunerChannels());
@@ -128,6 +130,7 @@ public class HeterodyneChannelSourceManager extends ChannelSourceManager
} }
} }
} }
}
@Override @Override
public void process(SourceEvent tunerSourceEvent) throws SourceException public void process(SourceEvent tunerSourceEvent) throws SourceException