mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
* WIP on new P25 message framer. * WIP on new P25 message framer. * Adds new 1/2 and 3/4 rate trellis decoders. Still trying to chase down why there is a sync pattern mismatch in the NID buffer queue. * WIP - new p25 message framer works correctly now. PDU's are dectected and decoded using the 1/2 and 3/4 rate trellis decoders. Packet Sequences are assembled. Need to add a new packet sequence message factory that can detect Motorola Auto Registration Service (ARS) formatted UDP/ID packets and SNDCP command packets. * WIP - removes nullify on channel results queue. * WIP - updates message framer for TSBK 1/2/3 processing. * WIP removing P25 sync pattern and nid bits from all message parsers. * WIP - merges identifier framework branch changes into this branch. * WIP on updating link control words to new format and identifier framework. * WIP - implements rest of link control words for extended formats * WIP - initial work on ISP/OSP TSBK message restructuring. * WIP - adds more TSBK ISP and OSP messages * WIP - finished updating most of the TSBK ISP and OSP messages. Converted all messages to no longer include the NID (nac + dataunitID) so that each message can simply hold the parsed values. Removed AliasList as an argument to each message and updated all messges to use the new IIdentifer and IAPCO25Channel interfaces. Removed legacy TDU and LDU link control messages and replaced with a single LinkControlWord class hierarchy. P25 decoder state is not yet updated for the new message structure. PDU message parsing is not fully implemented. * WIP - adds some Multi-Block trunking control messages with Alternate and Unconfirmed formats. * WIP - Fully implements AMBTC and UMBTC PDU message parsers. Some package restructuring. * WIP - Resolves Link control parsing in LDU1 and 2 messages. * WIP - finishes updating TSBK and Link Control messages. Adds support for moto link control messages for patch groups. * WIP - finishes updating TSBK and Link Control messages. Adds support for moto link control messages for patch groups. Adds support for moto ARS service, IPV4 decoding, and UDP/IP packets. * WIP - finishes SNDCP packet data with header parsing. Compressed IP or UDP headers are not yet supported, but are logged as such. * WIP - converts all talkgroup identifiers to integers and updates alias list to create a per-protocol map of talkgroup id's to alias. Inserts a legacy talkgroup (ltr, p25, passport, mpt1327, mdc, etc.) conversion utility to convert existing legacy (string) talkgroups to new integer talkgroup format. Creates an audio packet manager to insert metadata into audio packets before streaming packets for playback, recording, and/or streaming. Creates identifier collection to manage current identifiers in each of the channel and decoder states. Creates simplified channel metadata to maintain the now playing display. Moves channel attributes (alias list, system, site, name) as configuration identifiers in the channel state. Many other refactoring and updates. * WIP - numerous updates to push use of identifier collection throughout the system. Updates the channel metadata and audio packet processing logic. Implements a large portion of the P25 decode state processing. Updates traffic channel management. Adds user preferences for timestamp and identifier formatting, however doesn't add a user interface yet. * WIP - initial implementation of user preferences editor window. * WIP - updates preferences editor window to close and dispose window but retain javafx event thread running. * WIP - fully updates p25 decoder state and traffic channel processing to use the new identifier framework. Cleans up channel event processing and removes channel model as the sole broadcaster of channel events. Channel processing manager now listens for all start/stop events and requestors dispatch event directly to the channel processing manager. Resolves issue in airspy that was causing user interface to lock-up. The issue appears to occur when the dongle is plugged into a usb port that can't fully support the data rate. sdrtrunk now recognizes these errors and warns the user that they should use another usb port. * WIP - updates alias action manager and adds new talkgroup range alias identifier. Updates playlist to incorporate a version number so that the playlist updater only runs when needed, to update a playlist to the correct version format. Updates user preferences to use the google event bus to broadcast preference update notifications to remove the need for listeners to register directly on the user preferences instance. * WIP - updates alias id editors to flag invalid values and moves legacy alias ids to legacy package. Updates event logging configuration to add traffic channel decode events and decoded message logging. Removes binary message logging since that is now replaced with demodulated bitstream recording. * Removes system properties from user preferences. Preferences are stored in the OS-dependent settings store (windows - registry) * Updates MapService to use new PlottableDecodeEvent instead of monitoring all of the decoded messages. Updates Fleetsync decoder and related messages to identifier framework. * Updates LTR-Net, Fleetsync and LJ1200 decoders to new identifier framework and adds support for user preferences for formatting of LTR-Net and fleetsync talkgroup identifiers. Breaks LTR-Net messages into various message types and uses a new message factory. Removes alias list from message processing for ltr-net, fleetsync and lj1200. * Updates LTR-Standard messages to Identifier framework. * Removes Plottable and IPlottable from codebase. * wip * WIP on MPT-1327 messages. * Updates MPT1327 decoder to identifier framework and new traffic channel manager. This decoder still needs to be updated with a new message parser factory and a sync detector like what is now used for P25. * Updates MDC1200 decoder and message to identifier framework. * Updates Tait1200 and Passport decoders to identifier framework. * Merges changes from master branch. * Removes legacy alias support classes. Updates passport message processor to only pass valid messages. Adds support to playlist updater for converting passport mobile ids to become passport talkgroup values. * Updates P25 decoder state and channel state to better track allocated traffic channels. Resolves issue in timestamp manager for trackig message timestamps. Resolves issue in airspy tuner that was causing the tuner to stop sending samples to the application. * Update P25 Decoder state to process SNDCP management messages and PDU messages. Updates P25 activity summary to display network and site details. Resolves issue with overlay panel that prevented enabled channels from rendering correctly when zoomed in. * Creates a new FilePreferences as part of the user preferences to begin the transition of SystemProperties over to user preferences and consolidate file preferences in one location. Updates playlist manager to use the new file preferences and to use default.xml as the new default playlist name, following conversion of a playlist_v2.xml format to the new format. In the near future, the user will be able to edit file locations and to create/use other playlists. Resolved an issue with all decoder states where not all identifiers were being included in decode events.
489 lines
14 KiB
Java
489 lines
14 KiB
Java
/*******************************************************************************
|
|
* sdrtrunk
|
|
* Copyright (C) 2014-2017 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.spectrum;
|
|
|
|
import io.github.dsheirer.dsp.filter.smoothing.GaussianSmoothingFilter;
|
|
import io.github.dsheirer.dsp.filter.smoothing.NoSmoothingFilter;
|
|
import io.github.dsheirer.dsp.filter.smoothing.RectangularSmoothingFilter;
|
|
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter;
|
|
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter.SmoothingType;
|
|
import io.github.dsheirer.dsp.filter.smoothing.TriangularSmoothingFilter;
|
|
import io.github.dsheirer.settings.ColorSetting;
|
|
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
|
import io.github.dsheirer.settings.Setting;
|
|
import io.github.dsheirer.settings.SettingChangeListener;
|
|
import io.github.dsheirer.settings.SettingsManager;
|
|
import org.apache.commons.lang3.Validate;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import javax.swing.JPanel;
|
|
import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.GradientPaint;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Rectangle;
|
|
import java.awt.RenderingHints;
|
|
import java.awt.geom.GeneralPath;
|
|
import java.awt.geom.Line2D;
|
|
import java.util.Arrays;
|
|
|
|
public class SpectrumPanel extends JPanel implements DFTResultsListener, SettingChangeListener, SpectralDisplayAdjuster
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final static Logger mLog = LoggerFactory.getLogger(SpectrumPanel.class);
|
|
|
|
private static final RenderingHints RENDERING_HINTS =
|
|
new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
static
|
|
{
|
|
RENDERING_HINTS.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
}
|
|
|
|
private Color mColorSpectrumBackground;
|
|
private Color mColorSpectrumGradientTop;
|
|
private Color mColorSpectrumGradientBottom;
|
|
private Color mColorSpectrumLine;
|
|
|
|
//Defines the panel inset along the bottom for frequency display
|
|
private float mSpectrumInset = 20.0f;
|
|
|
|
//Current DFT output bins in dB
|
|
private float[] mDisplayFFTBins = new float[1];
|
|
|
|
//Averaging across multiple DFT result sets
|
|
private int mAveraging = 4;
|
|
|
|
//Smoothing across bins in the same DFT result set
|
|
private SmoothingFilter mSmoothingFilter = new NoSmoothingFilter();
|
|
|
|
//Reference dB value set according to the source sample size
|
|
private float mDBScale;
|
|
|
|
private int mZoom = 0;
|
|
private int mZoomWindowOffset = 0;
|
|
;
|
|
|
|
private SettingsManager mSettingsManager;
|
|
|
|
public SpectrumPanel(SettingsManager settingsManager)
|
|
{
|
|
mSettingsManager = settingsManager;
|
|
|
|
if(mSettingsManager != null)
|
|
{
|
|
mSettingsManager.addListener(this);
|
|
}
|
|
|
|
setSampleSize(16.0);
|
|
|
|
mSmoothingFilter.setPointSize(SmoothingFilter.SMOOTHING_DEFAULT);
|
|
|
|
getColors();
|
|
|
|
setAveraging(mAveraging);
|
|
}
|
|
|
|
public void dispose()
|
|
{
|
|
if(mSettingsManager != null)
|
|
{
|
|
mSettingsManager.removeListener(this);
|
|
}
|
|
|
|
mSettingsManager = null;
|
|
}
|
|
|
|
/**
|
|
* DFTResultsListener interface for receiving the processed data
|
|
* to display
|
|
*/
|
|
public void receive(float[] currentFFTBins)
|
|
{
|
|
//Prevent arrays of NaN values from being rendered. The first few
|
|
//DFT result sets on startup will contain NaN values
|
|
if(Float.isInfinite(currentFFTBins[0]) || Float.isNaN(currentFFTBins[0]))
|
|
{
|
|
currentFFTBins = new float[currentFFTBins.length];
|
|
}
|
|
|
|
//Construct and/or resize our DFT results variables
|
|
if(mDisplayFFTBins == null ||
|
|
mDisplayFFTBins.length != currentFFTBins.length)
|
|
{
|
|
mDisplayFFTBins = currentFFTBins;
|
|
}
|
|
|
|
//Apply smoothing across the bins of the DFT results
|
|
float[] smoothedBins = mSmoothingFilter.filter(currentFFTBins);
|
|
|
|
//Apply averaging over multiple DFT output frames
|
|
if(mAveraging > 1)
|
|
{
|
|
float gain = 1.0f / (float)mAveraging;
|
|
|
|
for(int x = 0; x < mDisplayFFTBins.length; x++)
|
|
{
|
|
mDisplayFFTBins[x] +=
|
|
(smoothedBins[x] - mDisplayFFTBins[x]) * gain;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mDisplayFFTBins = smoothedBins;
|
|
}
|
|
|
|
repaint();
|
|
}
|
|
|
|
@Override
|
|
public void paintComponent(Graphics g)
|
|
{
|
|
super.paintComponent(g);
|
|
|
|
Graphics2D graphics = (Graphics2D)g;
|
|
|
|
graphics.setBackground(mColorSpectrumBackground);
|
|
|
|
graphics.setRenderingHints(RENDERING_HINTS);
|
|
|
|
drawSpectrum(graphics);
|
|
}
|
|
|
|
/**
|
|
* Draws the current fft spectrum with a line and a gradient fill.
|
|
*/
|
|
private void drawSpectrum(Graphics2D graphics)
|
|
{
|
|
Dimension size = getSize();
|
|
|
|
//Draw the background
|
|
Rectangle background = new Rectangle(0, 0, size.width, size.height);
|
|
graphics.setColor(mColorSpectrumBackground);
|
|
graphics.draw(background);
|
|
graphics.fill(background);
|
|
|
|
//Define the gradient
|
|
GradientPaint gradient = new GradientPaint(0,
|
|
(getSize().height - mSpectrumInset) / 2,
|
|
mColorSpectrumGradientTop,
|
|
0,
|
|
getSize().height,
|
|
mColorSpectrumGradientBottom);
|
|
|
|
graphics.setBackground(mColorSpectrumBackground);
|
|
|
|
GeneralPath spectrumShape = new GeneralPath();
|
|
|
|
//Start at the lower right inset point
|
|
spectrumShape.moveTo(size.getWidth(),
|
|
size.getHeight() - mSpectrumInset);
|
|
|
|
//Draw to the lower left
|
|
spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);
|
|
|
|
float[] bins = getBins();
|
|
|
|
//If we have FFT data to display ...
|
|
if(bins != null)
|
|
{
|
|
float insideHeight = size.height - mSpectrumInset;
|
|
|
|
float scalor = insideHeight / -mDBScale;
|
|
|
|
/* Calculate based on bin size - 1, since bin 0 is rendered at zero
|
|
* and the last bin is rendered at the width */
|
|
float binSize = (float)size.width / ((float)(bins.length));
|
|
|
|
for(int x = 0; x < bins.length; x++)
|
|
{
|
|
float height;
|
|
|
|
height = bins[x] * scalor;
|
|
|
|
if(height > insideHeight)
|
|
{
|
|
height = insideHeight;
|
|
}
|
|
|
|
if(height < 0)
|
|
{
|
|
height = 0;
|
|
}
|
|
|
|
float xAxis = (float)x * binSize;
|
|
|
|
spectrumShape.lineTo(xAxis, height);
|
|
}
|
|
}
|
|
//Otherwise show an empty spectrum
|
|
else
|
|
{
|
|
//Draw Left Size
|
|
graphics.setPaint(gradient);
|
|
spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);
|
|
//Draw Middle
|
|
spectrumShape.lineTo(size.getWidth(),
|
|
size.getHeight() - mSpectrumInset);
|
|
}
|
|
|
|
//Draw Right Side
|
|
spectrumShape.lineTo(size.getWidth(),
|
|
size.getHeight() - mSpectrumInset);
|
|
|
|
graphics.setPaint(gradient);
|
|
graphics.draw(spectrumShape);
|
|
graphics.fill(spectrumShape);
|
|
|
|
graphics.setPaint(mColorSpectrumLine);
|
|
|
|
//Draw the bottom line under the spectrum
|
|
graphics.draw(new Line2D.Float(0,
|
|
size.height - mSpectrumInset,
|
|
size.width,
|
|
size.height - mSpectrumInset));
|
|
}
|
|
|
|
/**
|
|
* Sets the current zoom level
|
|
*
|
|
* 0 No Zoom
|
|
* 1 2x Zoom
|
|
* 2 4x Zoom
|
|
* 3 8x Zoom
|
|
* 4 16x Zoom
|
|
* 5 32x Zoom
|
|
* 6 64x Zoom
|
|
*
|
|
* @param zoom level, 0 - 6.
|
|
*/
|
|
public void setZoom(int zoom)
|
|
{
|
|
Validate.isTrue(0 <= zoom && zoom <= 6, "Unrecognized Zoom Level: " + zoom);
|
|
|
|
mZoom = zoom;
|
|
}
|
|
|
|
/**
|
|
* Sets the offset to define which subset of zoomed bins to display
|
|
*
|
|
* @param offset
|
|
*/
|
|
public void setZoomWindowOffset(int offset)
|
|
{
|
|
mZoomWindowOffset = offset;
|
|
}
|
|
|
|
/**
|
|
* Sets the source sample size in bits which defines the lowest dB value to
|
|
* display in the spectrum
|
|
*
|
|
* @param sampleSize in bits
|
|
*/
|
|
public void setSampleSize(double sampleSize)
|
|
{
|
|
Validate.isTrue(2.0 <= sampleSize && sampleSize <= 64.0);
|
|
|
|
mDBScale = (float)(20.0 * Math.log10(Math.pow(2.0, sampleSize - 1)));
|
|
}
|
|
|
|
/**
|
|
* Defines the number of DFT result sets to average across
|
|
*/
|
|
public void setAveraging(int size)
|
|
{
|
|
mAveraging = size;
|
|
}
|
|
|
|
/**
|
|
* DFT result sets averaging value
|
|
*/
|
|
public int getAveraging()
|
|
{
|
|
return mAveraging;
|
|
}
|
|
|
|
/**
|
|
* Clears the spectral display
|
|
*/
|
|
public void clearSpectrum()
|
|
{
|
|
Arrays.fill(mDisplayFFTBins, 0.0f);
|
|
repaint();
|
|
}
|
|
|
|
private void getColors()
|
|
{
|
|
mColorSpectrumBackground =
|
|
getColor(ColorSettingName.SPECTRUM_BACKGROUND);
|
|
|
|
mColorSpectrumGradientBottom =
|
|
getColor(ColorSettingName.SPECTRUM_GRADIENT_BOTTOM);
|
|
|
|
mColorSpectrumGradientTop =
|
|
getColor(ColorSettingName.SPECTRUM_GRADIENT_TOP);
|
|
|
|
mColorSpectrumLine = getColor(ColorSettingName.SPECTRUM_LINE);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the current setting for the named color setting
|
|
*/
|
|
private Color getColor(ColorSettingName name)
|
|
{
|
|
ColorSetting setting = mSettingsManager.getColorSetting(name);
|
|
|
|
return setting.getColor();
|
|
}
|
|
|
|
/**
|
|
* Listener interface to receive setting change notifications
|
|
*/
|
|
@Override
|
|
public void settingChanged(Setting setting)
|
|
{
|
|
if(setting instanceof ColorSetting)
|
|
{
|
|
ColorSetting colorSetting = (ColorSetting)setting;
|
|
|
|
switch(((ColorSetting)setting).getColorSettingName())
|
|
{
|
|
case SPECTRUM_BACKGROUND:
|
|
mColorSpectrumBackground = colorSetting.getColor();
|
|
break;
|
|
case SPECTRUM_GRADIENT_BOTTOM:
|
|
mColorSpectrumGradientBottom = colorSetting.getColor();
|
|
break;
|
|
case SPECTRUM_GRADIENT_TOP:
|
|
mColorSpectrumGradientTop = colorSetting.getColor();
|
|
break;
|
|
case SPECTRUM_LINE:
|
|
mColorSpectrumLine = colorSetting.getColor();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private int getZoomMultiplier()
|
|
{
|
|
return (int)Math.pow(2.0, mZoom);
|
|
}
|
|
|
|
/**
|
|
* Returns the DFT result bins, or a zoomed and offset version of the bins
|
|
* when the display is zoomed.
|
|
*/
|
|
private float[] getBins()
|
|
{
|
|
if(mZoom == 0)
|
|
{
|
|
return mDisplayFFTBins;
|
|
}
|
|
else
|
|
{
|
|
int length = mDisplayFFTBins.length / getZoomMultiplier();
|
|
|
|
int offset = mZoomWindowOffset;
|
|
|
|
if((offset + length) >= mDisplayFFTBins.length)
|
|
{
|
|
offset = mDisplayFFTBins.length - length;
|
|
}
|
|
|
|
if(offset < 0)
|
|
{
|
|
offset = 0;
|
|
}
|
|
|
|
return Arrays.copyOfRange(mDisplayFFTBins, offset, offset + length);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void settingDeleted(Setting setting)
|
|
{ /* not implemented */ }
|
|
|
|
/**
|
|
* Returns the current inter-bin smoothing setting
|
|
*/
|
|
@Override
|
|
public int getSmoothing()
|
|
{
|
|
return mSmoothingFilter.getPointSize();
|
|
}
|
|
|
|
/**
|
|
* Sets the bin smoothing value to define how wide the smoothing window is
|
|
* when averaging across DFT bins
|
|
*/
|
|
@Override
|
|
public void setSmoothing(int smoothing)
|
|
{
|
|
mSmoothingFilter.setPointSize(smoothing);
|
|
}
|
|
|
|
/**
|
|
* Returns the current smoothing filter type
|
|
*/
|
|
@Override
|
|
public SmoothingType getSmoothingType()
|
|
{
|
|
return mSmoothingFilter.getSmoothingType();
|
|
}
|
|
|
|
/**
|
|
* Sets the smoothing filter type
|
|
*/
|
|
@Override
|
|
public void setSmoothingType(SmoothingType type)
|
|
{
|
|
if(mSmoothingFilter.getSmoothingType() != type)
|
|
{
|
|
int pointSize = getSmoothing();
|
|
|
|
synchronized(mSmoothingFilter)
|
|
{
|
|
switch(type)
|
|
{
|
|
case GAUSSIAN:
|
|
mSmoothingFilter = new GaussianSmoothingFilter();
|
|
break;
|
|
case RECTANGLE:
|
|
mSmoothingFilter = new RectangularSmoothingFilter();
|
|
break;
|
|
case TRIANGLE:
|
|
mSmoothingFilter = new TriangularSmoothingFilter();
|
|
break;
|
|
case NONE:
|
|
default:
|
|
mSmoothingFilter = new NoSmoothingFilter();
|
|
break;
|
|
}
|
|
}
|
|
|
|
setSmoothing(pointSize);
|
|
}
|
|
}
|
|
}
|