Identifier Framework and Message/Event Processing Overhaul (#455)

* WIP on new P25 message framer.

* WIP on new P25 message framer.

* Adds new 1/2 and 3/4 rate trellis decoders.  Still trying to chase
down why there is a sync pattern mismatch in the NID buffer queue.

* WIP - new p25 message framer works correctly now.  PDU's are dectected
and decoded using the 1/2 and 3/4 rate trellis decoders.  Packet
Sequences are assembled.  Need to add a new packet sequence message
factory that can detect Motorola Auto Registration Service (ARS)
formatted UDP/ID packets and SNDCP command packets.

* WIP - removes nullify on channel results queue.

* WIP - updates message framer for TSBK 1/2/3 processing.

* WIP removing P25 sync pattern and nid bits from all message parsers.

* WIP - merges identifier framework branch changes into this branch.

* WIP on updating link control words to new format and identifier framework.

* WIP - implements rest of link control words for extended formats

* WIP - initial work on ISP/OSP TSBK message restructuring.

* WIP - adds more TSBK ISP and OSP messages

* WIP - finished updating most of the TSBK ISP and OSP messages.  Converted
all messages to no longer include the NID (nac + dataunitID) so that
each message can simply hold the parsed values.  Removed AliasList as
an argument to each message and updated all messges to use the new
IIdentifer and IAPCO25Channel interfaces.

Removed legacy TDU and LDU link control messages and replaced with a
single LinkControlWord class hierarchy.

P25 decoder state is not yet updated for the new message structure.

PDU message parsing is not fully implemented.

* WIP - adds some Multi-Block trunking control messages with Alternate
and Unconfirmed formats.

* WIP - Fully implements AMBTC and UMBTC PDU message parsers.

Some package restructuring.

* WIP - Resolves Link control parsing in LDU1 and 2 messages.

* WIP - finishes updating TSBK and Link Control messages.  Adds support
for moto link control messages for patch groups.

* WIP - finishes updating TSBK and Link Control messages.  Adds support
for moto link control messages for patch groups.  Adds support for moto
ARS service, IPV4 decoding, and UDP/IP packets.

* WIP - finishes SNDCP packet data with header parsing.  Compressed IP or
UDP headers are not yet supported, but are logged as such.

* WIP - converts all talkgroup identifiers to integers and updates
alias list to create a per-protocol map of talkgroup id's to alias.

Inserts a legacy talkgroup (ltr, p25, passport, mpt1327, mdc, etc.)
conversion utility to convert existing legacy (string) talkgroups to
new integer talkgroup format.

Creates an audio packet manager to insert metadata into audio packets
before streaming packets for playback, recording, and/or streaming.

Creates identifier collection to manage current identifiers in each of
the channel and decoder states.

Creates simplified channel metadata to maintain the now playing display.

Moves channel attributes (alias list, system, site, name) as configuration
identifiers in the channel state.

Many other refactoring and updates.

* WIP - numerous updates to push use of identifier collection throughout
the system.  Updates the channel metadata and audio packet processing
logic.  Implements a large portion of the P25 decode state processing.
Updates traffic channel management.  Adds user preferences for timestamp
and identifier formatting, however doesn't add a user interface yet.

* WIP - initial implementation of user preferences editor window.

* WIP - updates preferences editor window to close and dispose window but
retain javafx event thread running.

* WIP - fully updates p25 decoder state and traffic channel processing to
use the new identifier framework.

Cleans up channel event processing and removes channel model as the sole
broadcaster of channel events.  Channel processing manager now listens
for all start/stop events and requestors dispatch event directly to the
channel processing manager.

Resolves issue in airspy that was causing user interface to lock-up.  The
issue appears to occur when the dongle is plugged into a usb port that
can't fully support the data rate.  sdrtrunk now recognizes these errors
and warns the user that they should use another usb port.

* WIP - updates alias action manager and adds new talkgroup range alias identifier.

Updates playlist to incorporate a version number so that the playlist
updater only runs when needed, to update a playlist to the correct
version format.

Updates user preferences to use the google event bus to broadcast
preference update notifications to remove the need for listeners to
register directly on the user preferences instance.

* WIP - updates alias id editors to flag invalid values and moves legacy
alias ids to legacy package.

Updates event logging configuration to add traffic channel decode events
and decoded message logging.  Removes binary message logging since that
is now replaced with demodulated bitstream recording.

* Removes system properties from user preferences.  Preferences are stored
in the OS-dependent settings store (windows - registry)

* Updates MapService to use new PlottableDecodeEvent instead of monitoring
all of the decoded messages.

Updates Fleetsync decoder and related messages to identifier framework.

* Updates LTR-Net, Fleetsync and LJ1200 decoders to new identifier
framework and adds support for user preferences for formatting of
LTR-Net and fleetsync talkgroup identifiers.

Breaks LTR-Net messages into various message types and uses a new
message factory.

Removes alias list from message processing for ltr-net, fleetsync and
lj1200.

* Updates LTR-Standard messages to Identifier framework.

* Removes Plottable and IPlottable from codebase.

* wip

* WIP on MPT-1327 messages.

* Updates MPT1327 decoder to identifier framework and new traffic channel
manager.  This decoder still needs to be updated with a new message
parser factory and a sync detector like what is now used for P25.

* Updates MDC1200 decoder and message to identifier framework.

* Updates Tait1200 and Passport decoders to identifier framework.

* Merges changes from master branch.

* Removes legacy alias support classes.  Updates passport message processor
to only pass valid messages.  Adds support to playlist updater for
converting passport mobile ids to become passport talkgroup values.

* Updates P25 decoder state and channel state to better track allocated
traffic channels.  Resolves issue in timestamp manager for trackig
message timestamps. Resolves issue in airspy tuner that was causing
the tuner to stop sending samples to the application.

* Update P25 Decoder state to process SNDCP management messages and
PDU messages.

Updates P25 activity summary to display network and site details.

Resolves issue with overlay panel that prevented enabled channels from
rendering correctly when zoomed in.

* Creates a new FilePreferences as part of the user preferences to begin
the transition of SystemProperties over to user preferences and consolidate
file preferences in one location.

Updates playlist manager to use the new file preferences and to use
default.xml as the new default playlist name, following conversion of
a playlist_v2.xml format to the new format.

In the near future, the user will be able to edit file locations and to
create/use other playlists.

Resolved an issue with all decoder states where not all identifiers were
being included in decode events.
This commit is contained in:
Denny Sheirer
2018-12-24 09:08:34 -05:00
committed by GitHub
parent 735fca16d6
commit b67d4d92dc
869 changed files with 64776 additions and 45233 deletions

View File

@@ -1,18 +1,21 @@
/*
* *********************************************************************************************************************
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
* Copyright (C) 2014-2018 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 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.
* 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/>
* *********************************************************************************************************************
* 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.playlist;
@@ -26,11 +29,11 @@ import io.github.dsheirer.audio.broadcast.BroadcastEvent;
import io.github.dsheirer.audio.broadcast.BroadcastModel;
import io.github.dsheirer.controller.channel.Channel.ChannelType;
import io.github.dsheirer.controller.channel.ChannelEvent;
import io.github.dsheirer.controller.channel.ChannelEventListener;
import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.map.ChannelMapEvent;
import io.github.dsheirer.controller.channel.map.ChannelMapModel;
import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.playlist.FilePreferences;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.util.ThreadPool;
import org.slf4j.Logger;
@@ -40,25 +43,21 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class PlaylistManager implements ChannelEventListener
public class PlaylistManager implements Listener<ChannelEvent>
{
private final static Logger mLog = LoggerFactory.getLogger(PlaylistManager.class);
public static final int PLAYLIST_CURRENT_VERSION = 2;
private AliasModel mAliasModel;
private BroadcastModel mBroadcastModel;
private ChannelModel mChannelModel;
private ChannelMapModel mChannelMapModel;
private Path mPlaylistFolderPath;
private Path mPlaylistCurrentPath;
private Path mPlaylistBackupPath;
private Path mPlaylistLockPath;
private UserPreferences mUserPreferences;
private AtomicBoolean mPlaylistSavePending = new AtomicBoolean();
private boolean mPlaylistLoading = false;
@@ -71,12 +70,14 @@ public class PlaylistManager implements ChannelEventListener
*
* @param channelModel
*/
public PlaylistManager(AliasModel aliasModel, BroadcastModel broadcastModel, ChannelModel channelModel, ChannelMapModel channelMapModel)
public PlaylistManager(AliasModel aliasModel, BroadcastModel broadcastModel, ChannelModel channelModel,
ChannelMapModel channelMapModel, UserPreferences userPreferences)
{
mAliasModel = aliasModel;
mBroadcastModel = broadcastModel;
mChannelModel = channelModel;
mChannelMapModel = channelMapModel;
mUserPreferences = userPreferences;
//Register for alias, channel and channel map events so that we can
//save the playlist when there are any changes
@@ -164,7 +165,7 @@ public class PlaylistManager implements ChannelEventListener
* and queues automatic playlist saving.
*/
@Override
public void channelChanged(ChannelEvent event)
public void receive(ChannelEvent event)
{
//Only save playlist for changes to standard channels (not traffic)
if(event.getChannel().getChannelType() == ChannelType.STANDARD)
@@ -180,124 +181,50 @@ public class PlaylistManager implements ChannelEventListener
}
}
/**
* Folder where playlist, backup and lock file are stored
*/
private Path getPlaylistFolderPath()
{
if(mPlaylistFolderPath == null)
{
SystemProperties props = SystemProperties.getInstance();
mPlaylistFolderPath = props.getApplicationFolder("playlist");
}
return mPlaylistFolderPath;
}
/**
* Path to current playlist
*/
private Path getPlaylistPath()
{
if(mPlaylistCurrentPath == null)
{
//Temporarily removed and hard-coding the V2 playlist name. Will be reimplemented with future
//enhancement that allows multiple playlists.
// SystemProperties props = SystemProperties.getInstance();
// String playlistDefault = props.get("playlist.defaultfilename", "playlist_v2.xml");
// String playlistCurrent = props.get("playlist.currentfilename", playlistDefault);
mPlaylistCurrentPath = getPlaylistFolderPath().resolve("playlist_v2.xml");
}
return mPlaylistCurrentPath;
}
/**
* Path to most recent playlist backup
*/
private Path getPlaylistBackupPath()
{
if(mPlaylistBackupPath == null)
{
SystemProperties props = SystemProperties.getInstance();
String playlistDefault = props.get("playlist.defaultfilename", "playlist_v2.xml");
String playlistCurrent = props.get("playlist.currentfilename", playlistDefault);
String playlistBackup = playlistCurrent.replace(".xml", ".bak");
mPlaylistBackupPath = getPlaylistFolderPath().resolve(playlistBackup);
}
return mPlaylistBackupPath;
}
/**
* Path to playlist lock file that is created prior to saving a playlist and removed immediately thereafter.
* Presence of a lock file indicates an incomplete or corrupt playlist file on startup.
*/
private Path getPlaylistLockPath()
{
if(mPlaylistLockPath == null)
{
SystemProperties props = SystemProperties.getInstance();
String playlistDefault = props.get("playlist.defaultfilename", "playlist_v2.xml");
String playlistCurrent = props.get("playlist.currentfilename", playlistDefault);
String playlistLock = playlistCurrent.replace(".xml", ".lock");
mPlaylistLockPath = getPlaylistFolderPath().resolve(playlistLock);
}
return mPlaylistLockPath;
}
/**
* Saves the current playlist
*/
private void save()
{
FilePreferences files = mUserPreferences.getFilePreferences();
PlaylistV2 playlist = new PlaylistV2();
playlist.setAliases(mAliasModel.getAliases());
playlist.setBroadcastConfigurations(mBroadcastModel.getBroadcastConfigurations());
playlist.setChannels(mChannelModel.getChannels());
playlist.setChannelMaps(mChannelMapModel.getChannelMaps());
playlist.setVersion(PLAYLIST_CURRENT_VERSION);
//Create a backup copy of the current playlist
if(Files.exists(getPlaylistPath()))
if(Files.exists(files.getPlaylist()))
{
try
{
Files.copy(getPlaylistPath(), getPlaylistBackupPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(files.getPlaylist(), files.getPlaylistBackup(), StandardCopyOption.REPLACE_EXISTING);
}
catch(Exception e)
{
mLog.error("Error creating backup copy of current playlist prior to saving updates [" +
getPlaylistPath().toString() + "]", e);
files.getPlaylist().toString() + "]", e);
}
}
//Create a temporary lock file to signify that we're in the process of updating the playlist
if(!Files.exists(getPlaylistLockPath()))
if(!Files.exists(files.getPlaylistLock()))
{
try
{
Files.createFile(getPlaylistLockPath());
Files.createFile(files.getPlaylistLock());
}
catch(IOException e)
{
mLog.error("Error creating temporary lock file prior to saving playlist [" +
getPlaylistLockPath().toString() + "]", e);
files.getPlaylistLock().toString() + "]", e);
}
}
try(OutputStream out = Files.newOutputStream(getPlaylistPath()))
try(OutputStream out = Files.newOutputStream(files.getPlaylist()))
{
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
@@ -307,18 +234,20 @@ public class PlaylistManager implements ChannelEventListener
out.flush();
//Remove the playlist lock file to indicate that we successfully saved the file
if(Files.exists(getPlaylistLockPath()))
if(Files.exists(files.getPlaylistLock()))
{
Files.delete(getPlaylistLockPath());
Files.delete(files.getPlaylistLock());
}
mUserPreferences.getFilePreferences().setPlaylistLastAccessedPath(files.getPlaylist());
}
catch(IOException ioe)
{
mLog.error("IO error while writing the playlist to a file [" + getPlaylistPath().toString() + "]", ioe);
mLog.error("IO error while writing the playlist to a file [" + files.getPlaylist().toString() + "]", ioe);
}
catch(Exception e)
{
mLog.error("Error while saving playlist [" + getPlaylistPath().toString() + "]", e);
mLog.error("Error while saving playlist [" + files.getPlaylist().toString() + "]", e);
}
}
@@ -327,26 +256,28 @@ public class PlaylistManager implements ChannelEventListener
*/
public PlaylistV2 load()
{
mLog.info("Attempting to load version 2 playlist file [" + getPlaylistPath().toString() + "]");
FilePreferences files = mUserPreferences.getFilePreferences();
PlaylistV2 playlist = null;
//Check for a lock file that indicates the previous save attempt was incomplete or had an error
if(Files.exists(getPlaylistLockPath()))
if(Files.exists(files.getPlaylistLock()))
{
mLog.info("Previous playlist save was incomplete -- restoring from backup file (if possible)");
try
{
//Remove the previous playlist
Files.delete(getPlaylistPath());
Files.delete(files.getPlaylist());
//Copy the backup file to restore the previous playlist
if(Files.exists(getPlaylistBackupPath()))
if(Files.exists(files.getPlaylistBackup()))
{
Files.copy(getPlaylistBackupPath(), getPlaylistPath());
Files.copy(files.getPlaylistBackup(), files.getPlaylist());
}
//Remove the lock file
Files.delete(getPlaylistLockPath());
Files.delete(files.getPlaylistLock());
}
catch(IOException ioe)
{
@@ -355,13 +286,15 @@ public class PlaylistManager implements ChannelEventListener
}
}
if(Files.exists(getPlaylistPath()))
if(Files.exists(files.getPlaylist()))
{
mLog.info("Loading playlist file [" + files.getPlaylist().toString() + "]");
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
ObjectMapper objectMapper = new XmlMapper(xmlModule);
try(InputStream in = Files.newInputStream(getPlaylistPath()))
try(InputStream in = Files.newInputStream(files.getPlaylist()))
{
playlist = objectMapper.readValue(in, PlaylistV2.class);
}
@@ -370,9 +303,39 @@ public class PlaylistManager implements ChannelEventListener
mLog.error("IO error while reading playlist file", ioe);
}
}
else if(Files.exists(files.getLegacyPlaylist()))
{
mLog.info("Loading legacy playlist file [" + files.getLegacyPlaylist().toString() + "]");
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
ObjectMapper objectMapper = new XmlMapper(xmlModule);
try(InputStream in = Files.newInputStream(files.getLegacyPlaylist()))
{
playlist = objectMapper.readValue(in, PlaylistV2.class);
//Perform any updates that may be needed for the playist.
if(PlaylistUpdater.update(playlist))
{
mLog.info("Legacy playlist was updated to version [" + PLAYLIST_CURRENT_VERSION + "] - saving");
schedulePlaylistSave();
}
}
catch(IOException ioe)
{
mLog.error("IO error while reading playlist file", ioe);
}
}
else
{
mLog.info("PlaylistManager - playlist not found at [" + getPlaylistPath().toString() + "]");
mLog.info("PlaylistManager - playlist not found at [" + files.getPlaylist().toString() + "] - creating new (empty) playlist");
}
if(playlist == null)
{
playlist = new PlaylistV2();
schedulePlaylistSave();
}
return playlist;

View File

@@ -0,0 +1,452 @@
/*
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2018 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.playlist;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.id.AliasID;
import io.github.dsheirer.alias.id.AliasIDType;
import io.github.dsheirer.alias.id.legacy.fleetsync.FleetsyncID;
import io.github.dsheirer.alias.id.legacy.mdc.MDC1200ID;
import io.github.dsheirer.alias.id.legacy.mpt1327.MPT1327ID;
import io.github.dsheirer.alias.id.legacy.talkgroup.LegacyTalkgroupID;
import io.github.dsheirer.alias.id.mobileID.Min;
import io.github.dsheirer.alias.id.talkgroup.Talkgroup;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.module.log.EventLogType;
import io.github.dsheirer.module.log.config.EventLogConfiguration;
import io.github.dsheirer.protocol.Protocol;
import io.github.dsheirer.record.RecorderType;
import io.github.dsheirer.record.config.RecordConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Playlist updater will automatically update a playlist from version 1 up to the current version specified by the
* Playlist manager
*/
public class PlaylistUpdater
{
private final static Logger mLog = LoggerFactory.getLogger(PlaylistUpdater.class);
private static final String APCO25_RADIO_ID = "[A-Fa-f\\d\\*]{6}";
private static final String APCO25_TALKGROUP = "[A-Fa-f\\d\\*]{4}";
private static final String FLEETSYNC_TALKGROUP = "(\\d{3})-(\\d{4})";
private static final String LTR_TALKGROUP = "([\\d\\*]{1})-([\\d\\*]{2})-([\\d\\*]{3})";
private static final String LTR_TALKGROUP_WILDCARD = "\\*-\\*{2}-([\\d]{3})";
private static final String MDC1200_TALKGROUP = "[A-Fa-f\\d\\*]{4}";
private static final String MOBILE_ID_NUMBER = "[A-Fa-f\\d\\*]{6}";
private static final String MPT1327_TALKGROUP = "(\\d{3})-(\\d{4})";
private static final String PASSPORT_TALKGROUP = "[\\d\\*]{5}";
private static final Pattern FLEETSYNC_PATTERN = Pattern.compile(FLEETSYNC_TALKGROUP);
private static final Pattern LTR_PATTERN = Pattern.compile(LTR_TALKGROUP);
private static final Pattern MPT1327_PATTERN = Pattern.compile(MPT1327_TALKGROUP);
/**
* Updates the playlist as necessary.
*
* @param playlist to update
* @return true if the playlist was updated
*/
public static boolean update(PlaylistV2 playlist)
{
boolean updated = false;
switch(playlist.getVersion())
{
case 1:
mLog.info("Updating playlist from version [1] to version [" + PlaylistManager.PLAYLIST_CURRENT_VERSION + "]");
removeVersion1AudioRecordType(playlist);
removeVersion1BinaryMessageLogger(playlist);
removeVersion1NonRecordableAliasIdentifiers(playlist);
updateVersion1Talkgroups(playlist);
updated = true;
break;
}
return updated;
}
/**
* Removes version 1 AUDIO record type from the record configuration
*/
private static void removeVersion1AudioRecordType(PlaylistV2 playlist)
{
int removed = 0;
for(Channel channel : playlist.getChannels())
{
RecordConfiguration recordConfiguration = channel.getRecordConfiguration();
if(recordConfiguration.contains(RecorderType.AUDIO))
{
Iterator<RecorderType> it = recordConfiguration.getRecorders().iterator();
while(it.hasNext())
{
if(it.next() == RecorderType.AUDIO)
{
it.remove();
removed++;
}
}
}
}
if(removed > 0)
{
mLog.info("Removed audio-record setting from [" + removed + "] channels. Audio recording is now a setting for each individual alias");
}
}
/**
* Removes version 1 BINARY message event logger
*/
private static void removeVersion1BinaryMessageLogger(PlaylistV2 playlist)
{
int removed = 0;
for(Channel channel : playlist.getChannels())
{
EventLogConfiguration eventLogConfiguration = channel.getEventLogConfiguration();
if(eventLogConfiguration.getLoggers().contains(EventLogType.BINARY_MESSAGE))
{
Iterator<EventLogType> it = eventLogConfiguration.getLoggers().iterator();
while(it.hasNext())
{
if(it.next() == EventLogType.BINARY_MESSAGE)
{
it.remove();
removed++;
}
}
}
}
if(removed > 0)
{
mLog.info("Removed binary message event logging from [" + removed +
"] channels. Use demodulated bitstream recorder instead");
}
}
/**
* Removes non-recordable alias identifiers from all aliases. These have been replaced with the 'Record' alias
* identifier.
*/
private static void removeVersion1NonRecordableAliasIdentifiers(PlaylistV2 playlist)
{
int removed = 0;
for(Alias alias : playlist.getAliases())
{
Iterator<AliasID> it = alias.getId().iterator();
while(it.hasNext())
{
if(it.next().getType() == AliasIDType.NON_RECORDABLE)
{
it.remove();
removed++;
}
}
}
if(removed > 0)
{
mLog.info("Removed [" + removed + "] non-recordable alias identifiers from aliases");
}
}
/**
* Converts legacy version 1talkgroups to the new talkgroup format. Previously, each protocol had a talkgroup
* flavor and now there is a generic talkgroup identifier with a protocol specifier.
*
* @param playlist to update
*/
private static void updateVersion1Talkgroups(PlaylistV2 playlist)
{
int updated = 0;
int notUpdated = 0;
AliasID next = null;
List<AliasID> toAdd = new ArrayList<>();
for(Alias alias : playlist.getAliases())
{
Iterator<AliasID> it = alias.getId().iterator();
while(it.hasNext())
{
next = it.next();
switch(next.getType())
{
case LEGACY_TALKGROUP:
LegacyTalkgroupID legacyTalkgroupId = (LegacyTalkgroupID)next;
String talkgroup = legacyTalkgroupId.getTalkgroup();
if(talkgroup != null)
{
if(talkgroup.matches(APCO25_TALKGROUP) || talkgroup.matches(APCO25_RADIO_ID))
{
if(talkgroup.contains("*"))
{
notUpdated++;
}
else
{
try
{
Integer value = Integer.parseInt(talkgroup, 16);
it.remove();
toAdd.add(new Talkgroup(Protocol.APCO25, value));
updated++;
}
catch(Exception e)
{
//Unable to parse integer value from talkgroup .. do nothing
notUpdated++;
}
}
}
else if(talkgroup.matches(LTR_TALKGROUP))
{
if(talkgroup.contains("*"))
{
if(talkgroup.matches(LTR_TALKGROUP_WILDCARD))
{
try
{
Integer group = Integer.parseInt(talkgroup.substring(5));
for(int area = 0; area <= 1; area++)
{
for(int channel = 1; channel <= 20; channel++)
{
int value = (area << 13) + (channel << 8) + group;
toAdd.add(new Talkgroup(Protocol.LTR, value));
mLog.debug("LTR Talkgroup [" + talkgroup + "] updated to [" + value + "]");
}
}
it.remove();
updated++;
}
catch(Exception e)
{
notUpdated++;
}
}
else
{
notUpdated++;
}
}
else
{
try
{
Matcher m = LTR_PATTERN.matcher(talkgroup);
if(m.matches())
{
int value = Integer.valueOf(m.group(3));
value += (Integer.valueOf(m.group(2)) << 8);
value += (Integer.valueOf(m.group(1)) << 13);
toAdd.add(new Talkgroup(Protocol.LTR, value));
it.remove();
updated++;
}
}
catch(Exception e)
{
notUpdated++;
}
}
}
else if(talkgroup.matches(PASSPORT_TALKGROUP))
{
if(talkgroup.contains("*"))
{
notUpdated++;
}
else
{
try
{
Integer value = Integer.parseInt(talkgroup);
it.remove();
toAdd.add(new Talkgroup(Protocol.PASSPORT, value));
updated++;
}
catch(Exception e)
{
//Unable to parse integer value from talkgroup .. do nothing
notUpdated++;
}
}
}
}
else
{
//Throw away any legacy talkgroup identifiers with a null value
it.remove();
}
break;
case FLEETSYNC:
String fleetsync = ((FleetsyncID)next).getIdent();
try
{
Matcher matcher = FLEETSYNC_PATTERN.matcher(fleetsync);
if(matcher.matches())
{
int value = Integer.valueOf(matcher.group(2));
value += (Integer.valueOf(matcher.group(1)) << 12);
toAdd.add(new Talkgroup(Protocol.FLEETSYNC, value));
it.remove();
updated++;
}
else
{
notUpdated++;
}
}
catch(Exception e)
{
notUpdated++;
}
break;
case MDC1200:
String mdc = ((MDC1200ID)next).getIdent();
if(mdc != null && mdc.matches(MDC1200_TALKGROUP))
{
try
{
int mdcValue = Integer.parseInt(mdc, 16);
toAdd.add(new Talkgroup(Protocol.MDC1200, mdcValue));
it.remove();
updated++;
}
catch(Exception e)
{
notUpdated++;
}
}
else
{
notUpdated++;
}
break;
case MPT1327:
String mpt = ((MPT1327ID)next).getIdent();
if(mpt != null && mpt.matches(MPT1327_TALKGROUP))
{
try
{
Matcher matcher = MPT1327_PATTERN.matcher(mpt);
if(matcher.matches())
{
int value = Integer.valueOf(matcher.group(2));
value += (Integer.valueOf(matcher.group(1)) << 13);
toAdd.add(new Talkgroup(Protocol.MPT1327, value));
it.remove();
updated++;
mLog.debug("MPT-1327 Talkgroup [" + mpt + "] updated to [" + value + "]");
}
else
{
notUpdated++;
}
}
catch(Exception e)
{
notUpdated++;
}
}
break;
case MIN:
String min = ((Min)next).getMin();
if(min.matches(MOBILE_ID_NUMBER))
{
if(min.contains("*"))
{
notUpdated++;
}
else
{
try
{
Integer value = Integer.parseInt(min, 16);
it.remove();
toAdd.add(new Talkgroup(Protocol.PASSPORT, value));
updated++;
}
catch(Exception e)
{
//Unable to parse integer value from talkgroup .. do nothing
notUpdated++;
}
}
}
break;
}
}
//Add any alias identifiers that were converted. We have to do this here in order
//to avoid concurrent modification errors on the alias id list.
for(AliasID aliasID : toAdd)
{
alias.addAliasID(aliasID);
}
toAdd.clear();
}
if(updated > 0)
{
mLog.info("Updated [" + updated + "] legacy talkgroup identifiers to new talkgroup format");
}
if(notUpdated > 0)
{
mLog.info("Unable to update [" + notUpdated + "] legacy talkgroup identifiers - please edit and convert to new talkgroup format");
}
}
}

View File

@@ -30,6 +30,7 @@ import java.util.List;
@JacksonXmlRootElement(localName = "playlist")
public class PlaylistV2
{
private int mVersion = 1;
private List<Alias> mAliases = new ArrayList<>();
private List<BroadcastConfiguration> mBroadcastConfigurations = new ArrayList<>();
private List<Channel> mChannels = new ArrayList<>();
@@ -39,6 +40,23 @@ public class PlaylistV2
{
}
/**
* Version number for this playlist
*/
@JacksonXmlProperty(isAttribute = true, localName = "version")
public int getVersion()
{
return mVersion;
}
/**
* Sets the version for this playlist.
*/
public void setVersion(int version)
{
mVersion = version;
}
@JacksonXmlProperty(isAttribute = false, localName = "alias")
public List<Alias> getAliases()
{