mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
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:
52
src/main/java/io/github/dsheirer/preference/Preference.java
Normal file
52
src/main/java/io/github/dsheirer/preference/Preference.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
/**
|
||||
* Preference base class with support for broadcasting preference changes
|
||||
*/
|
||||
public abstract class Preference
|
||||
{
|
||||
private Listener<PreferenceType> mPreferenceUpdateListener;
|
||||
|
||||
public Preference(Listener<PreferenceType> updateListener)
|
||||
{
|
||||
mPreferenceUpdateListener = updateListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates which type of preference for this class
|
||||
*/
|
||||
public abstract PreferenceType getPreferenceType();
|
||||
|
||||
/**
|
||||
* Notifies any registered listeners that a preference has been updated
|
||||
*/
|
||||
public void notifyPreferenceUpdated()
|
||||
{
|
||||
if(mPreferenceUpdateListener != null)
|
||||
{
|
||||
mPreferenceUpdateListener.receive(getPreferenceType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference;
|
||||
|
||||
/**
|
||||
* Types of preferences
|
||||
*/
|
||||
public enum PreferenceType
|
||||
{
|
||||
DECODE_EVENT,
|
||||
IDENTIFIER,
|
||||
FILES;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Timestamp formats
|
||||
*/
|
||||
public enum TimestampFormat
|
||||
{
|
||||
TIMESTAMP_DEFAULT("yyyy-MM-dd HH:mm:ss", "Timestamp: yyyy-MM-dd HH:mm:ss"),
|
||||
TIMESTAMP_COLONS("yyyy:MM:dd:HH:mm:ss", "Timestamp Colons: yyyy:MM:dd:HH:mm:ss"),
|
||||
TIMESTAMP_MILLIS("yyyy:MM:dd:HH:mm:ss.SSS", "Timestamp Milliseconds: yyyy:MM:dd:HH:mm:ss.SSS"),
|
||||
TIMESTAMP_COMPACT("yyyyMMddHHmmss", "Timestamp Compact: yyyyMMddHHmmss"),
|
||||
DATE_DASHES("yyyy-MM-dd", "Date Dashes: YYYY-MM-DD"),
|
||||
DATE_COLONS("yyyy:MM:dd", "Date Colons: YYYY:MM:DD"),
|
||||
DATE_COMPACT("yyyyMMdd", "Date Compact: YYYYMMDD"),
|
||||
TIME_COMPACT("HHmmss", "Time Compact: HHmmss"),
|
||||
TIME_COLONS("HH:mm:ss", "Time Colons: HH:mm:ss"),
|
||||
TIME_MILLIS("HH:mm:ss.SSS", "Time Milliseconds: HH:mm:ss.SSS"),
|
||||
TIME_SECONDS("ss.SSS", "Time Seconds: ss.SSS"),
|
||||
;
|
||||
|
||||
private String mFormat;
|
||||
private String mLabel;
|
||||
|
||||
/**
|
||||
* Constructs a timestamp format
|
||||
* @param format for the timestamp
|
||||
* @param label to describe the format
|
||||
*/
|
||||
TimestampFormat(String format, String label)
|
||||
{
|
||||
mFormat = format;
|
||||
mLabel = label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format string for the timestamp format
|
||||
*/
|
||||
public String getFormat()
|
||||
{
|
||||
return mFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Simple Date Formatter to use format string.
|
||||
*/
|
||||
public SimpleDateFormat getFormatter()
|
||||
{
|
||||
return new SimpleDateFormat(mFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the toString() with a descriptive label
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference;
|
||||
|
||||
import io.github.dsheirer.eventbus.MyEventBus;
|
||||
import io.github.dsheirer.preference.event.DecodeEventPreference;
|
||||
import io.github.dsheirer.preference.identifier.TalkgroupFormatPreference;
|
||||
import io.github.dsheirer.preference.playlist.FilePreferences;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
|
||||
/**
|
||||
* User Preferences. A collection of preferences that can be accessed by preference type.
|
||||
*/
|
||||
public class UserPreferences implements Listener<PreferenceType>
|
||||
{
|
||||
private DecodeEventPreference mDecodeEventPreference;
|
||||
private FilePreferences mFilePreferences;
|
||||
private TalkgroupFormatPreference mTalkgroupFormatPreference;
|
||||
|
||||
/**
|
||||
* Constructs a new user preferences instance
|
||||
*/
|
||||
public UserPreferences()
|
||||
{
|
||||
loadPreferenceTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Event preferences
|
||||
*/
|
||||
public DecodeEventPreference getDecodeEventPreference()
|
||||
{
|
||||
return mDecodeEventPreference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Playlist preferences
|
||||
*/
|
||||
public FilePreferences getFilePreferences()
|
||||
{
|
||||
return mFilePreferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier preferences
|
||||
*/
|
||||
public TalkgroupFormatPreference getTalkgroupFormatPreference()
|
||||
{
|
||||
return mTalkgroupFormatPreference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the managed preferences
|
||||
*/
|
||||
private void loadPreferenceTypes()
|
||||
{
|
||||
mDecodeEventPreference = new DecodeEventPreference(this);
|
||||
mFilePreferences = new FilePreferences(this::receive);
|
||||
mTalkgroupFormatPreference = new TalkgroupFormatPreference(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Primary method for receiving notification from a managed preference that a preference type
|
||||
* has been changed/updated.
|
||||
*
|
||||
* @param preferenceType that is updated
|
||||
*/
|
||||
@Override
|
||||
public void receive(PreferenceType preferenceType)
|
||||
{
|
||||
MyEventBus.getEventBus().post(preferenceType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.event;
|
||||
|
||||
import io.github.dsheirer.preference.Preference;
|
||||
import io.github.dsheirer.preference.PreferenceType;
|
||||
import io.github.dsheirer.preference.TimestampFormat;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* User preferences for the display of channel decode events
|
||||
*/
|
||||
public class DecodeEventPreference extends Preference
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(DecodeEventPreference.class);
|
||||
private Preferences mPreferences = Preferences.userNodeForPackage(DecodeEventPreference.class);
|
||||
private TimestampFormat mTimestampFormat = TimestampFormat.TIMESTAMP_DEFAULT;
|
||||
private static final String TIMESTAMP_FORMAT_KEY = "timestamp.format";
|
||||
|
||||
public DecodeEventPreference(Listener<PreferenceType> updateListener)
|
||||
{
|
||||
super(updateListener);
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceType getPreferenceType()
|
||||
{
|
||||
return PreferenceType.DECODE_EVENT;
|
||||
}
|
||||
|
||||
private void loadSettings()
|
||||
{
|
||||
String format = mPreferences.get(TIMESTAMP_FORMAT_KEY, TimestampFormat.TIMESTAMP_COLONS.name());
|
||||
|
||||
if(format != null && !format.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
mTimestampFormat = TimestampFormat.valueOf(format);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Error loading decode event timestamp format [" + format + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamp format to use for decode event timestamps
|
||||
*/
|
||||
public TimestampFormat getTimestampFormat()
|
||||
{
|
||||
return mTimestampFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the timestamp format preference
|
||||
*
|
||||
* @param timestampFormat
|
||||
*/
|
||||
public void setTimestampFormat(TimestampFormat timestampFormat)
|
||||
{
|
||||
mTimestampFormat = timestampFormat;
|
||||
mPreferences.put(TIMESTAMP_FORMAT_KEY, mTimestampFormat.name());
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier;
|
||||
|
||||
/**
|
||||
* Options for formatting of integer values.
|
||||
*/
|
||||
public enum IntegerFormat
|
||||
{
|
||||
DECIMAL("Decimal"),
|
||||
FORMATTED("Formatted"),
|
||||
HEXADECIMAL("Hexadecimal");
|
||||
|
||||
private String mLabel;
|
||||
|
||||
IntegerFormat(String label)
|
||||
{
|
||||
mLabel = label;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier;
|
||||
|
||||
import io.github.dsheirer.identifier.Identifier;
|
||||
import io.github.dsheirer.identifier.patch.PatchGroupIdentifier;
|
||||
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
|
||||
import io.github.dsheirer.preference.Preference;
|
||||
import io.github.dsheirer.preference.PreferenceType;
|
||||
import io.github.dsheirer.preference.identifier.talkgroup.APCO25TalkgroupFormatter;
|
||||
import io.github.dsheirer.preference.identifier.talkgroup.FleetsyncTalkgroupFormatter;
|
||||
import io.github.dsheirer.preference.identifier.talkgroup.LtrNetTalkgroupFormatter;
|
||||
import io.github.dsheirer.preference.identifier.talkgroup.MPT1327TalkgroupFormatter;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* Specifies and applies user preferences for formatting identifiers
|
||||
*/
|
||||
public class TalkgroupFormatPreference extends Preference
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(TalkgroupFormatPreference.class);
|
||||
private Preferences mPreferences = Preferences.userNodeForPackage(TalkgroupFormatPreference.class);
|
||||
|
||||
public static final String TALKGROUP_FORMAT_PROPERTY = "talkgroup.format.";
|
||||
public static final String TALKGROUP_FIXED_WIDTH_PROPERTY = "talkgroup.fixed.width.";
|
||||
|
||||
private Map<Protocol,IntegerFormat> mTalkgroupFormatProtocolMap = new HashMap<>();
|
||||
private Map<Protocol,Boolean> mTalkgroupFixedWidthProtocolMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs an instance of identifier formatting preference.
|
||||
*
|
||||
* @param updateListener to be notified when this preference is updated
|
||||
*/
|
||||
public TalkgroupFormatPreference(Listener<PreferenceType> updateListener)
|
||||
{
|
||||
super(updateListener);
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an identifier
|
||||
*
|
||||
* @param identifier to format
|
||||
* @return formatted string representing the identifier or null if the identifier is null
|
||||
*/
|
||||
public String format(Identifier identifier)
|
||||
{
|
||||
if(identifier == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
switch(identifier.getForm())
|
||||
{
|
||||
case TALKGROUP:
|
||||
if(identifier instanceof TalkgroupIdentifier)
|
||||
{
|
||||
return formatTalkgroupIdentifier((TalkgroupIdentifier)identifier);
|
||||
}
|
||||
break;
|
||||
case PATCH_GROUP:
|
||||
if(identifier instanceof PatchGroupIdentifier)
|
||||
{
|
||||
return formatPatchGroupIdentifier((PatchGroupIdentifier)identifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return identifier.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceType getPreferenceType()
|
||||
{
|
||||
return PreferenceType.IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads persisted properties on startup
|
||||
*/
|
||||
private void loadProperties()
|
||||
{
|
||||
for(Protocol protocol : Protocol.TALKGROUP_PROTOCOLS)
|
||||
{
|
||||
mTalkgroupFixedWidthProtocolMap.put(protocol, mPreferences.getBoolean(getTalkgroupFixedWidthProperty(protocol),
|
||||
getDefaultFixedWidth(protocol)));
|
||||
|
||||
try
|
||||
{
|
||||
String format = mPreferences.get(getTalkgroupFormatProperty(protocol), getDefaultFormat(protocol).name());
|
||||
mTalkgroupFormatProtocolMap.put(protocol, IntegerFormat.valueOf(format));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//If there is a problem parsing the enum entry, default to DECIMAL
|
||||
mTalkgroupFormatProtocolMap.put(protocol, getDefaultFormat(protocol));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default format for each protocol
|
||||
*/
|
||||
private IntegerFormat getDefaultFormat(Protocol protocol)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case APCO25:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case FLEETSYNC:
|
||||
return IntegerFormat.FORMATTED;
|
||||
case IPV4:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case LOJACK:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case LTR:
|
||||
return IntegerFormat.FORMATTED;
|
||||
case LTR_NET:
|
||||
return IntegerFormat.FORMATTED;
|
||||
case LTR_STANDARD:
|
||||
return IntegerFormat.FORMATTED;
|
||||
case MDC1200:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case MPT1327:
|
||||
return IntegerFormat.FORMATTED;
|
||||
case PASSPORT:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case TAIT1200:
|
||||
return IntegerFormat.DECIMAL;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return IntegerFormat.DECIMAL;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getDefaultFixedWidth(Protocol protocol)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case APCO25:
|
||||
return true;
|
||||
case FLEETSYNC:
|
||||
return true;
|
||||
case IPV4:
|
||||
return true;
|
||||
case LOJACK:
|
||||
return true;
|
||||
case LTR:
|
||||
return true;
|
||||
case LTR_NET:
|
||||
return true;
|
||||
case LTR_STANDARD:
|
||||
return true;
|
||||
case MDC1200:
|
||||
return false;
|
||||
case MPT1327:
|
||||
return true;
|
||||
case PASSPORT:
|
||||
return false;
|
||||
case TAIT1200:
|
||||
return false;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property identifier for talkgroup prepad for a specific protocol
|
||||
*/
|
||||
private String getTalkgroupFixedWidthProperty(Protocol protocol)
|
||||
{
|
||||
return TALKGROUP_FIXED_WIDTH_PROPERTY + protocol.name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Property identifier for talkgroup format for a specific protocol
|
||||
*/
|
||||
private String getTalkgroupFormatProperty(Protocol protocol)
|
||||
{
|
||||
return TALKGROUP_FORMAT_PROPERTY + protocol.name();
|
||||
}
|
||||
|
||||
/**
|
||||
* User preference for formatting talkgroups for the specified protocol
|
||||
*
|
||||
* @param protocol specified
|
||||
* @return format
|
||||
*/
|
||||
public IntegerFormat getTalkgroupFormat(Protocol protocol)
|
||||
{
|
||||
if(mTalkgroupFormatProtocolMap.containsKey(protocol))
|
||||
{
|
||||
return mTalkgroupFormatProtocolMap.get(protocol);
|
||||
}
|
||||
|
||||
return IntegerFormat.DECIMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the formatting for talkgroup identifiers by protocol
|
||||
*
|
||||
* @param protocol for the talkgroup
|
||||
* @param talkgroupFormat
|
||||
*/
|
||||
public void setTalkgroupFormat(Protocol protocol, IntegerFormat talkgroupFormat)
|
||||
{
|
||||
IntegerFormat existing = mTalkgroupFormatProtocolMap.get(protocol);
|
||||
|
||||
if(existing == null || existing != talkgroupFormat)
|
||||
{
|
||||
mTalkgroupFormatProtocolMap.put(protocol, talkgroupFormat);
|
||||
mPreferences.put(getTalkgroupFormatProperty(protocol), talkgroupFormat.name());
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fixed-width for talkgroup identifiers by protocol
|
||||
*
|
||||
* @param protocol for the talkgroup
|
||||
* @param fixedWidth
|
||||
*/
|
||||
public void setTalkgroupFormat(Protocol protocol, boolean fixedWidth)
|
||||
{
|
||||
mTalkgroupFixedWidthProtocolMap.put(protocol, fixedWidth);
|
||||
mPreferences.putBoolean(getTalkgroupFixedWidthProperty(protocol), fixedWidth);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if talkgroups for the specified protocol should be prepadded to a fixed length using '0' padding characters
|
||||
*
|
||||
* @param protocol to prepad
|
||||
* @return true if the talkgroups should be fixed length/prepadded.
|
||||
*/
|
||||
public boolean isTalkgroupFixedWidth(Protocol protocol)
|
||||
{
|
||||
Boolean fixedWidth = mTalkgroupFixedWidthProtocolMap.get(protocol);
|
||||
|
||||
if(fixedWidth == null)
|
||||
{
|
||||
fixedWidth = false;
|
||||
}
|
||||
|
||||
return fixedWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the talkgroup for the specified protocol to the fixed width argument.
|
||||
*
|
||||
* @param protocol to set
|
||||
* @param fixedWidth true for prepadded (0) fixed width values or false for no prepadding.
|
||||
*/
|
||||
public void setTalkgroupFixedWidth(Protocol protocol, boolean fixedWidth)
|
||||
{
|
||||
if(isTalkgroupFixedWidth(protocol) != fixedWidth)
|
||||
{
|
||||
mTalkgroupFixedWidthProtocolMap.put(protocol, fixedWidth);
|
||||
mPreferences.putBoolean(getTalkgroupFixedWidthProperty(protocol), fixedWidth);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the identifier according to user specified preferences for number format and length.
|
||||
*
|
||||
* @param talkgroupIdentifier to format
|
||||
* @return formatted talkgroups
|
||||
*/
|
||||
private String formatTalkgroupIdentifier(TalkgroupIdentifier talkgroupIdentifier)
|
||||
{
|
||||
switch(talkgroupIdentifier.getProtocol())
|
||||
{
|
||||
case APCO25:
|
||||
return APCO25TalkgroupFormatter.format(talkgroupIdentifier, getTalkgroupFormat(Protocol.APCO25),
|
||||
isTalkgroupFixedWidth(Protocol.APCO25));
|
||||
case FLEETSYNC:
|
||||
return FleetsyncTalkgroupFormatter.format(talkgroupIdentifier, getTalkgroupFormat(Protocol.FLEETSYNC),
|
||||
isTalkgroupFixedWidth(Protocol.FLEETSYNC));
|
||||
case LTR_NET:
|
||||
return LtrNetTalkgroupFormatter.format(talkgroupIdentifier, getTalkgroupFormat(Protocol.LTR_NET),
|
||||
isTalkgroupFixedWidth(Protocol.LTR_NET));
|
||||
case MPT1327:
|
||||
return MPT1327TalkgroupFormatter.format(talkgroupIdentifier, getTalkgroupFormat(Protocol.MPT1327),
|
||||
isTalkgroupFixedWidth(Protocol.MPT1327));
|
||||
default:
|
||||
return talkgroupIdentifier.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the identifier according to user specified preferences for number format and length.
|
||||
*
|
||||
* @param patchGroupIdentifier to format
|
||||
* @return formatted talkgroups
|
||||
*/
|
||||
private String formatPatchGroupIdentifier(PatchGroupIdentifier patchGroupIdentifier)
|
||||
{
|
||||
switch(patchGroupIdentifier.getProtocol())
|
||||
{
|
||||
case APCO25:
|
||||
return APCO25TalkgroupFormatter.format(patchGroupIdentifier, getTalkgroupFormat(Protocol.APCO25),
|
||||
isTalkgroupFixedWidth(Protocol.APCO25));
|
||||
default:
|
||||
return patchGroupIdentifier.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier.talkgroup;
|
||||
|
||||
import io.github.dsheirer.identifier.patch.PatchGroup;
|
||||
import io.github.dsheirer.identifier.patch.PatchGroupIdentifier;
|
||||
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
|
||||
import io.github.dsheirer.preference.identifier.IntegerFormat;
|
||||
|
||||
public class APCO25TalkgroupFormatter extends IntegerFormatter
|
||||
{
|
||||
public static final int GROUP_DECIMAL_WIDTH = 5;
|
||||
public static final int UNIT_DECIMAL_WIDTH = 8;
|
||||
public static final int GROUP_HEXADECIMAL_WIDTH = 4;
|
||||
public static final int UNIT_HEXADECIMAL_WIDTH = 6;
|
||||
|
||||
/**
|
||||
* Formats the individual or group identifier to the specified format and width.
|
||||
*/
|
||||
public static String format(TalkgroupIdentifier identifier, IntegerFormat format, boolean fixedWidth)
|
||||
{
|
||||
if(fixedWidth)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return toDecimal(identifier.getValue(),
|
||||
(identifier.isGroup() ? GROUP_DECIMAL_WIDTH : UNIT_DECIMAL_WIDTH));
|
||||
case HEXADECIMAL:
|
||||
return toHex(identifier.getValue(),
|
||||
(identifier.isGroup() ? GROUP_HEXADECIMAL_WIDTH : UNIT_HEXADECIMAL_WIDTH));
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
case FORMATTED:
|
||||
return identifier.getValue().toString();
|
||||
case HEXADECIMAL:
|
||||
return toHex(identifier.getValue());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the patch group to the specified format and width
|
||||
*/
|
||||
public static String format(PatchGroupIdentifier identifier, IntegerFormat format, boolean fixedWidth)
|
||||
{
|
||||
PatchGroup patchGroup = identifier.getValue();
|
||||
|
||||
if(patchGroup != null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("P:");
|
||||
sb.append(format(patchGroup.getPatchGroup(), format, fixedWidth));
|
||||
sb.append("[");
|
||||
|
||||
int counter = 0;
|
||||
for(TalkgroupIdentifier patchedGroup: patchGroup.getPatchedGroupIdentifiers())
|
||||
{
|
||||
sb.append(format(patchedGroup, format, fixedWidth));
|
||||
if(counter++ < patchGroup.getPatchedGroupIdentifiers().size() - 1)
|
||||
{
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return identifier.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier.talkgroup;
|
||||
|
||||
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
|
||||
import io.github.dsheirer.module.decode.fleetsync2.identifier.FleetsyncIdentifier;
|
||||
import io.github.dsheirer.preference.identifier.IntegerFormat;
|
||||
|
||||
/**
|
||||
* Formats Fleetsync 20-bit identifiers into either an integer value or an 8-bit fleet and 12-bit ident
|
||||
*/
|
||||
public class FleetsyncTalkgroupFormatter extends IntegerFormatter
|
||||
{
|
||||
private static final int IDENTIFIER_DECIMAL_WIDTH = 7;
|
||||
private static final int IDENTIFIER_HEXADECIMAL_WIDTH = 5;
|
||||
private static final int FLEET_DECIMAL_WIDTH = 3;
|
||||
private static final int IDENT_DECIMAL_WIDTH = 4;
|
||||
private static final String SEPARATOR = "-";
|
||||
|
||||
/**
|
||||
* Formats the individual or group identifier to the specified format and width.
|
||||
*/
|
||||
public static String format(TalkgroupIdentifier identifier, IntegerFormat format, boolean fixedWidth)
|
||||
{
|
||||
if(identifier instanceof FleetsyncIdentifier)
|
||||
{
|
||||
FleetsyncIdentifier fleetsync = (FleetsyncIdentifier)identifier;
|
||||
|
||||
if(fixedWidth)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return toDecimal(fleetsync.getValue(), IDENTIFIER_DECIMAL_WIDTH);
|
||||
case FORMATTED:
|
||||
return toDecimal(fleetsync.getFleet(), FLEET_DECIMAL_WIDTH) + SEPARATOR +
|
||||
toDecimal(fleetsync.getIdent(), IDENT_DECIMAL_WIDTH);
|
||||
case HEXADECIMAL:
|
||||
return toHex(fleetsync.getValue(), IDENTIFIER_HEXADECIMAL_WIDTH);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return fleetsync.toString();
|
||||
case FORMATTED:
|
||||
return fleetsync.getFleet() + SEPARATOR + fleetsync.getIdent();
|
||||
case HEXADECIMAL:
|
||||
return toHex(identifier.getValue());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return identifier.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier.talkgroup;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Base formatter class for integer values
|
||||
*/
|
||||
public class IntegerFormatter
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(IntegerFormatter.class);
|
||||
|
||||
public static String toHex(int value)
|
||||
{
|
||||
return Integer.toHexString(value).toUpperCase();
|
||||
}
|
||||
|
||||
public static String toHex(int value, int width)
|
||||
{
|
||||
return String.format("%0" + width + "X", value);
|
||||
}
|
||||
|
||||
public static String toDecimal(int value, int width)
|
||||
{
|
||||
return String.format("%0" + width + "d", value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier.talkgroup;
|
||||
|
||||
import io.github.dsheirer.identifier.talkgroup.LTRTalkgroup;
|
||||
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
|
||||
import io.github.dsheirer.preference.identifier.IntegerFormat;
|
||||
|
||||
/**
|
||||
* Formats Fleetsync 20-bit identifiers into either an integer value or an 8-bit fleet and 12-bit ident
|
||||
*/
|
||||
public class LtrNetTalkgroupFormatter extends IntegerFormatter
|
||||
{
|
||||
private static final int IDENTIFIER_DECIMAL_WIDTH = 4;
|
||||
private static final int IDENTIFIER_HEXADECIMAL_WIDTH = 4;
|
||||
private static final int HOME_REPEATER_DECIMAL_WIDTH = 2;
|
||||
private static final int TALKGROUP_DECIMAL_WIDTH = 3;
|
||||
private static final String SEPARATOR = "-";
|
||||
|
||||
/**
|
||||
* Formats the individual or group identifier to the specified format and width.
|
||||
*/
|
||||
public static String format(TalkgroupIdentifier identifier, IntegerFormat format, boolean fixedWidth)
|
||||
{
|
||||
if(identifier instanceof LTRTalkgroup)
|
||||
{
|
||||
LTRTalkgroup ltrnet = (LTRTalkgroup)identifier;
|
||||
|
||||
if(fixedWidth)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return toDecimal(ltrnet.getValue(), IDENTIFIER_DECIMAL_WIDTH);
|
||||
case FORMATTED:
|
||||
return toDecimal(ltrnet.getHomeChannel(), HOME_REPEATER_DECIMAL_WIDTH) + SEPARATOR +
|
||||
toDecimal(ltrnet.getTalkgroup(), TALKGROUP_DECIMAL_WIDTH);
|
||||
case HEXADECIMAL:
|
||||
return toHex(ltrnet.getValue(), IDENTIFIER_HEXADECIMAL_WIDTH);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return ltrnet.toString();
|
||||
case FORMATTED:
|
||||
return ltrnet.getHomeChannel() + SEPARATOR + ltrnet.getTalkgroup();
|
||||
case HEXADECIMAL:
|
||||
return toHex(identifier.getValue());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return identifier.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.identifier.talkgroup;
|
||||
|
||||
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
|
||||
import io.github.dsheirer.module.decode.mpt1327.identifier.MPT1327Talkgroup;
|
||||
import io.github.dsheirer.preference.identifier.IntegerFormat;
|
||||
|
||||
/**
|
||||
* Formats Fleetsync 20-bit identifiers into either an integer value or an 8-bit fleet and 12-bit ident
|
||||
*/
|
||||
public class MPT1327TalkgroupFormatter extends IntegerFormatter
|
||||
{
|
||||
private static final int IDENTIFIER_DECIMAL_WIDTH = 7;
|
||||
private static final int IDENTIFIER_HEXADECIMAL_WIDTH = 5;
|
||||
private static final int FLEET_DECIMAL_WIDTH = 3;
|
||||
private static final int IDENT_DECIMAL_WIDTH = 4;
|
||||
private static final String SEPARATOR = "-";
|
||||
|
||||
/**
|
||||
* Formats the individual or group identifier to the specified format and width.
|
||||
*/
|
||||
public static String format(TalkgroupIdentifier identifier, IntegerFormat format, boolean fixedWidth)
|
||||
{
|
||||
if(identifier instanceof MPT1327Talkgroup)
|
||||
{
|
||||
MPT1327Talkgroup mpt = (MPT1327Talkgroup)identifier;
|
||||
|
||||
if(fixedWidth)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return toDecimal(mpt.getValue(), IDENTIFIER_DECIMAL_WIDTH);
|
||||
case FORMATTED:
|
||||
return toDecimal(mpt.getPrefix(), FLEET_DECIMAL_WIDTH) + SEPARATOR +
|
||||
toDecimal(mpt.getIdent(), IDENT_DECIMAL_WIDTH);
|
||||
case HEXADECIMAL:
|
||||
return toHex(mpt.getValue(), IDENTIFIER_HEXADECIMAL_WIDTH);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DECIMAL:
|
||||
return mpt.toString();
|
||||
case FORMATTED:
|
||||
return mpt.getPrefix() + SEPARATOR + mpt.getIdent();
|
||||
case HEXADECIMAL:
|
||||
return toHex(identifier.getValue());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized integer format: " + format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return identifier.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* 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.preference.playlist;
|
||||
|
||||
import io.github.dsheirer.preference.Preference;
|
||||
import io.github.dsheirer.preference.PreferenceType;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* User preferences for playlists
|
||||
*/
|
||||
public class FilePreferences extends Preference
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(FilePreferences.class);
|
||||
private Preferences mPreferences = Preferences.userNodeForPackage(FilePreferences.class);
|
||||
|
||||
private static final String FOLDER_APPLICATION_ROOT = "SDRTrunk";
|
||||
private static final String FOLDER_PLAYLIST = "playlist";
|
||||
private static final String FILE_PLAYLIST = "default.xml";
|
||||
private static final String FILE_LEGACY_PLAYLIST = "playlist_v2.xml";
|
||||
|
||||
private static final String PREFERENCE_KEY_PLAYLIST_FOLDER = "playlist.folder";
|
||||
private static final String PREFERENCE_KEY_PLAYLIST_LAST_ACCESSED = "playlist.last.accessed";
|
||||
private static final String PREFERENCE_KEY_PLAYLIST_STARTUP = "playlist.default";
|
||||
private static final String PREFERENCE_KEY_PLAYLIST_USE_LAST_ACCESSED = "playlist.use.last.accessed";
|
||||
|
||||
private Path mPlaylistFolder;
|
||||
private Path mPlaylistStartupPath;
|
||||
private Path mPlaylistLastAccessedPath;
|
||||
private Boolean mUsePlaylistLastAccessedByDefault = true;
|
||||
|
||||
/**
|
||||
* Constructs this preference with an update listener
|
||||
* @param updateListener to receive notifications whenever these preferences change
|
||||
*/
|
||||
public FilePreferences(Listener<PreferenceType> updateListener)
|
||||
{
|
||||
super(updateListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceType getPreferenceType()
|
||||
{
|
||||
return PreferenceType.FILES;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Path to the current playlist
|
||||
*/
|
||||
public Path getPlaylist()
|
||||
{
|
||||
if(mUsePlaylistLastAccessedByDefault)
|
||||
{
|
||||
return getPlaylistLastAccessedPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
return getPlaylistStartupPath();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy (version 2) playlist path.
|
||||
*/
|
||||
public Path getLegacyPlaylist()
|
||||
{
|
||||
return getPlaylistFolder().resolve(FILE_LEGACY_PLAYLIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock file for the playlist when updating the file.
|
||||
*/
|
||||
public Path getPlaylistLock()
|
||||
{
|
||||
String playlist = getPlaylist().toAbsolutePath().toString();
|
||||
return Paths.get(playlist + ".lck");
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock file for the playlist when updating the file.
|
||||
*/
|
||||
public Path getPlaylistBackup()
|
||||
{
|
||||
String playlist = getPlaylist().toString();
|
||||
return Paths.get(playlist + ".backup");
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to the playlist to use at startup when 'use last accessed' is set to false.
|
||||
*/
|
||||
public Path getPlaylistStartupPath()
|
||||
{
|
||||
if(mPlaylistStartupPath == null)
|
||||
{
|
||||
mPlaylistStartupPath = getPath(PREFERENCE_KEY_PLAYLIST_STARTUP, getDefaultPlaylistPath());
|
||||
}
|
||||
|
||||
return mPlaylistStartupPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the default playlist
|
||||
*/
|
||||
public void setPlaylistStartupPath(Path path)
|
||||
{
|
||||
mPlaylistStartupPath = path;
|
||||
mPreferences.put(PREFERENCE_KEY_PLAYLIST_STARTUP, path.toString());
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Path for the last accesssed playlist
|
||||
*/
|
||||
public Path getPlaylistLastAccessedPath()
|
||||
{
|
||||
if(mPlaylistLastAccessedPath == null)
|
||||
{
|
||||
mPlaylistLastAccessedPath = getPath(PREFERENCE_KEY_PLAYLIST_LAST_ACCESSED, getDefaultPlaylistPath());
|
||||
}
|
||||
|
||||
return mPlaylistLastAccessedPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the last accessed playlist
|
||||
*/
|
||||
public void setPlaylistLastAccessedPath(Path path)
|
||||
{
|
||||
mPlaylistLastAccessedPath = path;
|
||||
mPreferences.put(PREFERENCE_KEY_PLAYLIST_LAST_ACCESSED, path.toString());
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to the folder for storing playlist
|
||||
*/
|
||||
public Path getPlaylistFolder()
|
||||
{
|
||||
if(mPlaylistFolder == null)
|
||||
{
|
||||
mPlaylistFolder = getPath(PREFERENCE_KEY_PLAYLIST_FOLDER, getDefaultPlaylistFolder());
|
||||
}
|
||||
|
||||
return mPlaylistFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the playlist folder
|
||||
*/
|
||||
public void setPlaylistFolder(Path path)
|
||||
{
|
||||
mPlaylistFolder = path;
|
||||
mPreferences.put(PREFERENCE_KEY_PLAYLIST_FOLDER, path.toString());
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the playlist to load on startup, either the last accessed playlist (true) or the default playlist (false).
|
||||
*/
|
||||
public boolean usePlaylistLastAccessedByDefault()
|
||||
{
|
||||
if(mUsePlaylistLastAccessedByDefault == null)
|
||||
{
|
||||
mUsePlaylistLastAccessedByDefault = mPreferences.getBoolean(PREFERENCE_KEY_PLAYLIST_USE_LAST_ACCESSED, true);
|
||||
}
|
||||
|
||||
return mUsePlaylistLastAccessedByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets using the last accessed playlist by default (true) or the default playlist (false).
|
||||
*/
|
||||
public void setUsePlaylistLastAccessedByDefault(boolean useLastAccessed)
|
||||
{
|
||||
mUsePlaylistLastAccessedByDefault = useLastAccessed;
|
||||
mPreferences.putBoolean(PREFERENCE_KEY_PLAYLIST_USE_LAST_ACCESSED, useLastAccessed);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default application root path
|
||||
*/
|
||||
private Path getDefaultApplicationFolder()
|
||||
{
|
||||
Path defaultApplicationPath = Paths.get(System.getProperty("user.home"), FOLDER_APPLICATION_ROOT);
|
||||
createDirectory(defaultApplicationPath);
|
||||
return defaultApplicationPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default playlist folder
|
||||
*/
|
||||
public Path getDefaultPlaylistFolder()
|
||||
{
|
||||
Path defaultPlaylistFolder = getDefaultApplicationFolder().resolve(FOLDER_PLAYLIST);
|
||||
createDirectory(defaultPlaylistFolder);
|
||||
return defaultPlaylistFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default playlist
|
||||
*/
|
||||
private Path getDefaultPlaylistPath()
|
||||
{
|
||||
return getDefaultPlaylistFolder().resolve(FILE_PLAYLIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path stored in preferences and referenced by the key argument if it exists, otherwise returns the
|
||||
* default path.
|
||||
*
|
||||
* Note: the default path is not checked for existence.
|
||||
*
|
||||
* @param key to the preferences service for the path
|
||||
* @param defaultPath to use if the preferred path does not exist
|
||||
* @return requested path
|
||||
*/
|
||||
private Path getPath(String key, Path defaultPath)
|
||||
{
|
||||
String stringPath = mPreferences.get(PREFERENCE_KEY_PLAYLIST_STARTUP, defaultPath.toString());
|
||||
|
||||
if(stringPath != null && !stringPath.isEmpty())
|
||||
{
|
||||
Path temp = Paths.get(stringPath);
|
||||
if(Files.exists(temp))
|
||||
{
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a directory if it does not already exist
|
||||
*/
|
||||
private void createDirectory(Path directory)
|
||||
{
|
||||
if(!Files.exists(directory) && Files.isDirectory(directory))
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.createDirectory(directory);
|
||||
mLog.info("Created directory [" + directory.toString() + "]");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Error creating directory [" + directory.toString() + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user