#90 [WIP] adds AttributeMonitor and AliasedStringAttributeMonitor for managing the metadata attributes and issuing attribute change requests, so that we can remove attribute management code out of the decoder states. Adds heuristic tracking with the monitor so that we can better track the talkgroups and other attributes and smooth out the rapidly changing values when we're decoding a weak signal. This will eventually close out issue #101

This commit is contained in:
Denny
2017-01-18 20:34:37 -05:00
parent acabab35ff
commit 5f179c4863
6 changed files with 423 additions and 257 deletions

View File

@@ -48,16 +48,16 @@ public class AliasList implements Listener<AliasEvent>
public static final String WILDCARD = "*"; public static final String WILDCARD = "*";
public static final String REGEX_WILDCARD = "."; public static final String REGEX_WILDCARD = ".";
private Map<String, Alias> mESN = new HashMap<>(); private Map<String,Alias> mESN = new HashMap<>();
private Map<String, Alias> mFleetsync = new HashMap<>(); private Map<String,Alias> mFleetsync = new HashMap<>();
private Map<LoJackFunctionAndID, Alias> mLoJack = new HashMap<>(); private Map<LoJackFunctionAndID,Alias> mLoJack = new HashMap<>();
private Map<String, Alias> mMDC1200 = new HashMap<>(); private Map<String,Alias> mMDC1200 = new HashMap<>();
private Map<String, Alias> mMobileID = new HashMap<>(); private Map<String,Alias> mMobileID = new HashMap<>();
private Map<String, Alias> mMPT1327 = new HashMap<>(); private Map<String,Alias> mMPT1327 = new HashMap<>();
private Map<String, Alias> mSiteID = new HashMap<>(); private Map<String,Alias> mSiteID = new HashMap<>();
private Map<Integer, Alias> mStatus = new HashMap<>(); private Map<Integer,Alias> mStatus = new HashMap<>();
private Map<String, Alias> mTalkgroup = new HashMap<>(); private Map<String,Alias> mTalkgroup = new HashMap<>();
private Map<Integer, Alias> mUniqueID = new HashMap<>(); private Map<Integer,Alias> mUniqueID = new HashMap<>();
private List<WildcardID> mESNWildcards = new ArrayList<>(); private List<WildcardID> mESNWildcards = new ArrayList<>();
private List<WildcardID> mMobileIDWildcards = new ArrayList<>(); private List<WildcardID> mMobileIDWildcards = new ArrayList<>();
@@ -124,7 +124,7 @@ public class AliasList implements Listener<AliasEvent>
if(fleetsync != null) if(fleetsync != null)
{ {
if (fleetsync.contains(WILDCARD)) if(fleetsync.contains(WILDCARD))
{ {
mFleetsyncWildcards.add(new WildcardID(fleetsync)); mFleetsyncWildcards.add(new WildcardID(fleetsync));
Collections.sort(mFleetsyncWildcards); Collections.sort(mFleetsyncWildcards);
@@ -137,11 +137,11 @@ public class AliasList implements Listener<AliasEvent>
mLoJack.put((LoJackFunctionAndID) id, alias); mLoJack.put((LoJackFunctionAndID) id, alias);
break; break;
case MDC1200: case MDC1200:
String mdc = ((MDC1200ID)id).getIdent(); String mdc = ((MDC1200ID) id).getIdent();
if(mdc != null) if(mdc != null)
{ {
if (mdc.contains(WILDCARD)) if(mdc.contains(WILDCARD))
{ {
mMDC1200Wildcards.add(new WildcardID(mdc)); mMDC1200Wildcards.add(new WildcardID(mdc));
Collections.sort(mMDC1200Wildcards); Collections.sort(mMDC1200Wildcards);
@@ -151,11 +151,11 @@ public class AliasList implements Listener<AliasEvent>
} }
break; break;
case MPT1327: case MPT1327:
String mpt = ((MPT1327ID)id).getIdent(); String mpt = ((MPT1327ID) id).getIdent();
if(mpt != null) if(mpt != null)
{ {
if (mpt.contains(WILDCARD)) if(mpt.contains(WILDCARD))
{ {
mMPT1327Wildcards.add(new WildcardID(mpt)); mMPT1327Wildcards.add(new WildcardID(mpt));
Collections.sort(mMPT1327Wildcards); Collections.sort(mMPT1327Wildcards);
@@ -165,11 +165,11 @@ public class AliasList implements Listener<AliasEvent>
} }
break; break;
case MIN: case MIN:
String min = ((Min)id).getMin(); String min = ((Min) id).getMin();
if(min != null) if(min != null)
{ {
if (min.contains(WILDCARD)) if(min.contains(WILDCARD))
{ {
mMobileIDWildcards.add(new WildcardID(min)); mMobileIDWildcards.add(new WildcardID(min));
Collections.sort(mMobileIDWildcards); Collections.sort(mMobileIDWildcards);
@@ -179,14 +179,14 @@ public class AliasList implements Listener<AliasEvent>
} }
break; break;
case LTR_NET_UID: case LTR_NET_UID:
mUniqueID.put(((UniqueID)id).getUid(), alias); mUniqueID.put(((UniqueID) id).getUid(), alias);
break; break;
case SITE: case SITE:
String siteID = ((SiteID)id).getSite(); String siteID = ((SiteID) id).getSite();
if(siteID != null) if(siteID != null)
{ {
if (siteID.contains(WILDCARD)) if(siteID.contains(WILDCARD))
{ {
mSiteWildcards.add(new WildcardID(siteID)); mSiteWildcards.add(new WildcardID(siteID));
Collections.sort(mSiteWildcards); Collections.sort(mSiteWildcards);
@@ -199,11 +199,11 @@ public class AliasList implements Listener<AliasEvent>
mStatus.put(((StatusID) id).getStatus(), alias); mStatus.put(((StatusID) id).getStatus(), alias);
break; break;
case TALKGROUP: case TALKGROUP:
String tgid = ((TalkgroupID)id).getTalkgroup(); String tgid = ((TalkgroupID) id).getTalkgroup();
if(tgid != null) if(tgid != null)
{ {
if (tgid.contains(WILDCARD)) if(tgid.contains(WILDCARD))
{ {
mTalkgroupWildcards.add(new WildcardID(tgid)); mTalkgroupWildcards.add(new WildcardID(tgid));
Collections.sort(mTalkgroupWildcards); Collections.sort(mTalkgroupWildcards);
@@ -222,7 +222,7 @@ public class AliasList implements Listener<AliasEvent>
break; break;
} }
} }
catch (Exception e) catch(Exception e)
{ {
mLog.error("Couldn't add alias ID " + id + " for alias " + alias); mLog.error("Couldn't add alias ID " + id + " for alias " + alias);
} }
@@ -234,9 +234,9 @@ public class AliasList implements Listener<AliasEvent>
*/ */
public void removeAlias(Alias alias) public void removeAlias(Alias alias)
{ {
if (alias != null) if(alias != null)
{ {
for (AliasID aliasID : alias.getId()) for(AliasID aliasID : alias.getId())
{ {
removeAliasID(aliasID, alias); removeAliasID(aliasID, alias);
} }
@@ -247,7 +247,7 @@ public class AliasList implements Listener<AliasEvent>
{ {
if(value != null) if(value != null)
{ {
for(WildcardID wildcardID: wildcards) for(WildcardID wildcardID : wildcards)
{ {
if(wildcardID.value().equals(value)) if(wildcardID.value().equals(value))
{ {
@@ -262,12 +262,12 @@ public class AliasList implements Listener<AliasEvent>
*/ */
private void removeAliasID(AliasID id, Alias alias) private void removeAliasID(AliasID id, Alias alias)
{ {
if (id.isValid()) if(id.isValid())
{ {
switch (id.getType()) switch(id.getType())
{ {
case ESN: case ESN:
String esn = ((Esn)id).getEsn(); String esn = ((Esn) id).getEsn();
if(esn != null) if(esn != null)
{ {
@@ -280,13 +280,13 @@ public class AliasList implements Listener<AliasEvent>
mESN.remove(esn); mESN.remove(esn);
break; break;
case FLEETSYNC: case FLEETSYNC:
String fleetsync = ((FleetsyncID)id).getIdent(); String fleetsync = ((FleetsyncID) id).getIdent();
if(fleetsync != null) if(fleetsync != null)
{ {
if(fleetsync.contains(WILDCARD)) if(fleetsync.contains(WILDCARD))
{ {
removeWildcard(fleetsync,mFleetsyncWildcards); removeWildcard(fleetsync, mFleetsyncWildcards);
} }
mFleetsync.remove(fleetsync); mFleetsync.remove(fleetsync);
@@ -296,7 +296,7 @@ public class AliasList implements Listener<AliasEvent>
mLoJack.remove((LoJackFunctionAndID) id); mLoJack.remove((LoJackFunctionAndID) id);
break; break;
case MDC1200: case MDC1200:
String mdc = ((MDC1200ID)id).getIdent(); String mdc = ((MDC1200ID) id).getIdent();
if(mdc != null) if(mdc != null)
{ {
@@ -309,7 +309,7 @@ public class AliasList implements Listener<AliasEvent>
} }
break; break;
case MPT1327: case MPT1327:
String mpt = ((MPT1327ID)id).getIdent(); String mpt = ((MPT1327ID) id).getIdent();
if(mpt != null) if(mpt != null)
{ {
@@ -322,7 +322,7 @@ public class AliasList implements Listener<AliasEvent>
} }
break; break;
case MIN: case MIN:
String min = ((Min)id).getMin(); String min = ((Min) id).getMin();
if(min != null) if(min != null)
{ {
@@ -344,7 +344,7 @@ public class AliasList implements Listener<AliasEvent>
mStatus.remove(((StatusID) id).getStatus()); mStatus.remove(((StatusID) id).getStatus());
break; break;
case TALKGROUP: case TALKGROUP:
String tgid = ((TalkgroupID)id).getTalkgroup(); String tgid = ((TalkgroupID) id).getTalkgroup();
if(tgid != null) if(tgid != null)
{ {
@@ -378,11 +378,11 @@ public class AliasList implements Listener<AliasEvent>
*/ */
private String getWildcardMatch(String id, List<WildcardID> wildcards) private String getWildcardMatch(String id, List<WildcardID> wildcards)
{ {
if (id != null) if(id != null)
{ {
for (WildcardID wildcard : wildcards) for(WildcardID wildcard : wildcards)
{ {
if (wildcard.matches(id)) if(wildcard.matches(id))
{ {
return wildcard.value(); return wildcard.value();
} }
@@ -399,15 +399,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (siteID != null) if(siteID != null)
{ {
alias = mSiteID.get(siteID); alias = mSiteID.get(siteID);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(siteID, mSiteWildcards); String wildcard = getWildcardMatch(siteID, mSiteWildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mSiteID.get(wildcard); alias = mSiteID.get(wildcard);
} }
@@ -440,15 +440,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (esn != null) if(esn != null)
{ {
alias = mESN.get(esn); alias = mESN.get(esn);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(esn, mESNWildcards); String wildcard = getWildcardMatch(esn, mESNWildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mESN.get(wildcard); alias = mESN.get(wildcard);
} }
@@ -465,15 +465,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (ident != null) if(ident != null)
{ {
alias = mFleetsync.get(ident); alias = mFleetsync.get(ident);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(ident, mFleetsyncWildcards); String wildcard = getWildcardMatch(ident, mFleetsyncWildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mFleetsync.get(wildcard); alias = mFleetsync.get(wildcard);
} }
@@ -488,11 +488,11 @@ public class AliasList implements Listener<AliasEvent>
*/ */
public Alias getLoJackAlias(Function function, String id) public Alias getLoJackAlias(Function function, String id)
{ {
if (id != null) if(id != null)
{ {
for (LoJackFunctionAndID lojack : mLoJack.keySet()) for(LoJackFunctionAndID lojack : mLoJack.keySet())
{ {
if (lojack.matches(function, id)) if(lojack.matches(function, id))
{ {
return mLoJack.get(lojack); return mLoJack.get(lojack);
} }
@@ -509,15 +509,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (ident != null) if(ident != null)
{ {
alias = mMDC1200.get(ident); alias = mMDC1200.get(ident);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(ident, mMDC1200Wildcards); String wildcard = getWildcardMatch(ident, mMDC1200Wildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mMDC1200.get(wildcard); alias = mMDC1200.get(wildcard);
} }
@@ -534,15 +534,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (ident != null) if(ident != null)
{ {
alias = mMPT1327.get(ident); alias = mMPT1327.get(ident);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(ident, mMPT1327Wildcards); String wildcard = getWildcardMatch(ident, mMPT1327Wildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mMPT1327.get(wildcard); alias = mMPT1327.get(wildcard);
} }
@@ -559,15 +559,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (ident != null) if(ident != null)
{ {
alias = mMobileID.get(ident); alias = mMobileID.get(ident);
if (alias == null) if(alias == null)
{ {
String wildcard = getWildcardMatch(ident, mMobileIDWildcards); String wildcard = getWildcardMatch(ident, mMobileIDWildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mMobileID.get(wildcard); alias = mMobileID.get(wildcard);
} }
@@ -588,15 +588,15 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = null; Alias alias = null;
if (tgid != null) if(tgid != null)
{ {
alias = mTalkgroup.get(tgid); alias = mTalkgroup.get(tgid);
if (alias == null && includeWildcards) if(alias == null && includeWildcards)
{ {
String wildcard = getWildcardMatch(tgid, mTalkgroupWildcards); String wildcard = getWildcardMatch(tgid, mTalkgroupWildcards);
if (wildcard != null) if(wildcard != null)
{ {
alias = mTalkgroup.get(wildcard); alias = mTalkgroup.get(wildcard);
} }
@@ -614,9 +614,9 @@ public class AliasList implements Listener<AliasEvent>
return getTalkgroupAlias(tgid, true); return getTalkgroupAlias(tgid, true);
} }
/** /**
* Alias list name * Alias list name
*/ */
public String toString() public String toString()
{ {
return mName; return mName;
@@ -639,22 +639,22 @@ public class AliasList implements Listener<AliasEvent>
{ {
Alias alias = event.getAlias(); Alias alias = event.getAlias();
switch (event.getEvent()) switch(event.getEvent())
{ {
case ADD: case ADD:
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList())) if(alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
{ {
addAlias(alias); addAlias(alias);
} }
break; break;
case CHANGE: case CHANGE:
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList())) if(alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
{ {
addAlias(alias); addAlias(alias);
} }
break; break;
case DELETE: case DELETE:
if (alias.getList() != null && getName().equalsIgnoreCase(alias.getList())) if(alias.getList() != null && getName().equalsIgnoreCase(alias.getList()))
{ {
removeAlias(alias); removeAlias(alias);
} }

View File

@@ -0,0 +1,114 @@
/*******************************************************************************
* 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 channel.metadata;
import alias.Alias;
import alias.AliasList;
import alias.id.AliasIDType;
import sample.Listener;
import static alias.id.AliasIDType.*;
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;
}
}

View File

@@ -0,0 +1,185 @@
/*******************************************************************************
* 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 channel.metadata;
import alias.Alias;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sample.Listener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AttributeMonitor<T>
{
private final static Logger mLog = LoggerFactory.getLogger(AttributeMonitor.class);
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
*/
public void process(T t)
{
if(t != null && !mIllegalValues.contains(t))
{
boolean changed = false;
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()));
}
}
}
/**
* 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;
}
public static void main(String[] args)
{
AttributeMonitor<String> monitor = new AttributeMonitor<>(Attribute.PRIMARY_ADDRESS_TO, new Listener<AttributeChangeRequest>()
{
@Override
public void receive(AttributeChangeRequest attributeChangeRequest)
{
mLog.debug("Attribute Changed - value:" + attributeChangeRequest.getValue());
}
});
monitor.addIllegalValue("0000");
monitor.addIllegalValue("000000");
monitor.process("ABCD");
monitor.process("EFGH");
monitor.process("0000");
monitor.process("0000");
monitor.process("ABCD");
monitor.reset();
monitor.process("EFGH");
monitor.process("ABCD");
monitor.process("ABCD");
monitor.process("EFGH");
monitor.process("EFGH");
monitor.process("000000");
monitor.process("000000");
monitor.process("000000");
monitor.process("000000");
}
}

View File

@@ -24,5 +24,5 @@ public interface IAttributeChangeRequestProvider
{ {
public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener); public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener);
public void removeAttributeChangeRequestListener(); public void removeAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener);
} }

View File

@@ -25,7 +25,7 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
{ {
/* This has to be a broadcaster in order for references to persist */ /* This has to be a broadcaster in order for references to persist */
private Broadcaster<CallEvent> mCallEventBroadcaster = new Broadcaster<>(); private Broadcaster<CallEvent> mCallEventBroadcaster = new Broadcaster<>();
private Listener<AttributeChangeRequest> mAttributeChangeRequestListener; private Broadcaster<AttributeChangeRequest> mAttributeChangeRequestBroadcaster = new Broadcaster<>();
private Listener<DecoderStateEvent> mDecoderStateListener; private Listener<DecoderStateEvent> mDecoderStateListener;
private DecoderStateEventListener mDecoderStateEventListener = new DecoderStateEventListener(); private DecoderStateEventListener mDecoderStateEventListener = new DecoderStateEventListener();
@@ -167,10 +167,7 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
*/ */
protected void broadcast(AttributeChangeRequest<?> request) protected void broadcast(AttributeChangeRequest<?> request)
{ {
if(mAttributeChangeRequestListener != null) mAttributeChangeRequestBroadcaster.broadcast(request);
{
mAttributeChangeRequestListener.receive(request);
}
} }
/** /**
@@ -179,16 +176,23 @@ public abstract class DecoderState extends Module implements ActivitySummaryProv
@Override @Override
public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener) public void setAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
{ {
mAttributeChangeRequestListener = listener; mAttributeChangeRequestBroadcaster.addListener(listener);
} }
/** /**
* Removes any listener from receiving attribute change requests * Removes any listener from receiving attribute change requests
*/ */
@Override @Override
public void removeAttributeChangeRequestListener() public void removeAttributeChangeRequestListener(Listener<AttributeChangeRequest> listener)
{ {
mAttributeChangeRequestListener = null; mAttributeChangeRequestBroadcaster.removeListener(listener);
} }
/**
* Broadaster so that Attribute monitors can broadcast attribute change requests
*/
protected Listener<AttributeChangeRequest> getAttributeChangeRequestListener()
{
return mAttributeChangeRequestBroadcaster;
}
} }

View File

@@ -20,7 +20,9 @@ package module.decode.p25;
import alias.Alias; import alias.Alias;
import alias.AliasList; import alias.AliasList;
import alias.PatchGroupAlias; import alias.PatchGroupAlias;
import alias.id.AliasIDType;
import alias.id.talkgroup.TalkgroupID; import alias.id.talkgroup.TalkgroupID;
import channel.metadata.AliasedStringAttributeMonitor;
import channel.metadata.Attribute; import channel.metadata.Attribute;
import channel.metadata.AttributeChangeRequest; import channel.metadata.AttributeChangeRequest;
import channel.state.ChangeChannelTimeoutEvent; import channel.state.ChangeChannelTimeoutEvent;
@@ -169,14 +171,12 @@ public class P25DecoderState extends DecoderState
private String mLastRegistrationEventID; private String mLastRegistrationEventID;
private String mLastResponseEventID; private String mLastResponseEventID;
//TODO: create multi-attribute monitor for NAC and System
private String mNAC; private String mNAC;
private String mSystem; private String mSystem;
private String mSite; private AliasedStringAttributeMonitor mSiteAttributeMonitor;
private String mSiteAlias; private AliasedStringAttributeMonitor mFromTalkgroupMonitor;
private String mFromTalkgroup; private AliasedStringAttributeMonitor mToTalkgroupMonitor;
private Alias mFromAlias;
private String mToTalkgroup;
private Alias mToAlias;
private String mCurrentChannel = "CURRENT"; private String mCurrentChannel = "CURRENT";
private long mCurrentChannelFrequency = 0; private long mCurrentChannelFrequency = 0;
@@ -198,6 +198,13 @@ public class P25DecoderState extends DecoderState
mChannelType = channelType; mChannelType = channelType;
mModulation = modulation; mModulation = modulation;
mIgnoreDataCalls = ignoreDataCalls; mIgnoreDataCalls = ignoreDataCalls;
mSiteAttributeMonitor = new AliasedStringAttributeMonitor(Attribute.NETWORK_ID_2,
getAttributeChangeRequestListener(), getAliasList(), AliasIDType.SITE);
mFromTalkgroupMonitor = new AliasedStringAttributeMonitor(Attribute.PRIMARY_ADDRESS_FROM,
getAttributeChangeRequestListener(), getAliasList(), AliasIDType.TALKGROUP);
mToTalkgroupMonitor = new AliasedStringAttributeMonitor(Attribute.PRIMARY_ADDRESS_TO,
getAttributeChangeRequestListener(), getAliasList(), AliasIDType.TALKGROUP);
} }
public Modulation getModulation() public Modulation getModulation()
@@ -225,8 +232,7 @@ public class P25DecoderState extends DecoderState
resetState(); resetState();
mNAC = null; mNAC = null;
mSite = null; mSiteAttributeMonitor.reset();
mSiteAlias = null;
mSystem = null; mSystem = null;
} }
@@ -235,10 +241,8 @@ public class P25DecoderState extends DecoderState
*/ */
private void resetState() private void resetState()
{ {
mFromTalkgroup = null; mFromTalkgroupMonitor.reset();
mFromAlias = null; mToTalkgroupMonitor.reset();
mToTalkgroup = null;
mToAlias = null;
mCallDetectTalkgroups.clear(); mCallDetectTalkgroups.clear();
@@ -405,7 +409,7 @@ public class P25DecoderState extends DecoderState
String to = hdu.getToID(); String to = hdu.getToID();
updateTo(to); mToTalkgroupMonitor.process(to);
if(mCurrentCallEvent == null) if(mCurrentCallEvent == null)
{ {
@@ -495,7 +499,7 @@ public class P25DecoderState extends DecoderState
//TODO: does the activity summary need this message? //TODO: does the activity summary need this message?
/* This message is handled by the P25MessageProcessor and /* This message is handled by the P25MessageProcessor and
* inserted into any channels needing frequency band info */ * inserted into any channels needing frequency band info */
break; break;
case CHANNEL_IDENTIFIER_UPDATE_EXPLICIT: case CHANNEL_IDENTIFIER_UPDATE_EXPLICIT:
//TODO: does the activity summary need this message? //TODO: does the activity summary need this message?
@@ -614,8 +618,8 @@ public class P25DecoderState extends DecoderState
String from = gvcuser.getSourceAddress(); String from = gvcuser.getSourceAddress();
String to = gvcuser.getGroupAddress(); String to = gvcuser.getGroupAddress();
updateFrom(from); mFromTalkgroupMonitor.process(from);
updateTo(to); mToTalkgroupMonitor.process(to);
if(mCurrentCallEvent == null) if(mCurrentCallEvent == null)
{ {
@@ -702,7 +706,7 @@ public class P25DecoderState extends DecoderState
String site = rfsssb.getRFSubsystemID() + "-" + String site = rfsssb.getRFSubsystemID() + "-" +
rfsssb.getSiteID(); rfsssb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
if(mCurrentChannel == null || if(mCurrentChannel == null ||
!mCurrentChannel.contentEquals(rfsssb.getChannel())) !mCurrentChannel.contentEquals(rfsssb.getChannel()))
@@ -725,7 +729,7 @@ public class P25DecoderState extends DecoderState
String site = rfsssbe.getRFSubsystemID() + "-" + String site = rfsssbe.getRFSubsystemID() + "-" +
rfsssbe.getSiteID(); rfsssbe.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
if(mCurrentChannel == null || if(mCurrentChannel == null ||
!mCurrentChannel.contentEquals(rfsssbe.getTransmitChannel())) !mCurrentChannel.contentEquals(rfsssbe.getTransmitChannel()))
@@ -748,7 +752,7 @@ public class P25DecoderState extends DecoderState
String site = sccb.getRFSubsystemID() + "-" + String site = sccb.getRFSubsystemID() + "-" +
sccb.getSiteID(); sccb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -764,7 +768,7 @@ public class P25DecoderState extends DecoderState
String site = sccb.getRFSubsystemID() + "-" + String site = sccb.getRFSubsystemID() + "-" +
sccb.getSiteID(); sccb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -838,7 +842,7 @@ public class P25DecoderState extends DecoderState
String to = tivcu.getAddress(); String to = tivcu.getAddress();
updateTo(to); mToTalkgroupMonitor.process(to);
if(mCurrentCallEvent == null) if(mCurrentCallEvent == null)
{ {
@@ -915,10 +919,10 @@ public class P25DecoderState extends DecoderState
(module.decode.p25.message.tdu.lc.UnitToUnitVoiceChannelUser) tdulc; (module.decode.p25.message.tdu.lc.UnitToUnitVoiceChannelUser) tdulc;
String from = uuvcu.getSourceAddress(); String from = uuvcu.getSourceAddress();
updateFrom(from); mFromTalkgroupMonitor.process(from);
String to = uuvcu.getTargetAddress(); String to = uuvcu.getTargetAddress();
updateTo(to); mToTalkgroupMonitor.process(to);
if(mCurrentCallEvent != null) if(mCurrentCallEvent != null)
{ {
@@ -1163,9 +1167,9 @@ public class P25DecoderState extends DecoderState
module.decode.p25.message.ldu.lc.GroupVoiceChannelUser gvcuser = module.decode.p25.message.ldu.lc.GroupVoiceChannelUser gvcuser =
(module.decode.p25.message.ldu.lc.GroupVoiceChannelUser) ldu; (module.decode.p25.message.ldu.lc.GroupVoiceChannelUser) ldu;
updateFrom(gvcuser.getSourceAddress()); mFromTalkgroupMonitor.process(gvcuser.getSourceAddress());
updateTo(gvcuser.getGroupAddress()); mToTalkgroupMonitor.process(gvcuser.getGroupAddress());
if(mChannelType == ChannelType.STANDARD) if(mChannelType == ChannelType.STANDARD)
{ {
@@ -1258,7 +1262,7 @@ public class P25DecoderState extends DecoderState
String site = rfsssb.getRFSubsystemID() + "-" + String site = rfsssb.getRFSubsystemID() + "-" +
rfsssb.getSiteID(); rfsssb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -1274,7 +1278,7 @@ public class P25DecoderState extends DecoderState
String site = rfsssbe.getRFSubsystemID() + "-" + String site = rfsssbe.getRFSubsystemID() + "-" +
rfsssbe.getSiteID(); rfsssbe.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -1290,7 +1294,7 @@ public class P25DecoderState extends DecoderState
String site = sccb.getRFSubsystemID() + "-" + String site = sccb.getRFSubsystemID() + "-" +
sccb.getSiteID(); sccb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -1306,7 +1310,7 @@ public class P25DecoderState extends DecoderState
String site = sccb.getRFSubsystemID() + "-" + String site = sccb.getRFSubsystemID() + "-" +
sccb.getSiteID(); sccb.getSiteID();
updateSite(site); mSiteAttributeMonitor.process(site);
} }
else else
{ {
@@ -1379,7 +1383,7 @@ public class P25DecoderState extends DecoderState
TelephoneInterconnectVoiceChannelUser tivcu = TelephoneInterconnectVoiceChannelUser tivcu =
(TelephoneInterconnectVoiceChannelUser) ldu; (TelephoneInterconnectVoiceChannelUser) ldu;
updateTo(tivcu.getAddress()); mToTalkgroupMonitor.process(tivcu.getAddress());
if(mCurrentCallEvent.getCallEventType() != CallEventType.TELEPHONE_INTERCONNECT) if(mCurrentCallEvent.getCallEventType() != CallEventType.TELEPHONE_INTERCONNECT)
{ {
@@ -1460,9 +1464,9 @@ public class P25DecoderState extends DecoderState
UnitToUnitVoiceChannelUser uuvcu = UnitToUnitVoiceChannelUser uuvcu =
(UnitToUnitVoiceChannelUser) ldu; (UnitToUnitVoiceChannelUser) ldu;
updateFrom(uuvcu.getSourceAddress()); mFromTalkgroupMonitor.process(uuvcu.getSourceAddress());
updateTo(uuvcu.getTargetAddress()); mToTalkgroupMonitor.process(uuvcu.getTargetAddress());
if(mCurrentCallEvent.getCallEventType() != CallEventType.UNIT_TO_UNIT_CALL) if(mCurrentCallEvent.getCallEventType() != CallEventType.UNIT_TO_UNIT_CALL)
{ {
@@ -1877,7 +1881,7 @@ public class P25DecoderState extends DecoderState
updateNAC(mRFSSStatusMessageExtended.getNAC()); updateNAC(mRFSSStatusMessageExtended.getNAC());
updateSystem(mRFSSStatusMessageExtended.getSystemID()); updateSystem(mRFSSStatusMessageExtended.getSystemID());
updateSite(mRFSSStatusMessageExtended.getRFSubsystemID() + mSiteAttributeMonitor.process(mRFSSStatusMessageExtended.getRFSubsystemID() +
"-" + mRFSSStatusMessageExtended.getSiteID()); "-" + mRFSSStatusMessageExtended.getSiteID());
} }
else else
@@ -2651,7 +2655,7 @@ public class P25DecoderState extends DecoderState
updateSystem(message.getSystemID()); updateSystem(message.getSystemID());
updateSite(message.getRFSubsystemID() + "-" + message.getSiteID()); mSiteAttributeMonitor.process(message.getRFSubsystemID() + "-" + message.getSiteID());
} }
private void processTSBKDataChannelAnnouncement(TSBKMessage message) private void processTSBKDataChannelAnnouncement(TSBKMessage message)
@@ -3354,99 +3358,6 @@ public class P25DecoderState extends DecoderState
} }
} }
/**
* Broadcasts an update for the TO group or unit address
*/
private void updateTo(final String to)
{
if(to != null && !to.contentEquals("0000") && !to.contentEquals("000000"))
{
if(mToTalkgroup == null || !mToTalkgroup.contentEquals(to))
{
mToTalkgroup = to;
if(hasAliasList())
{
mToAlias = getAliasList().getTalkgroupAlias(mToTalkgroup);
}
else
{
mToAlias = null;
}
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, mToTalkgroup, mToAlias));
if(mCurrentCallEvent != null &&
(mCurrentCallEvent.getToID() == null || !mCurrentCallEvent.getToID().contentEquals(to)))
{
mCurrentCallEvent.setToID(to);
broadcast(mCurrentCallEvent);
}
}
}
}
/**
* Broadcasts an update for the FROM group or unit address
*/
private void updateFrom(final String from)
{
if(from != null && !from.contentEquals("0000") && !from.contentEquals("000000"))
{
if(mFromTalkgroup == null || !mFromTalkgroup.contentEquals(from))
{
mFromTalkgroup = from;
if(hasAliasList())
{
mFromAlias = getAliasList().getTalkgroupAlias(mFromTalkgroup);
}
else
{
mFromAlias = null;
}
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_FROM, mFromTalkgroup,
mFromAlias));
if(mCurrentCallEvent != null &&
(mCurrentCallEvent.getFromID() == null || !mCurrentCallEvent.getFromID().contentEquals(from)))
{
mCurrentCallEvent.setFromID(from);
broadcast(mCurrentCallEvent);
}
}
}
}
/**
* Updates the site information
*/
private void updateSite(String site)
{
if(mSite == null || (site != null && !mSite.contentEquals(site)))
{
mSite = site;
if(hasAliasList())
{
Alias alias = getAliasList().getSiteID(mSite);
if(alias != null)
{
mSiteAlias = alias.getName();
}
else
{
mSiteAlias = null;
}
}
}
}
private void updateSystem(String system) private void updateSystem(String system)
{ {
if(mSystem == null || (system != null && !mSystem.contentEquals(system))) if(mSystem == null || (system != null && !mSystem.contentEquals(system)))
@@ -3739,46 +3650,6 @@ public class P25DecoderState extends DecoderState
return sb.toString(); return sb.toString();
} }
public String getNAC()
{
return mNAC;
}
public String getSystem()
{
return mSystem;
}
public String getSiteAlias()
{
return mSiteAlias;
}
public String getSite()
{
return mSite;
}
public String getFromTalkgroup()
{
return mFromTalkgroup;
}
public Alias getFromAlias()
{
return mFromAlias;
}
public String getToTalkgroup()
{
return mToTalkgroup;
}
public Alias getToAlias()
{
return mToAlias;
}
@Override @Override
public void receiveDecoderStateEvent(DecoderStateEvent event) public void receiveDecoderStateEvent(DecoderStateEvent event)
{ {
@@ -3806,19 +3677,11 @@ public class P25DecoderState extends DecoderState
mCurrentChannelFrequency = allocationEvent.getCallEvent().getFrequency(); mCurrentChannelFrequency = allocationEvent.getCallEvent().getFrequency();
broadcast(new AttributeChangeRequest<Long>(Attribute.CHANNEL_FREQUENCY, mCurrentChannelFrequency)); broadcast(new AttributeChangeRequest<Long>(Attribute.CHANNEL_FREQUENCY, mCurrentChannelFrequency));
mFromTalkgroup = allocationEvent.getCallEvent().getFromID(); mFromTalkgroupMonitor.reset();
mToTalkgroup = allocationEvent.getCallEvent().getToID(); mFromTalkgroupMonitor.process(allocationEvent.getCallEvent().getFromID());
if(allocationEvent.getCallEvent().hasAliasList()) mToTalkgroupMonitor.reset();
{ mToTalkgroupMonitor.process(allocationEvent.getCallEvent().getToID());
AliasList aliasList = allocationEvent.getCallEvent().getAliasList();
mFromAlias = aliasList.getTalkgroupAlias(mFromTalkgroup);
mToAlias = aliasList.getTalkgroupAlias(mToTalkgroup);
}
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_FROM, mFromTalkgroup, mFromAlias));
broadcast(new AttributeChangeRequest<String>(Attribute.PRIMARY_ADDRESS_TO, mToTalkgroup, mToAlias));
} }
} }
break; break;