mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-19 03:57:26 -05:00
Compare commits
1 Commits
master
...
2697-talke
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a202a2caf7 |
@@ -52,7 +52,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* Only aliases whose only identifier is the radio are created or renamed. An alias that combines the radio with other
|
* 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.
|
* identifiers (e.g. several radios or talkgroups) is left alone. The exception is a P25 radio's simple and fully
|
||||||
|
* qualified radio identifiers with the same radio ID: the second form decoded is added to the alias for the first
|
||||||
|
* form, including a user alias outside the managed group, instead of creating a second alias for the same radio.
|
||||||
*
|
*
|
||||||
* This class is thread safe. Talker aliases are received on decoder threads and the alias model is updated on the
|
* This class is thread safe. Talker aliases are received on decoder threads and the alias model is updated on the
|
||||||
* JavaFX application thread.
|
* JavaFX application thread.
|
||||||
@@ -200,6 +202,21 @@ public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAl
|
|||||||
AliasList aliasList = mAliasModel.getAliasList(mAliasListName);
|
AliasList aliasList = mAliasModel.getAliasList(mAliasListName);
|
||||||
Alias existing = findExactMatch(aliasList.getAliases(radio), aliasId);
|
Alias existing = findExactMatch(aliasList.getAliases(radio), aliasId);
|
||||||
|
|
||||||
|
if(existing == null)
|
||||||
|
{
|
||||||
|
existing = findCompanion(aliasList.aliases(), radio, aliasId);
|
||||||
|
|
||||||
|
if(existing != null)
|
||||||
|
{
|
||||||
|
//Add the radio to the alias for the same radio's other identifier form, then continue below to
|
||||||
|
//compare the talker alias with the alias name (only managed aliases are renamed).
|
||||||
|
existing.addAliasID(aliasId);
|
||||||
|
aliasList.updateAlias(existing);
|
||||||
|
mLog.info("Talker alias radio [" + aliasId + "] added to existing alias [" + existing.getName() +
|
||||||
|
"] in alias list [" + mAliasListName + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(existing == null)
|
if(existing == null)
|
||||||
{
|
{
|
||||||
Alias alias = new Alias(value);
|
Alias alias = new Alias(value);
|
||||||
@@ -408,22 +425,114 @@ public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of identifiers (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
* Finds the alias for the other identifier form of a P25 radio, so that a radio's simple and fully qualified
|
||||||
* streaming.
|
* identifiers share one alias instead of creating an alias for each. This includes user aliases outside the
|
||||||
|
* managed group, so that either identifier maps to the user's alias. The user alias is never renamed.
|
||||||
|
* <ul>
|
||||||
|
* <li>Fully qualified radio: the alias whose only identifier is the simple radio with the same radio
|
||||||
|
* ID. Only when the fully qualified radio isn't using a different local address (e.g. a roaming radio), since
|
||||||
|
* the radio ID then belongs to the home system and doesn't identify the radio on this system.</li>
|
||||||
|
* <li>Simple radio: the alias whose only identifier is a fully qualified radio with the same radio ID. None
|
||||||
|
* when more than one fully qualified radio alias matches.</li>
|
||||||
|
* </ul>
|
||||||
|
* @param aliases to search
|
||||||
|
* @param radio decoded radio identifier
|
||||||
|
* @param aliasId created from the decoded radio
|
||||||
|
* @return companion alias or null.
|
||||||
*/
|
*/
|
||||||
private static int getIdentityCount(Alias alias)
|
@VisibleForTesting
|
||||||
|
static Alias findCompanion(List<Alias> aliases, RadioIdentifier radio, Radio aliasId)
|
||||||
{
|
{
|
||||||
int count = 0;
|
if(aliases == null || aliasId.getProtocol() != Protocol.APCO25)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean fullyQualified = aliasId instanceof P25FullyQualifiedRadio;
|
||||||
|
|
||||||
|
if(fullyQualified && !(radio instanceof FullyQualifiedRadioIdentifier fqri &&
|
||||||
|
fqri.getValue() != null && fqri.getValue() == fqri.getRadio()))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alias match = null;
|
||||||
|
|
||||||
|
for(Alias alias: aliases)
|
||||||
|
{
|
||||||
|
if(getSoleIdentity(alias) instanceof Radio candidate &&
|
||||||
|
(candidate instanceof P25FullyQualifiedRadio) != fullyQualified &&
|
||||||
|
candidate.getProtocol() == Protocol.APCO25 && candidate.getValue() == aliasId.getValue())
|
||||||
|
{
|
||||||
|
if(match != null)
|
||||||
|
{
|
||||||
|
//Ambiguous - more than one candidate.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
match = alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifier of an alias that has exactly one identifier, excluding audio settings.
|
||||||
|
* @return identifier or null if the alias has none or more than one.
|
||||||
|
*/
|
||||||
|
private static AliasID getSoleIdentity(Alias alias)
|
||||||
|
{
|
||||||
|
AliasID sole = null;
|
||||||
|
|
||||||
for(AliasID id: alias.getAliasIdentifiers())
|
for(AliasID id: alias.getAliasIdentifiers())
|
||||||
{
|
{
|
||||||
if(!id.isAudioIdentifier())
|
if(!id.isAudioIdentifier())
|
||||||
{
|
{
|
||||||
count++;
|
if(sole != null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
sole = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return sole;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of identities (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
||||||
|
* streaming. A P25 radio's simple and fully qualified radio identifiers with the same radio ID count as one
|
||||||
|
* identity.
|
||||||
|
*/
|
||||||
|
private static int getIdentityCount(Alias alias)
|
||||||
|
{
|
||||||
|
List<AliasID> ids = alias.getAliasIdentifiers().stream().filter(id -> !id.isAudioIdentifier()).toList();
|
||||||
|
|
||||||
|
if(ids.size() == 2 && isRadioPair(ids.get(0), ids.get(1)))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the identifiers are the simple and fully qualified forms of the same P25 radio ID.
|
||||||
|
*/
|
||||||
|
private static boolean isRadioPair(AliasID a, AliasID b)
|
||||||
|
{
|
||||||
|
if(a instanceof P25FullyQualifiedRadio)
|
||||||
|
{
|
||||||
|
AliasID swap = a;
|
||||||
|
a = b;
|
||||||
|
b = swap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a instanceof Radio simple && !(a instanceof P25FullyQualifiedRadio) &&
|
||||||
|
b instanceof P25FullyQualifiedRadio fqr && simple.getProtocol() == Protocol.APCO25 &&
|
||||||
|
simple.getValue() == fqr.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getKey(Radio aliasId)
|
private static String getKey(Radio aliasId)
|
||||||
|
|||||||
@@ -255,6 +255,118 @@ public class TalkerAliasAutoAdderTest
|
|||||||
assertNull(alias(RADIO), "local radio with the same value isn't aliased");
|
assertNull(alias(RADIO), "local radio with the same value isn't aliased");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fully qualified form of RADIO, with a local address that matches the radio ID.
|
||||||
|
*/
|
||||||
|
private static final RadioIdentifier QUALIFIED = APCO25FullyQualifiedRadioIdentifier.createFrom(1234, 0xBEE00,
|
||||||
|
0x123, 1234);
|
||||||
|
|
||||||
|
private void assertSingleAliasForBothForms(String name)
|
||||||
|
{
|
||||||
|
assertEquals(1, aliases().size(), "one alias for both radio identifier forms");
|
||||||
|
Alias alias = aliases().get(0);
|
||||||
|
assertEquals(name, alias.getName());
|
||||||
|
assertEquals(2, alias.getAliasIdentifiers().size());
|
||||||
|
AliasList aliasList = mAliasModel.getAliasList(LIST);
|
||||||
|
assertEquals(List.of(alias), aliasList.getAliases(RADIO), "alias list finds the simple radio");
|
||||||
|
assertEquals(List.of(alias), aliasList.getAliases(QUALIFIED), "alias list finds the fully qualified radio");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fullyQualifiedRadioAddedToSimpleRadioAlias()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
assertSingleAliasForBothForms("ENGINE 12");
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertSingleAliasForBothForms("ENGINE 12");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleRadioAddedToFullyQualifiedRadioAlias()
|
||||||
|
{
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertSingleAliasForBothForms("ENGINE 12");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergedAliasIsStillRenamed()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 1");
|
||||||
|
decode(QUALIFIED, "ENGINE 12 OFFICER");
|
||||||
|
assertSingleAliasForBothForms("ENGINE 12 OFFICER");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
assertSingleAliasForBothForms("LADDER 3");
|
||||||
|
decode(QUALIFIED, "RESCUE 5");
|
||||||
|
decode(QUALIFIED, "RESCUE 5");
|
||||||
|
assertSingleAliasForBothForms("RESCUE 5");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roamingRadioIsNotAddedToHomeRadioIdAlias()
|
||||||
|
{
|
||||||
|
RadioIdentifier home = APCO25RadioIdentifier.createFrom(777);
|
||||||
|
decode(home, "LOCAL 777");
|
||||||
|
decode(APCO25FullyQualifiedRadioIdentifier.createFrom(1234, 0xBEE00, 0x123, 777), "ROAMER");
|
||||||
|
assertEquals(2, aliases().size());
|
||||||
|
assertEquals("LOCAL 777", alias(home).getName());
|
||||||
|
assertEquals(1, alias(home).getAliasIdentifiers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleRadioIsNotAddedToAmbiguousFullyQualifiedAliases()
|
||||||
|
{
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
decode(APCO25FullyQualifiedRadioIdentifier.createFrom(1234, 0xBEE01, 0x456, 1234), "OTHER 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(3, aliases().size());
|
||||||
|
assertEquals(1, alias(RADIO).getAliasIdentifiers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Alias userAlias(Radio radio)
|
||||||
|
{
|
||||||
|
Alias alias = new Alias("Custom Name");
|
||||||
|
alias.setAliasListName(LIST);
|
||||||
|
alias.setGroup("Apparatus");
|
||||||
|
alias.addAliasID(radio);
|
||||||
|
mAliasModel.addAlias(alias);
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void userAliasIsGivenFullyQualifiedRadio()
|
||||||
|
{
|
||||||
|
Alias alias = userAlias(new Radio(Protocol.APCO25, 1234));
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
assertSingleAliasForBothForms("Custom Name");
|
||||||
|
assertEquals("Apparatus", alias.getGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void userAliasIsGivenSimpleRadio()
|
||||||
|
{
|
||||||
|
Alias alias = userAlias(new P25FullyQualifiedRadio(0xBEE00, 0x123, 1234));
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertSingleAliasForBothForms("Custom Name");
|
||||||
|
assertEquals("Apparatus", alias.getGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multiIdentifierUserAliasIsNotGivenFullyQualifiedRadio()
|
||||||
|
{
|
||||||
|
Alias alias = userAlias(new Radio(Protocol.APCO25, 1234));
|
||||||
|
alias.addAliasID(new Talkgroup(Protocol.APCO25, 100));
|
||||||
|
mAliasModel.getAliasList(LIST).updateAlias(alias);
|
||||||
|
decode(QUALIFIED, "ENGINE 12");
|
||||||
|
assertEquals(2, aliases().size());
|
||||||
|
assertEquals(2, alias.getAliasIdentifiers().size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decide()
|
public void decide()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user