Identifier Framework and Message/Event Processing Overhaul (#455)

* 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.
This commit is contained in:
Denny Sheirer
2018-12-24 09:08:34 -05:00
committed by GitHub
parent 735fca16d6
commit b67d4d92dc
869 changed files with 64776 additions and 45233 deletions

View File

@@ -0,0 +1,67 @@
/*
* ******************************************************************************
* sdrtrunk
* 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.channel;
import io.github.dsheirer.module.decode.p25.message.IFrequencyBand;
import io.github.dsheirer.protocol.Protocol;
/**
* Channel descriptor
*/
public interface IChannelDescriptor
{
/**
* Downlink frequency for the channel
* @return frequency in hertz
*/
long getDownlinkFrequency();
/**
* Uplink frequency for the channel
* @return frequency in hertz
*/
long getUplinkFrequency();
/**
* Frequency band identifiers (0 - 15)
*/
int[] getFrequencyBandIdentifiers();
/**
* Assigns the frequency band message to the channel to use in calculating the up/downlink frequencies
* @param bandIdentifier
*/
void setFrequencyBand(IFrequencyBand bandIdentifier);
/**
* Indicates if the timeslot count is greater than 1;
*/
boolean isTDMAChannel();
/**
* Number of timeslots. FDMA has 1 timeslot and TDMA has at least 2 timeslots
*/
int getTimeslotCount();
/**
* Protocol associated with the channel
*/
Protocol getProtocol();
}

View File

@@ -1,111 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
public class AliasedIdentifier
{
private String mIdentifier;
private Alias mAlias;
/**
* Identifier and corresponding optional alias
*/
public AliasedIdentifier()
{
}
/**
* Resets alias and value to null
*
* Package Private - should only be changed within MutableMetadata
*/
void reset()
{
mIdentifier = null;
mAlias = null;
}
/**
* Identifier
*/
public String getIdentifier()
{
return mIdentifier;
}
/**
* Sets the identifier to the argument value
*
* Package Private - should only be changed within MutableMetadata
*/
void setIdentifier(String identifier)
{
mIdentifier = identifier;
}
/**
* Indicates if there is a non-null, non-empty identifier
*/
public boolean hasIdentifier()
{
return mIdentifier != null && !mIdentifier.isEmpty();
}
/**
* Alias for the identifier.
*/
public Alias getAlias()
{
return mAlias;
}
/**
* Sets the alias to the argument
*
* Package Private - should only be changed within MutableMetadata
*/
void setAlias(Alias alias)
{
mAlias = alias;
}
/**
* Indicates if there is an alias corresponding to the identifier
*/
public boolean hasAlias()
{
return mAlias != null;
}
public AliasedIdentifier copyOf()
{
AliasedIdentifier copy = new AliasedIdentifier();
copy.setAlias(mAlias);
if(mIdentifier != null)
{
copy.setIdentifier(new String(mIdentifier));
}
return copy;
}
}

View File

@@ -1,101 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.id.AliasIDType;
import io.github.dsheirer.sample.Listener;
import static io.github.dsheirer.alias.id.AliasIDType.LTR_NET_UID;
import static io.github.dsheirer.alias.id.AliasIDType.STATUS;
public class AliasedIntegerAttributeMonitor extends AttributeMonitor<Integer>
{
private static final AliasIDType[] VALID_ID_TYPES = {STATUS, LTR_NET_UID};
private AliasList mAliasList;
private AliasIDType mAliasIDType;
/**
* Provides monitoring of a String attribute's values with occurrence heuristics enabled and alias lookup with each
* change in the attribute's value.
*
* @param attribute to monitor
* @param listener to receive change requests
* @param aliasList to lookup alias from
* @param aliasIDType to determine correct alias lookup method in alias list
*/
public AliasedIntegerAttributeMonitor(Attribute attribute, Listener<AttributeChangeRequest> listener, AliasList aliasList,
AliasIDType aliasIDType)
{
super(attribute, listener);
if(!isValidIDType(aliasIDType))
{
throw new IllegalArgumentException("Alias ID Type [" + aliasIDType.name() + "] is not supported");
}
mAliasList = aliasList;
mAliasIDType = aliasIDType;
}
/**
* Indicates if the alias ID type is a supported/valid type for this monitor.
*/
public static boolean isValidIDType(AliasIDType type)
{
for(AliasIDType validType: VALID_ID_TYPES)
{
if(type == validType)
{
return true;
}
}
return false;
}
/**
* Lookup of the alias that corresponds to the value's alias ID type
*/
@Override
protected Alias getAlias()
{
Alias alias = null;
if(mAliasList != null)
{
if(hasValue())
{
switch(mAliasIDType)
{
case STATUS:
alias = mAliasList.getStatus(getValue());
break;
case LTR_NET_UID:
alias = mAliasList.getUniqueID(getValue());
break;
}
}
}
return alias;
}
}

View File

@@ -1,121 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.id.AliasIDType;
import io.github.dsheirer.sample.Listener;
import static io.github.dsheirer.alias.id.AliasIDType.ESN;
import static io.github.dsheirer.alias.id.AliasIDType.FLEETSYNC;
import static io.github.dsheirer.alias.id.AliasIDType.MDC1200;
import static io.github.dsheirer.alias.id.AliasIDType.MIN;
import static io.github.dsheirer.alias.id.AliasIDType.MPT1327;
import static io.github.dsheirer.alias.id.AliasIDType.SITE;
import static io.github.dsheirer.alias.id.AliasIDType.TALKGROUP;
public class AliasedStringAttributeMonitor extends AttributeMonitor<String>
{
private static final AliasIDType[] VALID_ID_TYPES = {ESN, FLEETSYNC, MDC1200, MIN, MPT1327, SITE, TALKGROUP};
private AliasList mAliasList;
private AliasIDType mAliasIDType;
/**
* Provides monitoring of a String attribute's values with occurrence heuristics enabled and alias lookup with each
* change in the attribute's value.
*
* @param attribute to monitor
* @param listener to receive change requests
* @param aliasList to lookup alias from
* @param aliasIDType to determine correct alias lookup method in alias list
*/
public AliasedStringAttributeMonitor(Attribute attribute, Listener<AttributeChangeRequest> listener, AliasList aliasList,
AliasIDType aliasIDType)
{
super(attribute, listener);
if(!isValidIDType(aliasIDType))
{
throw new IllegalArgumentException("Alias ID Type [" + aliasIDType.name() + "] is not supported");
}
mAliasList = aliasList;
mAliasIDType = aliasIDType;
}
/**
* Indicates if the alias ID type is a supported/valid type for this monitor.
*/
public static boolean isValidIDType(AliasIDType type)
{
for(AliasIDType validType: VALID_ID_TYPES)
{
if(type == validType)
{
return true;
}
}
return false;
}
/**
* Lookup of the alias that corresponds to the value's alias ID type
*/
@Override
protected Alias getAlias()
{
Alias alias = null;
if(mAliasList != null)
{
if(hasValue())
{
switch(mAliasIDType)
{
case ESN:
alias = mAliasList.getESNAlias(getValue());
break;
case FLEETSYNC:
alias = mAliasList.getFleetsyncAlias(getValue());
break;
case MDC1200:
alias = mAliasList.getMDC1200Alias(getValue());
break;
case MIN:
alias = mAliasList.getMobileIDNumberAlias(getValue());
break;
case MPT1327:
alias = mAliasList.getMPT1327Alias(getValue());
break;
case SITE:
alias = mAliasList.getSiteID(getValue());
break;
case TALKGROUP:
alias = mAliasList.getTalkgroupAlias(getValue());
break;
}
}
}
return alias;
}
}

View File

@@ -1,159 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.sample.Listener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AttributeMonitor<T>
{
private Attribute mAttribute;
private Listener<AttributeChangeRequest> mListener;
private boolean mHeuristicsEnabled = true;
private Map<T,Integer> mOccurrenceCounts = new HashMap<>();
private T mCurrentValue;
private List<T> mIllegalValues = new ArrayList<>();
public AttributeMonitor(Attribute attribute, Listener<AttributeChangeRequest> listener)
{
mAttribute = attribute;
mListener = listener;
}
/**
* Processes the value and emits a change request if the value needs to be changed. If heuristics are enabled,
* an internal mapping of values to occurrence counts is updated and a change is emitted once a value that is
* different from the current value, has a higher occurrence count than the current value. If heuristics are
* disabled, then a change is emitted at each change in the value.
*
* @param t type
* @return true if the value was changed after processing
*/
public boolean process(T t)
{
boolean changed = false;
if(t != null && !mIllegalValues.contains(t))
{
if(mHeuristicsEnabled)
{
if(mOccurrenceCounts.containsKey(t))
{
mOccurrenceCounts.put(t, mOccurrenceCounts.get(t) + 1);
}
else
{
mOccurrenceCounts.put(t, 1);
}
}
if(mCurrentValue == null)
{
mCurrentValue = t;
changed = true;
}
else if(!mCurrentValue.equals(t))
{
if(mHeuristicsEnabled)
{
int count = mOccurrenceCounts.get(mCurrentValue);
for(Map.Entry<T,Integer> entry : mOccurrenceCounts.entrySet())
{
if(entry.getValue() > count)
{
count = entry.getValue();
mCurrentValue = entry.getKey();
changed = true;
}
}
}
else
{
mCurrentValue = t;
changed = true;
}
}
if(changed && mListener != null)
{
mListener.receive(new AttributeChangeRequest(mAttribute, getValue(), getAlias()));
}
}
return changed;
}
/**
* Alias for the current value. This class does not return an alias, but subclasses can return an alias that
* is appropriate for the monitored attribute value.
*
* @return an optional alias for the current value
*/
protected Alias getAlias()
{
return null;
}
/**
* Resets the attribute value to null and resets occurrence heuristics.
*/
public void reset()
{
mCurrentValue = null;
mOccurrenceCounts.clear();
if(mListener != null)
{
mListener.receive(new AttributeChangeRequest(mAttribute, null, null));
}
}
/**
* Adds a value to the internal list of illegal values. The monitor will not allow the attribute to be changed to
* any values contained in this list.
*
* @param illegalValue to prevent for the monitored alias
*/
public void addIllegalValue(T illegalValue)
{
mIllegalValues.add(illegalValue);
}
/**
* Returns the current value or null if the monitor is newly started or reset.
*/
public T getValue()
{
return mCurrentValue;
}
/**
* Indicates if the current value is non-null
*/
public boolean hasValue()
{
return mCurrentValue != null;
}
}

View File

@@ -0,0 +1,336 @@
/*
* ******************************************************************************
* sdrtrunk
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierUpdateListener;
import io.github.dsheirer.identifier.IdentifierUpdateNotification;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.ChannelNameConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.DecoderTypeConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.FrequencyConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.SiteConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.SystemConfigurationIdentifier;
import io.github.dsheirer.identifier.decoder.DecoderLogicalChannelNameIdentifier;
import io.github.dsheirer.identifier.decoder.DecoderStateIdentifier;
import io.github.dsheirer.sample.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Channel metadata containing details about the channel configuration, decoder state and current
* set of decoded user identifiers (ie TO and FROM).
*/
public class ChannelMetadata implements Listener<IdentifierUpdateNotification>, IdentifierUpdateListener
{
private final static Logger mLog = LoggerFactory.getLogger(ChannelMetadata.class);
private SystemConfigurationIdentifier mSystemConfigurationIdentifier;
private SiteConfigurationIdentifier mSiteConfigurationIdentifier;
private ChannelNameConfigurationIdentifier mChannelNameConfigurationIdentifier;
private FrequencyConfigurationIdentifier mFrequencyConfigurationIdentifier;
private DecoderStateIdentifier mDecoderStateIdentifier = DecoderStateIdentifier.IDLE;
private DecoderLogicalChannelNameIdentifier mDecoderLogicalChannelNameIdentifier;
private DecoderTypeConfigurationIdentifier mDecoderTypeConfigurationIdentifier;
private Identifier mFromIdentifier;
private Alias mFromIdentifierAlias;
private Identifier mToIdentifier;
private Alias mToIdentifierAlias;
private IChannelMetadataUpdateListener mIChannelMetadataUpdateListener;
private AliasModel mAliasModel;
private AliasList mAliasList;
public ChannelMetadata(AliasModel aliasModel)
{
mAliasModel = aliasModel;
}
@Override
public Listener<IdentifierUpdateNotification> getIdentifierUpdateListener()
{
return this;
}
/**
* System configuration identifier
*/
public SystemConfigurationIdentifier getSystemConfigurationIdentifier()
{
return mSystemConfigurationIdentifier;
}
public boolean hasSystemConfigurationIdentifier()
{
return mSystemConfigurationIdentifier != null;
}
/**
* Site configuration identifier
*/
public SiteConfigurationIdentifier getSiteConfigurationIdentifier()
{
return mSiteConfigurationIdentifier;
}
public boolean hasSiteConfigurationIdentifier()
{
return mSiteConfigurationIdentifier != null;
}
/**
* Channel configuration identifier
*/
public ChannelNameConfigurationIdentifier getChannelNameConfigurationIdentifier()
{
return mChannelNameConfigurationIdentifier;
}
public boolean hasChannelConfigurationIdentifier()
{
return mChannelNameConfigurationIdentifier != null;
}
/**
* Logical channel name/number expoded by the decoder
*/
public DecoderLogicalChannelNameIdentifier getDecoderLogicalChannelNameIdentifier()
{
return mDecoderLogicalChannelNameIdentifier;
}
public boolean hasDecoderLogicalChannelNameIdentifier()
{
return mDecoderLogicalChannelNameIdentifier != null;
}
/**
* Frequency configuration identifier
*/
public FrequencyConfigurationIdentifier getFrequencyConfigurationIdentifier()
{
return mFrequencyConfigurationIdentifier;
}
public boolean hasFrequencyConfigurationIdentifier()
{
return mFrequencyConfigurationIdentifier != null;
}
/**
* Decoder state identifier
*/
public DecoderStateIdentifier getDecoderStateIdentifier()
{
return mDecoderStateIdentifier;
}
public boolean hasDecoderStateIdentifier()
{
return mDecoderStateIdentifier != null;
}
/**
* Decoder type identifier
*/
public DecoderTypeConfigurationIdentifier getDecoderTypeConfigurationIdentifier()
{
return mDecoderTypeConfigurationIdentifier;
}
public boolean hasDecoderTypeIdentifier()
{
return mDecoderTypeConfigurationIdentifier != null;
}
/**
* Current call event FROM identifier
*/
public Identifier getFromIdentifier()
{
return mFromIdentifier;
}
public boolean hasFromIdentifier()
{
return mFromIdentifier != null;
}
/**
* Optional alias associated with the FROM identifier
*/
public Alias getFromIdentifierAlias()
{
return mFromIdentifierAlias;
}
/**
* Current call event TO identifier
*/
public Identifier getToIdentifier()
{
return mToIdentifier;
}
public boolean hasToIdentifier()
{
return mToIdentifier != null;
}
/**
* Optional alias associated with the TO identifier
*/
public Alias getToIdentifierAlias()
{
return mToIdentifierAlias;
}
/**
* Registers the listener for receiving field update events
*/
public void setUpdateEventListener(IChannelMetadataUpdateListener listener)
{
mIChannelMetadataUpdateListener = listener;
}
/**
* Deregisters the listener from receiving field update events
*/
public void removeUpdateEventListener()
{
mIChannelMetadataUpdateListener = null;
}
/**
* Broadcasts this metadata and the field that has been updated
*
* @param field that has been updated
*/
private void broadcastUpdate(ChannelMetadataField field)
{
if(mIChannelMetadataUpdateListener != null)
{
mIChannelMetadataUpdateListener.updated(this, field);
}
}
@Override
public void receive(IdentifierUpdateNotification update)
{
Identifier identifier = update.getIdentifier();
switch(identifier.getIdentifierClass())
{
case CONFIGURATION:
switch(identifier.getForm())
{
case ALIAS_LIST:
if(update.isAdded())
{
mAliasList = mAliasModel.getAliasList((AliasListConfigurationIdentifier)identifier);
if(mAliasList != null)
{
if(mToIdentifier != null)
{
mToIdentifierAlias = mAliasList.getAlias(mToIdentifier);
}
if(mFromIdentifier != null)
{
mFromIdentifierAlias = mAliasList.getAlias(mFromIdentifier);
}
}
}
break;
case CHANNEL:
mChannelNameConfigurationIdentifier = update.isAdded() ? (ChannelNameConfigurationIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.CONFIGURATION_CHANNEL);
break;
case CHANNEL_FREQUENCY:
mFrequencyConfigurationIdentifier = update.isAdded() ? (FrequencyConfigurationIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.CONFIGURATION_FREQUENCY);
break;
case DECODER_TYPE:
mDecoderTypeConfigurationIdentifier = update.isAdded() ? (DecoderTypeConfigurationIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.DECODER_TYPE);
break;
case SITE:
mSiteConfigurationIdentifier = update.isAdded() ? (SiteConfigurationIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.CONFIGURATION_SITE);
break;
case SYSTEM:
mSystemConfigurationIdentifier = update.isAdded() ? (SystemConfigurationIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.CONFIGURATION_SYSTEM);
break;
}
break;
case DECODER:
switch(identifier.getForm())
{
case CHANNEL_NAME:
mDecoderLogicalChannelNameIdentifier = update.isAdded() ? (DecoderLogicalChannelNameIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.DECODER_CHANNEL_NAME);
break;
case STATE:
mDecoderStateIdentifier = update.isAdded() ? (DecoderStateIdentifier)identifier : null;
broadcastUpdate(ChannelMetadataField.DECODER_STATE);
break;
}
break;
case USER:
if(identifier.getRole() == Role.FROM)
{
mFromIdentifier = update.isAdded() ? identifier : null;
if(mAliasList != null && mFromIdentifier != null)
{
mFromIdentifierAlias = mAliasList.getAlias(mFromIdentifier);
}
else
{
mFromIdentifierAlias = null;
}
broadcastUpdate(ChannelMetadataField.USER_FROM);
}
else if(identifier.getRole() == Role.TO)
{
mToIdentifier = update.isAdded() ? identifier : null;
if(mAliasList != null && mToIdentifier != null)
{
mToIdentifierAlias = mAliasList.getAlias(mToIdentifier);
}
else
{
mToIdentifierAlias = null;
}
broadcastUpdate(ChannelMetadataField.USER_TO);
}
break;
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* ******************************************************************************
* sdrtrunk
* 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.channel.metadata;
public enum ChannelMetadataField
{
CONFIGURATION_CHANNEL,
CONFIGURATION_FREQUENCY,
CONFIGURATION_SITE,
CONFIGURATION_SYSTEM,
DECODER_CHANNEL_NAME,
DECODER_STATE,
DECODER_TYPE,
USER_FROM,
USER_TO;
}

View File

@@ -15,44 +15,65 @@
******************************************************************************/
package io.github.dsheirer.channel.metadata;
import io.github.dsheirer.channel.state.State;
import com.google.common.eventbus.Subscribe;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.preference.PreferenceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.table.AbstractTableModel;
import java.awt.EventQueue;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChannelMetadataModel extends AbstractTableModel implements Listener<MutableMetadataChangeEvent>
public class ChannelMetadataModel extends AbstractTableModel implements IChannelMetadataUpdateListener
{
private final static Logger mLog = LoggerFactory.getLogger(ChannelMetadataModel.class);
private final DecimalFormat FREQUENCY_FORMATTER = new DecimalFormat( "#.00000" );
public static final int COLUMN_DECODER_STATE = 0;
public static final int COLUMN_DECODER_TYPE = 1;
public static final int COLUMN_USER_FROM = 2;
public static final int COLUMN_USER_FROM_ALIAS = 3;
public static final int COLUMN_USER_TO = 4;
public static final int COLUMN_USER_TO_ALIAS = 5;
public static final int COLUMN_DECODER_LOGICAL_CHANNEL_NAME = 6;
public static final int COLUMN_CONFIGURATION_FREQUENCY = 7;
public static final int COLUMN_CONFIGURATION_CHANNEL = 8;
public static final int COLUMN_STATE = 0;
public static final int COLUMN_DECODER = 1;
public static final int COLUMN_CHANNEL = 2;
public static final int COLUMN_FREQUENCY = 3;
public static final int COLUMN_PRIMARY_FROM = 4;
public static final int COLUMN_PRIMARY_TO = 5;
public static final int COLUMN_SECONDARY_FROM = 6;
public static final int COLUMN_SECONDARY_TO = 7;
public static final int COLUMN_CONFIGURATION_NAME = 8;
public static final int COLUMN_MESSAGE = 9;
private static final String[] COLUMNS = {"Status", "Decoder", "From", "Alias", "To", "Alias", "Channel", "Frequency", "Channel Name"};
private static final String[] COLUMNS = {"Status", "Decoder", "Channel", "Frequency", "Primary From", "Primary To",
"Secondary From", "Secondary To", "Channel Name", "Message"};
private List<ChannelMetadata> mChannelMetadata = new ArrayList();
private Map<ChannelMetadata,Channel> mMetadataChannelMap = new HashMap();
private List<MutableMetadata> mChannelMetadata = new ArrayList();
private Map<MutableMetadata,Channel> mMetadataChannelMap = new HashMap();
public ChannelMetadataModel()
{
MyEventBus.getEventBus().register(this);
}
public void add(MutableMetadata metadata, Channel channel)
/**
* Receives preference update notifications via the event bus
* @param preferenceType that was updated
*/
@Subscribe
public void preferenceUpdated(PreferenceType preferenceType)
{
if(preferenceType == PreferenceType.IDENTIFIER)
{
for(int row = 0; row < mChannelMetadata.size(); row++)
{
fireTableCellUpdated(row, COLUMN_USER_FROM);
fireTableCellUpdated(row, COLUMN_USER_TO);
}
}
}
public void add(ChannelMetadata channelMetadata, Channel channel)
{
//Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable()
@@ -60,19 +81,16 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
@Override
public void run()
{
mChannelMetadata.add(metadata);
mMetadataChannelMap.put(metadata, channel);
int index = mChannelMetadata.indexOf(metadata);
mChannelMetadata.add(channelMetadata);
mMetadataChannelMap.put(channelMetadata, channel);
int index = mChannelMetadata.indexOf(channelMetadata);
fireTableRowsInserted(index, index);
metadata.addListener(ChannelMetadataModel.this);
channelMetadata.setUpdateEventListener(ChannelMetadataModel.this);
}
});
}
public void remove(MutableMetadata metadata)
public void remove(ChannelMetadata channelMetadata)
{
//Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable()
@@ -80,13 +98,10 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
@Override
public void run()
{
metadata.removeListener(ChannelMetadataModel.this);
int index = mChannelMetadata.indexOf(metadata);
mChannelMetadata.remove(metadata);
mMetadataChannelMap.remove(metadata);
channelMetadata.removeUpdateEventListener();
int index = mChannelMetadata.indexOf(channelMetadata);
mChannelMetadata.remove(channelMetadata);
mMetadataChannelMap.remove(channelMetadata);
fireTableRowsDeleted(index, index);
}
});
@@ -95,7 +110,7 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
/**
* Get the channel metadata at the specified model row index
*/
public Metadata getMetadata(int row)
public ChannelMetadata getChannelMetadata(int row)
{
if(row < mChannelMetadata.size())
{
@@ -108,9 +123,9 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
/**
* Returns the channel that matches the metadata or null
*/
public Channel getChannelFromMetadata(Metadata metadata)
public Channel getChannelFromMetadata(ChannelMetadata channelMetadata)
{
return mMetadataChannelMap.get(metadata);
return mMetadataChannelMap.get(channelMetadata);
}
@Override
@@ -136,24 +151,14 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
{
switch(columnIndex)
{
case COLUMN_STATE:
return State.class;
case COLUMN_DECODER:
case COLUMN_CHANNEL:
case COLUMN_FREQUENCY:
case COLUMN_MESSAGE:
case COLUMN_CONFIGURATION_NAME:
return String.class;
case COLUMN_PRIMARY_TO:
case COLUMN_PRIMARY_FROM:
case COLUMN_SECONDARY_TO:
case COLUMN_SECONDARY_FROM:
return MutableMetadata.class;
case COLUMN_USER_FROM:
case COLUMN_USER_TO:
return ChannelMetadata.class;
case COLUMN_USER_FROM_ALIAS:
case COLUMN_USER_TO_ALIAS:
return Alias.class;
default:
return String.class;
return Identifier.class;
}
}
@@ -162,60 +167,28 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
{
if(rowIndex <= mChannelMetadata.size())
{
Metadata metadata = mChannelMetadata.get(rowIndex);
ChannelMetadata channelMetadata = mChannelMetadata.get(rowIndex);
switch(columnIndex)
{
case COLUMN_STATE:
return metadata.getState();
case COLUMN_DECODER:
if(metadata.hasPrimaryDecoderType())
{
return metadata.getPrimaryDecoderType().getShortDisplayString();
}
return null;
case COLUMN_CHANNEL:
return metadata.getChannelFrequencyLabel();
case COLUMN_FREQUENCY:
if(metadata.hasChannelFrequency())
{
return FREQUENCY_FORMATTER.format((double)metadata.getChannelFrequency() / 1E6d);
}
return null;
case COLUMN_MESSAGE:
if(metadata.isBufferOverflow())
{
return "**OVERFLOW**";
}
else if(metadata.hasMessageType() || metadata.hasMessage())
{
StringBuilder sb = new StringBuilder();
if(metadata.hasMessageType())
{
sb.append(metadata.getMessageType()).append(" ");
}
if(metadata.hasMessage())
{
sb.append(metadata.getMessage());
}
return sb.toString();
}
return null;
case COLUMN_CONFIGURATION_NAME:
return metadata.getChannelConfigurationName();
case COLUMN_PRIMARY_TO:
case COLUMN_PRIMARY_FROM:
case COLUMN_SECONDARY_TO:
case COLUMN_SECONDARY_FROM:
return metadata;
default:
return String.class;
case COLUMN_DECODER_STATE:
return channelMetadata.getDecoderStateIdentifier();
case COLUMN_DECODER_TYPE:
return channelMetadata.getDecoderTypeConfigurationIdentifier();
case COLUMN_DECODER_LOGICAL_CHANNEL_NAME:
return channelMetadata.getDecoderLogicalChannelNameIdentifier();
case COLUMN_CONFIGURATION_FREQUENCY:
return channelMetadata.getFrequencyConfigurationIdentifier();
case COLUMN_CONFIGURATION_CHANNEL:
return channelMetadata.getChannelNameConfigurationIdentifier();
case COLUMN_USER_TO:
return channelMetadata;
case COLUMN_USER_FROM:
return channelMetadata;
case COLUMN_USER_FROM_ALIAS:
return channelMetadata.getFromIdentifierAlias();
case COLUMN_USER_TO_ALIAS:
return channelMetadata.getToIdentifierAlias();
}
}
@@ -223,59 +196,46 @@ public class ChannelMetadataModel extends AbstractTableModel implements Listener
}
@Override
public void receive(MutableMetadataChangeEvent mutableMetadataChangeEvent)
public void updated(ChannelMetadata channelMetadata, ChannelMetadataField channelMetadataField)
{
//Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
int rowIndex = mChannelMetadata.indexOf(mutableMetadataChangeEvent.getMetadata());
final int rowIndex = mChannelMetadata.indexOf(channelMetadata);
if(rowIndex >= 0)
if(rowIndex >= 0)
{
//Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
switch(mutableMetadataChangeEvent.getAttribute())
switch(channelMetadataField)
{
case CHANNEL_CONFIGURATION_SYSTEM:
case CONFIGURATION_CHANNEL:
fireTableCellUpdated(rowIndex, COLUMN_CONFIGURATION_CHANNEL);
break;
case CHANNEL_CONFIGURATION_SITE:
case CONFIGURATION_FREQUENCY:
fireTableCellUpdated(rowIndex, COLUMN_CONFIGURATION_FREQUENCY);
break;
case CHANNEL_CONFIGURATION_NAME:
fireTableCellUpdated(rowIndex, COLUMN_CONFIGURATION_NAME);
case DECODER_CHANNEL_NAME:
fireTableCellUpdated(rowIndex, COLUMN_DECODER_LOGICAL_CHANNEL_NAME);
break;
case CHANNEL_FREQUENCY:
fireTableCellUpdated(rowIndex, COLUMN_FREQUENCY);
case DECODER_TYPE:
fireTableCellUpdated(rowIndex, COLUMN_DECODER_TYPE);
break;
case CHANNEL_FREQUENCY_LABEL:
fireTableCellUpdated(rowIndex, COLUMN_CHANNEL);
case DECODER_STATE:
fireTableCellUpdated(rowIndex, COLUMN_DECODER_STATE);
break;
case CHANNEL_STATE:
fireTableCellUpdated(rowIndex, COLUMN_STATE);
case USER_FROM:
fireTableCellUpdated(rowIndex, COLUMN_USER_FROM);
fireTableCellUpdated(rowIndex, COLUMN_USER_FROM_ALIAS);
break;
case BUFFER_OVERFLOW:
case MESSAGE:
case MESSAGE_TYPE:
fireTableCellUpdated(rowIndex, COLUMN_MESSAGE);
break;
case PRIMARY_ADDRESS_FROM:
fireTableCellUpdated(rowIndex, COLUMN_PRIMARY_FROM);
break;
case PRIMARY_ADDRESS_TO:
fireTableCellUpdated(rowIndex, COLUMN_PRIMARY_TO);
break;
case PRIMARY_DECODER_TYPE:
fireTableCellUpdated(rowIndex, COLUMN_DECODER);
break;
case SECONDARY_ADDRESS_FROM:
fireTableCellUpdated(rowIndex, COLUMN_SECONDARY_FROM);
break;
case SECONDARY_ADDRESS_TO:
fireTableCellUpdated(rowIndex, COLUMN_SECONDARY_TO);
case USER_TO:
fireTableCellUpdated(rowIndex, COLUMN_USER_TO);
fireTableCellUpdated(rowIndex, COLUMN_USER_TO_ALIAS);
break;
}
}
}
});
});
}
}
}

View File

@@ -1,6 +1,7 @@
/*******************************************************************************
/*
* ******************************************************************************
* sdrtrunk
* 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
@@ -14,21 +15,26 @@
*
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.channel.state.State;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.controller.channel.ChannelUtils;
import io.github.dsheirer.icon.IconManager;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.configuration.FrequencyConfigurationIdentifier;
import io.github.dsheirer.identifier.decoder.DecoderStateIdentifier;
import io.github.dsheirer.module.ProcessingChain;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.identifier.TalkgroupFormatPreference;
import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener;
import net.miginfocom.swing.MigLayout;
import org.apache.commons.lang3.Validate;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
@@ -44,13 +50,16 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
public class ChannelMetadataPanel extends JPanel implements ListSelectionListener
{
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private IconManager mIconManager;
private UserPreferences mUserPreferences;
private JTable mTable;
private Broadcaster<ProcessingChain> mSelectedProcessingChainBroadcaster = new Broadcaster<>();
private Map<State,Color> mBackgroundColors = new HashMap<>();
@@ -59,11 +68,13 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
/**
* Table view for currently decoding channel metadata
*/
public ChannelMetadataPanel(ChannelProcessingManager channelProcessingManager, IconManager iconManager)
public ChannelMetadataPanel(ChannelModel channelModel, ChannelProcessingManager channelProcessingManager,
IconManager iconManager, UserPreferences userPreferences)
{
mIconManager = iconManager;
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mIconManager = iconManager;
mUserPreferences = userPreferences;
init();
}
@@ -82,16 +93,18 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
mTable.getSelectionModel().addListSelectionListener(this);
mTable.addMouseListener(new MouseSupport());
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_STATE)
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_DECODER_STATE)
.setCellRenderer(new ColoredStateCellRenderer());
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_TO)
.setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_TO));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_FROM)
.setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_FROM));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_TO)
.setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_TO));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_FROM)
.setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_FROM));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_USER_FROM)
.setCellRenderer(new FromCellRenderer(mUserPreferences.getTalkgroupFormatPreference()));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_USER_TO)
.setCellRenderer(new ToCellRenderer(mUserPreferences.getTalkgroupFormatPreference()));
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_USER_FROM_ALIAS)
.setCellRenderer(new AliasCellRenderer());
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_USER_TO_ALIAS)
.setCellRenderer(new AliasCellRenderer());
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_CONFIGURATION_FREQUENCY)
.setCellRenderer(new FrequencyCellRenderer());
JScrollPane scrollPane = new JScrollPane(mTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
@@ -139,14 +152,16 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
{
int selectedModelRow = mTable.convertRowIndexToModel(selectedViewRow);
Metadata selectedMetadata = mChannelProcessingManager.getChannelMetadataModel()
.getMetadata(selectedModelRow);
ChannelMetadata selectedMetadata = mChannelProcessingManager.getChannelMetadataModel()
.getChannelMetadata(selectedModelRow);
if(selectedMetadata != null)
{
Channel selectedChannel = mChannelProcessingManager.getChannelMetadataModel()
.getChannelFromMetadata(selectedMetadata);
processingChain = mChannelProcessingManager.getProcessingChain(selectedChannel);
}
}
@@ -164,35 +179,148 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
mSelectedProcessingChainBroadcaster.addListener(listener);
}
public class AliasedValueCellRenderer extends DefaultTableCellRenderer
/**
* Cell renderer for frequency values
*/
public class FrequencyCellRenderer extends DefaultTableCellRenderer
{
private Attribute mAttribute;
private final DecimalFormat FREQUENCY_FORMATTER = new DecimalFormat( "#.00000" );
public AliasedValueCellRenderer(Attribute attribute)
public FrequencyCellRenderer()
{
Validate.isTrue(attribute != null);
mAttribute = attribute;
setHorizontalAlignment(JLabel.CENTER);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column)
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
Metadata metadata = (Metadata)value;
String value1 = metadata.getValue(mAttribute);
Alias alias = metadata.getAlias(mAttribute);
label.setText(alias != null ? alias.getName() : value1);
label.setIcon(alias != null ? mIconManager.getIcon(alias.getIconName(), IconManager.DEFAULT_ICON_SIZE) : null);
label.setForeground(alias != null ? alias.getDisplayColor() : table.getForeground());
if(value instanceof FrequencyConfigurationIdentifier)
{
long frequency = ((FrequencyConfigurationIdentifier)value).getValue();
label.setText(FREQUENCY_FORMATTER.format(frequency / 1e6d));
}
else
{
label.setText(null);
}
return label;
}
}
/**
* Alias cell renderer
*/
public class AliasCellRenderer extends DefaultTableCellRenderer
{
public AliasCellRenderer()
{
setHorizontalAlignment(JLabel.LEFT);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(value instanceof Alias)
{
Alias alias = (Alias)value;
label.setText(alias.getName());
label.setIcon(mIconManager.getIcon(alias.getIconName(), IconManager.DEFAULT_ICON_SIZE));
label.setForeground(alias.getDisplayColor());
}
else
{
label.setText(null);
label.setIcon(null);
label.setForeground(table.getForeground());
}
return label;
}
}
/**
* Abstract cell renderer for identifiers
*/
public abstract class IdentifierCellRenderer extends DefaultTableCellRenderer
{
private final static String EMPTY_VALUE = "-----";
private TalkgroupFormatPreference mTalkgroupFormatPreference;
public IdentifierCellRenderer(TalkgroupFormatPreference talkgroupFormatPreference)
{
mTalkgroupFormatPreference = talkgroupFormatPreference;
setHorizontalAlignment(JLabel.CENTER);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(value instanceof ChannelMetadata)
{
ChannelMetadata channelMetadata = (ChannelMetadata)value;
Identifier identifier = getIdentifier(channelMetadata);
String text = mTalkgroupFormatPreference.format(identifier);
if(text == null || text.isEmpty())
{
text = EMPTY_VALUE;
}
label.setText(text);
}
else
{
label.setText(EMPTY_VALUE);
}
return label;
}
public abstract Identifier getIdentifier(ChannelMetadata channelMetadata);
}
/**
* Cell renderer for the FROM identifier
*/
public class FromCellRenderer extends IdentifierCellRenderer
{
public FromCellRenderer(TalkgroupFormatPreference talkgroupFormatPreference)
{
super(talkgroupFormatPreference);
}
@Override
public Identifier getIdentifier(ChannelMetadata channelMetadata)
{
return channelMetadata.getFromIdentifier();
}
}
/**
* Cell renderer for the TO identifier
*/
public class ToCellRenderer extends IdentifierCellRenderer
{
public ToCellRenderer(TalkgroupFormatPreference talkgroupFormatPreference)
{
super(talkgroupFormatPreference);
}
@Override
public Identifier getIdentifier(ChannelMetadata channelMetadata)
{
return channelMetadata.getToIdentifier();
}
}
public class ColoredStateCellRenderer extends DefaultTableCellRenderer
{
public ColoredStateCellRenderer()
@@ -209,9 +337,9 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
Color background = table.getBackground();
Color foreground = table.getForeground();
if(value instanceof State)
if(value instanceof DecoderStateIdentifier)
{
State state = (State)value;
State state = ((DecoderStateIdentifier)value).getValue();
label.setText(state.getDisplayValue());
if(mBackgroundColors.containsKey(state))
@@ -226,7 +354,7 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
}
else
{
setText("");
setText("----");
}
setBackground(background);
@@ -255,7 +383,7 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
if(modelRowIndex >= 0)
{
Metadata metadata = mChannelProcessingManager.getChannelMetadataModel().getMetadata(modelRowIndex);
ChannelMetadata metadata = mChannelProcessingManager.getChannelMetadataModel().getChannelMetadata(modelRowIndex);
if(metadata != null)
{
@@ -264,9 +392,7 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
if(channel != null)
{
popupMenu.add(ChannelUtils.getContextMenu(mChannelProcessingManager.getChannelModel(),
mChannelProcessingManager, channel, mTable));
popupMenu.add(ChannelUtils.getContextMenu(mChannelModel, mChannelProcessingManager, channel, mTable));
populated = true;
}
}

View File

@@ -20,12 +20,14 @@ package io.github.dsheirer.channel.metadata;
import com.jidesoft.swing.JideSplitPane;
import com.jidesoft.swing.JideTabbedPane;
import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.channel.details.ChannelDetailPanel;
import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.icon.IconManager;
import io.github.dsheirer.module.decode.event.CallEventPanel;
import io.github.dsheirer.module.decode.event.DecodeEventPanel;
import io.github.dsheirer.module.decode.event.MessageActivityPanel;
import io.github.dsheirer.settings.SettingsManager;
import io.github.dsheirer.preference.UserPreferences;
import net.miginfocom.swing.MigLayout;
import javax.swing.JPanel;
@@ -36,20 +38,20 @@ public class ChannelMetadataViewer extends JPanel
private ChannelMetadataPanel mChannelMetadataPanel;
private ChannelDetailPanel mChannelDetailPanel;
private CallEventPanel mCallEventPanel;
private DecodeEventPanel mDecodeEventPanel;
private MessageActivityPanel mMessageActivityPanel;
/**
* GUI panel that combines the currently decoding channels metadata table and viewers for channel details,
* messages, events, and spectral view.
*/
public ChannelMetadataViewer(ChannelProcessingManager channelProcessingManager, IconManager iconManager,
SettingsManager settingsManager)
public ChannelMetadataViewer(ChannelModel channelModel, ChannelProcessingManager channelProcessingManager,
IconManager iconManager, AliasModel aliasModel, UserPreferences userPreferences)
{
mChannelDetailPanel = new ChannelDetailPanel(channelProcessingManager);
mCallEventPanel = new CallEventPanel(iconManager);
mDecodeEventPanel = new DecodeEventPanel(iconManager, userPreferences, aliasModel);
mMessageActivityPanel = new MessageActivityPanel(channelProcessingManager);
mChannelMetadataPanel = new ChannelMetadataPanel(channelProcessingManager, iconManager);
mChannelMetadataPanel = new ChannelMetadataPanel(channelModel, channelProcessingManager, iconManager, userPreferences);
init();
}
@@ -60,7 +62,7 @@ public class ChannelMetadataViewer extends JPanel
JideTabbedPane tabbedPane = new JideTabbedPane();
tabbedPane.addTab("Details", mChannelDetailPanel);
tabbedPane.addTab("Events", mCallEventPanel);
tabbedPane.addTab("Events", mDecodeEventPanel);
tabbedPane.addTab("Messages", mMessageActivityPanel);
// tabbedPane.addTab("Spectrum", mChannelSpectrumPanel);
tabbedPane.setFont(this.getFont());
@@ -73,7 +75,7 @@ public class ChannelMetadataViewer extends JPanel
add(splitPane);
mChannelMetadataPanel.addProcessingChainSelectionListener(mChannelDetailPanel);
mChannelMetadataPanel.addProcessingChainSelectionListener(mCallEventPanel);
mChannelMetadataPanel.addProcessingChainSelectionListener(mDecodeEventPanel);
mChannelMetadataPanel.addProcessingChainSelectionListener(mMessageActivityPanel);
}
}

View File

@@ -0,0 +1,29 @@
/*
* ******************************************************************************
* sdrtrunk
* 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.channel.metadata;
/**
* Interface to receive channel metadata update notifications
*/
public interface IChannelMetadataUpdateListener
{
void updated(ChannelMetadata channelMetadata, ChannelMetadataField channelMetadataField);
}

View File

@@ -1,664 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.id.broadcast.BroadcastChannel;
import io.github.dsheirer.alias.id.priority.Priority;
import io.github.dsheirer.channel.state.State;
import io.github.dsheirer.module.decode.DecoderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.TreeSet;
public class Metadata
{
private final static Logger mLog = LoggerFactory.getLogger(Metadata.class);
// Static unique metadata identifier tracking
private static int UNIQUE_METADATA_ID_GENERATOR = 0;
private int mMetadataID;
protected boolean mUpdated;
protected DecoderType mPrimaryDecoderType;
protected boolean mSelected;
protected boolean mBufferOverflow;
protected State mState = State.IDLE;
protected String mChannelConfigurationSystem;
protected String mChannelConfigurationSite;
protected String mChannelConfigurationName;
protected String mChannelFrequencyLabel;
protected long mChannelFrequency;
protected AliasedIdentifier mNetworkID1 = new AliasedIdentifier();
protected AliasedIdentifier mNetworkID2 = new AliasedIdentifier();
protected String mMessage;
protected String mMessageType;
protected AliasedIdentifier mPrimaryAddressFrom = new AliasedIdentifier();
protected AliasedIdentifier mPrimaryAddressTo = new AliasedIdentifier();
protected AliasedIdentifier mSecondaryAddressFrom = new AliasedIdentifier();
protected AliasedIdentifier mSecondaryAddressTo = new AliasedIdentifier();
//Lazily constructed member variables.
private Integer mAudioPriority;
protected Boolean mRecordable = false;
protected Boolean mDoNotRecord;
private Set<BroadcastChannel> mBroadcastChannels;
private long mTimestamp = System.currentTimeMillis();
/**
* Channel metadata. Contains all attributes that reflect the state and current attribute values for a channel
* that is currently decoding. This metadata is intended to support any decoding channel gui components to
* graphically convey the current state of a decoding channel and to provide audio metadata
*/
public Metadata()
{
mMetadataID = UNIQUE_METADATA_ID_GENERATOR++;
}
/**
* Protected constructor. Primarily used by the copyOf() method to create a metadata copy with the same ID
*/
protected Metadata(int metadataID)
{
mMetadataID = metadataID;
}
/**
* Timestamp when this metadata was created
* @return milliseconds since epoch
*/
public long getTimestamp()
{
return mTimestamp;
}
/**
* Unique string identifier for this metadata that is comprised of the channel ID and the primary TO address.
*
* This identifier can be used to uniquely identify a channel audio stream and the primary communicant.
*/
public String getUniqueIdentifier()
{
return "SRC:" + mMetadataID +
" ID:" + (mPrimaryAddressTo.hasIdentifier() ? mPrimaryAddressTo.getIdentifier() : "UNKNOWN");
}
/**
* Indicates if any of the fields of this metadata have been updated since the last time a copy was made from this
* metadata. This method is primarily used by downstream audio playback and audio recording to signal when changes
* are made to the metadata that requires the downstream component to reinspect the metadata.
*
* This flag is reset to false immediately after a copy is made of this metadata via the copyOf() method.
*/
public boolean isUpdated()
{
return mUpdated;
}
/**
* Audio Priority as the highest audio priority value from across the primary and secondary identifier aliases.
*
* A default priority will be used if there are no aliased values. If there is a conflict between audio priority
* and 'Do Not Monitor' among the aliases, the highest audio priority will be used (prefer to monitor).
*
* -1 Do Not Monitor
* 0 Channel Selected for immediate monitor
* 1 Highest Priority
* 100 Lowest Priority (default)
*
* @return audio priority
*/
public int getAudioPriority()
{
if(isSelected())
{
return Priority.SELECTED_PRIORITY;
}
if(mAudioPriority == null)
{
determineAudioPriority();
}
return mAudioPriority;
}
/**
* Indicates if the audio priority is set to 'Do Not Monitor'
*/
public boolean isDoNotMonitor()
{
return getAudioPriority() == Priority.DO_NOT_MONITOR;
}
/**
* Indicates if any of the primary or secondary TO/FROM aliases are identified as recordable
*/
public boolean isRecordable()
{
if(mDoNotRecord == null)
{
determineRecordable();
}
return mRecordable && !mDoNotRecord;
}
/**
* Indicates that this metadata has been selected by the user and any audio produced by this channel will be set
* to the highest playback priority (immediate monitor).
*/
public boolean isSelected()
{
return mSelected;
}
/**
* Indicates if the channel for this metadata is in a buffer overflow state.
*/
public boolean isBufferOverflow()
{
return mBufferOverflow;
}
/**
* List of de-duplicated broadcast channels aggregated from the primary and secondary TO/FROM aliases.
*/
public Set<BroadcastChannel> getBroadcastChannels()
{
if(mBroadcastChannels == null)
{
determineBroadcastChannels();
}
return mBroadcastChannels;
}
/**
* Indicates if this metadata is streamable, meaning that it contains one ore more broadcast channels
*/
public boolean isStreamable()
{
return !getBroadcastChannels().isEmpty();
}
/**
* Unique identifier for the source channel that produces this metadata
*/
public int getMetadataID()
{
return mMetadataID;
}
/**
* Decoder type (ie protocol) for the primary decoder
*/
public DecoderType getPrimaryDecoderType()
{
return mPrimaryDecoderType;
}
/**
* Indicates if this metadata has a primary decoder type defined
*/
public boolean hasPrimaryDecoderType()
{
return mPrimaryDecoderType != null;
}
/**
* Returns the alias associated with the attribute or null
*/
public Alias getAlias(Attribute attribute)
{
switch(attribute)
{
case NETWORK_ID_1:
return getNetworkID1().getAlias();
case NETWORK_ID_2:
return getNetworkID2().getAlias();
case PRIMARY_ADDRESS_FROM:
return getPrimaryAddressFrom().getAlias();
case PRIMARY_ADDRESS_TO:
return getPrimaryAddressTo().getAlias();
case SECONDARY_ADDRESS_FROM:
return getSecondaryAddressFrom().getAlias();
case SECONDARY_ADDRESS_TO:
return getSecondaryAddressTo().getAlias();
}
return null;
}
/**
* Returns the string value for the specified attribute or null
*/
public String getValue(Attribute attribute)
{
switch(attribute)
{
case CHANNEL_CONFIGURATION_SYSTEM:
return mChannelConfigurationSystem;
case CHANNEL_CONFIGURATION_SITE:
return mChannelConfigurationSite;
case CHANNEL_FREQUENCY_LABEL:
return mChannelFrequencyLabel;
case CHANNEL_STATE:
return mState.getDisplayValue();
case MESSAGE:
return mMessage;
case MESSAGE_TYPE:
return mMessageType;
case NETWORK_ID_1:
return mNetworkID1.getIdentifier();
case NETWORK_ID_2:
return mNetworkID2.getIdentifier();
case PRIMARY_ADDRESS_FROM:
return mPrimaryAddressFrom.getIdentifier();
case PRIMARY_ADDRESS_TO:
return mPrimaryAddressTo.getIdentifier();
case SECONDARY_ADDRESS_FROM:
return mSecondaryAddressFrom.getIdentifier();
case SECONDARY_ADDRESS_TO:
return mSecondaryAddressTo.getIdentifier();
}
return null;
}
/**
* Current channel state
*/
public State getState()
{
return mState;
}
/**
* System name from the channel configuration
*/
public String getChannelConfigurationSystem()
{
return mChannelConfigurationSystem;
}
/**
* Indicates if there is a non-null, non-empty channel configuration system value
*/
public boolean hasChannelConfigurationSystem()
{
return mChannelConfigurationSystem != null && !mChannelConfigurationSystem.isEmpty();
}
/**
* Site name from the channel configuration
*/
public String getChannelConfigurationSite()
{
return mChannelConfigurationSite;
}
/**
* Indicates if there is a non-null, non-empty channel configuration site value
*/
public boolean hasChannelConfigurationSite()
{
return mChannelConfigurationSite != null && !mChannelConfigurationSite.isEmpty();
}
/**
* Site name from the channel configuration
*/
public String getChannelConfigurationName()
{
return mChannelConfigurationName;
}
/**
* Indicates if there is a non-null, non-empty channel configuration name value
*/
public boolean hasChannelConfigurationName()
{
return mChannelConfigurationSite != null && !mChannelConfigurationSite.isEmpty();
}
/**
* Channel ID or Channel Number
*/
public String getChannelFrequencyLabel()
{
return mChannelFrequencyLabel;
}
/**
* Indicates if there is a non-null, non-empty channel identifier value
*/
public boolean hasChannelFrequencyLabel()
{
return mChannelFrequencyLabel != null && !mChannelFrequencyLabel.isEmpty();
}
/**
* Channel frequency
*/
public long getChannelFrequency()
{
return mChannelFrequency;
}
/**
* Indicates if there is a non-zero channel frequency value
*/
public boolean hasChannelFrequency()
{
return mChannelFrequency > 0;
}
/**
* Network Identifier 1
*/
public AliasedIdentifier getNetworkID1()
{
return mNetworkID1;
}
/**
* Network Identifier 2
*/
public AliasedIdentifier getNetworkID2()
{
return mNetworkID2;
}
/**
* Message
*/
public String getMessage()
{
return mMessage;
}
/**
* Indicates if there is a non-null, non-empty message value
*/
public boolean hasMessage()
{
return mMessage != null && !mMessage.isEmpty();
}
/**
* Message and Decoder type
*/
public String getMessageType()
{
return mMessageType;
}
/**
* Indicates if there is a non-null, non-empty message and decoder type value
*/
public boolean hasMessageType()
{
return mMessageType != null && !mMessageType.isEmpty();
}
/**
* Primary FROM Address
*/
public AliasedIdentifier getPrimaryAddressFrom()
{
return mPrimaryAddressFrom;
}
/**
* Primary TO Address
*/
public AliasedIdentifier getPrimaryAddressTo()
{
return mPrimaryAddressTo;
}
/**
* Secondary FROM Address
*/
public AliasedIdentifier getSecondaryAddressFrom()
{
return mSecondaryAddressFrom;
}
/**
* Secondary TO Address
*/
public AliasedIdentifier getSecondaryAddressTo()
{
return mSecondaryAddressTo;
}
/**
* Determines the audio priority from across the primary and secondary TO/FROM aliases when they exist
*/
private void determineAudioPriority()
{
int priority = Priority.DEFAULT_PRIORITY;
boolean doNotMonitorFound = false;
boolean audioPriorityFound = false;
if(getPrimaryAddressTo().hasAlias())
{
Alias primaryTo = getPrimaryAddressTo().getAlias();
if(primaryTo.hasCallPriority())
{
if(primaryTo.getCallPriority() == Priority.DO_NOT_MONITOR)
{
doNotMonitorFound = true;
}
else
{
audioPriorityFound = true;
if(primaryTo.getCallPriority() < priority)
{
priority = primaryTo.getCallPriority();
}
}
}
}
if(getPrimaryAddressFrom().hasAlias())
{
Alias primaryFrom = getPrimaryAddressFrom().getAlias();
if(primaryFrom.hasCallPriority())
{
if(primaryFrom.getCallPriority() == Priority.DO_NOT_MONITOR)
{
doNotMonitorFound = true;
}
else
{
audioPriorityFound = true;
if(primaryFrom.getCallPriority() < priority)
{
priority = primaryFrom.getCallPriority();
}
}
}
}
if(getSecondaryAddressTo().hasAlias())
{
Alias secondaryTo = getSecondaryAddressTo().getAlias();
if(secondaryTo.hasCallPriority())
{
if(secondaryTo.getCallPriority() == Priority.DO_NOT_MONITOR)
{
doNotMonitorFound = true;
}
else
{
audioPriorityFound = true;
if(secondaryTo.getCallPriority() < priority)
{
priority = secondaryTo.getCallPriority();
}
}
}
}
if(getSecondaryAddressFrom().hasAlias())
{
Alias secondaryFrom = getSecondaryAddressFrom().getAlias();
if(secondaryFrom.hasCallPriority())
{
if(secondaryFrom.getCallPriority() == Priority.DO_NOT_MONITOR)
{
doNotMonitorFound = true;
}
else
{
audioPriorityFound = true;
if(secondaryFrom.getCallPriority() < priority)
{
priority = secondaryFrom.getCallPriority();
}
}
}
}
//If we found a 'Do Not Monitor' and no other audio priority, then set to do not monitor
if(doNotMonitorFound && !audioPriorityFound)
{
mAudioPriority = Priority.DO_NOT_MONITOR;
}
else
{
mAudioPriority = priority;
}
}
/**
* Determines if any of the primary or secondary to/from aliases are recordable.
*/
private void determineRecordable()
{
mDoNotRecord = false;
if(mPrimaryAddressTo.hasAlias() && !mPrimaryAddressTo.getAlias().isRecordable())
{
mDoNotRecord = true;
return;
}
if(mPrimaryAddressFrom.hasAlias() && !mPrimaryAddressFrom.getAlias().isRecordable())
{
mDoNotRecord = true;
return;
}
if(mSecondaryAddressTo.hasAlias() && !mSecondaryAddressTo.getAlias().isRecordable())
{
mDoNotRecord = true;
return;
}
if(mSecondaryAddressFrom.hasAlias() && !mSecondaryAddressFrom.getAlias().isRecordable())
{
mDoNotRecord = true;
return;
}
}
/**
* Aggregates a de-duplicated list of broadcast channels from among the primary/secondary to/from aliases
*/
private void determineBroadcastChannels()
{
mBroadcastChannels = new TreeSet<>();
if(mPrimaryAddressTo.hasAlias() && mPrimaryAddressTo.getAlias().isStreamable())
{
mBroadcastChannels.addAll(mPrimaryAddressTo.getAlias().getBroadcastChannels());
}
if(mPrimaryAddressFrom.hasAlias() && mPrimaryAddressFrom.getAlias().isStreamable())
{
mBroadcastChannels.addAll(mPrimaryAddressFrom.getAlias().getBroadcastChannels());
}
if(mSecondaryAddressTo.hasAlias() && mSecondaryAddressTo.getAlias().isStreamable())
{
mBroadcastChannels.addAll(mSecondaryAddressTo.getAlias().getBroadcastChannels());
}
if(mSecondaryAddressFrom.hasAlias() && mSecondaryAddressFrom.getAlias().isStreamable())
{
mBroadcastChannels.addAll(mSecondaryAddressFrom.getAlias().getBroadcastChannels());
}
}
/**
* Creates a deep/full snapshot copy of this metadata set.
*
* The streamable, recordable, audio priority and broadcast channels are not copied. These are lazily determined
* when initially requested.
*/
public Metadata copyOf()
{
Metadata copy = new Metadata(mMetadataID);
copy.mDoNotRecord = mDoNotRecord;
copy.mRecordable = mRecordable;
copy.mState = mState;
copy.mPrimaryDecoderType = mPrimaryDecoderType;
copy.mChannelFrequency = mChannelFrequency;
copy.mChannelConfigurationSystem = hasChannelConfigurationSystem() ? new String(mChannelConfigurationSystem) : null;
copy.mChannelConfigurationSite = hasChannelConfigurationSite() ? new String(mChannelConfigurationSite) : null;
copy.mChannelConfigurationName = hasChannelConfigurationName() ? new String(mChannelConfigurationName) : null;
copy.mChannelFrequencyLabel = hasChannelFrequencyLabel() ? new String(mChannelFrequencyLabel) : null;
copy.mMessage = hasMessage() ? new String(mMessage) : null;
copy.mMessageType = hasMessageType() ? new String(mMessageType) : null;
copy.mNetworkID1 = mNetworkID1.copyOf();
copy.mNetworkID2 = mNetworkID2.copyOf();
copy.mPrimaryAddressFrom = mPrimaryAddressFrom.copyOf();
copy.mPrimaryAddressTo = mPrimaryAddressTo.copyOf();
copy.mSecondaryAddressFrom = mSecondaryAddressFrom.copyOf();
copy.mSecondaryAddressTo = mSecondaryAddressTo.copyOf();
copy.mUpdated = mUpdated;
//Reset the updated flag
mUpdated = false;
return copy;
}
}

View File

@@ -1,294 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
import io.github.dsheirer.channel.state.State;
import io.github.dsheirer.module.decode.DecoderType;
import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MutableMetadata extends Metadata implements Listener<AttributeChangeRequest>
{
private final static Logger mLog = LoggerFactory.getLogger(MutableMetadata.class);
private Broadcaster<MutableMetadataChangeEvent> mMetadataChangeEventBroadcaster = new Broadcaster<>();
/**
* Mutable channel metadata. Contains all attributes that reflect the state and current attribute values for a
* channel that is currently decoding. This metadata is intended to support any decoding channel gui components to
* graphically convey the current state of a decoding channel and to provide audio metadata
*/
public MutableMetadata()
{
super();
}
/**
* Sets the selected state for this metadata. Selected indicates that the user has selected this metadata for
* immediate monitor in the audio panel. When true, this overrides the audio priority for any audio produced
* by the channel and sets that audio to the highest priority.
*
* Any component that toggles the selected state for this metadata is also responsible for clearing the flag.
*/
public void setSelected(boolean selected)
{
mSelected = selected;
mUpdated = true;
}
/**
* Sets the recordable flag to the argument value and overrides any recordable settings in the enclosed aliases.
*/
public void setRecordable(boolean recordable)
{
mRecordable = recordable;
}
/**
* Sets the primary decoder type
*/
public void setPrimaryDecoderType(DecoderType decoderType)
{
mPrimaryDecoderType = decoderType;
mUpdated = true;
}
/**
* Request to change an attribute value for this metadata. This is the primary method for updating all attributes
* in this metadata set.
*/
@Override
public void receive(AttributeChangeRequest request)
{
switch(request.getAttribute())
{
case BUFFER_OVERFLOW:
mBufferOverflow = request.getBooleanValue();
broadcast(Attribute.BUFFER_OVERFLOW);
break;
case CHANNEL_CONFIGURATION_SYSTEM:
mChannelConfigurationSystem = request.getStringValue();
broadcast(Attribute.CHANNEL_CONFIGURATION_SYSTEM);
break;
case CHANNEL_CONFIGURATION_SITE:
mChannelConfigurationSite = request.getStringValue();
broadcast(Attribute.CHANNEL_CONFIGURATION_SITE);
break;
case CHANNEL_CONFIGURATION_NAME:
mChannelConfigurationName = request.getStringValue();
broadcast(Attribute.CHANNEL_CONFIGURATION_NAME);
break;
case CHANNEL_FREQUENCY:
if(request.hasValue())
{
mChannelFrequency = request.getLongValue();
}
broadcast(Attribute.CHANNEL_FREQUENCY);
break;
case CHANNEL_FREQUENCY_LABEL:
mChannelFrequencyLabel = request.getStringValue();
broadcast(Attribute.CHANNEL_FREQUENCY_LABEL);
break;
case MESSAGE:
mMessage = request.getStringValue();
broadcast(Attribute.MESSAGE);
break;
case MESSAGE_TYPE:
mMessageType = request.getStringValue();
broadcast(Attribute.MESSAGE_TYPE);
break;
case NETWORK_ID_1:
mNetworkID1.setIdentifier(request.getStringValue());
mNetworkID1.setAlias(request.getAlias());
broadcast(Attribute.NETWORK_ID_1);
break;
case NETWORK_ID_2:
mNetworkID2.setIdentifier(request.getStringValue());
mNetworkID2.setAlias(request.getAlias());
broadcast(Attribute.NETWORK_ID_2);
break;
case PRIMARY_ADDRESS_FROM:
mPrimaryAddressFrom.setIdentifier(request.getStringValue());
mPrimaryAddressFrom.setAlias(request.getAlias());
broadcast(Attribute.PRIMARY_ADDRESS_FROM);
break;
case PRIMARY_ADDRESS_TO:
mPrimaryAddressTo.setIdentifier(request.getStringValue());
mPrimaryAddressTo.setAlias(request.getAlias());
broadcast(Attribute.PRIMARY_ADDRESS_TO);
break;
case PRIMARY_DECODER_TYPE:
mPrimaryDecoderType = request.getDecoderTypeValue();
broadcast(Attribute.PRIMARY_DECODER_TYPE);
break;
case SECONDARY_ADDRESS_FROM:
mSecondaryAddressFrom.setIdentifier(request.getStringValue());
mSecondaryAddressFrom.setAlias(request.getAlias());
broadcast(Attribute.SECONDARY_ADDRESS_FROM);
break;
case SECONDARY_ADDRESS_TO:
mSecondaryAddressTo.setIdentifier(request.getStringValue());
mSecondaryAddressTo.setAlias(request.getAlias());
broadcast(Attribute.SECONDARY_ADDRESS_TO);
break;
case CHANNEL_STATE:
mState = (State) request.getValue();
broadcast(Attribute.CHANNEL_STATE);
break;
default:
throw new IllegalArgumentException("Unrecognized Metadata Attribute: " +
request.getAttribute().name());
}
mUpdated = true;
}
/**
* Resets temporal attributes to null value. This only resets attributes that have a non-ull value in order to
* limit the number of change events that are produced.
*/
public void resetTemporalAttributes()
{
mDoNotRecord = null;
mBufferOverflow = false;
if(hasMessage())
{
mMessage = null;
broadcast(Attribute.MESSAGE);
}
if(hasMessageType())
{
mMessageType = null;
broadcast(Attribute.MESSAGE_TYPE);
}
if(mPrimaryAddressFrom.hasIdentifier())
{
mPrimaryAddressFrom.reset();
broadcast(Attribute.PRIMARY_ADDRESS_FROM);
}
if(mPrimaryAddressTo.hasIdentifier())
{
mPrimaryAddressTo.reset();
broadcast(Attribute.PRIMARY_ADDRESS_TO);
}
if(mSecondaryAddressFrom.hasIdentifier())
{
mSecondaryAddressFrom.reset();
broadcast(Attribute.SECONDARY_ADDRESS_FROM);
}
if(mSecondaryAddressTo.hasIdentifier())
{
mSecondaryAddressTo.reset();
broadcast(Attribute.SECONDARY_ADDRESS_TO);
}
mUpdated = true;
}
/**
* Resets all attributes to empty values
*/
public void resetAllAttributes()
{
resetTemporalAttributes();
if(hasChannelConfigurationSystem())
{
mChannelConfigurationSystem = null;
broadcast(Attribute.CHANNEL_CONFIGURATION_SYSTEM);
}
if(hasChannelConfigurationSite())
{
mChannelConfigurationSite = null;
broadcast(Attribute.CHANNEL_CONFIGURATION_SITE);
}
if(hasChannelConfigurationName())
{
mChannelConfigurationSite = null;
broadcast(Attribute.CHANNEL_CONFIGURATION_NAME);
}
if(hasChannelFrequencyLabel())
{
mChannelFrequencyLabel = null;
broadcast(Attribute.CHANNEL_FREQUENCY_LABEL);
}
if(hasChannelFrequency())
{
mChannelFrequency = 0;
broadcast(Attribute.CHANNEL_FREQUENCY);
}
if(hasPrimaryDecoderType())
{
mPrimaryDecoderType = null;
broadcast(Attribute.PRIMARY_DECODER_TYPE);
}
if(mNetworkID1.hasIdentifier())
{
mNetworkID1.reset();
broadcast(Attribute.NETWORK_ID_1);
}
if(mNetworkID2.hasIdentifier())
{
mNetworkID2.reset();
broadcast(Attribute.NETWORK_ID_2);
}
mUpdated = true;
}
/**
* Broadcasts to registered listeners that an attribute has changed for this metadata
*/
private void broadcast(Attribute attribute)
{
mMetadataChangeEventBroadcaster.broadcast(new MutableMetadataChangeEvent(this, attribute));
}
/**
* Adds the listener to receive metadata change events for this channel metadata
*/
public void addListener(Listener<MutableMetadataChangeEvent> listener)
{
mMetadataChangeEventBroadcaster.addListener(listener);
}
/**
* Removes the listener from receiving metadata change events for this channel metadata
*/
public void removeListener(Listener<MutableMetadataChangeEvent> listener)
{
mMetadataChangeEventBroadcaster.removeListener(listener);
}
}

View File

@@ -1,53 +0,0 @@
/*******************************************************************************
* 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.channel.metadata;
public class MutableMetadataChangeEvent
{
private MutableMetadata mMetadata;
private Attribute mAttribute;
/**
* Channel metadata changed attribute event
*
* @param metadata where the change occurred
* @param attribute that changed
*/
public MutableMetadataChangeEvent(MutableMetadata metadata, Attribute attribute)
{
mMetadata = metadata;
mAttribute = attribute;
}
/**
* Channel metadata where the change occurred
*/
public MutableMetadata getMetadata()
{
return mMetadata;
}
/**
* Channel metadata attribute that has changed
*/
public Attribute getAttribute()
{
return mAttribute;
}
}

View File

@@ -1,26 +1,26 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014,2015 Dennis Sheirer
/*
* ******************************************************************************
* sdrtrunk
* 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.channel.state;
import io.github.dsheirer.channel.metadata.Attribute;
import io.github.dsheirer.channel.metadata.AttributeChangeRequest;
import io.github.dsheirer.channel.state.DecoderStateEvent.Event;
import io.github.dsheirer.message.Message;
import io.github.dsheirer.message.IMessage;
import io.github.dsheirer.module.decode.DecoderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,8 +39,6 @@ public class AlwaysUnsquelchedDecoderState extends DecoderState
public AlwaysUnsquelchedDecoderState(DecoderType decoderType, String channelName)
{
super(null);
mDecoderType = decoderType;
mChannelName = channelName;
}
@@ -69,9 +67,9 @@ public class AlwaysUnsquelchedDecoderState extends DecoderState
}
@Override
public void receive(Message t)
public void receive(IMessage t)
{
/* Not implemented */
/* Not implemented */
}
@Override
@@ -81,7 +79,7 @@ public class AlwaysUnsquelchedDecoderState extends DecoderState
{
//Each time we're reset, set the PRIMARY TO attribute back to the channel name, otherwise we won't have
//a primary ID for any audio produced by this state.
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, NO_SQUELCH));
// broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, NO_SQUELCH));
}
}
@@ -94,7 +92,7 @@ public class AlwaysUnsquelchedDecoderState extends DecoderState
@Override
public void start()
{
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, NO_SQUELCH));
// broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, NO_SQUELCH));
broadcast(new DecoderStateEvent(this, Event.ALWAYS_UNSQUELCH, State.IDLE));
}

View File

@@ -18,51 +18,64 @@
******************************************************************************/
package io.github.dsheirer.channel.state;
import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.audio.squelch.ISquelchStateProvider;
import io.github.dsheirer.audio.squelch.SquelchState;
import io.github.dsheirer.channel.metadata.Attribute;
import io.github.dsheirer.channel.metadata.AttributeChangeRequest;
import io.github.dsheirer.channel.metadata.IAttributeChangeRequestListener;
import io.github.dsheirer.channel.metadata.MutableMetadata;
import io.github.dsheirer.channel.metadata.ChannelMetadata;
import io.github.dsheirer.channel.state.DecoderStateEvent.Event;
import io.github.dsheirer.channel.traffic.TrafficChannelManager;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.Channel.ChannelType;
import io.github.dsheirer.controller.channel.ChannelEvent;
import io.github.dsheirer.controller.channel.IChannelEventProvider;
import io.github.dsheirer.identifier.IdentifierUpdateListener;
import io.github.dsheirer.identifier.IdentifierUpdateNotification;
import io.github.dsheirer.identifier.IdentifierUpdateProvider;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.ChannelNameConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.DecoderTypeConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.FrequencyConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.SiteConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.SystemConfigurationIdentifier;
import io.github.dsheirer.identifier.decoder.DecoderStateIdentifier;
import io.github.dsheirer.module.Module;
import io.github.dsheirer.module.decode.DecoderType;
import io.github.dsheirer.module.decode.config.DecodeConfiguration;
import io.github.dsheirer.module.decode.event.CallEvent;
import io.github.dsheirer.module.decode.event.ICallEventProvider;
import io.github.dsheirer.module.decode.event.IDecodeEvent;
import io.github.dsheirer.module.decode.event.IDecodeEventProvider;
import io.github.dsheirer.sample.IOverflowListener;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.source.ISourceEventListener;
import io.github.dsheirer.source.ISourceEventProvider;
import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.SourceType;
import io.github.dsheirer.source.config.SourceConfigTuner;
import io.github.dsheirer.source.heartbeat.Heartbeat;
import io.github.dsheirer.source.heartbeat.IHeartbeatListener;
import io.github.dsheirer.source.tuner.channel.TunerChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelState extends Module implements ICallEventProvider, IDecoderStateEventListener,
IDecoderStateEventProvider, ISourceEventListener, ISourceEventProvider, IHeartbeatListener,
ISquelchStateProvider, IAttributeChangeRequestListener, IOverflowListener
public class ChannelState extends Module implements IChannelEventProvider, IDecodeEventProvider,
IDecoderStateEventListener, IDecoderStateEventProvider, ISourceEventListener, ISourceEventProvider,
IHeartbeatListener, ISquelchStateProvider, IOverflowListener, IdentifierUpdateListener, IdentifierUpdateProvider
{
private final static Logger mLog = LoggerFactory.getLogger(ChannelState.class);
public static final long FADE_TIMEOUT_DELAY = 1200;
public static final long RESET_TIMEOUT_DELAY = 2000;
private MutableMetadata mMutableMetadata = new MutableMetadata();
private State mState = State.IDLE;
private Listener<CallEvent> mCallEventListener;
private MutableIdentifierCollection mIdentifierCollection = new MutableIdentifierCollection();
private Listener<ChannelEvent> mChannelEventListener;
private Listener<IDecodeEvent> mDecodeEventListener;
private Listener<DecoderStateEvent> mDecoderStateListener;
private Listener<SquelchState> mSquelchStateListener;
private Listener<SourceEvent> mExternalSourceEventListener;
private DecoderStateEventReceiver mDecoderStateEventReceiver = new DecoderStateEventReceiver();
private HeartbeatReceiver mHeartbeatReceiver = new HeartbeatReceiver();
private ChannelType mChannelType;
private TrafficChannelManager mTrafficChannelEndListener;
private CallEvent mTrafficChannelCallEvent;
private Channel mChannel;
private SourceEventListener mInternalSourceEventListener;
private ChannelMetadata mChannelMetadata;
private boolean mSquelchLocked = false;
private boolean mSelected = false;
@@ -87,25 +100,85 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
* IDLE: Normal state. No voice or data call activity
* CALL/DATA/ENCRYPTED/CONTROL: Decoding states.
* FADE: The phase after a voice or data call when either an explicit call end has been received, or when no new
* signalling updates have been received, and the fade timer has expired. This phase allows for gui updates to
* signal to the user that the call is ended, while continuing to display the call details for the user
* signalling updates have been received, and the fade timer has expired. This phase allows for gui updates to
* signal to the user that the call is ended, while continuing to display the call details for the user
* TEARDOWN: Indicates a traffic channel that will be torn down for reuse.
*/
public ChannelState(ChannelType channelType)
public ChannelState(Channel channel, AliasModel aliasModel)
{
mChannelType = channelType;
mChannel = channel;
mChannelMetadata = new ChannelMetadata(aliasModel);
createConfigurationIdentifiers(channel);
}
/**
* Creates configuration identifiers for the channel name, system, site and alias list name.
*/
private void createConfigurationIdentifiers(Channel channel)
{
mIdentifierCollection.update(DecoderTypeConfigurationIdentifier.create(channel.getDecodeConfiguration().getDecoderType()));
if(channel.hasSystem())
{
mIdentifierCollection.update(SystemConfigurationIdentifier.create(channel.getSystem()));
}
if(channel.hasSite())
{
mIdentifierCollection.update(SiteConfigurationIdentifier.create(channel.getSite()));
}
if(channel.getName() != null && !channel.getName().isEmpty())
{
mIdentifierCollection.update(ChannelNameConfigurationIdentifier.create(channel.getName()));
}
if(channel.getAliasListName() != null && !channel.getAliasListName().isEmpty())
{
mIdentifierCollection.update(AliasListConfigurationIdentifier.create(channel.getAliasListName()));
}
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
TunerChannel tunerChannel = ((SourceConfigTuner)channel.getSourceConfiguration()).getTunerChannel();
mIdentifierCollection.update(FrequencyConfigurationIdentifier.create(tunerChannel.getFrequency()));
}
}
/**
* Metadata for this channel containing channel details, primary and secondary entities for call events and any
* decoded messages. This metadata is primarily intended to be used by graphical components to convey the
* details of the current channel state and to provide metadata backing any decoded audio packets produced by
* any audio streams for this channel.
* Interface to receive channel identifier updates from this channel state and from any
* decoder states.
*/
public MutableMetadata getMutableMetadata()
@Override
public Listener<IdentifierUpdateNotification> getIdentifierUpdateListener()
{
return mMutableMetadata;
return mChannelMetadata;
}
/**
* Updates the channel state identifier collection using the update notification. This update will be reflected
* in the internal channel state and will also be broadcast to any listeners, including the channel metadata for
* this channel state.
*/
public void updateChannelStateIdentifiers(IdentifierUpdateNotification notification)
{
mIdentifierCollection.receive(notification);
}
@Override
public void setIdentifierUpdateListener(Listener<IdentifierUpdateNotification> listener)
{
mIdentifierCollection.setIdentifierUpdateListener(listener);
}
@Override
public void removeIdentifierUpdateListener()
{
mIdentifierCollection.removeIdentifierUpdateListener();
}
/**
* Channel metadata for this channel.
*/
public ChannelMetadata getChannelMetadata()
{
return mChannelMetadata;
}
/**
@@ -114,21 +187,18 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
@Override
public void reset()
{
getMutableMetadata().resetTemporalAttributes();
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
mState = State.IDLE;
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
mIdentifierCollection.update(DecoderStateIdentifier.IDLE);
mSourceOverflow = false;
}
@Override
public void start()
{
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
mIdentifierCollection.broadcastIdentifiers();
if(mTrafficChannelEndListener != null)
if(mChannel.getChannelType() == ChannelType.TRAFFIC)
{
setState(State.CALL);
}
@@ -143,7 +213,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
public void dispose()
{
mCallEventListener = null;
mDecodeEventListener = null;
mDecoderStateListener = null;
mSquelchStateListener = null;
}
@@ -159,21 +229,11 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
return mInternalSourceEventListener;
}
private boolean isStandardChannel()
{
return mChannelType == ChannelType.STANDARD;
}
private boolean isTrafficChannel()
{
return mChannelType == ChannelType.TRAFFIC;
}
public void setStandardChannelTimeout(long milliseconds)
{
mStandardChannelFadeTimeout = milliseconds;
if(mChannelType == ChannelType.STANDARD)
if(mChannel.isStandardChannel())
{
mFadeTimeout = mStandardChannelFadeTimeout;
}
@@ -183,7 +243,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
{
mTrafficChannelFadeTimeout = milliseconds;
if(mChannelType == ChannelType.TRAFFIC)
if(mChannel.isTrafficChannel())
{
mFadeTimeout = System.currentTimeMillis() + mTrafficChannelFadeTimeout;
}
@@ -209,7 +269,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
*/
private void updateFadeTimeout()
{
if(isTrafficChannel())
if(mChannel.isTrafficChannel())
{
mFadeTimeout = System.currentTimeMillis() + mTrafficChannelFadeTimeout;
}
@@ -225,7 +285,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
*/
private void updateResetTimeout()
{
if(isTrafficChannel())
if(mChannel.isTrafficChannel())
{
mEndTimeout = System.currentTimeMillis();
}
@@ -298,26 +358,35 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
broadcast(SquelchState.SQUELCH);
updateFadeTimeout();
mState = state;
mIdentifierCollection.update(DecoderStateIdentifier.ACTIVE);
break;
case CONTROL:
//Don't allow traffic channels to be control channels, otherwise they can't transition to teardown
if(isStandardChannel())
if(mChannel.isStandardChannel())
{
broadcast(SquelchState.SQUELCH);
updateFadeTimeout();
mState = state;
mIdentifierCollection.update(DecoderStateIdentifier.CONTROL);
}
break;
case DATA:
broadcast(SquelchState.SQUELCH);
updateFadeTimeout();
mState = state;
mIdentifierCollection.update(DecoderStateIdentifier.DATA);
break;
case ENCRYPTED:
broadcast(SquelchState.SQUELCH);
updateFadeTimeout();
mState = state;
mIdentifierCollection.update(DecoderStateIdentifier.ENCRYPTED);
break;
case CALL:
broadcast(SquelchState.UNSQUELCH);
updateFadeTimeout();
mState = state;
mIdentifierCollection.update(DecoderStateIdentifier.CALL);
break;
case FADE:
processFadeState();
@@ -330,12 +399,11 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
break;
case RESET:
mState = State.IDLE;
mIdentifierCollection.update(DecoderStateIdentifier.IDLE);
break;
default:
break;
}
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
}
}
@@ -351,14 +419,13 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
/**
* This method is invoked if the source buffer provider goes into overflow state. Since this is an external state,
* we use the mSourceOverflow variable to override the internal state reported to external listeners.
*
* @param overflow true to indicate an overflow state
*/
@Override
public void sourceOverflow(boolean overflow)
{
mSourceOverflow = overflow;
mMutableMetadata.receive(new AttributeChangeRequest<Boolean>(Attribute.BUFFER_OVERFLOW, mSourceOverflow));
}
/**
@@ -380,9 +447,9 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
{
updateResetTimeout();
mState = State.FADE;
mIdentifierCollection.update(DecoderStateIdentifier.FADE);
broadcast(SquelchState.SQUELCH);
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
}
private void processIdleState()
@@ -391,12 +458,11 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
if(mState == State.FADE)
{
getMutableMetadata().resetTemporalAttributes();
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
}
mState = State.IDLE;
getMutableMetadata().receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
mIdentifierCollection.update(DecoderStateIdentifier.IDLE);
}
private void processTeardownState()
@@ -404,48 +470,58 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
broadcast(SquelchState.SQUELCH);
mState = State.TEARDOWN;
mIdentifierCollection.update(DecoderStateIdentifier.TEARDOWN);
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
if(mTrafficChannelEndListener != null && mTrafficChannelCallEvent != null)
if(mChannel.isTrafficChannel())
{
mTrafficChannelCallEvent.end();
broadcast(mTrafficChannelCallEvent);
mTrafficChannelEndListener.callEnd(mTrafficChannelCallEvent.getChannel());
mTrafficChannelEndListener = null;
mTrafficChannelCallEvent = null;
broadcast(new ChannelEvent(mChannel, ChannelEvent.Event.REQUEST_DISABLE));
}
}
/**
* Broadcasts the call event to the registered listener
*/
protected void broadcast(CallEvent event)
protected void broadcast(IDecodeEvent event)
{
if(mCallEventListener != null)
if(mDecodeEventListener != null)
{
mCallEventListener.receive(event);
mDecodeEventListener.receive(event);
}
}
/**
* Broadcasts the channel event to a registered listener
*/
private void broadcast(ChannelEvent channelEvent)
{
if(mChannelEventListener != null)
{
mChannelEventListener.receive(channelEvent);
}
}
@Override
public void addCallEventListener(Listener<CallEvent> listener)
public void setChannelEventListener(Listener<ChannelEvent> listener)
{
mCallEventListener = listener;
mChannelEventListener = listener;
}
@Override
public void removeCallEventListener(Listener<CallEvent> listener)
public void removeChannelEventListener()
{
mCallEventListener = null;
mChannelEventListener = null;
}
//NEW:
@Override
public Listener<AttributeChangeRequest> getAttributeChangeRequestListener()
public void addDecodeEventListener(Listener<IDecodeEvent> listener)
{
return mMutableMetadata;
mDecodeEventListener = listener;
}
@Override
public void removeDecodeEventListener(Listener<IDecodeEvent> listener)
{
mDecodeEventListener = null;
}
/**
@@ -483,57 +559,6 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
return mDecoderStateEventReceiver;
}
/**
* Registers a listener to be notified when a traffic channel call event is
* completed, so that the listener can perform call tear-down
*/
public void configureAsTrafficChannel(TrafficChannelManager manager, CallEvent callEvent)
{
mTrafficChannelEndListener = manager;
mTrafficChannelCallEvent = callEvent;
/* Broadcast the call event details as metadata for the audio manager */
String channel = mTrafficChannelCallEvent.getChannel();
if(channel != null)
{
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.CHANNEL_FREQUENCY_LABEL, channel));
}
long frequency = mTrafficChannelCallEvent.getFrequency();
if(frequency > 0)
{
mMutableMetadata.receive(new AttributeChangeRequest<Long>(Attribute.CHANNEL_FREQUENCY, frequency));
}
mMutableMetadata.receive(new AttributeChangeRequest<DecoderType>(Attribute.PRIMARY_DECODER_TYPE,
mTrafficChannelCallEvent.getDecoderType()));
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.CHANNEL_CONFIGURATION_NAME, "TRAFFIC"));
String from = mTrafficChannelCallEvent.getFromID();
if(from != null)
{
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_FROM, from,
mTrafficChannelCallEvent.getFromIDAlias()));
}
String to = mTrafficChannelCallEvent.getToID();
if(to != null)
{
mMutableMetadata.receive(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, to,
mTrafficChannelCallEvent.getToIDAlias()));
}
/* Rebroadcast the allocation event so that the internal decoder states
* can self-configure with the call event details */
broadcast(mTrafficChannelCallEvent);
}
/**
* Registers the listener to receive source events from the channel state
*/
@@ -572,7 +597,8 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
//in an active (ie sync locked) state.
if(getState().isActiveState())
{
broadcast(SourceEvent.frequencyErrorMeasurementSyncLocked(sourceEvent.getValue().longValue(), mChannelType.name()));
broadcast(SourceEvent.frequencyErrorMeasurementSyncLocked(sourceEvent.getValue().longValue(),
mChannel.getChannelType().name()));
}
break;
}
@@ -598,7 +624,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
case CHANGE_CALL_TIMEOUT:
if(event instanceof ChangeChannelTimeoutEvent)
{
ChangeChannelTimeoutEvent timeout = (ChangeChannelTimeoutEvent) event;
ChangeChannelTimeoutEvent timeout = (ChangeChannelTimeoutEvent)event;
if(timeout.getChannelType() == ChannelType.STANDARD)
{
@@ -618,7 +644,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
}
break;
case END:
if(isTrafficChannel())
if(mChannel.isTrafficChannel())
{
setState(State.TEARDOWN);
}
@@ -628,7 +654,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
}
break;
case RESET:
/* Channel State does not respond to reset events */
/* Channel State does not respond to reset events */
break;
default:
break;
@@ -660,7 +686,7 @@ public class ChannelState extends Module implements ICallEventProvider, IDecoder
}
else if(mState == State.FADE && mEndTimeout <= System.currentTimeMillis())
{
if(isTrafficChannel())
if(mChannel.isTrafficChannel())
{
processTeardownState();
}

View File

@@ -1,15 +1,23 @@
package io.github.dsheirer.channel.state;
import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.channel.metadata.AttributeChangeRequest;
import io.github.dsheirer.channel.metadata.IAttributeChangeRequestProvider;
import io.github.dsheirer.channel.IChannelDescriptor;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.IdentifierUpdateListener;
import io.github.dsheirer.identifier.IdentifierUpdateNotification;
import io.github.dsheirer.identifier.IdentifierUpdateProvider;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.configuration.ChannelDescriptorConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.DecoderTypeConfigurationIdentifier;
import io.github.dsheirer.message.IMessage;
import io.github.dsheirer.message.IMessageListener;
import io.github.dsheirer.message.Message;
import io.github.dsheirer.module.Module;
import io.github.dsheirer.module.decode.DecoderType;
import io.github.dsheirer.module.decode.event.ActivitySummaryProvider;
import io.github.dsheirer.module.decode.event.CallEvent;
import io.github.dsheirer.module.decode.event.ICallEventProvider;
import io.github.dsheirer.module.decode.event.IDecodeEvent;
import io.github.dsheirer.module.decode.event.IDecodeEventProvider;
import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener;
@@ -19,47 +27,87 @@ import io.github.dsheirer.sample.Listener;
*
* Provides access to a textual activity summary of events observed.
*/
public abstract class DecoderState extends Module implements ActivitySummaryProvider, Listener<Message>,
IAttributeChangeRequestProvider, ICallEventProvider, IDecoderStateEventListener,
IDecoderStateEventProvider, IMessageListener
public abstract class DecoderState extends Module implements ActivitySummaryProvider, Listener<IMessage>,
IDecodeEventProvider, IDecoderStateEventListener, IDecoderStateEventProvider, IMessageListener,
IdentifierUpdateProvider, IdentifierUpdateListener
{
// private final static Logger mLog = LoggerFactory.getLogger(DecoderState.class);
protected String DIVIDER1 = "======================================================\n";
protected String DIVIDER2 = "------------------------------------------------------\n";
/* This has to be a broadcaster in order for references to persist */
private Broadcaster<CallEvent> mCallEventBroadcaster = new Broadcaster<>();
private Broadcaster<AttributeChangeRequest> mAttributeChangeRequestBroadcaster = new Broadcaster<>();
private Broadcaster<IDecodeEvent> mDecodeEventBroadcaster = new Broadcaster<>();
private Listener<DecoderStateEvent> mDecoderStateListener;
private DecoderStateEventListener mDecoderStateEventListener = new DecoderStateEventListener();
private MutableIdentifierCollection mIdentifierCollection = new MutableIdentifierCollection();
private ConfigurationIdentifierListener mConfigurationIdentifierListener = new ConfigurationIdentifierListener();
private IChannelDescriptor mCurrentChannel;
protected CallEvent mCurrentCallEvent;
private AliasList mAliasList;
public DecoderState(AliasList aliasList)
public DecoderState()
{
mAliasList = aliasList;
mIdentifierCollection.update(new DecoderTypeConfigurationIdentifier(getDecoderType()));
}
@Override
public void start()
{
//Broadcast the existing identifiers (as add events) so that they can be received by external listeners
mIdentifierCollection.broadcastIdentifiers();
}
public abstract DecoderType getDecoderType();
public AliasList getAliasList()
/**
* Current collection of identifiers managed by the decoder state.
*/
public MutableIdentifierCollection getIdentifierCollection()
{
return mAliasList;
return mIdentifierCollection;
}
public boolean hasAliasList()
/**
* Registers the listener to receive identifier update notifications
*/
@Override
public void setIdentifierUpdateListener(Listener<IdentifierUpdateNotification> listener)
{
return mAliasList != null;
getIdentifierCollection().setIdentifierUpdateListener(listener);
}
/**
* Removes the listener from receiving identifier update notifications
*/
@Override
public void removeIdentifierUpdateListener()
{
getIdentifierCollection().removeIdentifierUpdateListener();
}
/**
* Provides subclass reference to the call event broadcaster
*/
protected Broadcaster<CallEvent> getCallEventBroadcaster()
protected Broadcaster<IDecodeEvent> getDecodeEventBroadcaster()
{
return mCallEventBroadcaster;
return mDecodeEventBroadcaster;
}
@Override
public Listener<IMessage> getMessageListener()
{
return this;
}
/**
* Resets the current temporal state variables to end the current event and prepare for the next.
*/
protected void resetState()
{
mIdentifierCollection.remove(IdentifierClass.USER);
mCurrentChannel = null;
}
/**
@@ -85,11 +133,9 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
*/
public void dispose()
{
mCallEventBroadcaster.dispose();
mCallEventBroadcaster = null;
mDecodeEventBroadcaster.dispose();
mDecodeEventBroadcaster = null;
mDecoderStateListener = null;
mAliasList = null;
}
/**
@@ -98,29 +144,29 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
public abstract String getActivitySummary();
/**
* Broadcasts a call event to any registered listeners
* Broadcasts a decode event to any registered listeners
*/
protected void broadcast(CallEvent event)
protected void broadcast(IDecodeEvent event)
{
mCallEventBroadcaster.broadcast(event);
mDecodeEventBroadcaster.broadcast(event);
}
/**
* Adds a call event listener
*/
@Override
public void addCallEventListener(Listener<CallEvent> listener)
public void addDecodeEventListener(Listener<IDecodeEvent> listener)
{
mCallEventBroadcaster.addListener(listener);
mDecodeEventBroadcaster.addListener(listener);
}
/**
* Removes the call event listener
*/
@Override
public void removeCallEventListener(Listener<CallEvent> listener)
public void removeDecodeEventListener(Listener<IDecodeEvent> listener)
{
mCallEventBroadcaster.removeListener(listener);
mDecodeEventBroadcaster.removeListener(listener);
}
@Override
@@ -167,43 +213,66 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
mDecoderStateListener = null;
}
@Override
public Listener<Message> getMessageListener()
{
return this;
}
/**
* Broadcasts the attribute change request to the registered listener
*/
protected void broadcast(AttributeChangeRequest<?> request)
{
mAttributeChangeRequestBroadcaster.broadcast(request);
}
/**
* Sets the listener to receive attribute change requests from this decoder state
* Listens for configuration identifiers and adds them to this decoder state's identifier collection.
* @return
*/
@Override
public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
public Listener<IdentifierUpdateNotification> getIdentifierUpdateListener()
{
mAttributeChangeRequestBroadcaster.addListener(listener);
return mConfigurationIdentifierListener;
}
/**
* Removes any listener from receiving attribute change requests
* Configuration identifier listener.
*/
@Override
public void removeAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
public ConfigurationIdentifierListener getConfigurationIdentifierListener()
{
mAttributeChangeRequestBroadcaster.removeListener(listener);
return mConfigurationIdentifierListener;
}
/**
* Broadaster so that Attribute monitors can broadcast attribute change requests
* Optional current channel descriptor
*/
protected Listener<AttributeChangeRequest> getAttributeChangeRequestListener()
protected IChannelDescriptor getCurrentChannel()
{
return mAttributeChangeRequestBroadcaster;
return mCurrentChannel;
}
/**
* Sets the current channel descriptor
*/
protected void setCurrentChannel(IChannelDescriptor channel)
{
mCurrentChannel = channel;
}
/**
* Listener for configuration type identifier updates sent from the channel state. Adds configuration
* identifiers to this decoder state so that decode events will contain configuration details in the
* event's identifier collection.
*/
public class ConfigurationIdentifierListener implements Listener<IdentifierUpdateNotification>
{
@Override
public void receive(IdentifierUpdateNotification identifierUpdateNotification)
{
if(identifierUpdateNotification.getIdentifier().getIdentifierClass() == IdentifierClass.CONFIGURATION &&
identifierUpdateNotification.getIdentifier().getForm() != Form.DECODER_TYPE &&
identifierUpdateNotification.getIdentifier().getForm() != Form.CHANNEL_DESCRIPTOR)
{
getIdentifierCollection().update(identifierUpdateNotification.getIdentifier());
}
if(identifierUpdateNotification.getOperation() == IdentifierUpdateNotification.Operation.ADD)
{
Identifier identifier = identifierUpdateNotification.getIdentifier();
if(identifier instanceof ChannelDescriptorConfigurationIdentifier)
{
mCurrentChannel = ((ChannelDescriptorConfigurationIdentifier)identifier).getValue();
}
}
}
}
}

View File

@@ -62,7 +62,6 @@ public class DecoderStateEvent
END,
RESET,
SOURCE_FREQUENCY,
START,
TRAFFIC_CHANNEL_ALLOCATION;
START;
}
}

View File

@@ -4,6 +4,6 @@ import io.github.dsheirer.sample.Listener;
public interface IDecoderStateEventProvider
{
public void setDecoderStateListener( Listener<DecoderStateEvent> listener );
public void removeDecoderStateListener();
void setDecoderStateListener( Listener<DecoderStateEvent> listener );
void removeDecoderStateListener();
}

View File

@@ -1,45 +0,0 @@
/*******************************************************************************
* 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.channel.traffic;
import io.github.dsheirer.channel.state.DecoderStateEvent;
import io.github.dsheirer.channel.state.State;
import io.github.dsheirer.module.decode.event.CallEvent;
/**
* Traffic channel allocation event wraps a call event indicating the channel
* and frequency for a traffic channel allocation event, so that the traffic
* channel manager can respond and allocate a decoder channel and source if
* available, or change the wrapped call event to a call detect event and log it.
*/
public class TrafficChannelAllocationEvent extends DecoderStateEvent
{
private CallEvent mCallEvent;
public TrafficChannelAllocationEvent( Object source, CallEvent callEvent )
{
super( source, Event.TRAFFIC_CHANNEL_ALLOCATION, State.CALL );
mCallEvent = callEvent;
}
public CallEvent getCallEvent()
{
return mCallEvent;
}
}

View File

@@ -1,391 +0,0 @@
/*******************************************************************************
* sdr-trunk
* 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.channel.traffic;
import io.github.dsheirer.channel.state.DecoderStateEvent;
import io.github.dsheirer.channel.state.IDecoderStateEventListener;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.Channel.ChannelType;
import io.github.dsheirer.controller.channel.ChannelEvent;
import io.github.dsheirer.controller.channel.ChannelEvent.Event;
import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.TrafficChannelEvent;
import io.github.dsheirer.module.Module;
import io.github.dsheirer.module.decode.config.DecodeConfiguration;
import io.github.dsheirer.module.decode.event.CallEvent;
import io.github.dsheirer.module.decode.event.CallEvent.CallEventType;
import io.github.dsheirer.module.decode.event.ICallEventProvider;
import io.github.dsheirer.record.config.RecordConfiguration;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.source.config.SourceConfigTuner;
import io.github.dsheirer.source.tuner.channel.TunerChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TrafficChannelManager extends Module implements ICallEventProvider, IDecoderStateEventListener
{
private final static Logger mLog = LoggerFactory.getLogger(TrafficChannelManager.class);
public static final String CHANNEL_START_REJECTED = "CHANNEL START REJECTED";
public static final String NO_TUNER_AVAILABLE = "NO TUNER AVAILABLE";
public static final String UNKNOWN_FREQUENCY = "UNKNOWN FREQUENCY";
private int mTrafficChannelPoolMaximumSize = DecodeConfiguration.TRAFFIC_CHANNEL_LIMIT_DEFAULT;
private List<Channel> mTrafficChannelPool = new ArrayList<Channel>();
private Map<String,Channel> mTrafficChannelsInUse = new ConcurrentHashMap<String,Channel>();
private DecoderStateEventListener mEventListener = new DecoderStateEventListener();
private Listener<CallEvent> mCallEventListener;
private ChannelModel mChannelModel;
private DecodeConfiguration mDecodeConfiguration;
private RecordConfiguration mRecordConfiguration;
private String mSystem;
private String mSite;
private String mAliasListName;
/**
* Monitors call events and allocates traffic decoder channels in response
* to traffic channel allocation call events. Manages a pool of reusable
* traffic channel allocations.
*
* @param channelModel containing channels currently in use
* @param decodeConfiguration - decoder configuration to use for each
* traffic channel allocation.
* @param recordConfiguration - recording options for each traffic channel
* @param system label to use to describe the system
* @param site label to use to describe the site
* @param aliasListName designated for the channel
* @param trafficChannelPoolSize - maximum number of allocated traffic channels
* in the pool
*/
public TrafficChannelManager(ChannelModel channelModel,
DecodeConfiguration decodeConfiguration,
RecordConfiguration recordConfiguration,
String system,
String site,
String aliasListName,
int trafficChannelPoolSize)
{
mChannelModel = channelModel;
mDecodeConfiguration = decodeConfiguration;
mRecordConfiguration = recordConfiguration;
mSystem = system;
mSite = site;
mAliasListName = aliasListName;
mTrafficChannelPoolMaximumSize = trafficChannelPoolSize;
}
@Override
public void dispose()
{
for(Channel trafficChannel : mTrafficChannelPool)
{
mChannelModel.broadcast(new ChannelEvent(trafficChannel, Event.REQUEST_DISABLE));
}
mTrafficChannelPool.clear();
mTrafficChannelsInUse.clear();
mCallEventListener = null;
mDecodeConfiguration = null;
}
/**
* Provides a channel by either reusing an existing channel or constructing
* a new one, limited by the total number of constructed channels allowed.
*
* Note: you must enforce thread safety on the mTrafficChannelsInUse
* external to this method.
*
* @param channelNumber
* @param tunerChannel
* @return
*/
private Channel getChannel(String channelNumber, TunerChannel tunerChannel)
{
Channel channel = null;
if(!mTrafficChannelsInUse.containsKey(channelNumber))
{
for(Channel configuredChannel : mTrafficChannelPool)
{
if(!configuredChannel.isProcessing())
{
channel = configuredChannel;
break;
}
}
if(channel == null && mTrafficChannelPool.size() < mTrafficChannelPoolMaximumSize)
{
channel = new Channel("Traffic", ChannelType.TRAFFIC);
channel.setDecodeConfiguration(mDecodeConfiguration);
channel.setRecordConfiguration(mRecordConfiguration);
channel.setAliasListName(mAliasListName);
mChannelModel.addChannel(channel);
mTrafficChannelPool.add(channel);
}
/* If we have a configured channel, update metadata */
if(channel != null)
{
channel.setSourceConfiguration(new SourceConfigTuner(tunerChannel));
channel.setSystem(mSystem);
channel.setSite(mSite);
channel.setName(channelNumber);
mChannelModel.broadcast(new ChannelEvent(channel, Event.NOTIFICATION_CONFIGURATION_CHANGE));
}
}
return channel;
}
/**
* Processes the event and creates a traffic channel is resources are
* available
*/
private void process(TrafficChannelAllocationEvent event)
{
CallEvent callEvent = event.getCallEvent();
/* Check for duplicate events and suppress */
synchronized(mTrafficChannelsInUse)
{
if(mTrafficChannelsInUse.containsKey(callEvent.getChannel()))
{
return;
}
long frequency = callEvent.getFrequency();
if(frequency > 0)
{
Channel channel = getChannel(callEvent.getChannel(), new TunerChannel(frequency,
mDecodeConfiguration.getChannelSpecification().getBandwidth()));
if(channel != null)
{
TrafficChannelEvent trafficChannelEvent =
new TrafficChannelEvent(this, channel, Event.REQUEST_ENABLE, callEvent);
//Request to enable the channel
mChannelModel.broadcast(trafficChannelEvent);
if(channel.isProcessing())
{
mTrafficChannelsInUse.put(callEvent.getChannel(), channel);
}
else
{
callEvent.setCallEventType(CallEventType.CALL_DETECT);
String details = callEvent.getDetails();
if(details == null || details.isEmpty())
{
callEvent.setDetails(CHANNEL_START_REJECTED);
}
else if(!details.contains(CHANNEL_START_REJECTED))
{
callEvent.setDetails(new StringBuilder(CHANNEL_START_REJECTED).append(" : ")
.append(callEvent.getDetails()).toString());
}
}
}
else
{
callEvent.setCallEventType(CallEventType.CALL_DETECT);
String details = callEvent.getDetails();
if(details == null || details.isEmpty())
{
callEvent.setDetails(NO_TUNER_AVAILABLE);
}
else if(!details.contains(NO_TUNER_AVAILABLE))
{
callEvent.setDetails(new StringBuilder(NO_TUNER_AVAILABLE).append(" : ")
.append(callEvent.getDetails()).toString());
}
}
}
else
{
callEvent.setCallEventType(CallEventType.CALL_DETECT);
String details = callEvent.getDetails();
if(details == null || details.isEmpty())
{
callEvent.setDetails(UNKNOWN_FREQUENCY);
}
else if(!details.contains(UNKNOWN_FREQUENCY))
{
callEvent.setDetails(new StringBuilder(UNKNOWN_FREQUENCY).append(" : ")
.append(callEvent.getDetails()).toString());
}
}
final Listener<CallEvent> listener = mCallEventListener;
if(listener != null)
{
listener.receive(callEvent);
}
}
}
/**
* Compares the call type, channel and to fields for equivalence and the
* from field for either both null, or equivalence.
*
* @param e1
* @param e2
* @return
*/
public static boolean isSameCallEvent(CallEvent e1, CallEvent e2)
{
if(e1 == null || e2 == null)
{
return false;
}
if(e1.getCallEventType() != e2.getCallEventType())
{
return false;
}
if(e1.getChannel() == null || e2.getChannel() == null || !e1.getChannel().contentEquals(e2.getChannel()))
{
return false;
}
if(e1.getToID() == null || e2.getToID() == null || !e1.getToID().contentEquals(e2.getToID()))
{
return false;
}
if(e1.getFromID() == null || e2.getFromID() == null)
{
return (e1.getFromID() == null && e2.getFromID() == null);
}
else if(e1.getFromID().contentEquals(e2.getFromID()))
{
return true;
}
return false;
}
@Override
public Listener<DecoderStateEvent> getDecoderStateListener()
{
return mEventListener;
}
@Override
public void addCallEventListener(Listener<CallEvent> listener)
{
mCallEventListener = listener;
}
@Override
public void removeCallEventListener(Listener<CallEvent> listener)
{
mCallEventListener = null;
}
@Override
public void reset()
{
}
@Override
public void start()
{
}
@Override
public void stop()
{
if(!mTrafficChannelsInUse.isEmpty())
{
List<String> channels = new ArrayList<>();
/* Copy the keyset so we don't get concurrent modification of the map */
channels.addAll(mTrafficChannelsInUse.keySet());
for(String channel : channels)
{
callEnd(channel);
}
}
}
/**
* Callback used by the TrafficChannelStatusListener class to signal the
* end of a an allocated traffic channel call event
*
* @param channelNumber - channel number from the call event that signaled
* the start of a traffic channel allocation
*/
public void callEnd(String channelNumber)
{
synchronized(mTrafficChannelsInUse)
{
if(channelNumber != null && mTrafficChannelsInUse.containsKey(channelNumber))
{
Channel channel = mTrafficChannelsInUse.get(channelNumber);
mChannelModel.broadcast(new ChannelEvent(channel, Event.REQUEST_DISABLE));
mTrafficChannelsInUse.remove(channelNumber);
}
}
}
/**
* Wrapper class for the decoder state event listener interface to catch
* traffic channel allocation requests
*/
public class DecoderStateEventListener implements Listener<DecoderStateEvent>
{
@Override
public void receive(DecoderStateEvent event)
{
switch(event.getEvent())
{
case TRAFFIC_CHANNEL_ALLOCATION:
process((TrafficChannelAllocationEvent) event);
break;
default:
break;
}
}
}
}