#2660 Now Playing Update With Talker Column & Column Management (#2661)

* #2660 Now Playing panel with events and messages are all recreated as JavaFX panels

* #2660 Talker alias cleanup across the decoders

* #2660 Talker alias cleanup across the decoders

---------

Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
Denny Sheirer
2026-11-15 07:43:04 -05:00
committed by GitHub
parent c93d099742
commit 5474a5a448
49 changed files with 5030 additions and 3210 deletions

View File

@@ -0,0 +1,232 @@
/*
* *****************************************************************************
* 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.gui.table;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javafx.application.Platform;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests storing, restoring and resetting table column order and visibility.
*/
public class TableColumnMonitorTest
{
private static final String KEY = "test.table";
private Preferences mPreferences;
@BeforeAll
public static void startToolkit() throws Exception
{
//Run without a display
System.setProperty("glass.platform", "Headless");
System.setProperty("prism.order", "sw");
CompletableFuture<Void> started = new CompletableFuture<>();
try
{
Platform.startup(() -> started.complete(null));
}
catch(IllegalStateException e)
{
started.complete(null); //Already started
}
started.get(10, TimeUnit.SECONDS);
}
@BeforeEach
public void createPreferences()
{
mPreferences = Preferences.userRoot().node("sdrtrunk-test/" + UUID.randomUUID());
}
@AfterEach
public void removePreferences() throws BackingStoreException
{
mPreferences.removeNode();
}
/**
* Runs the test on the JavaFX application thread.
*/
private static void onFx(Runnable runnable) throws Exception
{
CompletableFuture<Void> result = new CompletableFuture<>();
Platform.runLater(() -> {
try
{
runnable.run();
result.complete(null);
}
catch(Throwable t)
{
result.completeExceptionally(t);
}
});
result.get(10, TimeUnit.SECONDS);
}
private static TableView<String> createTable(String... ids)
{
TableView<String> tableView = new TableView<>();
for(String id: ids)
{
TableColumn<String,String> column = new TableColumn<>(id.toUpperCase());
column.setId(id);
tableView.getColumns().add(column);
}
return tableView;
}
private static List<String> ids(TableView<String> tableView)
{
return tableView.getColumns().stream().map(TableColumn::getId).toList();
}
private static List<String> visibleIds(TableView<String> tableView)
{
return tableView.getColumns().stream().filter(TableColumn::isVisible).map(TableColumn::getId).toList();
}
private TableColumnMonitor<String> monitor(TableView<String> tableView)
{
return new TableColumnMonitor<>(tableView, KEY, mPreferences, null, null);
}
@Test
public void defaultsWhenNothingIsStored() throws Exception
{
onFx(() -> {
TableView<String> table = createTable("a", "b", "c");
TableColumnMonitor<String> monitor = monitor(table);
assertEquals(List.of("a", "b", "c"), ids(table));
assertEquals(List.of("a", "b", "c"), visibleIds(table));
assertTrue(monitor.isDefault());
});
}
@Test
public void orderAndVisibilityAreRestored() throws Exception
{
onFx(() -> {
TableView<String> table = createTable("a", "b", "c", "d");
TableColumnMonitor<String> monitor = monitor(table);
assertTrue(monitor.move(table.getColumns().get(0), 1));
table.getColumns().get(3).setVisible(false);
assertEquals(List.of("b", "a", "c", "d"), ids(table));
assertFalse(monitor.isDefault());
//A new session
TableView<String> restored = createTable("a", "b", "c", "d");
monitor(restored);
assertEquals(List.of("b", "a", "c", "d"), ids(restored));
assertEquals(List.of("b", "a", "c"), visibleIds(restored));
});
}
@Test
public void resetRestoresDefaultsAndKeepsWidths() throws Exception
{
onFx(() -> {
TableView<String> table = createTable("a", "b", "c");
TableColumnMonitor<String> monitor = monitor(table);
monitor.move(table.getColumns().get(2), -1);
table.getColumns().get(0).setVisible(false);
mPreferences.putDouble(KEY + ".column.width.b", 123.0);
monitor.reset();
assertEquals(List.of("a", "b", "c"), ids(table));
assertEquals(List.of("a", "b", "c"), visibleIds(table));
assertTrue(monitor.isDefault());
assertNull(mPreferences.get(KEY + ".column.order", null));
assertNull(mPreferences.get(KEY + ".column.hidden", null));
TableView<String> restored = createTable("a", "b", "c");
monitor(restored);
assertEquals(List.of("a", "b", "c"), ids(restored));
assertEquals(123.0, restored.getColumns().get(1).getPrefWidth());
});
}
@Test
public void newColumnIsShownAtItsDefaultPosition() throws Exception
{
onFx(() -> {
mPreferences.put(KEY + ".column.order", "c,a,removed");
mPreferences.put(KEY + ".column.hidden", "a");
TableView<String> table = createTable("a", "b", "c");
monitor(table);
assertEquals(List.of("c", "b", "a"), ids(table));
assertEquals(List.of("c", "b"), visibleIds(table));
});
}
@Test
public void columnAddedBetweenStoredColumnsTakesItsDefaultPosition() throws Exception
{
onFx(() -> {
//Stored by a version without the 'talker' column, with the user's order and a hidden column
mPreferences.put(KEY + ".column.order", "status,from,from.alias,to");
mPreferences.put(KEY + ".column.hidden", "to");
TableView<String> table = createTable("status", "from", "talker", "from.alias", "to");
TableColumnMonitor<String> monitor = monitor(table);
assertEquals(List.of("status", "from", "talker", "from.alias", "to"), ids(table));
assertEquals(List.of("status", "from", "talker", "from.alias"), visibleIds(table));
monitor.reset();
assertEquals(List.of("status", "from", "talker", "from.alias", "to"), visibleIds(table));
});
}
@Test
public void lastVisibleColumnCantBeHidden() throws Exception
{
onFx(() -> {
TableView<String> table = createTable("a", "b");
monitor(table);
table.getColumns().get(0).setVisible(false);
table.getColumns().get(1).setVisible(false);
assertEquals(List.of("b"), visibleIds(table));
});
}
@Test
public void columnsNeedUniqueIds() throws Exception
{
onFx(() -> assertThrows(IllegalArgumentException.class, () -> monitor(createTable("a", "a"))));
}
}

View File

@@ -0,0 +1,259 @@
/*
* *****************************************************************************
* 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.identifier.alias;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.identifier.radio.RadioIdentifier;
import io.github.dsheirer.module.decode.p25.identifier.radio.APCO25FullyQualifiedRadioIdentifier;
import io.github.dsheirer.module.decode.p25.identifier.radio.APCO25RadioIdentifier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests assigning talker aliases to the right radio and keeping the shown talker alias matched to the talking radio.
*/
public class TalkerAliasTrackerTest
{
private static final RadioIdentifier RADIO_A = (RadioIdentifier)APCO25RadioIdentifier.createFrom(100);
private static final RadioIdentifier RADIO_B = (RadioIdentifier)APCO25RadioIdentifier.createFrom(200);
private static final TalkerAliasIdentifier ALIAS_A = P25TalkerAliasIdentifier.create("ENGINE 7");
private static final TalkerAliasIdentifier ALIAS_B = P25TalkerAliasIdentifier.create("MEDIC 12");
private MutableIdentifierCollection mIdentifiers;
private TalkerAliasManager mManager;
private TalkerAliasTracker mTracker;
private long mTime = 1_000_000;
@BeforeEach
public void setup()
{
mIdentifiers = new MutableIdentifierCollection();
mManager = new TalkerAliasManager();
mTracker = new TalkerAliasTracker(mIdentifiers, () -> mManager, TalkerAliasTracker.BetweenCalls.PREVIOUS_TALKER);
}
/**
* Call message from the radio: the decoder updates the identifiers and signals call activity
*/
private void talk(RadioIdentifier radio)
{
mIdentifiers.update(radio);
mTracker.callActivity(mTime);
mTime += 100;
}
/**
* Call ends: the decoder signals the end and removes the FROM identifiers
*/
private void endCall()
{
mTracker.callEnded();
mIdentifiers.remove(Role.FROM);
}
private Identifier getShownAlias()
{
return mIdentifiers.getIdentifier(IdentifierClass.USER, Form.TALKER_ALIAS, Role.FROM);
}
private Identifier getStoredAlias(RadioIdentifier radio)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection();
mic.update(radio);
mManager.enrichMutable(mic);
return mic.getIdentifier(IdentifierClass.USER, Form.TALKER_ALIAS, Role.FROM);
}
@Test
public void aliasDuringCallIsShownAndStored()
{
talk(RADIO_A);
assertEquals(TalkerAliasTracker.Assignment.CURRENT_CALL, mTracker.received(ALIAS_A, null, mTime));
assertEquals(ALIAS_A, getShownAlias());
assertEquals(ALIAS_A, getStoredAlias(RADIO_A));
endCall();
assertNull(getShownAlias());
//The talker's next call shows the stored alias right away
talk(RADIO_A);
assertEquals(ALIAS_A, getShownAlias());
}
@Test
public void aliasBeforeTheRadioIsIdentifiedIsStoredForTheRadio()
{
mTracker.callActivity(mTime); //Call starts without identifying the talker (e.g. a P25 Phase 1 HDU)
assertEquals(TalkerAliasTracker.Assignment.CURRENT_CALL, mTracker.received(ALIAS_A, null, mTime));
assertEquals(ALIAS_A, getShownAlias());
talk(RADIO_A);
assertEquals(ALIAS_A, getShownAlias(), "Alias is kept when the talker is identified");
assertEquals(ALIAS_A, getStoredAlias(RADIO_A), "and stored for the talker");
}
@Test
public void aliasBeforeTheRadioInANewCallIsntAssignedToThePreviousTalker()
{
talk(RADIO_A);
endCall();
mTracker.callActivity(mTime); //Next call starts without identifying the talker
mTracker.received(ALIAS_B, null, mTime);
assertNull(getStoredAlias(RADIO_A), "Not stored for the previous call's talker");
talk(RADIO_B);
assertEquals(ALIAS_B, getStoredAlias(RADIO_B));
}
@Test
public void aliasAfterTheCallEndsBelongsToThatCallsTalker()
{
talk(RADIO_A);
endCall();
assertEquals(TalkerAliasTracker.Assignment.ENDED_CALL, mTracker.received(ALIAS_A, null, mTime));
assertEquals(RADIO_A, mTracker.getEndedCallRadio());
assertNull(getShownAlias(), "Not shown with no call in progress");
assertEquals(ALIAS_A, getStoredAlias(RADIO_A));
talk(RADIO_B);
assertNull(getShownAlias(), "Not shown for a different talker");
endCall();
talk(RADIO_A);
assertEquals(ALIAS_A, getShownAlias());
}
@Test
public void callEndedMoreThanOnceKeepsTheTalker()
{
talk(RADIO_A);
endCall();
endCall(); //e.g. repeated TDULC or End PTT messages
assertEquals(TalkerAliasTracker.Assignment.ENDED_CALL, mTracker.received(ALIAS_A, null, mTime));
assertEquals(ALIAS_A, getStoredAlias(RADIO_A));
}
@Test
public void aliasIsRemovedWhenADifferentRadioTalks()
{
talk(RADIO_A);
mTracker.received(ALIAS_A, null, mTime);
talk(RADIO_B); //Talker changes without a call end
assertNull(getShownAlias());
mManager.update(RADIO_B, ALIAS_B);
talk(RADIO_B);
assertEquals(ALIAS_B, getShownAlias());
}
@Test
public void aliasIsKeptWhenTheRadioBecomesFullyQualified()
{
talk(RADIO_A);
mTracker.received(ALIAS_A, null, mTime);
mIdentifiers.update(APCO25FullyQualifiedRadioIdentifier.createFrom(100, 1, 2, 100));
mTracker.callActivity(mTime);
assertEquals(ALIAS_A, getShownAlias());
}
@Test
public void aliasWithItsOwnRadio()
{
//Motorola talker aliases identify their radio
talk(RADIO_A);
assertEquals(TalkerAliasTracker.Assignment.UNASSIGNED, mTracker.received(ALIAS_B, RADIO_B, mTime),
"Alias for a radio that isn't talking");
assertNull(getShownAlias());
assertEquals(ALIAS_B, getStoredAlias(RADIO_B));
assertEquals(TalkerAliasTracker.Assignment.CURRENT_CALL, mTracker.received(ALIAS_A, RADIO_A, mTime));
assertEquals(ALIAS_A, getShownAlias());
endCall();
assertEquals(TalkerAliasTracker.Assignment.ENDED_CALL, mTracker.received(ALIAS_A, RADIO_A, mTime));
assertEquals(TalkerAliasTracker.Assignment.UNASSIGNED, mTracker.received(ALIAS_B, RADIO_B, mTime));
}
@Test
public void aliasWithNoCallOrTalkerIsIgnored()
{
assertEquals(TalkerAliasTracker.Assignment.UNASSIGNED, mTracker.received(ALIAS_A, null, mTime));
assertNull(getShownAlias());
}
@Test
public void worksWithoutATalkerAliasManager()
{
TalkerAliasTracker tracker = new TalkerAliasTracker(mIdentifiers, () -> null,
TalkerAliasTracker.BetweenCalls.PREVIOUS_TALKER);
mIdentifiers.update(RADIO_A);
tracker.callActivity(mTime);
assertEquals(TalkerAliasTracker.Assignment.CURRENT_CALL, tracker.received(ALIAS_A, null, mTime));
assertEquals(ALIAS_A, getShownAlias());
mIdentifiers.update(RADIO_B);
tracker.callActivity(mTime);
assertNull(getShownAlias());
}
@Test
public void nextTalkerAliasBelongsToTheNextCall()
{
//P25 Phase 2 L3Harris: the alias arrives just before the next call's Push-To-Talk
mTracker = new TalkerAliasTracker(mIdentifiers, () -> mManager, TalkerAliasTracker.BetweenCalls.NEXT_TALKER);
talk(RADIO_A);
endCall();
assertEquals(TalkerAliasTracker.Assignment.NEXT_CALL, mTracker.received(ALIAS_B, null, mTime));
assertNull(getStoredAlias(RADIO_A), "Not stored for the previous call's talker");
assertNull(getShownAlias(), "Not shown until the next call starts");
talk(RADIO_B);
assertEquals(ALIAS_B, getShownAlias());
assertEquals(ALIAS_B, getStoredAlias(RADIO_B));
}
@Test
public void nextTalkerAliasBeforeACallWithoutARadio()
{
mTracker = new TalkerAliasTracker(mIdentifiers, () -> mManager, TalkerAliasTracker.BetweenCalls.NEXT_TALKER);
mTracker.received(ALIAS_B, null, mTime);
mTracker.callActivity(mTime + 50); //Voice before the talker is identified
assertEquals(ALIAS_B, getShownAlias());
talk(RADIO_B);
assertEquals(ALIAS_B, getShownAlias());
assertEquals(ALIAS_B, getStoredAlias(RADIO_B));
}
@Test
public void nextTalkerAliasExpires()
{
mTracker = new TalkerAliasTracker(mIdentifiers, () -> mManager, TalkerAliasTracker.BetweenCalls.NEXT_TALKER);
mTracker.received(ALIAS_B, null, mTime);
mTime += TalkerAliasTracker.NEXT_CALL_WINDOW_MS + 1;
talk(RADIO_A);
assertNull(getShownAlias(), "Too long before the call to belong to it");
assertNull(getStoredAlias(RADIO_A));
}
}

View File

@@ -0,0 +1,92 @@
/*
* *****************************************************************************
* 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.module.decode.dmr;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.identifier.alias.DmrTalkerAliasIdentifier;
import io.github.dsheirer.identifier.radio.RadioIdentifier;
import io.github.dsheirer.module.decode.dmr.channel.DMRAbsoluteChannel;
import io.github.dsheirer.module.decode.dmr.identifier.DMRRadio;
import io.github.dsheirer.module.decode.dmr.identifier.DMRTalkgroup;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.Opcode;
import io.github.dsheirer.module.decode.event.IDecodeEvent;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests that DMR channel grant events show the stored talker alias of the radio, learned from its earlier calls.
*/
public class DMRTrafficChannelManagerTalkerAliasTest
{
private static String getAlias(IDecodeEvent event)
{
Identifier alias = event.getIdentifierCollection().getIdentifier(IdentifierClass.USER, Form.TALKER_ALIAS,
Role.FROM);
return alias != null ? alias.getValue().toString() : null;
}
private static MutableIdentifierCollection grant(int radio, int talkgroup)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection();
mic.update(DMRTalkgroup.create(talkgroup));
mic.update(DMRRadio.createFrom(radio));
return mic;
}
@Test
public void channelGrantShowsTheStoredTalkerAlias()
{
DMRTrafficChannelManager manager = new DMRTrafficChannelManager(new Channel("Control"));
List<IDecodeEvent> events = new ArrayList<>();
manager.addDecodeEventListener(event -> {
if(!events.contains(event))
{
events.add(event);
}
});
manager.getTalkerAliasManager().update((RadioIdentifier)DMRRadio.createFrom(100),
DmrTalkerAliasIdentifier.create("ENGINE 7"));
//Radio 100 has a stored alias, radio 200 doesn't
manager.processChannelGrant(new DMRAbsoluteChannel(1, 1, 0, 0), grant(100, 10),
Opcode.STANDARD_TALKGROUP_VOICE_CHANNEL_GRANT, 1000, false);
manager.processChannelGrant(new DMRAbsoluteChannel(2, 1, 0, 0), grant(200, 20),
Opcode.STANDARD_TALKGROUP_VOICE_CHANNEL_GRANT, 1000, false);
assertEquals(2, events.size());
assertEquals("ENGINE 7", getAlias(events.get(0)));
assertNull(getAlias(events.get(1)));
//Repeated grants for the same call update the event instead of starting a new one
manager.processChannelGrant(new DMRAbsoluteChannel(1, 1, 0, 0), grant(100, 10),
Opcode.STANDARD_TALKGROUP_VOICE_CHANNEL_GRANT, 1500, false);
assertEquals(2, events.size());
assertFalse(events.get(0).getDuration() < 0);
}
}

View File

@@ -0,0 +1,292 @@
/*
* *****************************************************************************
* 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.module.decode.p25.phase1;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.module.decode.p25.P25TrafficChannelManager;
import io.github.dsheirer.message.IMessage;
import io.github.dsheirer.module.decode.p25.phase1.message.P25P1Message;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.standard.LCGroupVoiceChannelUser;
import io.github.dsheirer.protocol.Protocol;
import io.github.dsheirer.module.decode.event.IDecodeEvent;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.HarrisTalkerAliasAssembler;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasBase;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasBlock1;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasBlock2;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasBlock3;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasBlock4;
import io.github.dsheirer.module.decode.p25.phase1.message.lc.l3harris.LCHarrisTalkerAliasComplete;
import java.util.ArrayList;
import java.util.List;
import io.github.dsheirer.module.decode.p25.phase1.message.tdu.TDUMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests that P25 Phase 1 talker aliases are assigned to the right radio, including L3Harris talker aliases that
* complete after the call ends, and that the FROM radio and talker alias don't carry over to the next call.
*/
public class P25P1DecoderStateTalkerAliasTest
{
private static final int NAC = 0x293;
private static final int RADIO_A = 1001;
private static final int RADIO_B = 2002;
private static final int TALKGROUP = 100;
private P25P1DecoderState mDecoderState;
private P25TrafficChannelManager mTrafficChannelManager;
private final MutableIdentifierCollection mIdentifiers = new MutableIdentifierCollection();
private final List<IDecodeEvent> mEvents = new ArrayList<>();
private long mTimestamp = 1_700_000_000_000L;
@BeforeEach
public void setup()
{
Channel channel = new Channel("Test");
channel.setDecodeConfiguration(new DecodeConfigP25Phase1());
mTrafficChannelManager = new P25TrafficChannelManager(channel);
mTrafficChannelManager.addDecodeEventListener(event -> {
if(!mEvents.contains(event))
{
mEvents.add(event);
}
});
mDecoderState = new P25P1DecoderState(channel, mTrafficChannelManager);
mDecoderState.setDecoderStateListener(event -> {});
//Mirrors the decoder state identifier collection, the same as the channel metadata and audio modules
mDecoderState.setIdentifierUpdateListener(mIdentifiers);
mDecoderState.start();
}
/**
* Call from the radio: group voice channel user link control messages, as carried in the LDU1s.
*/
private void talk(int radio)
{
//A call carries the channel user link control in each LDU1
for(int x = 0; x < 3; x++)
{
CorrectedBinaryMessage message = new CorrectedBinaryMessage(72);
message.load(32, 16, TALKGROUP); //Group address
message.load(48, 24, radio); //Source address
ChannelUser lcw = new ChannelUser(message, mTimestamp);
lcw.setValid(true);
mDecoderState.receive(lcw);
mTimestamp += 360;
}
}
private void endCall()
{
mDecoderState.receive(new TDUMessage(new CorrectedBinaryMessage(28), NAC, mTimestamp));
mTimestamp += 500;
}
/**
* Completed L3Harris talker alias, reassembled from link control blocks that carry 7 characters each.
*/
private void harrisTalkerAlias(String alias)
{
mDecoderState.receive(assemble(alias, mTimestamp));
mTimestamp += 180;
}
/**
* Creates the L3Harris talker alias blocks for the alias and reassembles them with the assembler.
* @param alias of up to 28 characters
* @param timestamp for the blocks
* @return reassembled talker alias
*/
static LCHarrisTalkerAliasComplete assemble(String alias, long timestamp)
{
HarrisTalkerAliasAssembler assembler = new HarrisTalkerAliasAssembler();
LCHarrisTalkerAliasComplete complete = null;
int blocks = Math.max(2, (alias.length() + 6) / 7);
for(int block = 0; block < blocks; block++)
{
CorrectedBinaryMessage message = new CorrectedBinaryMessage(72);
message.load(2, 6, 50 + block); //L3Harris talker alias block opcode
message.load(8, 8, 164); //L3Harris vendor
for(int x = 0; x < 7 && block * 7 + x < alias.length(); x++)
{
message.load(16 + x * 8, 8, alias.charAt(block * 7 + x));
}
LCHarrisTalkerAliasBase lcw = switch(block)
{
case 0 -> new LCHarrisTalkerAliasBlock1(message);
case 1 -> new LCHarrisTalkerAliasBlock2(message);
case 2 -> new LCHarrisTalkerAliasBlock3(message);
default -> new LCHarrisTalkerAliasBlock4(message);
};
lcw.setValid(true);
LCHarrisTalkerAliasComplete assembled = assembler.process(lcw, timestamp);
if(assembled != null)
{
complete = assembled;
}
}
return complete;
}
private Identifier getFromRadio()
{
return mIdentifiers.getIdentifier(IdentifierClass.USER, Form.RADIO, Role.FROM);
}
private String getTalkerAlias()
{
Identifier alias = mIdentifiers.getIdentifier(IdentifierClass.USER, Form.TALKER_ALIAS, Role.FROM);
return alias != null ? alias.getValue().toString() : null;
}
/**
* Group voice channel user link control as a message, the same way that the decoder state receives the
* reassembled link control messages.
*/
private static class ChannelUser extends LCGroupVoiceChannelUser implements IMessage
{
private final long mMessageTimestamp;
ChannelUser(CorrectedBinaryMessage message, long timestamp)
{
super(message, timestamp, false);
mMessageTimestamp = timestamp;
}
@Override
public long getTimestamp()
{
return mMessageTimestamp;
}
@Override
public Protocol getProtocol()
{
return Protocol.APCO25;
}
@Override
public int getTimeslot()
{
return P25P1Message.TIMESLOT_1;
}
}
@Test
public void harrisAliasAfterCallEndIsStoredForThatCallsTalker()
{
talk(RADIO_A);
assertEquals(RADIO_A, getFromRadio().getValue());
endCall();
assertNull(getFromRadio(), "FROM radio is cleared at the end of the call");
//Alias completes after the call ended
harrisTalkerAlias("ENGINE 7");
assertNull(getTalkerAlias(), "No call in progress, so the alias isn't shown");
//A different talker doesn't get the alias
talk(RADIO_B);
assertEquals(RADIO_B, getFromRadio().getValue());
assertNull(getTalkerAlias());
endCall();
//The talker's next call shows the alias
talk(RADIO_A);
assertEquals("ENGINE 7", getTalkerAlias());
endCall();
assertNull(getTalkerAlias(), "Talker alias is cleared at the end of the call");
}
@Test
public void harrisAliasDuringCallIsShownAndStored()
{
talk(RADIO_A);
harrisTalkerAlias("ENGINE 7");
assertEquals("ENGINE 7", getTalkerAlias());
endCall();
talk(RADIO_A);
assertEquals("ENGINE 7", getTalkerAlias());
}
@Test
public void aliasIsReplacedWhenTheTalkerChangesWithoutACallEnd()
{
talk(RADIO_A);
harrisTalkerAlias("ENGINE 7");
talk(RADIO_B);
assertEquals(RADIO_B, getFromRadio().getValue());
assertNull(getTalkerAlias());
}
private static String getEventTalkerAlias(IDecodeEvent event)
{
Identifier alias = event.getIdentifierCollection().getIdentifier(IdentifierClass.USER, Form.TALKER_ALIAS,
Role.FROM);
return alias != null ? alias.getValue().toString() : null;
}
private static Identifier getEventRadio(IDecodeEvent event)
{
return event.getIdentifierCollection().getIdentifier(IdentifierClass.USER, Form.RADIO, Role.FROM);
}
@Test
public void harrisAliasAfterCallEndIsAddedToTheEndedCallEvent()
{
talk(RADIO_A);
endCall();
talk(RADIO_B);
endCall();
assertEquals(2, mEvents.size());
long duration = mEvents.get(1).getDuration();
//Alias completes after radio B's call ended
harrisTalkerAlias("ENGINE 7");
assertEquals(2, mEvents.size(), "No new event");
assertNull(getEventTalkerAlias(mEvents.get(0)), "Radio A's call event isn't changed");
assertEquals(RADIO_B, getEventRadio(mEvents.get(1)).getValue());
assertEquals("ENGINE 7", getEventTalkerAlias(mEvents.get(1)));
assertEquals(duration, mEvents.get(1).getDuration(), "Event duration isn't changed");
}
@Test
public void spaceAtAFragmentBoundaryIsKept()
{
//Characters 7 and 8 are spaces, at the end of block 1 and the start of block 2
assertEquals("ENGINE 7", assemble("ENGINE 7", 0).getTalkerAlias().getValue());
assertEquals("ENGINE 7", assemble("ENGINE 7", 0).getTalkerAlias().getValue());
assertEquals("BATTALION CHIEF 1", assemble("BATTALION CHIEF 1", 0).getTalkerAlias().getValue());
//Trailing padding is removed
assertEquals("A", assemble("A", 0).getTalkerAlias().getValue());
}
}

View File

@@ -0,0 +1,70 @@
/*
* *****************************************************************************
* 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.module.decode.p25.phase2.message.mac.structure.l3harris;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests decoding P25 Phase 2 L3Harris talker alias MAC structures, using structures captured from a Duke Energy
* Florida recording: opcode A8, vendor A4 (L3Harris), length 0x11 (17 octets), then 14 alias characters padded with
* zero bytes.
*/
public class L3HarrisTalkerAliasTest
{
/**
* Creates the alias structure at bit offset 8 (after the MAC header octet) in a FACCH or SACCH sized message.
*/
private static L3HarrisTalkerAlias create(int messageBits, int... structure)
{
CorrectedBinaryMessage message = new CorrectedBinaryMessage(messageBits);
for(int x = 0; x < structure.length && (x + 2) * 8 <= messageBits; x++)
{
message.load((x + 1) * 8, 8, structure[x]);
}
return new L3HarrisTalkerAlias(message, 8);
}
@Test
public void allFourteenCharactersAreDecoded()
{
//FACCH: FL-DCC-02_StPe
L3HarrisTalkerAlias alias = create(156, 0xA8, 0xA4, 0x11, 0x46, 0x4C, 0x2D, 0x44, 0x43, 0x43, 0x2D, 0x30, 0x32,
0x5F, 0x53, 0x74, 0x50, 0x65, 0xC5);
assertEquals("FL-DCC-02_StPe", alias.getAlias().getValue());
//SACCH: LBVA-17168-SBK
alias = create(180, 0xA8, 0xA4, 0x11, 0x4C, 0x42, 0x56, 0x41, 0x2D, 0x31, 0x37, 0x31, 0x36, 0x38, 0x2D, 0x53,
0x42, 0x4B, 0x00, 0x00, 0x00, 0xA7);
assertEquals("LBVA-17168-SBK", alias.getAlias().getValue());
}
@Test
public void zeroPaddingEndsTheAlias()
{
//A shorter alias padded with zero bytes, followed by unrelated bytes after the structure
L3HarrisTalkerAlias alias = create(156, 0xA8, 0xA4, 0x11, 0x46, 0x4C, 0x2D, 0x44, 0x43, 0x43, 0x2D, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x44);
assertEquals("FL-DCC-0", alias.getAlias().getValue());
}
}