#78 patch group alias and call event management. Adds new PatchGroupAlias which is a temporary alias group that is added to the alias list by the decoder state. The P25 decoder state maintains a mapping of patch group identifier to patched talkgroups and creates the patch group alias. This allows audio recording and audio streaming of patched talkgroups, according to the aliases corresponding to the group of patched aliases contained in the patch group alias.

Event logging is now pared down to only logging events when the internal patch group mapping is updated.
This commit is contained in:
Denny
2017-01-08 07:54:48 -05:00
parent de9c51c228
commit 6bfe98dae6
5 changed files with 3811 additions and 3416 deletions

View File

@@ -0,0 +1,214 @@
/*******************************************************************************
* 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 alias;
import alias.action.AliasAction;
import alias.id.AliasID;
import alias.id.AliasIDType;
import alias.id.broadcast.BroadcastChannel;
import alias.id.priority.Priority;
import alias.id.talkgroup.TalkgroupID;
import java.util.ArrayList;
import java.util.List;
public class PatchGroupAlias extends Alias
{
private List<Alias> mPatchedAliases = new ArrayList<>();
/**
* Patch group alias is a single alias for a group of aliases that are temporarily patched together. This will
* normally be used for patched talkgroups, but could be used with any type of alias identifiers that can be
* temporarily joined to form a patch group.
*
* Alias properties such as recordable, streamable and call priority are an aggregation from the set of patched
* aliases contained in this patch group alias and where applicable, return the highest value/priority from the
* group of patched aliases.
*/
public PatchGroupAlias()
{
}
/**
* List of patched aliases contained in this patch group
*/
public List<Alias> getPatchedAliases()
{
return mPatchedAliases;
}
/**
* Removes/clears all patched aliases from this patch alias group
*/
public void clearPatchedAliases()
{
mPatchedAliases.clear();
}
/**
* Adds the patched alias to this patch alias group
*/
public void addPatchedAlias(Alias alias)
{
mPatchedAliases.add(alias);
}
/**
* Removes the patched alias from this patch alias group
*/
public void removePatchedAlias(Alias alias)
{
mPatchedAliases.remove(alias);
}
@Override
public String getName()
{
if(getId().size() > 0)
{
for(AliasID id: getId())
{
if(id.getType() == AliasIDType.TALKGROUP)
{
return "PATCH:" + ((TalkgroupID)id).getTalkgroup();
}
}
}
return "PATCH";
}
@Override
public List<AliasAction> getAction()
{
List<AliasAction> aliasActions = new ArrayList<>();
for(Alias alias: mPatchedAliases)
{
aliasActions.addAll(alias.getAction());
}
return aliasActions;
}
@Override
public boolean hasActions()
{
for(Alias alias: mPatchedAliases)
{
if(alias.hasActions())
{
return true;
}
}
return false;
}
@Override
public int getCallPriority()
{
int highestPriority = Priority.DEFAULT_PRIORITY;
for(Alias alias: mPatchedAliases)
{
if(alias.getCallPriority() < highestPriority)
{
highestPriority = alias.getCallPriority();
}
}
return highestPriority;
}
@Override
public boolean hasCallPriority()
{
for(Alias alias: mPatchedAliases)
{
if(alias.hasCallPriority())
{
return true;
}
}
return false;
}
@Override
public boolean isRecordable()
{
for(Alias alias: mPatchedAliases)
{
if(alias.isRecordable())
{
return true;
}
}
return false;
}
@Override
public boolean isStreamable()
{
for(Alias alias: mPatchedAliases)
{
if(alias.isStreamable())
{
return true;
}
}
return false;
}
@Override
public List<BroadcastChannel> getBroadcastChannels()
{
List<BroadcastChannel> broadcastChannels = new ArrayList<>();
for(Alias alias: mPatchedAliases)
{
for(BroadcastChannel broadcastChannel: alias.getBroadcastChannels())
{
if(!broadcastChannels.contains(broadcastChannel))
{
broadcastChannels.add(broadcastChannel);
}
}
}
return broadcastChannels;
}
@Override
public boolean hasBroadcastChannel(String channel)
{
for(Alias alias: mPatchedAliases)
{
if(alias.hasBroadcastChannel(channel))
{
return true;
}
}
return false;
}
}

View File

@@ -17,11 +17,11 @@
******************************************************************************/ ******************************************************************************/
package alias.id.talkgroup; package alias.id.talkgroup;
import javax.xml.bind.annotation.XmlAttribute;
import alias.id.AliasID; import alias.id.AliasID;
import alias.id.AliasIDType; import alias.id.AliasIDType;
import javax.xml.bind.annotation.XmlAttribute;
public class TalkgroupID extends AliasID public class TalkgroupID extends AliasID
{ {
@@ -29,6 +29,12 @@ public class TalkgroupID extends AliasID
public TalkgroupID() public TalkgroupID()
{ {
//No arg JAXB constructor
}
public TalkgroupID(String talkgroup)
{
mTalkgroup = talkgroup;
} }
@XmlAttribute @XmlAttribute

View File

@@ -19,6 +19,8 @@ package module.decode.p25;
import alias.Alias; import alias.Alias;
import alias.AliasList; import alias.AliasList;
import alias.PatchGroupAlias;
import alias.id.talkgroup.TalkgroupID;
import audio.metadata.Metadata; import audio.metadata.Metadata;
import audio.metadata.MetadataType; import audio.metadata.MetadataType;
import controller.channel.Channel.ChannelType; import controller.channel.Channel.ChannelType;
@@ -160,6 +162,7 @@ public class P25DecoderState extends DecoderState
private Map<Integer, IdentifierUpdate> mBands = new HashMap<>(); private Map<Integer, IdentifierUpdate> mBands = new HashMap<>();
private Map<String, Long> mRegistrations = new HashMap<>(); private Map<String, Long> mRegistrations = new HashMap<>();
private Map<String, IAdjacentSite> mNeighborMap = new HashMap<>(); private Map<String, IAdjacentSite> mNeighborMap = new HashMap<>();
private Map<String, List<String>> mPatchGroupMap = new HashMap<>();
private String mLastCommandEventID; private String mLastCommandEventID;
private String mLastPageEventID; private String mLastPageEventID;
@@ -2778,32 +2781,34 @@ public class P25DecoderState extends DecoderState
case PATCH_GROUP_ADD: case PATCH_GROUP_ADD:
PatchGroupAdd pga = (PatchGroupAdd) tsbk; PatchGroupAdd pga = (PatchGroupAdd) tsbk;
if(addPatchGroup(pga.getPatchGroupAddress(), pga.getPatchedTalkgroups()))
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("PATCH GROUP:").append(pga.getPatchGroupAddress()); sb.append("PATCH GROUP:").append(pga.getPatchGroupAddress());
sb.append(" 1:").append(pga.getGroupAddress1()); sb.append(" ").append(pga.getPatchedTalkgroups());
sb.append(" 2:").append(pga.getGroupAddress2());
sb.append(" 3:").append(pga.getGroupAddress3());
broadcast(new P25CallEvent.Builder(CallEventType.PATCH_GROUP_ADD) broadcast(new P25CallEvent.Builder(CallEventType.PATCH_GROUP_ADD)
.aliasList(getAliasList()) .aliasList(getAliasList())
.details(sb.toString()) .details(sb.toString())
.build()); .build());
}
break; break;
case PATCH_GROUP_DELETE: case PATCH_GROUP_DELETE:
PatchGroupDelete pgd = (PatchGroupDelete) tsbk; PatchGroupDelete pgd = (PatchGroupDelete) tsbk;
if(removePatchGroup(pgd.getPatchGroupAddress(), pgd.getPatchedTalkgroups()))
{
StringBuilder sbpgd = new StringBuilder(); StringBuilder sbpgd = new StringBuilder();
sbpgd.append("PATCH GROUP:").append(pgd.getPatchGroupAddress()); sbpgd.append("PATCH GROUP:").append(pgd.getPatchGroupAddress());
sbpgd.append(" 1:").append(pgd.getGroupAddress1()); sbpgd.append(" ").append(pgd.getPatchedTalkgroups());
sbpgd.append(" 2:").append(pgd.getGroupAddress2());
sbpgd.append(" 3:").append(pgd.getGroupAddress3());
broadcast(new P25CallEvent.Builder(CallEventType.PATCH_GROUP_DELETE) broadcast(new P25CallEvent.Builder(CallEventType.PATCH_GROUP_DELETE)
.aliasList(getAliasList()) .aliasList(getAliasList())
.details(sbpgd.toString()) .details(sbpgd.toString())
.build()); .build());
}
break; break;
case CCH_PLANNED_SHUTDOWN: case CCH_PLANNED_SHUTDOWN:
if(!mControlChannelShutdownLogged) if(!mControlChannelShutdownLogged)
@@ -2818,6 +2823,145 @@ public class P25DecoderState extends DecoderState
} }
} }
/**
* Creates a new patch group or updates an existing patch group with the patched talkgroup entries.
*
* @param patchGroupID for the patch group
* @param talkgroupsToAdd to include in the patch group
* @return true if the patch group or the patch group map was updated
*/
private boolean addPatchGroup(String patchGroupID, List<String> talkgroupsToAdd)
{
boolean updated = false;
if(patchGroupID != null && !talkgroupsToAdd.isEmpty())
{
List<String> patchedTalkgroups = mPatchGroupMap.get(patchGroupID);
if(patchedTalkgroups == null)
{
patchedTalkgroups = new ArrayList<>();
}
for(String talkgroupToAdd: talkgroupsToAdd)
{
if(!patchedTalkgroups.contains(talkgroupToAdd))
{
patchedTalkgroups.add(talkgroupToAdd);
updated = true;
}
}
if(updated)
{
mPatchGroupMap.put(patchGroupID, patchedTalkgroups);
updatePatchAlias(patchGroupID, patchedTalkgroups);
}
}
return updated;
}
/**
* Removes the patched talkgroups from the patch group and removes the patch group from the patch group map if
* there are no more patched talkgroups in the patch group.
*
* @param patchGroupID for the patch group
* @param talkgroupsToRemove to remove from the patch group
* @return true if the patch group or the patch group map was updated
*/
private boolean removePatchGroup(String patchGroupID, List<String> talkgroupsToRemove)
{
boolean updated = false;
if(patchGroupID != null && !talkgroupsToRemove.isEmpty())
{
List<String> patchedTalkgroups = mPatchGroupMap.get(patchGroupID);
if(patchedTalkgroups != null)
{
for(String talkgroupToRemove: talkgroupsToRemove)
{
if(patchedTalkgroups.contains(talkgroupToRemove))
{
patchedTalkgroups.remove(talkgroupToRemove);
updated = true;
}
}
if(patchedTalkgroups.isEmpty())
{
mPatchGroupMap.remove(patchGroupID);
removePatchGroupAlias(patchGroupID);
updated = true;
}
else
{
updatePatchAlias(patchGroupID, patchedTalkgroups);
}
}
}
return updated;
}
/**
* Adds/updates a patch group alias to the alias list containing aliases for each of the patched talkgroups
*
* @param patchGroupID for the patch group
* @param patchedTalkgroups containing the talkgroup IDs for each of the patched talkgroups
*/
private void updatePatchAlias(String patchGroupID, List<String> patchedTalkgroups)
{
PatchGroupAlias patchGroupAlias = null;
//Check for an existing alias for the patch talkgroup
Alias alias = getAliasList().getTalkgroupAlias(patchGroupID);
if(alias instanceof PatchGroupAlias)
{
patchGroupAlias = (PatchGroupAlias)alias;
}
else if(alias != null)
{
//If the talkgroup is already aliased to a non-patch group, do nothing
}
else
{
patchGroupAlias = new PatchGroupAlias();
patchGroupAlias.addAliasID(new TalkgroupID(patchGroupID));
getAliasList().addAlias(patchGroupAlias);
}
if(patchGroupAlias != null)
{
patchGroupAlias.clearPatchedAliases();
for(String patchedTalkgroup: patchedTalkgroups)
{
Alias patchedAlias = getAliasList().getTalkgroupAlias(patchedTalkgroup);
if(patchedAlias != null)
{
patchGroupAlias.addPatchedAlias(patchedAlias);
}
}
}
}
/**
* Removes the temporary patch group alias from the alias list
*/
private void removePatchGroupAlias(String patchGroupID)
{
Alias alias = getAliasList().getTalkgroupAlias(patchGroupID);
if(alias instanceof PatchGroupAlias)
{
getAliasList().removeAlias(alias);
}
}
/** /**
* Process a traffic channel allocation message * Process a traffic channel allocation message
*/ */

View File

@@ -4,6 +4,10 @@ import module.decode.p25.reference.DataUnitID;
import alias.AliasList; import alias.AliasList;
import bits.BinaryMessage; import bits.BinaryMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class PatchGroup extends MotorolaTSBKMessage public abstract class PatchGroup extends MotorolaTSBKMessage
{ {
public static final int[] PATCH_GROUP_ADDRESS = { 80,81,82,83,84,85,86,87, public static final int[] PATCH_GROUP_ADDRESS = { 80,81,82,83,84,85,86,87,
@@ -15,6 +19,8 @@ public abstract class PatchGroup extends MotorolaTSBKMessage
public static final int[] GROUP_ADDRESS_3 = { 128,129,130,131,132,133,134, public static final int[] GROUP_ADDRESS_3 = { 128,129,130,131,132,133,134,
135,136,137,138,139,140,141,142,143 }; 135,136,137,138,139,140,141,142,143 };
private List<String> mPatchedTalkgroups;
public PatchGroup( BinaryMessage message, DataUnitID duid, public PatchGroup( BinaryMessage message, DataUnitID duid,
AliasList aliasList ) AliasList aliasList )
{ {
@@ -28,14 +34,10 @@ public abstract class PatchGroup extends MotorolaTSBKMessage
sb.append( getMessageStub() ); sb.append( getMessageStub() );
sb.append( " PATCH GROUP:" ); sb.append( " " );
sb.append( getPatchGroupAddress() ); sb.append( getPatchGroupAddress() );
sb.append( " GRP1:" ); sb.append(" ");
sb.append( getGroupAddress1() ); sb.append(getPatchedTalkgroups());
sb.append( " GRP2:" );
sb.append( getGroupAddress2() );
sb.append( " GRP3:" );
sb.append( getGroupAddress3() );
return sb.toString(); return sb.toString();
} }
@@ -45,6 +47,35 @@ public abstract class PatchGroup extends MotorolaTSBKMessage
return mMessage.getHex( PATCH_GROUP_ADDRESS, 4 ); return mMessage.getHex( PATCH_GROUP_ADDRESS, 4 );
} }
/**
* List of de-deplicated patched talkgroups contained in this message
*/
public List<String> getPatchedTalkgroups()
{
if(mPatchedTalkgroups == null)
{
mPatchedTalkgroups = new ArrayList<>();
mPatchedTalkgroups.add(getGroupAddress1());
String group2 = getGroupAddress2();
if(!mPatchedTalkgroups.contains(group2))
{
mPatchedTalkgroups.add(group2);
}
String group3 = getGroupAddress3();
if(!mPatchedTalkgroups.contains(group3))
{
mPatchedTalkgroups.add(group3);
}
}
return mPatchedTalkgroups;
}
public String getGroupAddress1() public String getGroupAddress1()
{ {
return mMessage.getHex( GROUP_ADDRESS_1, 4 ); return mMessage.getHex( GROUP_ADDRESS_1, 4 );