mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-17 11:07:35 -05:00
#2680 Alias List optionally auto-adds/upates radio ID to talker alias value. Enable the feature in the playlist editor in the channel config for protocols that produce talker alias (P25, NXDN, DMR). (#2682)
Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
455
src/main/java/io/github/dsheirer/alias/TalkerAliasAutoAdder.java
Normal file
455
src/main/java/io/github/dsheirer/alias/TalkerAliasAutoAdder.java
Normal file
@@ -0,0 +1,455 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 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.alias;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.github.dsheirer.alias.id.AliasID;
|
||||
import io.github.dsheirer.alias.id.radio.NXDNTypeDRadio;
|
||||
import io.github.dsheirer.alias.id.radio.P25FullyQualifiedRadio;
|
||||
import io.github.dsheirer.alias.id.radio.Radio;
|
||||
import io.github.dsheirer.identifier.alias.TalkerAliasIdentifier;
|
||||
import io.github.dsheirer.identifier.radio.FullyQualifiedRadioIdentifier;
|
||||
import io.github.dsheirer.identifier.radio.RadioIdentifier;
|
||||
import io.github.dsheirer.module.decode.nxdn.identifier.NXDNRadioIdentifier;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import javafx.application.Platform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Automatically adds decoded talker aliases to an alias list as radio aliases, using the talker alias as the alias name,
|
||||
* and renames a stored radio alias when the radio's talker alias changes.
|
||||
*
|
||||
* Talker aliases span up to 4 messages, so a decoded talker alias can be a fragment (the leading characters) of the
|
||||
* full alias, even when the decoder reports it as complete. To avoid replacing a full alias with a fragment:
|
||||
* <ul>
|
||||
* <li>A decoded alias that is the start of the stored alias name is a fragment and never replaces it.</li>
|
||||
* <li>A decoded alias that starts with the stored alias name is a longer version of a stored fragment and
|
||||
* replaces it.</li>
|
||||
* <li>Any other decoded alias that differs from the stored alias name replaces it only after it is decoded
|
||||
* {@link #CONFIRMATIONS_REQUIRED} times in a row for the radio.</li>
|
||||
* </ul>
|
||||
*
|
||||
* Only aliases whose only identifier is the radio are created or renamed. An alias that combines the radio with other
|
||||
* identifiers (e.g. several radios or talkgroups) is left alone.
|
||||
*
|
||||
* This class is thread safe. Talker aliases are received on decoder threads and the alias model is updated on the
|
||||
* JavaFX application thread.
|
||||
*/
|
||||
public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAliasIdentifier>
|
||||
{
|
||||
private static final Logger mLog = LoggerFactory.getLogger(TalkerAliasAutoAdder.class);
|
||||
|
||||
/**
|
||||
* Group assigned to aliases created from talker aliases.
|
||||
*/
|
||||
public static final String ALIAS_GROUP = "Talker Alias";
|
||||
|
||||
/**
|
||||
* Number of consecutive times a different talker alias must be decoded for a radio before it replaces the stored
|
||||
* alias name.
|
||||
*/
|
||||
public static final int CONFIRMATIONS_REQUIRED = 2;
|
||||
|
||||
/**
|
||||
* Interval for re-checking the stored alias for a talker alias that was already checked, so that a renamed or
|
||||
* deleted alias is restored without checking the alias list for every decoded talker alias.
|
||||
*/
|
||||
private static final long RECHECK_INTERVAL_MS = 30_000;
|
||||
|
||||
/**
|
||||
* Outcome of comparing a decoded talker alias with the stored alias name.
|
||||
*/
|
||||
public enum Decision
|
||||
{
|
||||
/**
|
||||
* The stored alias name matches the talker alias.
|
||||
*/
|
||||
UNCHANGED,
|
||||
/**
|
||||
* The talker alias is a fragment of the stored alias name.
|
||||
*/
|
||||
FRAGMENT,
|
||||
/**
|
||||
* The talker alias differs from the stored alias name and is waiting for more decodes.
|
||||
*/
|
||||
AWAIT_CONFIRMATION,
|
||||
/**
|
||||
* The talker alias replaces the stored alias name.
|
||||
*/
|
||||
UPDATE
|
||||
}
|
||||
|
||||
private final AliasModel mAliasModel;
|
||||
private final String mAliasListName;
|
||||
//Guarded by this
|
||||
private final Map<String,Candidate> mCandidates = new HashMap<>();
|
||||
private final Map<String,Checked> mChecked = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param aliasModel to add aliases to
|
||||
* @param aliasListName of the alias list to add aliases to
|
||||
*/
|
||||
public TalkerAliasAutoAdder(AliasModel aliasModel, String aliasListName)
|
||||
{
|
||||
mAliasModel = aliasModel;
|
||||
mAliasListName = aliasListName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the alias list that talker aliases are added to.
|
||||
*/
|
||||
public String getAliasListName()
|
||||
{
|
||||
return mAliasListName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a talker alias that is assigned to a radio.
|
||||
* @param radio that the talker alias belongs to
|
||||
* @param talkerAlias for the radio
|
||||
*/
|
||||
@Override
|
||||
public void accept(RadioIdentifier radio, TalkerAliasIdentifier talkerAlias)
|
||||
{
|
||||
if(radio == null || talkerAlias == null || mAliasListName == null || mAliasListName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String value = normalize(talkerAlias.getValue());
|
||||
Radio aliasId = createAliasId(radio);
|
||||
|
||||
if(value == null || aliasId == null || !aliasId.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String key = getKey(aliasId);
|
||||
long now = System.currentTimeMillis();
|
||||
int confirmations;
|
||||
|
||||
synchronized(this)
|
||||
{
|
||||
Checked checked = mChecked.get(key);
|
||||
|
||||
if(checked != null && checked.value().equals(value) && (now - checked.timestamp()) < RECHECK_INTERVAL_MS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
confirmations = confirm(key, value);
|
||||
}
|
||||
|
||||
runOnFxThread(() -> apply(radio, aliasId, key, value, confirmations));
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the consecutive decodes of the talker alias for the radio. A fragment of the talker alias that is
|
||||
* waiting for confirmation doesn't interrupt the count, because fragments are decoded while the full alias is
|
||||
* assembled.
|
||||
* @return number of consecutive decodes of the value, including this one.
|
||||
*/
|
||||
private int confirm(String key, String value)
|
||||
{
|
||||
Candidate candidate = mCandidates.get(key);
|
||||
|
||||
if(candidate != null && candidate.value().equals(value))
|
||||
{
|
||||
candidate = new Candidate(value, candidate.count() + 1);
|
||||
mCandidates.put(key, candidate);
|
||||
return candidate.count();
|
||||
}
|
||||
|
||||
if(candidate != null && isFragment(value, candidate.value()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
mCandidates.put(key, new Candidate(value, 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or updates the alias for the radio. Runs on the JavaFX application thread.
|
||||
*/
|
||||
private synchronized void apply(RadioIdentifier radio, Radio aliasId, String key, String value, int confirmations)
|
||||
{
|
||||
AliasList aliasList = mAliasModel.getAliasList(mAliasListName);
|
||||
Alias existing = findExactMatch(aliasList.getAliases(radio), aliasId);
|
||||
|
||||
if(existing == null)
|
||||
{
|
||||
Alias alias = new Alias(value);
|
||||
alias.setAliasListName(mAliasListName);
|
||||
alias.setGroup(ALIAS_GROUP);
|
||||
alias.addAliasID(aliasId);
|
||||
mAliasModel.addAlias(alias);
|
||||
markChecked(key, value);
|
||||
mLog.info("Talker alias [" + value + "] added for radio [" + aliasId + "] to alias list [" +
|
||||
mAliasListName + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
if(getIdentityCount(existing) > 1)
|
||||
{
|
||||
//The alias also identifies other radios or talkgroups - leave it alone.
|
||||
markChecked(key, value);
|
||||
return;
|
||||
}
|
||||
|
||||
String stored = normalize(existing.getName());
|
||||
|
||||
switch(decide(stored, value, confirmations))
|
||||
{
|
||||
case UPDATE:
|
||||
existing.setName(value);
|
||||
markChecked(key, value);
|
||||
mLog.info("Talker alias for radio [" + aliasId + "] in alias list [" + mAliasListName +
|
||||
"] changed from [" + stored + "] to [" + value + "]");
|
||||
break;
|
||||
case UNCHANGED:
|
||||
case FRAGMENT:
|
||||
markChecked(key, value);
|
||||
break;
|
||||
case AWAIT_CONFIRMATION:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void markChecked(String key, String value)
|
||||
{
|
||||
mChecked.put(key, new Checked(value, System.currentTimeMillis()));
|
||||
mCandidates.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the decoded talker alias with the stored alias name.
|
||||
* @param stored alias name, normalized, or null
|
||||
* @param decoded talker alias, normalized
|
||||
* @param confirmations number of consecutive decodes of the talker alias
|
||||
* @return decision
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static Decision decide(String stored, String decoded, int confirmations)
|
||||
{
|
||||
if(stored == null || stored.isEmpty())
|
||||
{
|
||||
return Decision.UPDATE;
|
||||
}
|
||||
|
||||
if(stored.equals(decoded))
|
||||
{
|
||||
return Decision.UNCHANGED;
|
||||
}
|
||||
|
||||
if(isFragment(decoded, stored))
|
||||
{
|
||||
return Decision.FRAGMENT;
|
||||
}
|
||||
|
||||
//A longer version of a stored fragment.
|
||||
if(isFragment(stored, decoded) && !hasUndecodableCharacters(decoded))
|
||||
{
|
||||
return Decision.UPDATE;
|
||||
}
|
||||
|
||||
//A different alias that may be a corrupted or mis-assembled alias. It's replaced only once confirmed, and an
|
||||
//alias that has undecodable characters (e.g. a partial multi-byte character) never replaces a stored alias.
|
||||
if(confirmations >= CONFIRMATIONS_REQUIRED && !hasUndecodableCharacters(decoded))
|
||||
{
|
||||
return Decision.UPDATE;
|
||||
}
|
||||
|
||||
return Decision.AWAIT_CONFIRMATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the value is a fragment (the leading characters) of the full value.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static boolean isFragment(String value, String full)
|
||||
{
|
||||
return value != null && full != null && value.length() < full.length() && full.startsWith(value);
|
||||
}
|
||||
|
||||
private static boolean hasUndecodableCharacters(String value)
|
||||
{
|
||||
return value.indexOf('<27>') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes padding, control characters and trailing undecodable characters (e.g. from a partial multi-byte
|
||||
* character at the end of an alias fragment) from the talker alias.
|
||||
* @param value to normalize
|
||||
* @return normalized value or null if the value is empty.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static String normalize(String value)
|
||||
{
|
||||
if(value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(value.length());
|
||||
|
||||
for(int i = 0; i < value.length(); i++)
|
||||
{
|
||||
char c = value.charAt(i);
|
||||
|
||||
if(!Character.isISOControl(c))
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
int end = sb.length();
|
||||
|
||||
while(end > 0 && (sb.charAt(end - 1) == '<27>' || Character.isWhitespace(sb.charAt(end - 1))))
|
||||
{
|
||||
end--;
|
||||
}
|
||||
|
||||
String normalized = sb.substring(0, end).trim();
|
||||
return normalized.isEmpty() ? null : normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a radio alias identifier that exactly matches the radio.
|
||||
* @param radio identifier
|
||||
* @return alias identifier or null if the radio protocol isn't known.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static Radio createAliasId(RadioIdentifier radio)
|
||||
{
|
||||
if(radio instanceof FullyQualifiedRadioIdentifier fqri && fqri.getProtocol() == Protocol.APCO25)
|
||||
{
|
||||
return new P25FullyQualifiedRadio(fqri.getWacn(), fqri.getSystem(), fqri.getRadio());
|
||||
}
|
||||
|
||||
if(radio instanceof NXDNRadioIdentifier nxdn && nxdn.isTypeD())
|
||||
{
|
||||
return new NXDNTypeDRadio(nxdn.getTypeDHomeRepeater(), nxdn.getTypeDRadio());
|
||||
}
|
||||
|
||||
Protocol protocol = radio.getProtocol();
|
||||
|
||||
if(protocol == null || protocol == Protocol.UNKNOWN || radio.getValue() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Radio(protocol, radio.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the alias that has an identifier that exactly matches the radio (i.e. not a radio range).
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static Alias findExactMatch(List<Alias> aliases, Radio aliasId)
|
||||
{
|
||||
if(aliases != null)
|
||||
{
|
||||
for(Alias alias: aliases)
|
||||
{
|
||||
for(AliasID id: alias.getAliasIdentifiers())
|
||||
{
|
||||
if(isExactMatch(id, aliasId))
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isExactMatch(AliasID id, Radio aliasId)
|
||||
{
|
||||
if(aliasId instanceof P25FullyQualifiedRadio target)
|
||||
{
|
||||
return id instanceof P25FullyQualifiedRadio fqr && fqr.getHashKey().equals(target.getHashKey());
|
||||
}
|
||||
|
||||
return id instanceof Radio radio && !(id instanceof P25FullyQualifiedRadio) &&
|
||||
radio.getProtocol() == aliasId.getProtocol() && radio.getValue() == aliasId.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of identifiers (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
||||
* streaming.
|
||||
*/
|
||||
private static int getIdentityCount(Alias alias)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for(AliasID id: alias.getAliasIdentifiers())
|
||||
{
|
||||
if(!id.isAudioIdentifier())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private static String getKey(Radio aliasId)
|
||||
{
|
||||
if(aliasId instanceof P25FullyQualifiedRadio fqr)
|
||||
{
|
||||
return aliasId.getProtocol() + ":" + fqr.getHashKey();
|
||||
}
|
||||
|
||||
return aliasId.getProtocol() + ":" + aliasId.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs on the FX thread, or on this thread when the FX toolkit isn't running (headless).
|
||||
*/
|
||||
private static void runOnFxThread(Runnable runnable)
|
||||
{
|
||||
if(Platform.isFxApplicationThread())
|
||||
{
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Platform.runLater(runnable);
|
||||
}
|
||||
catch(IllegalStateException ise)
|
||||
{
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
private record Candidate(String value, int count) {}
|
||||
private record Checked(String value, long timestamp) {}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package io.github.dsheirer.controller.channel;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
@@ -83,6 +84,8 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
||||
|
||||
private BooleanProperty mProcessing = new SimpleBooleanProperty();
|
||||
private BooleanProperty mAutoStart = new SimpleBooleanProperty();
|
||||
//Enabled for new channels. Channels loaded from a playlist without the setting keep it disabled, see fromXml().
|
||||
private BooleanProperty mAutoAddTalkerAliases = new SimpleBooleanProperty(true);
|
||||
private IntegerProperty mAutoStartOrder = new SimpleIntegerProperty();
|
||||
private boolean mSelected;
|
||||
private List<TunerChannel> mTunerChannels = null;
|
||||
@@ -123,6 +126,19 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
||||
mChannelID = UNIQUE_ID++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a channel for deserialization from a playlist. Settings added after a channel was saved take their
|
||||
* legacy (disabled) value when the playlist doesn't specify them, instead of the default for new channels, so that
|
||||
* existing channels don't change behavior.
|
||||
*/
|
||||
@JsonCreator
|
||||
private static Channel fromXml()
|
||||
{
|
||||
Channel channel = new Channel();
|
||||
channel.setAutoAddTalkerAliases(false);
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a (new) deep copy of this channel
|
||||
*/
|
||||
@@ -134,6 +150,7 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
||||
channel.setAliasListName(mAliasListName.get());
|
||||
channel.setAutoStart(mAutoStart.get());
|
||||
channel.setAutoStartOrder(mAutoStartOrder.get());
|
||||
channel.setAutoAddTalkerAliases(mAutoAddTalkerAliases.get());
|
||||
|
||||
AuxDecodeConfiguration auxCopy = new AuxDecodeConfiguration();
|
||||
|
||||
@@ -509,6 +526,36 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
||||
mAutoStart.set(autoStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-add talker aliases property
|
||||
*/
|
||||
public BooleanProperty autoAddTalkerAliasesProperty()
|
||||
{
|
||||
return mAutoAddTalkerAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if decoded talker aliases are automatically added to the channel's alias list as radio aliases, using
|
||||
* the talker alias as the alias name.
|
||||
*
|
||||
* @return true if talker aliases are automatically added to the alias list
|
||||
*/
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "auto_add_talker_aliases")
|
||||
public boolean isAutoAddTalkerAliases()
|
||||
{
|
||||
return mAutoAddTalkerAliases.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets automatically adding decoded talker aliases to the channel's alias list.
|
||||
*
|
||||
* @param autoAdd true to automatically add talker aliases to the alias list
|
||||
*/
|
||||
public void setAutoAddTalkerAliases(boolean autoAdd)
|
||||
{
|
||||
mAutoAddTalkerAliases.set(autoAdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-start order. Specifies an optional ordering for channels so that when the application starts up,
|
||||
* the channels can be started in a user-specified order.
|
||||
|
||||
@@ -96,6 +96,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
private TextField mNameField;
|
||||
private ComboBox<String> mAliasListComboBox;
|
||||
private Button mNewAliasListButton;
|
||||
private CheckBox mAutoAddTalkerAliasesCheckBox;
|
||||
private GridPane mTextFieldPane;
|
||||
private Button mSaveButton;
|
||||
private Button mResetButton;
|
||||
@@ -187,6 +188,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
getNameField().setDisable(disable);
|
||||
getAliasListComboBox().setDisable(disable);
|
||||
getNewAliasListButton().setDisable(disable);
|
||||
getAutoAddTalkerAliasesCheckBox().setDisable(disable);
|
||||
getAutoStartSwitch().setDisable(disable);
|
||||
|
||||
if(channel != null)
|
||||
@@ -210,6 +212,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
getAliasListComboBox().getSelectionModel().select(null);
|
||||
}
|
||||
|
||||
getAutoAddTalkerAliasesCheckBox().setSelected(channel.isAutoAddTalkerAliases());
|
||||
getAutoStartSwitch().selectedProperty().set(channel.isAutoStart());
|
||||
getAutoStartOrderSpinner().setDisable(!channel.isAutoStart());
|
||||
Integer order = channel.getAutoStartOrder();
|
||||
@@ -251,6 +254,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
getSiteField().setText(null);
|
||||
getNameField().setText(null);
|
||||
getAliasListComboBox().getSelectionModel().select(null);
|
||||
getAutoAddTalkerAliasesCheckBox().setSelected(false);
|
||||
getAutoStartSwitch().selectedProperty().set(false);
|
||||
getAutoStartOrderSpinner().setDisable(true);
|
||||
getAutoStartOrderSpinner().getValueFactory().setValue(0);
|
||||
@@ -277,6 +281,12 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
getItem().setName(" ");
|
||||
getItem().setName(getNameField().getText());
|
||||
getItem().setAliasListName(getAliasListComboBox().getSelectionModel().getSelectedItem());
|
||||
|
||||
if(providesTalkerAlias())
|
||||
{
|
||||
getItem().setAutoAddTalkerAliases(getAutoAddTalkerAliasesCheckBox().isSelected());
|
||||
}
|
||||
|
||||
getItem().setAutoStart(getAutoStartSwitch().isSelected());
|
||||
|
||||
Integer order = getAutoStartOrderSpinner().getValue();
|
||||
@@ -598,6 +608,12 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
|
||||
GridPane.setConstraints(getNewAliasListButton(), 4, row);
|
||||
mTextFieldPane.getChildren().add(getNewAliasListButton());
|
||||
|
||||
if(providesTalkerAlias())
|
||||
{
|
||||
GridPane.setConstraints(getAutoAddTalkerAliasesCheckBox(), 3, ++row, 2, 1);
|
||||
mTextFieldPane.getChildren().add(getAutoAddTalkerAliasesCheckBox());
|
||||
}
|
||||
}
|
||||
|
||||
return mTextFieldPane;
|
||||
@@ -660,6 +676,32 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
return mAliasListComboBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the decoder for this editor produces talker aliases.
|
||||
*/
|
||||
private boolean providesTalkerAlias()
|
||||
{
|
||||
return getDecoderType() != null && getDecoderType().providesTalkerAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check box to automatically add decoded talker aliases to the selected alias list.
|
||||
*/
|
||||
private CheckBox getAutoAddTalkerAliasesCheckBox()
|
||||
{
|
||||
if(mAutoAddTalkerAliasesCheckBox == null)
|
||||
{
|
||||
mAutoAddTalkerAliasesCheckBox = new CheckBox("Auto-Add Talker Aliases");
|
||||
mAutoAddTalkerAliasesCheckBox.setDisable(true);
|
||||
mAutoAddTalkerAliasesCheckBox.setTooltip(new Tooltip("Adds a radio alias for each talker alias decoded " +
|
||||
"on this system, named with the talker alias, and renames the radio alias when its talker alias " +
|
||||
"changes. Applies when the channel is (re)started."));
|
||||
mAutoAddTalkerAliasesCheckBox.setOnAction(event -> modifiedProperty().set(true));
|
||||
}
|
||||
|
||||
return mAutoAddTalkerAliasesCheckBox;
|
||||
}
|
||||
|
||||
private Button getNewAliasListButton()
|
||||
{
|
||||
if(mNewAliasListButton == null)
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Talker alias cache manager. Collects observed talker aliases and inserts them into an identifier collection when
|
||||
@@ -41,6 +42,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class TalkerAliasManager
|
||||
{
|
||||
private Map<Integer,TalkerAliasIdentifier> mAliasMap = new ConcurrentHashMap<>();
|
||||
private volatile BiConsumer<RadioIdentifier,TalkerAliasIdentifier> mTalkerAliasListener;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -49,6 +51,16 @@ public class TalkerAliasManager
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an optional listener to receive each talker alias that is assigned to a radio, e.g. to automatically add
|
||||
* talker aliases to an alias list. The listener is invoked on the calling decoder thread.
|
||||
* @param listener to receive radio and talker alias updates, or null to clear the listener.
|
||||
*/
|
||||
public void setTalkerAliasListener(BiConsumer<RadioIdentifier,TalkerAliasIdentifier> listener)
|
||||
{
|
||||
mTalkerAliasListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the alias for the radio identifier
|
||||
*
|
||||
@@ -60,6 +72,13 @@ public class TalkerAliasManager
|
||||
if(identifier.getRole() == Role.FROM)
|
||||
{
|
||||
mAliasMap.put(identifier.getValue(), alias);
|
||||
|
||||
BiConsumer<RadioIdentifier,TalkerAliasIdentifier> listener = mTalkerAliasListener;
|
||||
|
||||
if(listener != null && alias != null)
|
||||
{
|
||||
listener.accept(identifier, alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package io.github.dsheirer.module.decode;
|
||||
|
||||
import io.github.dsheirer.alias.AliasList;
|
||||
import io.github.dsheirer.alias.AliasModel;
|
||||
import io.github.dsheirer.alias.TalkerAliasAutoAdder;
|
||||
import io.github.dsheirer.alias.action.AliasActionManager;
|
||||
import io.github.dsheirer.audio.*;
|
||||
import io.github.dsheirer.audio.codec.mbe.JmbeAudioModule;
|
||||
@@ -210,9 +211,37 @@ public class DecoderFactory
|
||||
throw new IllegalArgumentException("Unknown decoder type [" + decodeConfig.getDecoderType().toString() + "]");
|
||||
}
|
||||
|
||||
configureTalkerAliasAutoAdd(channel, modules, aliasModel);
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the traffic channel manager of a standard (control) channel to automatically add talker aliases to
|
||||
* the channel's alias list, when the channel is configured for it. Traffic channels share the talker alias manager
|
||||
* of their control channel, so they use the control channel's setting.
|
||||
* @param channel configuration
|
||||
* @param modules for the channel
|
||||
* @param aliasModel to add aliases to
|
||||
*/
|
||||
private static void configureTalkerAliasAutoAdd(Channel channel, List<Module> modules, AliasModel aliasModel)
|
||||
{
|
||||
if(channel.isStandardChannel() && channel.isAutoAddTalkerAliases() &&
|
||||
channel.getDecodeConfiguration().getDecoderType().providesTalkerAlias() &&
|
||||
channel.getAliasListName() != null && !channel.getAliasListName().isEmpty())
|
||||
{
|
||||
TalkerAliasAutoAdder autoAdder = new TalkerAliasAutoAdder(aliasModel, channel.getAliasListName());
|
||||
|
||||
for(Module module: modules)
|
||||
{
|
||||
if(module instanceof TrafficChannelManager tcm && tcm.getTalkerAliasManager() != null)
|
||||
{
|
||||
tcm.getTalkerAliasManager().setTalkerAliasListener(autoAdder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates decoder modules for APCO-25 Phase 2 decoder
|
||||
* @param channel configuration
|
||||
|
||||
@@ -78,6 +78,11 @@ public enum DecoderType
|
||||
*/
|
||||
public static final EnumSet<DecoderType> MBE_AUDIO_CODEC_DECODERS = EnumSet.of(DMR, NXDN, P25_PHASE1, P25_PHASE2);
|
||||
|
||||
/**
|
||||
* Decoders that produce talker aliases
|
||||
*/
|
||||
public static final EnumSet<DecoderType> TALKER_ALIAS_DECODERS = EnumSet.of(DMR, NXDN, P25_PHASE1, P25_PHASE2);
|
||||
|
||||
public Protocol getProtocol()
|
||||
{
|
||||
return mProtocol;
|
||||
@@ -114,4 +119,12 @@ public enum DecoderType
|
||||
{
|
||||
return MBE_AUDIO_CODEC_DECODERS.contains(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the decoder type produces talker aliases
|
||||
*/
|
||||
public boolean providesTalkerAlias()
|
||||
{
|
||||
return TALKER_ALIAS_DECODERS.contains(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ public class DMRTrafficChannelManager extends TrafficChannelManager implements I
|
||||
/**
|
||||
* Talker alias manager
|
||||
*/
|
||||
@Override
|
||||
public TalkerAliasManager getTalkerAliasManager()
|
||||
{
|
||||
return mTalkerAliasManager;
|
||||
|
||||
@@ -148,6 +148,7 @@ public class NXDNTrafficChannelManager extends TrafficChannelManager implements
|
||||
/**
|
||||
* Talker alias manager
|
||||
*/
|
||||
@Override
|
||||
public TalkerAliasManager getTalkerAliasManager()
|
||||
{
|
||||
return mTalkerAliasManager;
|
||||
|
||||
@@ -165,6 +165,7 @@ public class P25TrafficChannelManager extends TrafficChannelManager implements I
|
||||
* Talker alias manager
|
||||
* @return manager
|
||||
*/
|
||||
@Override
|
||||
public TalkerAliasManager getTalkerAliasManager()
|
||||
{
|
||||
return mTalkerAliasManager;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package io.github.dsheirer.module.decode.traffic;
|
||||
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.identifier.alias.TalkerAliasManager;
|
||||
import io.github.dsheirer.module.Module;
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,15 @@ public abstract class TrafficChannelManager extends Module
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Talker alias manager shared by the control and traffic channels of the system.
|
||||
* @return talker alias manager, or null if the protocol doesn't have talker aliases.
|
||||
*/
|
||||
public TalkerAliasManager getTalkerAliasManager()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current control frequency
|
||||
* @return frequency in hertz
|
||||
|
||||
Reference in New Issue
Block a user