mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 09:07:27 -05:00
Updates pull request from Roman Tsypuk to convert the build system from
ant to gradle. Removes linux and windows application launch scripts and produces an executable jar with all resources included.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
/*******************************************************************************
|
||||
* 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.details;
|
||||
|
||||
import io.github.dsheirer.channel.state.DecoderState;
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import io.github.dsheirer.module.ProcessingChain;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ChannelDetailPanel extends JPanel implements Listener<ProcessingChain>
|
||||
{
|
||||
private static final String EMPTY_DETAILS = "Please select a channel to view details";
|
||||
|
||||
private JLabel mSystemLabel;
|
||||
private JLabel mSiteLabel;
|
||||
private JLabel mNameLabel;
|
||||
private JTextArea mDetailTextPane;
|
||||
|
||||
private ChannelProcessingManager mChannelProcessingManager;
|
||||
private ProcessingChain mProcessingChain;
|
||||
|
||||
public ChannelDetailPanel(ChannelProcessingManager channelProcessingManager)
|
||||
{
|
||||
mChannelProcessingManager = channelProcessingManager;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[]0[grow,fill]"));
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new MigLayout("insets 1 1 1 1", "[][grow,fill][][grow,fill][][grow,fill][]", ""));
|
||||
|
||||
buttonPanel.add(new JLabel("System:"));
|
||||
mSystemLabel = new JLabel(" ");
|
||||
buttonPanel.add(mSystemLabel);
|
||||
|
||||
buttonPanel.add(new JLabel("Site:"));
|
||||
mSiteLabel = new JLabel(" ");
|
||||
buttonPanel.add(mSiteLabel);
|
||||
|
||||
buttonPanel.add(new JLabel("Channel Name:"));
|
||||
mNameLabel = new JLabel(" ");
|
||||
buttonPanel.add(mNameLabel);
|
||||
|
||||
JButton refreshButton = new JButton("Refresh");
|
||||
refreshButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
receive(mProcessingChain);
|
||||
}
|
||||
});
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
add(buttonPanel, "wrap");
|
||||
|
||||
mDetailTextPane = new JTextArea(EMPTY_DETAILS);
|
||||
DefaultCaret caret = (DefaultCaret)mDetailTextPane.getCaret();
|
||||
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||
add(new JScrollPane(mDetailTextPane));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(ProcessingChain processingChain)
|
||||
{
|
||||
mProcessingChain = processingChain;
|
||||
|
||||
Channel channel = mChannelProcessingManager.getChannel(processingChain);
|
||||
|
||||
final String system = channel != null ? channel.getSystem() : null;
|
||||
final String site = channel != null ? channel.getSite() : null;
|
||||
final String name = channel != null ?
|
||||
(channel.getChannelType() == Channel.ChannelType.TRAFFIC ? "Traffic Channel" : channel.getName()) : null;
|
||||
|
||||
final String details;
|
||||
|
||||
if(processingChain != null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(DecoderState decoderState : processingChain.getDecoderStates())
|
||||
{
|
||||
sb.append(decoderState.getActivitySummary());
|
||||
}
|
||||
|
||||
details = sb.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
details = EMPTY_DETAILS;
|
||||
}
|
||||
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mSystemLabel.setText(system);
|
||||
mSiteLabel.setText(site);
|
||||
mNameLabel.setText(name);
|
||||
mDetailTextPane.setText(details);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* 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.heartbeat;
|
||||
|
||||
public class Heartbeat
|
||||
{
|
||||
/**
|
||||
* Periodic pulse that is broadcast to subscribing modules within the demodulating chain so that
|
||||
* monitoring of state and other attributes can occur on the primary demodulation and decoding
|
||||
* thread.
|
||||
*/
|
||||
public Heartbeat()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* 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.heartbeat;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
public interface IHeartbeatListener
|
||||
{
|
||||
public Listener<Heartbeat> getHeartbeatListener();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* 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.heartbeat;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
public interface IHeartbeatProvider
|
||||
{
|
||||
public void setHeartbeatListener(Listener<Heartbeat> listener);
|
||||
|
||||
public void removeHeartbeatListener();
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*******************************************************************************
|
||||
* 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 enum Attribute
|
||||
{
|
||||
CHANNEL_CONFIGURATION_NAME,
|
||||
CHANNEL_CONFIGURATION_SITE,
|
||||
CHANNEL_CONFIGURATION_SYSTEM,
|
||||
CHANNEL_FREQUENCY,
|
||||
CHANNEL_FREQUENCY_LABEL,
|
||||
CHANNEL_STATE,
|
||||
MESSAGE,
|
||||
MESSAGE_TYPE,
|
||||
NETWORK_ID_1,
|
||||
NETWORK_ID_2,
|
||||
PRIMARY_ADDRESS_FROM,
|
||||
PRIMARY_ADDRESS_TO,
|
||||
PRIMARY_DECODER_TYPE,
|
||||
SECONDARY_ADDRESS_FROM,
|
||||
SECONDARY_ADDRESS_TO,
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*******************************************************************************
|
||||
* 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.module.decode.DecoderType;
|
||||
|
||||
public class AttributeChangeRequest<T>
|
||||
{
|
||||
private Attribute mAttribute;
|
||||
private T mValue;
|
||||
private Alias mAlias;
|
||||
|
||||
/**
|
||||
* Request to change the value of an attribute
|
||||
* @param attribute to change
|
||||
* @param value to change for the attribute
|
||||
* @param alias (optional) for the value
|
||||
*/
|
||||
public AttributeChangeRequest(Attribute attribute, T value, Alias alias)
|
||||
{
|
||||
mAttribute = attribute;
|
||||
mValue = value;
|
||||
mAlias = alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to change the value of an attribute
|
||||
* @param attribute to change
|
||||
* @param value to change for the attribute
|
||||
*/
|
||||
public AttributeChangeRequest(Attribute attribute, T value)
|
||||
{
|
||||
this(attribute, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute to change
|
||||
*/
|
||||
public Attribute getAttribute()
|
||||
{
|
||||
return mAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value to set for the attribute
|
||||
*/
|
||||
public T getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this change request has a non-null value for the attribute
|
||||
*/
|
||||
public boolean hasValue()
|
||||
{
|
||||
return mValue != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for the corresponding attribute value
|
||||
*/
|
||||
public Alias getAlias()
|
||||
{
|
||||
return mAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this change request contains an alias that corresponds to the attribute value
|
||||
*/
|
||||
public boolean hasAlias()
|
||||
{
|
||||
return mAlias != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as a String or null if the value is not a String instance.
|
||||
*/
|
||||
public String getStringValue()
|
||||
{
|
||||
if(mValue instanceof String)
|
||||
{
|
||||
return (String)mValue;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as a Long or null if the value is not a Long instance.
|
||||
*/
|
||||
public Long getLongValue()
|
||||
{
|
||||
if(mValue instanceof Long)
|
||||
{
|
||||
return (Long)mValue;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as a DecoderType or null if the value is not a DecoderType instance.
|
||||
*/
|
||||
public DecoderType getDecoderTypeValue()
|
||||
{
|
||||
if(mValue instanceof DecoderType)
|
||||
{
|
||||
return (DecoderType)mValue;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*******************************************************************************
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
/*******************************************************************************
|
||||
* 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.controller.channel.Channel;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.awt.*;
|
||||
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>
|
||||
{
|
||||
private final DecimalFormat FREQUENCY_FORMATTER = new DecimalFormat( "#.00000" );
|
||||
|
||||
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 = {"State", "Decoder", "Channel", "Frequency", "Primary From", "Primary To",
|
||||
"Secondary From", "Secondary To", "Channel Name", "Message"};
|
||||
|
||||
private List<MutableMetadata> mChannelMetadata = new ArrayList();
|
||||
private Map<MutableMetadata,Channel> mMetadataChannelMap = new HashMap();
|
||||
|
||||
public void add(MutableMetadata metadata, Channel channel)
|
||||
{
|
||||
//Execute on the swing thread to avoid threading issues
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mChannelMetadata.add(metadata);
|
||||
mMetadataChannelMap.put(metadata, channel);
|
||||
|
||||
int index = mChannelMetadata.indexOf(metadata);
|
||||
|
||||
fireTableRowsInserted(index, index);
|
||||
|
||||
metadata.addListener(ChannelMetadataModel.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void remove(MutableMetadata metadata)
|
||||
{
|
||||
//Execute on the swing thread to avoid threading issues
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
metadata.removeListener(ChannelMetadataModel.this);
|
||||
|
||||
int index = mChannelMetadata.indexOf(metadata);
|
||||
|
||||
mChannelMetadata.remove(metadata);
|
||||
mMetadataChannelMap.remove(metadata);
|
||||
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel metadata at the specified model row index
|
||||
*/
|
||||
public Metadata getMetadata(int row)
|
||||
{
|
||||
if(row < mChannelMetadata.size())
|
||||
{
|
||||
return mChannelMetadata.get(row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the channel that matches the metadata or null
|
||||
*/
|
||||
public Channel getChannelFromMetadata(Metadata metadata)
|
||||
{
|
||||
return mMetadataChannelMap.get(metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount()
|
||||
{
|
||||
return mChannelMetadata.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount()
|
||||
{
|
||||
return COLUMNS.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column)
|
||||
{
|
||||
return COLUMNS[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex)
|
||||
{
|
||||
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;
|
||||
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
{
|
||||
if(rowIndex <= mChannelMetadata.size())
|
||||
{
|
||||
Metadata metadata = 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.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;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(MutableMetadataChangeEvent mutableMetadataChangeEvent)
|
||||
{
|
||||
//Execute on the swing thread to avoid threading issues
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
int rowIndex = mChannelMetadata.indexOf(mutableMetadataChangeEvent.getMetadata());
|
||||
|
||||
if(rowIndex >= 0)
|
||||
{
|
||||
switch(mutableMetadataChangeEvent.getAttribute())
|
||||
{
|
||||
case CHANNEL_CONFIGURATION_SYSTEM:
|
||||
break;
|
||||
case CHANNEL_CONFIGURATION_SITE:
|
||||
break;
|
||||
case CHANNEL_CONFIGURATION_NAME:
|
||||
fireTableCellUpdated(rowIndex, COLUMN_CONFIGURATION_NAME);
|
||||
break;
|
||||
case CHANNEL_FREQUENCY:
|
||||
fireTableCellUpdated(rowIndex, COLUMN_FREQUENCY);
|
||||
break;
|
||||
case CHANNEL_FREQUENCY_LABEL:
|
||||
fireTableCellUpdated(rowIndex, COLUMN_CHANNEL);
|
||||
break;
|
||||
case CHANNEL_STATE:
|
||||
fireTableCellUpdated(rowIndex, COLUMN_STATE);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
/*******************************************************************************
|
||||
* 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.controller.channel.Channel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.controller.channel.ChannelUtils;
|
||||
import io.github.dsheirer.icon.IconManager;
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.module.ProcessingChain;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ChannelMetadataPanel extends JPanel implements ListSelectionListener
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ChannelMetadataPanel.class);
|
||||
|
||||
private static final String PROPERTY_PREFIX_BACKGROUND = "channel.metadata.panel.state.color.";
|
||||
private static final String PROPERTY_PREFIX_FOREGROUND = "channel.metadata.panel.text.color.";
|
||||
private ChannelProcessingManager mChannelProcessingManager;
|
||||
private IconManager mIconManager;
|
||||
private JTable mTable;
|
||||
private Broadcaster<ProcessingChain> mSelectedProcessingChainBroadcaster = new Broadcaster<>();
|
||||
|
||||
/**
|
||||
* Table view for currently decoding channel metadata
|
||||
*/
|
||||
public ChannelMetadataPanel(ChannelProcessingManager channelProcessingManager, IconManager iconManager)
|
||||
{
|
||||
mIconManager = iconManager;
|
||||
mChannelProcessingManager = channelProcessingManager;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the panel
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]") );
|
||||
|
||||
mTable = new JTable(mChannelProcessingManager.getChannelMetadataModel());
|
||||
|
||||
DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)mTable.getDefaultRenderer(String.class);
|
||||
renderer.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
mTable.getSelectionModel().addListSelectionListener(this);
|
||||
mTable.addMouseListener(new MouseSupport());
|
||||
|
||||
mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_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));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(mTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
add(scrollPane);
|
||||
|
||||
// new TableColumnWidthMonitor(mTable, PROPERTY_PREFIX, new int[] {15,15,15,15,25,25,25,25,15,40});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e)
|
||||
{
|
||||
if(!mTable.getSelectionModel().getValueIsAdjusting())
|
||||
{
|
||||
ProcessingChain processingChain = null;
|
||||
|
||||
int selectedViewRow = mTable.getSelectedRow();
|
||||
|
||||
if(selectedViewRow >= 0)
|
||||
{
|
||||
int selectedModelRow = mTable.convertRowIndexToModel(selectedViewRow);
|
||||
|
||||
Metadata selectedMetadata = mChannelProcessingManager.getChannelMetadataModel()
|
||||
.getMetadata(selectedModelRow);
|
||||
|
||||
if(selectedMetadata != null)
|
||||
{
|
||||
Channel selectedChannel = mChannelProcessingManager.getChannelMetadataModel()
|
||||
.getChannelFromMetadata(selectedMetadata);
|
||||
|
||||
processingChain = mChannelProcessingManager.getProcessingChain(selectedChannel);
|
||||
}
|
||||
}
|
||||
|
||||
mSelectedProcessingChainBroadcaster.broadcast(processingChain);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the listener to receive the processing chain associated with the metadata selected in the
|
||||
* metadata table.
|
||||
*/
|
||||
public void addProcessingChainSelectionListener(Listener<ProcessingChain> listener)
|
||||
{
|
||||
mSelectedProcessingChainBroadcaster.addListener(listener);
|
||||
}
|
||||
|
||||
public class AliasedValueCellRenderer extends DefaultTableCellRenderer
|
||||
{
|
||||
private Attribute mAttribute;
|
||||
|
||||
public AliasedValueCellRenderer(Attribute attribute)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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());
|
||||
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColoredStateCellRenderer extends DefaultTableCellRenderer
|
||||
{
|
||||
public ColoredStateCellRenderer()
|
||||
{
|
||||
setHorizontalAlignment(SwingConstants.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);
|
||||
|
||||
Color background = table.getBackground();
|
||||
Color foreground = table.getForeground();
|
||||
|
||||
if(value instanceof State)
|
||||
{
|
||||
State state = (State)value;
|
||||
label.setText(state.getDisplayValue());
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case CALL:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "call", Color.BLUE);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "call", Color.YELLOW);
|
||||
break;
|
||||
case CONTROL:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "control", Color.ORANGE);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "control", Color.BLUE);
|
||||
break;
|
||||
case DATA:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "data", Color.GREEN);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "data", Color.BLUE);
|
||||
break;
|
||||
case ENCRYPTED:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "encrypted", Color.MAGENTA);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "encrypted", Color.WHITE);
|
||||
break;
|
||||
case FADE:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "fade", Color.LIGHT_GRAY.BLUE);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "fade", Color.YELLOW);
|
||||
break;
|
||||
case IDLE:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "idle", Color.WHITE);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "idle", Color.BLUE);
|
||||
break;
|
||||
case OVERFLOW:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "overflow", Color.RED);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "overflow", Color.YELLOW);
|
||||
break;
|
||||
case RESET:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "reset", Color.PINK);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "reset", Color.YELLOW);
|
||||
break;
|
||||
case TEARDOWN:
|
||||
background = SystemProperties.getInstance().get(PROPERTY_PREFIX_BACKGROUND + "teardown", Color.DARK_GRAY);
|
||||
foreground = SystemProperties.getInstance().get(PROPERTY_PREFIX_FOREGROUND + "teardown", Color.WHITE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setText("");
|
||||
}
|
||||
|
||||
setBackground(background);
|
||||
setForeground(foreground);
|
||||
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
public class MouseSupport extends MouseAdapter
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
if(e.getButton() == MouseEvent.BUTTON3) //Right click for context
|
||||
{
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
|
||||
boolean populated = false;
|
||||
|
||||
int viewRowIndex = mTable.rowAtPoint(e.getPoint());
|
||||
|
||||
if(viewRowIndex >= 0)
|
||||
{
|
||||
int modelRowIndex = mTable.convertRowIndexToModel(viewRowIndex);
|
||||
|
||||
if(modelRowIndex >= 0)
|
||||
{
|
||||
Metadata metadata = mChannelProcessingManager.getChannelMetadataModel().getMetadata(modelRowIndex);
|
||||
|
||||
if(metadata != null)
|
||||
{
|
||||
Channel channel = mChannelProcessingManager.getChannelMetadataModel()
|
||||
.getChannelFromMetadata(metadata);
|
||||
|
||||
if(channel != null)
|
||||
{
|
||||
popupMenu.add(ChannelUtils.getContextMenu(mChannelProcessingManager.getChannelModel(),
|
||||
mChannelProcessingManager, channel, mTable));
|
||||
|
||||
populated = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!populated)
|
||||
{
|
||||
popupMenu.add(new JMenuItem("No Actions Available"));
|
||||
}
|
||||
|
||||
popupMenu.show(mTable, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* 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 com.jidesoft.swing.JideSplitPane;
|
||||
import com.jidesoft.swing.JideTabbedPane;
|
||||
import io.github.dsheirer.channel.details.ChannelDetailPanel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.icon.IconManager;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.spectrum.ChannelSpectrumPanel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import io.github.dsheirer.module.decode.event.CallEventPanel;
|
||||
import io.github.dsheirer.module.decode.event.MessageActivityPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ChannelMetadataViewer extends JPanel
|
||||
{
|
||||
private ChannelMetadataPanel mChannelMetadataPanel;
|
||||
|
||||
private ChannelDetailPanel mChannelDetailPanel;
|
||||
private CallEventPanel mCallEventPanel;
|
||||
private MessageActivityPanel mMessageActivityPanel;
|
||||
private ChannelSpectrumPanel mChannelSpectrumPanel;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
mChannelDetailPanel = new ChannelDetailPanel(channelProcessingManager);
|
||||
mCallEventPanel = new CallEventPanel(iconManager);
|
||||
mMessageActivityPanel = new MessageActivityPanel(channelProcessingManager);
|
||||
// mChannelSpectrumPanel = new ChannelSpectrumPanel(settingsManager, channelProcessingManager);
|
||||
mChannelMetadataPanel = new ChannelMetadataPanel(channelProcessingManager, iconManager);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]") );
|
||||
|
||||
JideTabbedPane tabbedPane = new JideTabbedPane();
|
||||
tabbedPane.addTab("Details", mChannelDetailPanel);
|
||||
tabbedPane.addTab("Events", mCallEventPanel);
|
||||
tabbedPane.addTab("Messages", mMessageActivityPanel);
|
||||
// tabbedPane.addTab("Spectrum", mChannelSpectrumPanel);
|
||||
tabbedPane.setFont(this.getFont());
|
||||
tabbedPane.setForeground(Color.BLACK);
|
||||
|
||||
JideSplitPane splitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
|
||||
splitPane.setShowGripper(true);
|
||||
splitPane.add(mChannelMetadataPanel);
|
||||
splitPane.add(tabbedPane);
|
||||
add(splitPane);
|
||||
|
||||
mChannelMetadataPanel.addProcessingChainSelectionListener(mChannelDetailPanel);
|
||||
mChannelMetadataPanel.addProcessingChainSelectionListener(mCallEventPanel);
|
||||
mChannelMetadataPanel.addProcessingChainSelectionListener(mMessageActivityPanel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* 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.sample.Listener;
|
||||
|
||||
public interface IAttributeChangeRequestListener
|
||||
{
|
||||
public Listener<AttributeChangeRequest> getAttributeChangeRequestListener();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* 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.sample.Listener;
|
||||
|
||||
public interface IAttributeChangeRequestProvider
|
||||
{
|
||||
public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener);
|
||||
|
||||
public void removeAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener);
|
||||
}
|
||||
645
src/main/java/io/github/dsheirer/channel/metadata/Metadata.java
Normal file
645
src/main/java/io/github/dsheirer/channel/metadata/Metadata.java
Normal file
@@ -0,0 +1,645 @@
|
||||
/*******************************************************************************
|
||||
* 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.module.decode.DecoderType;
|
||||
|
||||
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 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;
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
/*******************************************************************************
|
||||
* 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.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.github.dsheirer.module.decode.DecoderType;
|
||||
|
||||
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 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 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.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.module.decode.DecoderType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
/**
|
||||
* Basic decoder channel state - provides the minimum channel state functionality
|
||||
* to support an always un-squelched audio decoder.
|
||||
*/
|
||||
public class AlwaysUnsquelchedDecoderState extends DecoderState
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AlwaysUnsquelchedDecoderState.class);
|
||||
|
||||
private DecoderType mDecoderType;
|
||||
private String mChannelName;
|
||||
|
||||
public AlwaysUnsquelchedDecoderState(DecoderType decoderType, String channelName)
|
||||
{
|
||||
super(null);
|
||||
|
||||
mDecoderType = decoderType;
|
||||
mChannelName = channelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActivitySummary()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("Activity Summary\n");
|
||||
sb.append("\tDecoder:\t");
|
||||
sb.append(mDecoderType);
|
||||
sb.append("\n\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Message t)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveDecoderStateEvent(DecoderStateEvent event)
|
||||
{
|
||||
if(event.getEvent() == Event.RESET)
|
||||
{
|
||||
//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, mChannelName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecoderType getDecoderType()
|
||||
{
|
||||
return mDecoderType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(ScheduledExecutorService executor)
|
||||
{
|
||||
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, mChannelName));
|
||||
broadcast(new DecoderStateEvent(this, Event.ALWAYS_UNSQUELCH, State.IDLE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.dsheirer.channel.state;
|
||||
|
||||
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
||||
|
||||
/**
|
||||
* Allows decoders to change the call timeout setting in the channel state
|
||||
*/
|
||||
public class ChangeChannelTimeoutEvent extends DecoderStateEvent
|
||||
{
|
||||
private ChannelType mChannelType;
|
||||
private long mCallTimeout;
|
||||
|
||||
public ChangeChannelTimeoutEvent( Object source, ChannelType channelType, long timeout )
|
||||
{
|
||||
super( source, Event.CHANGE_CALL_TIMEOUT, State.IDLE );
|
||||
mChannelType = channelType;
|
||||
mCallTimeout = timeout;
|
||||
}
|
||||
|
||||
public ChannelType getChannelType()
|
||||
{
|
||||
return mChannelType;
|
||||
}
|
||||
|
||||
public long getCallTimeout()
|
||||
{
|
||||
return mCallTimeout;
|
||||
}
|
||||
}
|
||||
639
src/main/java/io/github/dsheirer/channel/state/ChannelState.java
Normal file
639
src/main/java/io/github/dsheirer/channel/state/ChannelState.java
Normal file
@@ -0,0 +1,639 @@
|
||||
/*******************************************************************************
|
||||
* 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.state;
|
||||
|
||||
import io.github.dsheirer.audio.squelch.ISquelchStateProvider;
|
||||
import io.github.dsheirer.audio.squelch.SquelchState;
|
||||
import io.github.dsheirer.channel.heartbeat.Heartbeat;
|
||||
import io.github.dsheirer.channel.heartbeat.IHeartbeatListener;
|
||||
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.state.DecoderStateEvent.Event;
|
||||
import io.github.dsheirer.channel.traffic.TrafficChannelManager;
|
||||
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
||||
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.sample.Listener;
|
||||
import io.github.dsheirer.sample.real.IOverflowListener;
|
||||
import io.github.dsheirer.source.tuner.frequency.FrequencyChangeEvent;
|
||||
import io.github.dsheirer.source.tuner.frequency.IFrequencyChangeListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static io.github.dsheirer.source.tuner.frequency.FrequencyChangeEvent.Event.NOTIFICATION_FREQUENCY_CHANGE;
|
||||
|
||||
public class ChannelState extends Module implements ICallEventProvider, IDecoderStateEventListener,
|
||||
IDecoderStateEventProvider, IFrequencyChangeListener, IHeartbeatListener, ISquelchStateProvider,
|
||||
IAttributeChangeRequestListener, IOverflowListener
|
||||
{
|
||||
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 Listener<DecoderStateEvent> mDecoderStateListener;
|
||||
private Listener<SquelchState> mSquelchStateListener;
|
||||
private DecoderStateEventReceiver mDecoderStateEventReceiver = new DecoderStateEventReceiver();
|
||||
private HeartbeatReceiver mHeartbeatReceiver = new HeartbeatReceiver();
|
||||
private ChannelType mChannelType;
|
||||
private TrafficChannelManager mTrafficChannelEndListener;
|
||||
private CallEvent mTrafficChannelCallEvent;
|
||||
private FrequencyChangeListener mFrequencyChangeListener;
|
||||
|
||||
private boolean mSquelchLocked = false;
|
||||
private boolean mSelected = false;
|
||||
private boolean mSourceOverflow = false;
|
||||
|
||||
private long mStandardChannelFadeTimeout = FADE_TIMEOUT_DELAY;
|
||||
private long mTrafficChannelFadeTimeout = DecodeConfiguration.DEFAULT_CALL_TIMEOUT_SECONDS * 1000;
|
||||
private long mFadeTimeout;
|
||||
private long mEndTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* Channel state tracks the overall state of all processing modules and decoders configured for the channel and
|
||||
* provides squelch control and decoder state reset events.
|
||||
*
|
||||
* Uses a state enumeration that defines allowable channel state transitions in order to track a call or data decode
|
||||
* event from start to finish. Uses a timer to monitor for inactivity and to provide a FADE period that indicates
|
||||
* to the user that the activity has stopped while continuing to provide details about the call, before the state is
|
||||
* reset to IDLE.
|
||||
*
|
||||
* State Descriptions:
|
||||
* 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
|
||||
* TEARDOWN: Indicates a traffic channel that will be torn down for reuse.
|
||||
*/
|
||||
public ChannelState(ChannelType channelType)
|
||||
{
|
||||
mChannelType = channelType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public MutableMetadata getMutableMetadata()
|
||||
{
|
||||
return mMutableMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this channel state and prepares it for reuse.
|
||||
*/
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
broadcast(new DecoderStateEvent(this, Event.RESET, State.IDLE));
|
||||
|
||||
mState = State.IDLE;
|
||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
||||
mSourceOverflow = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(ScheduledExecutorService executor)
|
||||
{
|
||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
||||
|
||||
if(mTrafficChannelEndListener != null)
|
||||
{
|
||||
setState(State.CALL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop()
|
||||
{
|
||||
mMutableMetadata.resetAllAttributes();
|
||||
|
||||
mTrafficChannelEndListener = null;
|
||||
|
||||
if(mTrafficChannelCallEvent != null)
|
||||
{
|
||||
mTrafficChannelCallEvent.end();
|
||||
broadcast(mTrafficChannelCallEvent);
|
||||
}
|
||||
|
||||
mTrafficChannelCallEvent = null;
|
||||
|
||||
mSquelchLocked = false;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mCallEventListener = null;
|
||||
mDecoderStateListener = null;
|
||||
mSquelchStateListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<FrequencyChangeEvent> getFrequencyChangeListener()
|
||||
{
|
||||
if(mFrequencyChangeListener == null)
|
||||
{
|
||||
mFrequencyChangeListener = new FrequencyChangeListener();
|
||||
}
|
||||
|
||||
return mFrequencyChangeListener;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mFadeTimeout = mStandardChannelFadeTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTrafficChannelTimeout(long milliseconds)
|
||||
{
|
||||
mTrafficChannelFadeTimeout = milliseconds;
|
||||
|
||||
if(mChannelType == ChannelType.TRAFFIC)
|
||||
{
|
||||
mFadeTimeout = System.currentTimeMillis() + mTrafficChannelFadeTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected)
|
||||
{
|
||||
mSelected = selected;
|
||||
}
|
||||
|
||||
public boolean isSelected()
|
||||
{
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
public State getState()
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the fade timeout threshold to the current time plus delay
|
||||
*/
|
||||
private void updateFadeTimeout()
|
||||
{
|
||||
if(isTrafficChannel())
|
||||
{
|
||||
mFadeTimeout = System.currentTimeMillis() + mTrafficChannelFadeTimeout;
|
||||
}
|
||||
else
|
||||
{
|
||||
mFadeTimeout = System.currentTimeMillis() + mStandardChannelFadeTimeout;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the reset timeout threshold to the current time plus delay
|
||||
*/
|
||||
private void updateResetTimeout()
|
||||
{
|
||||
if(isTrafficChannel())
|
||||
{
|
||||
mEndTimeout = System.currentTimeMillis();
|
||||
}
|
||||
else
|
||||
{
|
||||
mEndTimeout = System.currentTimeMillis() + RESET_TIMEOUT_DELAY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts the squelch state to the registered listener
|
||||
*/
|
||||
protected void broadcast(SquelchState state)
|
||||
{
|
||||
if(mSquelchStateListener != null && !mSquelchLocked)
|
||||
{
|
||||
mSquelchStateListener.receive(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the squelch state listener
|
||||
*/
|
||||
@Override
|
||||
public void setSquelchStateListener(Listener<SquelchState> listener)
|
||||
{
|
||||
mSquelchStateListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the squelch state listener
|
||||
*/
|
||||
@Override
|
||||
public void removeSquelchStateListener()
|
||||
{
|
||||
mSquelchStateListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the channel state to the specified state, or updates the timeout values so that the state monitor will not
|
||||
* change state. Broadcasts a squelch event when the state changes and the audio squelch state should change. Also
|
||||
* broadcasts changed attribute and decoder state events so that external processes can maintain sync with this
|
||||
* channel state.
|
||||
*/
|
||||
protected void setState(State state)
|
||||
{
|
||||
if(state == mState)
|
||||
{
|
||||
if(State.CALL_STATES.contains(state))
|
||||
{
|
||||
updateFadeTimeout();
|
||||
}
|
||||
}
|
||||
else if(mState.canChangeTo(state))
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case CONTROL:
|
||||
//Don't allow traffic channels to be control channels, otherwise they can't transition to teardown
|
||||
if(isStandardChannel())
|
||||
{
|
||||
broadcast(SquelchState.SQUELCH);
|
||||
updateFadeTimeout();
|
||||
mState = state;
|
||||
}
|
||||
break;
|
||||
case DATA:
|
||||
case ENCRYPTED:
|
||||
broadcast(SquelchState.SQUELCH);
|
||||
updateFadeTimeout();
|
||||
mState = state;
|
||||
break;
|
||||
case CALL:
|
||||
broadcast(SquelchState.UNSQUELCH);
|
||||
updateFadeTimeout();
|
||||
mState = state;
|
||||
break;
|
||||
case FADE:
|
||||
processFadeState();
|
||||
break;
|
||||
case IDLE:
|
||||
processIdleState();
|
||||
break;
|
||||
case TEARDOWN:
|
||||
processTeardownState();
|
||||
break;
|
||||
case RESET:
|
||||
mState = State.IDLE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE,
|
||||
mSourceOverflow ? State.OVERFLOW : mState));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receiver inner class that implements the IHeartbeatListener interface to receive heartbeat messages.
|
||||
*/
|
||||
@Override
|
||||
public Listener<Heartbeat> getHeartbeatListener()
|
||||
{
|
||||
return mHeartbeatReceiver;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<State>(Attribute.CHANNEL_STATE,
|
||||
mSourceOverflow ? State.OVERFLOW : mState));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state and processes related actions
|
||||
*/
|
||||
private void processFadeState()
|
||||
{
|
||||
updateResetTimeout();
|
||||
mState = State.FADE;
|
||||
|
||||
broadcast(SquelchState.SQUELCH);
|
||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
||||
}
|
||||
|
||||
private void processIdleState()
|
||||
{
|
||||
broadcast(SquelchState.SQUELCH);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private void processTeardownState()
|
||||
{
|
||||
broadcast(SquelchState.SQUELCH);
|
||||
|
||||
getMutableMetadata().resetTemporalAttributes();
|
||||
|
||||
mState = State.TEARDOWN;
|
||||
|
||||
mMutableMetadata.receive(new AttributeChangeRequest<State>(Attribute.CHANNEL_STATE, mState));
|
||||
|
||||
if(mTrafficChannelEndListener != null)
|
||||
{
|
||||
mTrafficChannelEndListener.callEnd(mTrafficChannelCallEvent.getChannel());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts the call event to the registered listener
|
||||
*/
|
||||
protected void broadcast(CallEvent event)
|
||||
{
|
||||
if(mCallEventListener != null)
|
||||
{
|
||||
mCallEventListener.receive(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallEventListener(Listener<CallEvent> listener)
|
||||
{
|
||||
mCallEventListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallEventListener(Listener<CallEvent> listener)
|
||||
{
|
||||
mCallEventListener = null;
|
||||
}
|
||||
|
||||
|
||||
//NEW:
|
||||
@Override
|
||||
public Listener<AttributeChangeRequest> getAttributeChangeRequestListener()
|
||||
{
|
||||
return mMutableMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a channel state event to any registered listeners
|
||||
*/
|
||||
protected void broadcast(DecoderStateEvent event)
|
||||
{
|
||||
if(mDecoderStateListener != null)
|
||||
{
|
||||
mDecoderStateListener.receive(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a decoder state event listener
|
||||
*/
|
||||
@Override
|
||||
public void setDecoderStateListener(Listener<DecoderStateEvent> listener)
|
||||
{
|
||||
mDecoderStateListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the decoder state event listener
|
||||
*/
|
||||
@Override
|
||||
public void removeDecoderStateListener()
|
||||
{
|
||||
mDecoderStateListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<DecoderStateEvent> getDecoderStateListener()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to receive frequency change events and rebroadcast them to the decoder states
|
||||
*/
|
||||
public class FrequencyChangeListener implements Listener<FrequencyChangeEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive(FrequencyChangeEvent frequencyChangeEvent)
|
||||
{
|
||||
if(frequencyChangeEvent.getEvent() == NOTIFICATION_FREQUENCY_CHANGE)
|
||||
{
|
||||
long frequency = frequencyChangeEvent.getValue().longValue();
|
||||
|
||||
broadcast(new DecoderStateEvent(this, Event.SOURCE_FREQUENCY, getState(), frequency));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DecoderStateEvent receiver wrapper
|
||||
*/
|
||||
public class DecoderStateEventReceiver implements Listener<DecoderStateEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive(DecoderStateEvent event)
|
||||
{
|
||||
if(event.getSource() != this)
|
||||
{
|
||||
switch(event.getEvent())
|
||||
{
|
||||
case ALWAYS_UNSQUELCH:
|
||||
broadcast(SquelchState.UNSQUELCH);
|
||||
mSquelchLocked = true;
|
||||
break;
|
||||
case CHANGE_CALL_TIMEOUT:
|
||||
if(event instanceof ChangeChannelTimeoutEvent)
|
||||
{
|
||||
ChangeChannelTimeoutEvent timeout = (ChangeChannelTimeoutEvent) event;
|
||||
|
||||
if(timeout.getChannelType() == ChannelType.STANDARD)
|
||||
{
|
||||
setStandardChannelTimeout(timeout.getCallTimeout());
|
||||
}
|
||||
else
|
||||
{
|
||||
setTrafficChannelTimeout(timeout.getCallTimeout());
|
||||
}
|
||||
}
|
||||
case CONTINUATION:
|
||||
case DECODE:
|
||||
case START:
|
||||
if(State.CALL_STATES.contains(event.getState()))
|
||||
{
|
||||
setState(event.getState());
|
||||
}
|
||||
break;
|
||||
case END:
|
||||
if(isTrafficChannel())
|
||||
{
|
||||
setState(State.TEARDOWN);
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(State.FADE);
|
||||
}
|
||||
break;
|
||||
case RESET:
|
||||
/* Channel State does not respond to reset events */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes periodic heartbeats received from the processing chain to perform state monitoring and cleanup
|
||||
* functions.
|
||||
*
|
||||
* Monitors decoder state events to automatically transition the channel state to IDLE (standard channel) or to
|
||||
* TEARDOWN (traffic channel) when decoding stops or the monitored channel returns to a no signal state.
|
||||
*
|
||||
* Provides a FADE transition state to allow for momentary decoding dropouts and to allow the user access to call
|
||||
* details for a fade period upon call end.
|
||||
*/
|
||||
public class HeartbeatReceiver implements Listener<Heartbeat>
|
||||
{
|
||||
@Override
|
||||
public void receive(Heartbeat heartbeat)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(State.CALL_STATES.contains(mState) && mFadeTimeout <= System.currentTimeMillis())
|
||||
{
|
||||
processFadeState();
|
||||
}
|
||||
else if(mState == State.FADE && mEndTimeout <= System.currentTimeMillis())
|
||||
{
|
||||
if(isTrafficChannel())
|
||||
{
|
||||
processTeardownState();
|
||||
}
|
||||
else
|
||||
{
|
||||
processIdleState();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
mLog.error("An error occurred while state monitor was running " +
|
||||
"- state [" + getState() +
|
||||
"] current [" + System.currentTimeMillis() +
|
||||
"] mResetTimeout [" + mEndTimeout +
|
||||
"] mFadeTimeout [" + mFadeTimeout +
|
||||
"]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.state;
|
||||
|
||||
|
||||
public interface ChannelStateSelectionListener
|
||||
{
|
||||
public void selected( ChannelState channelState );
|
||||
}
|
||||
209
src/main/java/io/github/dsheirer/channel/state/DecoderState.java
Normal file
209
src/main/java/io/github/dsheirer/channel/state/DecoderState.java
Normal file
@@ -0,0 +1,209 @@
|
||||
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.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.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
/**
|
||||
* Channel state monitors the stream of decoded messages produced by the
|
||||
* decoder and broadcasts call events as they occur within the decoded message activity.
|
||||
*
|
||||
* 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
|
||||
{
|
||||
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 Listener<DecoderStateEvent> mDecoderStateListener;
|
||||
|
||||
private DecoderStateEventListener mDecoderStateEventListener = new DecoderStateEventListener();
|
||||
|
||||
protected CallEvent mCurrentCallEvent;
|
||||
|
||||
private AliasList mAliasList;
|
||||
|
||||
public DecoderState(AliasList aliasList)
|
||||
{
|
||||
mAliasList = aliasList;
|
||||
}
|
||||
|
||||
public abstract DecoderType getDecoderType();
|
||||
|
||||
public AliasList getAliasList()
|
||||
{
|
||||
return mAliasList;
|
||||
}
|
||||
|
||||
public boolean hasAliasList()
|
||||
{
|
||||
return mAliasList != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides subclass reference to the call event broadcaster
|
||||
*/
|
||||
protected Broadcaster<CallEvent> getCallEventBroadcaster()
|
||||
{
|
||||
return mCallEventBroadcaster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the decoder state to prepare for processing a different sample
|
||||
* source
|
||||
*/
|
||||
public abstract void reset();
|
||||
|
||||
/**
|
||||
* Allow the decoder to perform any setup actions
|
||||
*/
|
||||
public abstract void init();
|
||||
|
||||
/**
|
||||
* Implements the IDecoderStateEventListener interface to receive state
|
||||
* reset events.
|
||||
*/
|
||||
public abstract void receiveDecoderStateEvent(DecoderStateEvent event);
|
||||
|
||||
/**
|
||||
* Disposes any resources or pointers held by this instance to prepare for
|
||||
* garbage collection
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
mCallEventBroadcaster.dispose();
|
||||
mCallEventBroadcaster = null;
|
||||
mDecoderStateListener = null;
|
||||
|
||||
mAliasList = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activity Summary - textual summary of activity observed by the channel state.
|
||||
*/
|
||||
public abstract String getActivitySummary();
|
||||
|
||||
/**
|
||||
* Broadcasts a call event to any registered listeners
|
||||
*/
|
||||
protected void broadcast(CallEvent event)
|
||||
{
|
||||
mCallEventBroadcaster.broadcast(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a call event listener
|
||||
*/
|
||||
@Override
|
||||
public void addCallEventListener(Listener<CallEvent> listener)
|
||||
{
|
||||
mCallEventBroadcaster.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the call event listener
|
||||
*/
|
||||
@Override
|
||||
public void removeCallEventListener(Listener<CallEvent> listener)
|
||||
{
|
||||
mCallEventBroadcaster.removeListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<DecoderStateEvent> getDecoderStateListener()
|
||||
{
|
||||
return mDecoderStateEventListener;
|
||||
}
|
||||
|
||||
private class DecoderStateEventListener implements Listener<DecoderStateEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive(DecoderStateEvent event)
|
||||
{
|
||||
receiveDecoderStateEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a channel state event to any registered listeners
|
||||
*/
|
||||
protected void broadcast(DecoderStateEvent event)
|
||||
{
|
||||
if(mDecoderStateListener != null)
|
||||
{
|
||||
mDecoderStateListener.receive(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a decoder state event listener
|
||||
*/
|
||||
@Override
|
||||
public void setDecoderStateListener(Listener<DecoderStateEvent> listener)
|
||||
{
|
||||
mDecoderStateListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the decoder state event listener
|
||||
*/
|
||||
@Override
|
||||
public void removeDecoderStateListener()
|
||||
{
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
|
||||
{
|
||||
mAttributeChangeRequestBroadcaster.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any listener from receiving attribute change requests
|
||||
*/
|
||||
@Override
|
||||
public void removeAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
|
||||
{
|
||||
mAttributeChangeRequestBroadcaster.removeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadaster so that Attribute monitors can broadcast attribute change requests
|
||||
*/
|
||||
protected Listener<AttributeChangeRequest> getAttributeChangeRequestListener()
|
||||
{
|
||||
return mAttributeChangeRequestBroadcaster;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.github.dsheirer.channel.state;
|
||||
|
||||
public class DecoderStateEvent
|
||||
{
|
||||
private Object mSource;
|
||||
private Event mEvent;
|
||||
private State mState;
|
||||
private long mFrequency;
|
||||
|
||||
public DecoderStateEvent( Object source, Event event, State state )
|
||||
{
|
||||
mSource = source;
|
||||
mEvent = event;
|
||||
mState = state;
|
||||
}
|
||||
|
||||
public DecoderStateEvent( Object source, Event event, State state, long frequency )
|
||||
{
|
||||
this( source, event, state );
|
||||
|
||||
mFrequency = frequency;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( "Decoder State Event - source[" + mSource.getClass() +
|
||||
"] event[" + mEvent.toString() +
|
||||
"] state[" + mState.toString() +
|
||||
"] frequency [" + mFrequency + "]" );
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object getSource()
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
public Event getEvent()
|
||||
{
|
||||
return mEvent;
|
||||
}
|
||||
|
||||
public State getState()
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
public long getFrequency()
|
||||
{
|
||||
return mFrequency;
|
||||
}
|
||||
|
||||
public enum Event
|
||||
{
|
||||
ALWAYS_UNSQUELCH,
|
||||
CHANGE_CALL_TIMEOUT,
|
||||
CONTINUATION,
|
||||
DECODE,
|
||||
END,
|
||||
RESET,
|
||||
SOURCE_FREQUENCY,
|
||||
START,
|
||||
TRAFFIC_CHANNEL_ALLOCATION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.dsheirer.channel.state;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
public interface IDecoderStateEventListener
|
||||
{
|
||||
public Listener<DecoderStateEvent> getDecoderStateListener();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.dsheirer.channel.state;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
public interface IDecoderStateEventProvider
|
||||
{
|
||||
public void setDecoderStateListener( Listener<DecoderStateEvent> listener );
|
||||
public void removeDecoderStateListener();
|
||||
}
|
||||
116
src/main/java/io/github/dsheirer/channel/state/State.java
Normal file
116
src/main/java/io/github/dsheirer/channel/state/State.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014-2016 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.state;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* Details the set of states for a channel and the allowable transition states
|
||||
*/
|
||||
public enum State
|
||||
{
|
||||
IDLE("IDLE")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state != TEARDOWN && state != RESET && state != OVERFLOW;
|
||||
}
|
||||
},
|
||||
CALL("CALL")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == CONTROL || state == DATA || state == ENCRYPTED || state == FADE || state == TEARDOWN;
|
||||
}
|
||||
},
|
||||
DATA("DATA")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == CALL || state == CONTROL || state == ENCRYPTED || state == FADE || state == TEARDOWN;
|
||||
}
|
||||
},
|
||||
ENCRYPTED("ENCRYPTED")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == FADE || state == TEARDOWN;
|
||||
}
|
||||
},
|
||||
CONTROL("CONTROL")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == IDLE || state == FADE;
|
||||
}
|
||||
},
|
||||
FADE("FADE")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state != FADE && state != RESET && state != OVERFLOW;
|
||||
}
|
||||
},
|
||||
OVERFLOW("OVERFLOW")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
},
|
||||
RESET("RESET")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == IDLE;
|
||||
}
|
||||
},
|
||||
TEARDOWN("TEARDOWN")
|
||||
{
|
||||
@Override
|
||||
public boolean canChangeTo(State state)
|
||||
{
|
||||
return state == RESET;
|
||||
}
|
||||
};
|
||||
|
||||
private String mDisplayValue;
|
||||
|
||||
public static final EnumSet<State> CALL_STATES = EnumSet.of(CALL, CONTROL, DATA, ENCRYPTED);
|
||||
public static final EnumSet<State> IDLE_STATES = EnumSet.of(IDLE, FADE);
|
||||
|
||||
private State(String displayValue)
|
||||
{
|
||||
mDisplayValue = displayValue;
|
||||
}
|
||||
|
||||
public abstract boolean canChangeTo(State state);
|
||||
|
||||
public String getDisplayValue()
|
||||
{
|
||||
return mDisplayValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
/*******************************************************************************
|
||||
* 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.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.ICallEventProvider;
|
||||
import io.github.dsheirer.module.log.config.EventLogConfiguration;
|
||||
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.TunerChannel;
|
||||
import io.github.dsheirer.source.tuner.TunerChannel.Type;
|
||||
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;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
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 EventLogConfiguration mEventLogConfiguration;
|
||||
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 eventLogConfiguration - logging configuration to use for traffic channels
|
||||
* @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,
|
||||
EventLogConfiguration eventLogConfiguration,
|
||||
RecordConfiguration recordConfiguration,
|
||||
String system,
|
||||
String site,
|
||||
String aliasListName,
|
||||
int trafficChannelPoolSize)
|
||||
{
|
||||
mChannelModel = channelModel;
|
||||
mDecodeConfiguration = decodeConfiguration;
|
||||
mEventLogConfiguration = eventLogConfiguration;
|
||||
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.getEnabled())
|
||||
{
|
||||
channel = configuredChannel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(channel == null && mTrafficChannelPool.size() < mTrafficChannelPoolMaximumSize)
|
||||
{
|
||||
channel = new Channel("Traffic", ChannelType.TRAFFIC);
|
||||
|
||||
channel.setDecodeConfiguration(mDecodeConfiguration);
|
||||
|
||||
channel.setEventLogConfiguration(mEventLogConfiguration);
|
||||
|
||||
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(Type.TRAFFIC,
|
||||
frequency, mDecodeConfiguration.getDecoderType().getChannelBandwidth()));
|
||||
|
||||
if(channel != null)
|
||||
{
|
||||
TrafficChannelEvent trafficChannelEvent =
|
||||
new TrafficChannelEvent(this, channel, Event.REQUEST_ENABLE, callEvent);
|
||||
|
||||
//Request to enable the channel
|
||||
mChannelModel.broadcast(trafficChannelEvent);
|
||||
|
||||
if(channel.getEnabled())
|
||||
{
|
||||
mTrafficChannelsInUse.put(callEvent.getChannel(), channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
callEvent.setCallEventType(CallEvent.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(CallEvent.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(CallEvent.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(ScheduledExecutorService executor)
|
||||
{
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user