mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
#1368 Restructures Message and Event filter framework.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2023 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
|
||||
@@ -15,23 +14,27 @@
|
||||
*
|
||||
* 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.ltrstandard;
|
||||
|
||||
import io.github.dsheirer.module.decode.event.DecodeEvent;
|
||||
import io.github.dsheirer.module.decode.event.DecodeEventType;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
|
||||
/**
|
||||
* LTR decode event
|
||||
*/
|
||||
public class LTRStandardDecodeEvent extends DecodeEvent
|
||||
{
|
||||
/**
|
||||
* Constructs an LTR Standard decode event
|
||||
* @param start
|
||||
*/
|
||||
public LTRStandardDecodeEvent(long start)
|
||||
public LTRStandardDecodeEvent(DecodeEventType decodeEventType, long start)
|
||||
{
|
||||
super(start);
|
||||
super(decodeEventType, start);
|
||||
setProtocol(Protocol.LTR);
|
||||
}
|
||||
|
||||
@@ -40,9 +43,9 @@ public class LTRStandardDecodeEvent extends DecodeEvent
|
||||
* @param timeStart for the event
|
||||
* @return builder
|
||||
*/
|
||||
public static DecodeEventBuilder builder(long timeStart)
|
||||
public static DecodeEventBuilder builder(DecodeEventType decodeEventType, long timeStart)
|
||||
{
|
||||
DecodeEventBuilder decodeEventBuilder = new DecodeEventBuilder(timeStart);
|
||||
DecodeEventBuilder decodeEventBuilder = new DecodeEventBuilder(decodeEventType, timeStart);
|
||||
decodeEventBuilder.protocol(Protocol.LTR);
|
||||
return decodeEventBuilder;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||
*
|
||||
* * ******************************************************************************
|
||||
* * Copyright (C) 2014-2019 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/>
|
||||
* * *****************************************************************************
|
||||
* 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.ltrstandard;
|
||||
|
||||
@@ -42,9 +39,6 @@ import io.github.dsheirer.module.decode.ltrstandard.message.CallEnd;
|
||||
import io.github.dsheirer.module.decode.ltrstandard.message.Idle;
|
||||
import io.github.dsheirer.module.decode.ltrstandard.message.LTRMessage;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -52,6 +46,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LTRStandardDecoderState extends DecoderState
|
||||
{
|
||||
@@ -82,10 +78,8 @@ public class LTRStandardDecoderState extends DecoderState
|
||||
switch(((LTRMessage)message).getMessageType())
|
||||
{
|
||||
case CALL:
|
||||
if(message instanceof Call)
|
||||
if(message instanceof Call start)
|
||||
{
|
||||
Call start = (Call)message;
|
||||
|
||||
int channel = start.getChannel();
|
||||
setChannelNumber(channel);
|
||||
mLCNTracker.processFreeChannel(start.getFree());
|
||||
@@ -98,11 +92,9 @@ public class LTRStandardDecoderState extends DecoderState
|
||||
mCurrentTalkgroup = start.getTalkgroup();
|
||||
getIdentifierCollection().remove(IdentifierClass.USER);
|
||||
getIdentifierCollection().update(start.getTalkgroup());
|
||||
mCurrentCallEvent = LTRStandardDecodeEvent.builder(start.getTimestamp())
|
||||
mCurrentCallEvent = LTRStandardDecodeEvent.builder(DecodeEventType.CALL, start.getTimestamp())
|
||||
.identifiers(getIdentifierCollection().copyOf())
|
||||
.channel(getCurrentChannel())
|
||||
.eventType(DecodeEventType.CALL)
|
||||
.eventDescription("Call")
|
||||
.build();
|
||||
}
|
||||
else
|
||||
@@ -115,10 +107,8 @@ public class LTRStandardDecoderState extends DecoderState
|
||||
}
|
||||
break;
|
||||
case CALL_END:
|
||||
if(message instanceof CallEnd)
|
||||
if(message instanceof CallEnd end)
|
||||
{
|
||||
CallEnd end = (CallEnd)message;
|
||||
|
||||
mCurrentTalkgroup = null;
|
||||
|
||||
//Home channel is 31 for call end -- use the free channel as the call end channel
|
||||
@@ -136,10 +126,10 @@ public class LTRStandardDecoderState extends DecoderState
|
||||
}
|
||||
break;
|
||||
case IDLE:
|
||||
if(message instanceof Idle)
|
||||
if(message instanceof Idle idle)
|
||||
{
|
||||
mCurrentTalkgroup = null;
|
||||
mLCNTracker.processCallChannel(((Idle)message).getChannel());
|
||||
mLCNTracker.processCallChannel(idle.getChannel());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2023 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
|
||||
@@ -15,7 +14,7 @@
|
||||
*
|
||||
* 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.ltrstandard;
|
||||
@@ -24,47 +23,53 @@ import io.github.dsheirer.filter.Filter;
|
||||
import io.github.dsheirer.filter.FilterElement;
|
||||
import io.github.dsheirer.message.IMessage;
|
||||
import io.github.dsheirer.module.decode.ltrstandard.message.LTRMessage;
|
||||
import java.util.function.Function;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LTRStandardMessageFilter extends Filter<IMessage>
|
||||
/**
|
||||
* Filter for LTR standard messages.
|
||||
*/
|
||||
public class LTRStandardMessageFilter extends Filter<IMessage,LtrStandardMessageType>
|
||||
{
|
||||
private Map<LtrStandardMessageType,FilterElement<LtrStandardMessageType>> mElements = new EnumMap<>(LtrStandardMessageType.class);
|
||||
private final KeyExtractor mKeyExtractor = new KeyExtractor();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public LTRStandardMessageFilter()
|
||||
{
|
||||
super("LTR Message Filter");
|
||||
super("LTR Messages");
|
||||
|
||||
mElements.put(LtrStandardMessageType.CALL, new FilterElement<>(LtrStandardMessageType.CALL));
|
||||
mElements.put(LtrStandardMessageType.CALL_END, new FilterElement<>(LtrStandardMessageType.CALL_END));
|
||||
mElements.put(LtrStandardMessageType.IDLE, new FilterElement<>(LtrStandardMessageType.IDLE));
|
||||
mElements.put(LtrStandardMessageType.UNKNOWN, new FilterElement<>(LtrStandardMessageType.UNKNOWN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passes(IMessage message)
|
||||
{
|
||||
if(mEnabled && canProcess(message))
|
||||
for(LtrStandardMessageType type: LtrStandardMessageType.values())
|
||||
{
|
||||
LTRMessage ltr = (LTRMessage)message;
|
||||
|
||||
if(mElements.containsKey(ltr.getMessageType()))
|
||||
{
|
||||
return mElements.get(ltr.getMessageType()).isEnabled();
|
||||
}
|
||||
add(new FilterElement<>(type));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canProcess(IMessage message)
|
||||
{
|
||||
return message instanceof LTRMessage;
|
||||
return message instanceof LTRMessage && super.canProcess(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FilterElement<?>> getFilterElements()
|
||||
public Function<IMessage, LtrStandardMessageType> getKeyExtractor()
|
||||
{
|
||||
return new ArrayList<FilterElement<?>>(mElements.values());
|
||||
return mKeyExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key extractor
|
||||
*/
|
||||
private class KeyExtractor implements Function<IMessage,LtrStandardMessageType>
|
||||
{
|
||||
@Override
|
||||
public LtrStandardMessageType apply(IMessage message)
|
||||
{
|
||||
if(message instanceof LTRMessage ltr)
|
||||
{
|
||||
return ltr.getMessageType();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user