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

@@ -55,7 +55,7 @@ public class BerlekempMassey_63
private static final int NN = 63;
/* Hamming distance between codewords: NN - KK + 1 = 2 * TT + 1 */
private static int KK;
private int KK;
/* Maximum number of errors that can be corrected */
int TT;
@@ -222,7 +222,7 @@ public class BerlekempMassey_63
/* put recd[i] into index form (ie as powers of alpha) */
for( int i = 0; i < NN; i++ )
{
output[ i ] = index_of[ input[ i ] ];
output[ i ] = index_of[ input[ i ] ];
}
/* first form the syndromes */

View File

@@ -1,73 +1,82 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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/>
******************************************************************************/
/*
* ******************************************************************************
* 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.edac;
public enum CRC
{
PASSED ( "*", "PASS" ),
PASSED_INV ( "#", "PASS INVERTED" ),
FAILED_CRC ( "f", "FAIL CRC" ),
FAILED_PARITY( "p", "FAIL PARITY" ),
CORRECTED ( "C", "CORRECTED" ),
UNKNOWN ( "-", "UNKNOWN");
PASSED("*", "PASS", true),
PASSED_INV("#", "PASS INVERTED", true),
FAILED_CRC("f", "FAIL CRC", false),
FAILED_PARITY("p", "FAIL PARITY", false),
CORRECTED("C", "CORRECTED", true),
UNKNOWN("-", "UNKNOWN", false);
private String mAbbreviation;
private String mDisplayText;
CRC( String abbreviation, String displayText )
{
mAbbreviation = abbreviation;
mDisplayText = displayText;
}
public String getAbbreviation()
{
return mAbbreviation;
}
public String getDisplayText()
{
return mDisplayText;
}
private String mAbbreviation;
private String mDisplayText;
private boolean mPass;
public static String format( CRC[] checks )
{
if( checks == null )
{
return CRC.UNKNOWN.getAbbreviation();
}
StringBuilder sb = new StringBuilder();
for( int x = 0; x < checks.length; x++ )
{
CRC check = checks[ x ];
if( check != null )
{
sb.append( check.getAbbreviation() );
}
else
{
sb.append( CRC.UNKNOWN.getAbbreviation() );
}
}
return sb.toString();
}
CRC(String abbreviation, String displayText, boolean pass)
{
mAbbreviation = abbreviation;
mDisplayText = displayText;
mPass = pass;
}
public String getAbbreviation()
{
return mAbbreviation;
}
public String getDisplayText()
{
return mDisplayText;
}
public boolean passes()
{
return mPass;
}
public static String format(CRC[] checks)
{
if(checks == null)
{
return CRC.UNKNOWN.getAbbreviation();
}
StringBuilder sb = new StringBuilder();
for(int x = 0; x < checks.length; x++)
{
CRC check = checks[x];
if(check != null)
{
sb.append(check.getAbbreviation());
}
else
{
sb.append(CRC.UNKNOWN.getAbbreviation());
}
}
return sb.toString();
}
}

View File

@@ -1,23 +1,22 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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/>
* sdr-trunk
* 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.edac;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,445 +25,485 @@ import org.slf4j.LoggerFactory;
*/
public class CRCP25
{
private final static Logger mLog = LoggerFactory.getLogger( CRCP25.class );
/**
* CRC-CCITT 16-bit checksums for a message length of 80 bits plus 16
* additional checksums representing CRC checksum bit errors
*
* Generated by:
* CRCUtil.generate( 80, 16, 0x11021l, 0xFFFFl, true );
*/
public static final int[] CCITT_80_CHECKSUMS = new int[]
{
0x1BCB, 0x8DE5, 0xC6F2, 0x6B69, 0xB5B4, 0x52CA, 0x2175, 0x90BA, 0x404D,
0xA026, 0x5803, 0xAC01, 0xD600, 0x6310, 0x3998, 0x14DC, 0x27E, 0x92F,
0x8497, 0xC24B, 0xE125, 0xF092, 0x7059, 0xB82C, 0x5406, 0x2213, 0x9109,
0xC884, 0x6C52, 0x3E39, 0x9F1C, 0x479E, 0x2BDF, 0x95EF, 0xCAF7, 0xE57B,
0xF2BD, 0xF95E, 0x74BF, 0xBA5F, 0xDD2F, 0xEE97, 0xF74B, 0xFBA5, 0xFDD2,
0x76F9, 0xBB7C, 0x55AE, 0x22C7, 0x9163, 0xC8B1, 0xE458, 0x7A3C, 0x350E,
0x1297, 0x894B, 0xC4A5, 0xE252, 0x7939, 0xBC9C, 0x565E, 0x233F, 0x919F,
0xC8CF, 0xE467, 0xF233, 0xF919, 0xFC8C, 0x7656, 0x333B, 0x999D, 0xCCCE,
0x6E77, 0xB73B, 0xDB9D, 0xEDCE, 0x7EF7, 0xBF7B, 0xDFBD, 0xEFDE, 0x0001,
0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200,
0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
};
/**
* Confirmed Packet Data Unit CRC-9 checksums, generated by:
*
* long[] table = generate( 135, 9, 0x259l, 0x1FF, false, Parity.NONE );
*/
public static final int[] CRC9_CHECKSUMS = new int[]
{
0x1E7, 0x1F3, 0x1F9, 0x1FC, 0x0D2, 0x045, 0x122, 0x0BD, 0x15E, 0x083,
0x141, 0x1A0, 0x0FC, 0x052, 0x005, 0x102, 0x0AD, 0x156, 0x087, 0x143,
0x1A1, 0x1D0, 0x0C4, 0x04E, 0x00B, 0x105, 0x182, 0x0ED, 0x176, 0x097,
0x14B, 0x1A5, 0x1D2, 0x0C5, 0x162, 0x09D, 0x14E, 0x08B, 0x145, 0x1A2,
0x0FD, 0x17E, 0x093, 0x149, 0x1A4, 0x0FE, 0x053, 0x129, 0x194, 0x0E6,
0x05F, 0x12F, 0x197, 0x1CB, 0x1E5, 0x1F2, 0x0D5, 0x16A, 0x099, 0x14C,
0x08A, 0x069, 0x134, 0x0B6, 0x077, 0x13B, 0x19D, 0x1CE, 0x0CB, 0x165,
0x1B2, 0x0F5, 0x17A, 0x091, 0x148, 0x088, 0x068, 0x018, 0x020, 0x03C,
0x302, 0x035, 0x11A, 0x0A1, 0x150, 0x084, 0x06E, 0x01B, 0x10D, 0x186,
0x0EF, 0x177, 0x1BB, 0x1DD, 0x1EE, 0x0DB, 0x16D, 0x1B6, 0x0F7, 0x17B,
0x1BD, 0x1DE, 0x0C3, 0x161, 0x1B0, 0x0F4, 0x056, 0x007, 0x103, 0x181,
0x1C0, 0x0CC, 0x04A, 0x009, 0x104, 0x0AE, 0x07B, 0x13D, 0x19E, 0x0E3,
0x171, 0x1B8, 0x0F0, 0x054, 0x006, 0x02F, 0x117, 0x18B, 0x1C5, 0x1E2,
0x0DD, 0x16E, 0x09B, 0x14D, 0x1A6
};
/**
* CRC-32 checksums for PDU1 ( HEADER + 1 Block ) messages, generated by:
*
* CRCUtil.generate( 64, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU1_CHECKSUMS = new long[]
{
0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl, 0x52275834l, 0x2B7322C1l,
0x95B99160l, 0x48BC466Bl, 0xA45E2335l, 0xD22F119Al, 0x6B770616l,
0x37DB0DD0l, 0x198D0833l, 0x8CC68419l, 0xC663420Cl, 0x61512FDDl,
0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl, 0x97BD7626l, 0x49BE35C8l,
0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl, 0xE4D7F287l, 0xF26BF943l,
0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l, 0xBE16F8F9l, 0xDF0B7C7Cl,
0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l, 0x2EEC6FAAl, 0x1516B90El,
0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl, 0x43E5D726l, 0x23926548l,
0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl, 0xE275378Fl, 0xF13A9BC7l,
0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l, 0x7D732767l, 0xBEB993B3l,
0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl, 0xBADBDE56l, 0x5F0D61F0l,
0x2DE63E23l, 0x96F31F11l, 0xCB798F88l, 0x67DC491Fl, 0xB3EE248Fl,
0xD9F71247l, 0xECFB8923l, 0xF67DC491l, 0xFB3EE248l, 0x00000001l,
0x00000002l, 0x00000004l, 0x00000008l, 0x00000010l, 0x00000020l,
0x00000040l, 0x00000080l, 0x00000100l, 0x00000200l, 0x00000400l,
0x00000800l, 0x00001000l, 0x00002000l, 0x00004000l, 0x00008000l,
0x00010000l, 0x00020000l, 0x00040000l, 0x00080000l, 0x00100000l,
0x00200000l, 0x00400000l, 0x00800000l, 0x01000000l, 0x02000000l,
0x04000000l, 0x08000000l, 0x10000000l, 0x20000000l, 0x40000000l,
0x80000000l
};
/**
* CRC-32 checksums for PDU2 ( HEADER + 2 Blocks ) messages, generated by:
*
* CRCUtil.generate( 160, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU2_CHECKSUMS = new long[]
{
0x9D231959l, 0xCE918CACl, 0x6528488Dl, 0xB2942446l, 0x5B2A9CF8l,
0x2FF5C0A7l, 0x97FAE053l, 0xCBFD7029l, 0xE5FEB814l, 0x709FD2D1l,
0xB84FE968l, 0x5E477A6Fl, 0xAF23BD37l, 0xD791DE9Bl, 0xEBC8EF4Dl,
0xF5E477A6l, 0x7892B508l, 0x3E29D45Fl, 0x9F14EA2Fl, 0xCF8A7517l,
0xE7C53A8Bl, 0xF3E29D45l, 0xF9F14EA2l, 0x7E98298Al, 0x3D2C9A1El,
0x1CF6C3D4l, 0x0C1BEF31l, 0x860DF798l, 0x41667517l, 0xA0B33A8Bl,
0xD0599D45l, 0xE82CCEA2l, 0x7676E98Al, 0x395BFA1El, 0x1ECD73D4l,
0x0D063731l, 0x86831B98l, 0x41210317l, 0xA090818Bl, 0xD04840C5l,
0xE8242062l, 0x76729EEAl, 0x3959C1AEl, 0x1ECC6E0Cl, 0x0D06B9DDl,
0x86835CEEl, 0x412120ACl, 0x22F01E8Dl, 0x91780F46l, 0x4ADC8978l,
0x270ECA67l, 0x93876533l, 0xC9C3B299l, 0xE4E1D94Cl, 0x7010627Dl,
0xB808313El, 0x5E649644l, 0x2D52C5F9l, 0x96A962FCl, 0x49343FA5l,
0xA49A1FD2l, 0x502D8132l, 0x2A764E42l, 0x175BA9FAl, 0x09CD5A26l,
0x068623C8l, 0x01239F3Fl, 0x8091CF9Fl, 0xC048E7CFl, 0xE02473E7l,
0xF01239F3l, 0xF8091CF9l, 0xFC048E7Cl, 0x7C62C9E5l, 0xBE3164F2l,
0x5D783CA2l, 0x2CDC908Al, 0x140EC69El, 0x0867ED94l, 0x06537811l,
0x8329BC08l, 0x43F450DFl, 0xA1FA286Fl, 0xD0FD1437l, 0xE87E8A1Bl,
0xF43F450Dl, 0xFA1FA286l, 0x7F6F5F98l, 0x3DD72117l, 0x9EEB908Bl,
0xCF75C845l, 0xE7BAE422l, 0x71BDFCCAl, 0x3ABE70BEl, 0x1F3FB684l,
0x0DFF5599l, 0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl, 0x52275834l,
0x2B7322C1l, 0x95B99160l, 0x48BC466Bl, 0xA45E2335l, 0xD22F119Al,
0x6B770616l, 0x37DB0DD0l, 0x198D0833l, 0x8CC68419l, 0xC663420Cl,
0x61512FDDl, 0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl, 0x97BD7626l,
0x49BE35C8l, 0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl, 0xE4D7F287l,
0xF26BF943l, 0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l, 0xBE16F8F9l,
0xDF0B7C7Cl, 0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l, 0x2EEC6FAAl,
0x1516B90El, 0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl, 0x43E5D726l,
0x23926548l, 0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl, 0xE275378Fl,
0xF13A9BC7l, 0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l, 0x7D732767l,
0xBEB993B3l, 0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl, 0xBADBDE56l,
0x5F0D61F0l, 0x2DE63E23l, 0x96F31F11l, 0xCB798F88l, 0x67DC491Fl,
0xB3EE248Fl, 0xD9F71247l, 0xECFB8923l, 0xF67DC491l, 0xFB3EE248l,
0x00000001l, 0x00000002l, 0x00000004l, 0x00000008l, 0x00000010l,
0x00000020l, 0x00000040l, 0x00000080l, 0x00000100l, 0x00000200l,
0x00000400l, 0x00000800l, 0x00001000l, 0x00002000l, 0x00004000l,
0x00008000l, 0x00010000l, 0x00020000l, 0x00040000l, 0x00080000l,
0x00100000l, 0x00200000l, 0x00400000l, 0x00800000l, 0x01000000l,
0x02000000l, 0x04000000l, 0x08000000l, 0x10000000l, 0x20000000l,
0x40000000l, 0x80000000l
};
/**
* CRC-32 checksums for PDU3 ( HEADER + 3 Blocks ) messages, generated by:
*
* CRCUtil.generate( 256, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU3_CHECKSUMS = new long[]
{
0xAA5FA470l, 0x574F5CE3l, 0xABA7AE71l, 0xD5D3D738l, 0x68896547l,
0xB444B2A3l, 0xDA225951l, 0xED112CA8l, 0x74E8188Fl, 0xBA740C47l,
0xDD3A0623l, 0xEE9D0311l, 0xF74E8188l, 0x79C7CE1Fl, 0xBCE3E70Fl,
0xDE71F387l, 0xEF38F9C3l, 0xF79C7CE1l, 0xFBCE3E70l, 0x7F8791E3l,
0xBFC3C8F1l, 0xDFE1E478l, 0x6D907CE7l, 0xB6C83E73l, 0xDB641F39l,
0xEDB20F9Cl, 0x74B98915l, 0xBA5CC48Al, 0x5F4EEC9El, 0x2DC7F894l,
0x14837291l, 0x8A41B948l, 0x4740527Fl, 0xA3A0293Fl, 0xD1D0149Fl,
0xE8E80A4Fl, 0xF4740527l, 0xFA3A0293l, 0xFD1D0149l, 0xFE8E80A4l,
0x7D27CE89l, 0xBE93E744l, 0x5D297D79l, 0xAE94BEBCl, 0x552AD185l,
0xAA9568C2l, 0x572A3ABAl, 0x29F59386l, 0x169A4718l, 0x092DAD57l,
0x8496D6ABl, 0xC24B6B55l, 0xE125B5AAl, 0x72F2540El, 0x3B19A4DCl,
0x1FEC5CB5l, 0x8FF62E5Al, 0x459B99F6l, 0x20AD4220l, 0x12362FCBl,
0x891B17E5l, 0xC48D8BF2l, 0x60264B22l, 0x3273AB4Al, 0x1B595B7El,
0x0FCC2364l, 0x05869F69l, 0x82C34FB4l, 0x43012901l, 0xA1809480l,
0x52A0C49Bl, 0xA950624Dl, 0xD4A83126l, 0x68349648l, 0x367AC5FFl,
0x9B3D62FFl, 0xCD9EB17Fl, 0xE6CF58BFl, 0xF367AC5Fl, 0xF9B3D62Fl,
0xFCD9EB17l, 0xFE6CF58Bl, 0xFF367AC5l, 0xFF9B3D62l, 0x7DAD106Al,
0x3CB606EEl, 0x1C3B8DACl, 0x0C7D480Dl, 0x863EA406l, 0x417FDCD8l,
0x22DF60B7l, 0x916FB05Bl, 0xC8B7D82Dl, 0xE45BEC16l, 0x704D78D0l,
0x3A4632B3l, 0x9D231959l, 0xCE918CACl, 0x6528488Dl, 0xB2942446l,
0x5B2A9CF8l, 0x2FF5C0A7l, 0x97FAE053l, 0xCBFD7029l, 0xE5FEB814l,
0x709FD2D1l, 0xB84FE968l, 0x5E477A6Fl, 0xAF23BD37l, 0xD791DE9Bl,
0xEBC8EF4Dl, 0xF5E477A6l, 0x7892B508l, 0x3E29D45Fl, 0x9F14EA2Fl,
0xCF8A7517l, 0xE7C53A8Bl, 0xF3E29D45l, 0xF9F14EA2l, 0x7E98298Al,
0x3D2C9A1El, 0x1CF6C3D4l, 0x0C1BEF31l, 0x860DF798l, 0x41667517l,
0xA0B33A8Bl, 0xD0599D45l, 0xE82CCEA2l, 0x7676E98Al, 0x395BFA1El,
0x1ECD73D4l, 0x0D063731l, 0x86831B98l, 0x41210317l, 0xA090818Bl,
0xD04840C5l, 0xE8242062l, 0x76729EEAl, 0x3959C1AEl, 0x1ECC6E0Cl,
0x0D06B9DDl, 0x86835CEEl, 0x412120ACl, 0x22F01E8Dl, 0x91780F46l,
0x4ADC8978l, 0x270ECA67l, 0x93876533l, 0xC9C3B299l, 0xE4E1D94Cl,
0x7010627Dl, 0xB808313El, 0x5E649644l, 0x2D52C5F9l, 0x96A962FCl,
0x49343FA5l, 0xA49A1FD2l, 0x502D8132l, 0x2A764E42l, 0x175BA9FAl,
0x09CD5A26l, 0x068623C8l, 0x01239F3Fl, 0x8091CF9Fl, 0xC048E7CFl,
0xE02473E7l, 0xF01239F3l, 0xF8091CF9l, 0xFC048E7Cl, 0x7C62C9E5l,
0xBE3164F2l, 0x5D783CA2l, 0x2CDC908Al, 0x140EC69El, 0x0867ED94l,
0x06537811l, 0x8329BC08l, 0x43F450DFl, 0xA1FA286Fl, 0xD0FD1437l,
0xE87E8A1Bl, 0xF43F450Dl, 0xFA1FA286l, 0x7F6F5F98l, 0x3DD72117l,
0x9EEB908Bl, 0xCF75C845l, 0xE7BAE422l, 0x71BDFCCAl, 0x3ABE70BEl,
0x1F3FB684l, 0x0DFF5599l, 0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl,
0x52275834l, 0x2B7322C1l, 0x95B99160l, 0x48BC466Bl, 0xA45E2335l,
0xD22F119Al, 0x6B770616l, 0x37DB0DD0l, 0x198D0833l, 0x8CC68419l,
0xC663420Cl, 0x61512FDDl, 0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl,
0x97BD7626l, 0x49BE35C8l, 0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl,
0xE4D7F287l, 0xF26BF943l, 0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l,
0xBE16F8F9l, 0xDF0B7C7Cl, 0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l,
0x2EEC6FAAl, 0x1516B90El, 0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl,
0x43E5D726l, 0x23926548l, 0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl,
0xE275378Fl, 0xF13A9BC7l, 0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l,
0x7D732767l, 0xBEB993B3l, 0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl,
0xBADBDE56l, 0x5F0D61F0l, 0x2DE63E23l, 0x96F31F11l, 0xCB798F88l,
0x67DC491Fl, 0xB3EE248Fl, 0xD9F71247l, 0xECFB8923l, 0xF67DC491l,
0xFB3EE248l, 0x00000001l, 0x00000002l, 0x00000004l, 0x00000008l,
0x00000010l, 0x00000020l, 0x00000040l, 0x00000080l, 0x00000100l,
0x00000200l, 0x00000400l, 0x00000800l, 0x00001000l, 0x00002000l,
0x00004000l, 0x00008000l, 0x00010000l, 0x00020000l, 0x00040000l,
0x00080000l, 0x00100000l, 0x00200000l, 0x00400000l, 0x00800000l,
0x01000000l, 0x02000000l, 0x04000000l, 0x08000000l, 0x10000000l,
0x20000000l, 0x40000000l, 0x80000000l
};
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU1 message.
*/
public static BinaryMessage correctPDU1( BinaryMessage message )
{
return correctPDU( message, PDU1_CHECKSUMS, 224 );
}
private final static Logger mLog = LoggerFactory.getLogger(CRCP25.class);
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU2 message.
*/
public static BinaryMessage correctPDU2( BinaryMessage message )
{
return correctPDU( message, PDU2_CHECKSUMS, 320 );
}
/**
* CRC-CCITT 16-bit checksums for a message length of 80 bits plus 16
* additional checksums representing CRC checksum bit errors
*
* Generated by:
* CRCUtil.generate( 80, 16, 0x11021l, 0xFFFFl, true );
*/
public static final int[] CCITT_80_CHECKSUMS = new int[]
{
0x1BCB, 0x8DE5, 0xC6F2, 0x6B69, 0xB5B4, 0x52CA, 0x2175, 0x90BA, 0x404D,
0xA026, 0x5803, 0xAC01, 0xD600, 0x6310, 0x3998, 0x14DC, 0x27E, 0x92F,
0x8497, 0xC24B, 0xE125, 0xF092, 0x7059, 0xB82C, 0x5406, 0x2213, 0x9109,
0xC884, 0x6C52, 0x3E39, 0x9F1C, 0x479E, 0x2BDF, 0x95EF, 0xCAF7, 0xE57B,
0xF2BD, 0xF95E, 0x74BF, 0xBA5F, 0xDD2F, 0xEE97, 0xF74B, 0xFBA5, 0xFDD2,
0x76F9, 0xBB7C, 0x55AE, 0x22C7, 0x9163, 0xC8B1, 0xE458, 0x7A3C, 0x350E,
0x1297, 0x894B, 0xC4A5, 0xE252, 0x7939, 0xBC9C, 0x565E, 0x233F, 0x919F,
0xC8CF, 0xE467, 0xF233, 0xF919, 0xFC8C, 0x7656, 0x333B, 0x999D, 0xCCCE,
0x6E77, 0xB73B, 0xDB9D, 0xEDCE, 0x7EF7, 0xBF7B, 0xDFBD, 0xEFDE, 0x0001,
0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200,
0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
};
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU3 message.
*/
public static BinaryMessage correctPDU3( BinaryMessage message )
{
return correctPDU( message, PDU3_CHECKSUMS, 416 );
}
/**
* Confirmed Packet Data Unit CRC-9 checksums, generated by:
*
* long[] table = CRCUtil.generate( 135, 9, 0x259l, 0x1FF, false, Parity.NONE );
*/
public static final int[] CRC9_CHECKSUMS = new int[]
{
0x1E7, 0x1F3, 0x1F9, 0x1FC, 0x0D2, 0x045, 0x122, 0x0BD, 0x15E, 0x083,
0x141, 0x1A0, 0x0FC, 0x052, 0x005, 0x102, 0x0AD, 0x156, 0x087, 0x143,
0x1A1, 0x1D0, 0x0C4, 0x04E, 0x00B, 0x105, 0x182, 0x0ED, 0x176, 0x097,
0x14B, 0x1A5, 0x1D2, 0x0C5, 0x162, 0x09D, 0x14E, 0x08B, 0x145, 0x1A2,
0x0FD, 0x17E, 0x093, 0x149, 0x1A4, 0x0FE, 0x053, 0x129, 0x194, 0x0E6,
0x05F, 0x12F, 0x197, 0x1CB, 0x1E5, 0x1F2, 0x0D5, 0x16A, 0x099, 0x14C,
0x08A, 0x069, 0x134, 0x0B6, 0x077, 0x13B, 0x19D, 0x1CE, 0x0CB, 0x165,
0x1B2, 0x0F5, 0x17A, 0x091, 0x148, 0x088, 0x068, 0x018, 0x020, 0x03C,
0x032, 0x035, 0x11A, 0x0A1, 0x150, 0x084, 0x06E, 0x01B, 0x10D, 0x186,
0x0EF, 0x177, 0x1BB, 0x1DD, 0x1EE, 0x0DB, 0x16D, 0x1B6, 0x0F7, 0x17B,
0x1BD, 0x1DE, 0x0C3, 0x161, 0x1B0, 0x0F4, 0x056, 0x007, 0x103, 0x181,
0x1C0, 0x0CC, 0x04A, 0x009, 0x104, 0x0AE, 0x07B, 0x13D, 0x19E, 0x0E3,
0x171, 0x1B8, 0x0F0, 0x054, 0x006, 0x02F, 0x117, 0x18B, 0x1C5, 0x1E2,
0x0DD, 0x16E, 0x09B, 0x14D, 0x1A6
};
public static BinaryMessage correctPDU( BinaryMessage message, long[] checksums, int crcStart )
{
long calculated = 0; //Starting value
int messageStart = 160;
/**
* CRC-32 checksums for PDU1 ( HEADER + 1 Block ) messages, generated by:
*
* CRCUtil.generate( 64, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU1_CHECKSUMS = new long[]
{
0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl, 0x52275834l, 0x2B7322C1l,
0x95B99160l, 0x48BC466Bl, 0xA45E2335l, 0xD22F119Al, 0x6B770616l,
0x37DB0DD0l, 0x198D0833l, 0x8CC68419l, 0xC663420Cl, 0x61512FDDl,
0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl, 0x97BD7626l, 0x49BE35C8l,
0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl, 0xE4D7F287l, 0xF26BF943l,
0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l, 0xBE16F8F9l, 0xDF0B7C7Cl,
0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l, 0x2EEC6FAAl, 0x1516B90El,
0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl, 0x43E5D726l, 0x23926548l,
0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl, 0xE275378Fl, 0xF13A9BC7l,
0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l, 0x7D732767l, 0xBEB993B3l,
0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl, 0xBADBDE56l, 0x5F0D61F0l,
0x2DE63E23l, 0x96F31F11l, 0xCB798F88l, 0x67DC491Fl, 0xB3EE248Fl,
0xD9F71247l, 0xECFB8923l, 0xF67DC491l, 0xFB3EE248l, 0x00000001l,
0x00000002l, 0x00000004l, 0x00000008l, 0x00000010l, 0x00000020l,
0x00000040l, 0x00000080l, 0x00000100l, 0x00000200l, 0x00000400l,
0x00000800l, 0x00001000l, 0x00002000l, 0x00004000l, 0x00008000l,
0x00010000l, 0x00020000l, 0x00040000l, 0x00080000l, 0x00100000l,
0x00200000l, 0x00400000l, 0x00800000l, 0x01000000l, 0x02000000l,
0x04000000l, 0x08000000l, 0x10000000l, 0x20000000l, 0x40000000l,
0x80000000l
};
/* Iterate the set bits and XOR running checksum with lookup value */
for (int i = message.nextSetBit( messageStart );
i >= messageStart && i < crcStart;
i = message.nextSetBit( i+1 ) )
{
calculated ^= checksums[ i - messageStart ];
}
long checksum = getLongChecksum( message, crcStart, 32 );
/**
* CRC-32 checksums for PDU2 ( HEADER + 2 Blocks ) messages, generated by:
*
* CRCUtil.generate( 160, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU2_CHECKSUMS = new long[]
{
0x9D231959l, 0xCE918CACl, 0x6528488Dl, 0xB2942446l, 0x5B2A9CF8l,
0x2FF5C0A7l, 0x97FAE053l, 0xCBFD7029l, 0xE5FEB814l, 0x709FD2D1l,
0xB84FE968l, 0x5E477A6Fl, 0xAF23BD37l, 0xD791DE9Bl, 0xEBC8EF4Dl,
0xF5E477A6l, 0x7892B508l, 0x3E29D45Fl, 0x9F14EA2Fl, 0xCF8A7517l,
0xE7C53A8Bl, 0xF3E29D45l, 0xF9F14EA2l, 0x7E98298Al, 0x3D2C9A1El,
0x1CF6C3D4l, 0x0C1BEF31l, 0x860DF798l, 0x41667517l, 0xA0B33A8Bl,
0xD0599D45l, 0xE82CCEA2l, 0x7676E98Al, 0x395BFA1El, 0x1ECD73D4l,
0x0D063731l, 0x86831B98l, 0x41210317l, 0xA090818Bl, 0xD04840C5l,
0xE8242062l, 0x76729EEAl, 0x3959C1AEl, 0x1ECC6E0Cl, 0x0D06B9DDl,
0x86835CEEl, 0x412120ACl, 0x22F01E8Dl, 0x91780F46l, 0x4ADC8978l,
0x270ECA67l, 0x93876533l, 0xC9C3B299l, 0xE4E1D94Cl, 0x7010627Dl,
0xB808313El, 0x5E649644l, 0x2D52C5F9l, 0x96A962FCl, 0x49343FA5l,
0xA49A1FD2l, 0x502D8132l, 0x2A764E42l, 0x175BA9FAl, 0x09CD5A26l,
0x068623C8l, 0x01239F3Fl, 0x8091CF9Fl, 0xC048E7CFl, 0xE02473E7l,
0xF01239F3l, 0xF8091CF9l, 0xFC048E7Cl, 0x7C62C9E5l, 0xBE3164F2l,
0x5D783CA2l, 0x2CDC908Al, 0x140EC69El, 0x0867ED94l, 0x06537811l,
0x8329BC08l, 0x43F450DFl, 0xA1FA286Fl, 0xD0FD1437l, 0xE87E8A1Bl,
0xF43F450Dl, 0xFA1FA286l, 0x7F6F5F98l, 0x3DD72117l, 0x9EEB908Bl,
0xCF75C845l, 0xE7BAE422l, 0x71BDFCCAl, 0x3ABE70BEl, 0x1F3FB684l,
0x0DFF5599l, 0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl, 0x52275834l,
0x2B7322C1l, 0x95B99160l, 0x48BC466Bl, 0xA45E2335l, 0xD22F119Al,
0x6B770616l, 0x37DB0DD0l, 0x198D0833l, 0x8CC68419l, 0xC663420Cl,
0x61512FDDl, 0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl, 0x97BD7626l,
0x49BE35C8l, 0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl, 0xE4D7F287l,
0xF26BF943l, 0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l, 0xBE16F8F9l,
0xDF0B7C7Cl, 0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l, 0x2EEC6FAAl,
0x1516B90El, 0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl, 0x43E5D726l,
0x23926548l, 0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl, 0xE275378Fl,
0xF13A9BC7l, 0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l, 0x7D732767l,
0xBEB993B3l, 0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl, 0xBADBDE56l,
0x5F0D61F0l, 0x2DE63E23l, 0x96F31F11l, 0xCB798F88l, 0x67DC491Fl,
0xB3EE248Fl, 0xD9F71247l, 0xECFB8923l, 0xF67DC491l, 0xFB3EE248l,
0x00000001l, 0x00000002l, 0x00000004l, 0x00000008l, 0x00000010l,
0x00000020l, 0x00000040l, 0x00000080l, 0x00000100l, 0x00000200l,
0x00000400l, 0x00000800l, 0x00001000l, 0x00002000l, 0x00004000l,
0x00008000l, 0x00010000l, 0x00020000l, 0x00040000l, 0x00080000l,
0x00100000l, 0x00200000l, 0x00400000l, 0x00800000l, 0x01000000l,
0x02000000l, 0x04000000l, 0x08000000l, 0x10000000l, 0x20000000l,
0x40000000l, 0x80000000l
};
long error = calculated ^ checksum;
if( error == 0 || error == 0xFFFFFFFFl )
{
message.setCRC( CRC.PASSED );
return message;
}
else
{
int errorLocation = getBitError( error, checksums );
if( errorLocation >= 0 )
{
message.flip( errorLocation + messageStart );
/**
* CRC-32 checksums for PDU3 ( HEADER + 3 Blocks ) messages, generated by:
*
* CRCUtil.generate( 256, 32, 0x104C11DB7l, 0xFFFFFFFFl, true );
*/
public static final long[] PDU3_CHECKSUMS = new long[]
{
0xAA5FA470l, 0x574F5CE3l, 0xABA7AE71l, 0xD5D3D738l, 0x68896547l,
0xB444B2A3l, 0xDA225951l, 0xED112CA8l, 0x74E8188Fl, 0xBA740C47l,
0xDD3A0623l, 0xEE9D0311l, 0xF74E8188l, 0x79C7CE1Fl, 0xBCE3E70Fl,
0xDE71F387l, 0xEF38F9C3l, 0xF79C7CE1l, 0xFBCE3E70l, 0x7F8791E3l,
0xBFC3C8F1l, 0xDFE1E478l, 0x6D907CE7l, 0xB6C83E73l, 0xDB641F39l,
0xEDB20F9Cl, 0x74B98915l, 0xBA5CC48Al, 0x5F4EEC9El, 0x2DC7F894l,
0x14837291l, 0x8A41B948l, 0x4740527Fl, 0xA3A0293Fl, 0xD1D0149Fl,
0xE8E80A4Fl, 0xF4740527l, 0xFA3A0293l, 0xFD1D0149l, 0xFE8E80A4l,
0x7D27CE89l, 0xBE93E744l, 0x5D297D79l, 0xAE94BEBCl, 0x552AD185l,
0xAA9568C2l, 0x572A3ABAl, 0x29F59386l, 0x169A4718l, 0x092DAD57l,
0x8496D6ABl, 0xC24B6B55l, 0xE125B5AAl, 0x72F2540El, 0x3B19A4DCl,
0x1FEC5CB5l, 0x8FF62E5Al, 0x459B99F6l, 0x20AD4220l, 0x12362FCBl,
0x891B17E5l, 0xC48D8BF2l, 0x60264B22l, 0x3273AB4Al, 0x1B595B7El,
0x0FCC2364l, 0x05869F69l, 0x82C34FB4l, 0x43012901l, 0xA1809480l,
0x52A0C49Bl, 0xA950624Dl, 0xD4A83126l, 0x68349648l, 0x367AC5FFl,
0x9B3D62FFl, 0xCD9EB17Fl, 0xE6CF58BFl, 0xF367AC5Fl, 0xF9B3D62Fl,
0xFCD9EB17l, 0xFE6CF58Bl, 0xFF367AC5l, 0xFF9B3D62l, 0x7DAD106Al,
0x3CB606EEl, 0x1C3B8DACl, 0x0C7D480Dl, 0x863EA406l, 0x417FDCD8l,
0x22DF60B7l, 0x916FB05Bl, 0xC8B7D82Dl, 0xE45BEC16l, 0x704D78D0l,
0x3A4632B3l, 0x9D231959l, 0xCE918CACl, 0x6528488Dl, 0xB2942446l,
0x5B2A9CF8l, 0x2FF5C0A7l, 0x97FAE053l, 0xCBFD7029l, 0xE5FEB814l,
0x709FD2D1l, 0xB84FE968l, 0x5E477A6Fl, 0xAF23BD37l, 0xD791DE9Bl,
0xEBC8EF4Dl, 0xF5E477A6l, 0x7892B508l, 0x3E29D45Fl, 0x9F14EA2Fl,
0xCF8A7517l, 0xE7C53A8Bl, 0xF3E29D45l, 0xF9F14EA2l, 0x7E98298Al,
0x3D2C9A1El, 0x1CF6C3D4l, 0x0C1BEF31l, 0x860DF798l, 0x41667517l,
0xA0B33A8Bl, 0xD0599D45l, 0xE82CCEA2l, 0x7676E98Al, 0x395BFA1El,
0x1ECD73D4l, 0x0D063731l, 0x86831B98l, 0x41210317l, 0xA090818Bl,
0xD04840C5l, 0xE8242062l, 0x76729EEAl, 0x3959C1AEl, 0x1ECC6E0Cl,
0x0D06B9DDl, 0x86835CEEl, 0x412120ACl, 0x22F01E8Dl, 0x91780F46l,
0x4ADC8978l, 0x270ECA67l, 0x93876533l, 0xC9C3B299l, 0xE4E1D94Cl,
0x7010627Dl, 0xB808313El, 0x5E649644l, 0x2D52C5F9l, 0x96A962FCl,
0x49343FA5l, 0xA49A1FD2l, 0x502D8132l, 0x2A764E42l, 0x175BA9FAl,
0x09CD5A26l, 0x068623C8l, 0x01239F3Fl, 0x8091CF9Fl, 0xC048E7CFl,
0xE02473E7l, 0xF01239F3l, 0xF8091CF9l, 0xFC048E7Cl, 0x7C62C9E5l,
0xBE3164F2l, 0x5D783CA2l, 0x2CDC908Al, 0x140EC69El, 0x0867ED94l,
0x06537811l, 0x8329BC08l, 0x43F450DFl, 0xA1FA286Fl, 0xD0FD1437l,
0xE87E8A1Bl, 0xF43F450Dl, 0xFA1FA286l, 0x7F6F5F98l, 0x3DD72117l,
0x9EEB908Bl, 0xCF75C845l, 0xE7BAE422l, 0x71BDFCCAl, 0x3ABE70BEl,
0x1F3FB684l, 0x0DFF5599l, 0x86FFAACCl, 0x411F5BBDl, 0xA08FADDEl,
0x52275834l, 0x2B7322C1l, 0x95B99160l, 0x48BC466Bl, 0xA45E2335l,
0xD22F119Al, 0x6B770616l, 0x37DB0DD0l, 0x198D0833l, 0x8CC68419l,
0xC663420Cl, 0x61512FDDl, 0xB0A897EEl, 0x5A34C52Cl, 0x2F7AEC4Dl,
0x97BD7626l, 0x49BE35C8l, 0x26BF943Fl, 0x935FCA1Fl, 0xC9AFE50Fl,
0xE4D7F287l, 0xF26BF943l, 0xF935FCA1l, 0xFC9AFE50l, 0x7C2DF1F3l,
0xBE16F8F9l, 0xDF0B7C7Cl, 0x6DE530E5l, 0xB6F29872l, 0x5919C2E2l,
0x2EEC6FAAl, 0x1516B90El, 0x08EBD25Cl, 0x061567F5l, 0x830AB3FAl,
0x43E5D726l, 0x23926548l, 0x13A9BC7Fl, 0x89D4DE3Fl, 0xC4EA6F1Fl,
0xE275378Fl, 0xF13A9BC7l, 0xF89D4DE3l, 0xFC4EA6F1l, 0xFE275378l,
0x7D732767l, 0xBEB993B3l, 0xDF5CC9D9l, 0xEFAE64ECl, 0x75B7BCADl,
0xBADBDE56l, 0x5F0D61F0l, 0x2DE63E23l, 0x96F31F11l, 0xCB798F88l,
0x67DC491Fl, 0xB3EE248Fl, 0xD9F71247l, 0xECFB8923l, 0xF67DC491l,
0xFB3EE248l, 0x00000001l, 0x00000002l, 0x00000004l, 0x00000008l,
0x00000010l, 0x00000020l, 0x00000040l, 0x00000080l, 0x00000100l,
0x00000200l, 0x00000400l, 0x00000800l, 0x00001000l, 0x00002000l,
0x00004000l, 0x00008000l, 0x00010000l, 0x00020000l, 0x00040000l,
0x00080000l, 0x00100000l, 0x00200000l, 0x00400000l, 0x00800000l,
0x01000000l, 0x02000000l, 0x04000000l, 0x08000000l, 0x10000000l,
0x20000000l, 0x40000000l, 0x80000000l
};
message.setCRC( CRC.CORRECTED );
return message;
}
}
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU1 message.
*/
public static BinaryMessage correctPDU1(BinaryMessage message)
{
return correctPDU(message, PDU1_CHECKSUMS, 224);
}
message.setCRC( CRC.FAILED_CRC );
return message;
}
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU2 message.
*/
public static BinaryMessage correctPDU2(BinaryMessage message)
{
return correctPDU(message, PDU2_CHECKSUMS, 320);
}
/**
* Error detection and correction of single-bit errors for CCITT 16-bit
* CRC protected 80-bit messages.
*/
public static BinaryMessage correctCCITT80( BinaryMessage message,
int messageStart,
int crcStart )
{
int calculated = 0; //Starting value
/**
* Performs error detection and single-bit error correction against the
* data blocks of a PDU3 message.
*/
public static BinaryMessage correctPDU3(BinaryMessage message)
{
return correctPDU(message, PDU3_CHECKSUMS, 416);
}
/* Iterate the set bits and XOR running checksum with lookup value */
for (int i = message.nextSetBit( messageStart );
i >= messageStart && i < crcStart;
i = message.nextSetBit( i+1 ) )
{
calculated ^= CCITT_80_CHECKSUMS[ i - messageStart ];
}
int checksum = getIntChecksum( message, crcStart, 16 );
public static BinaryMessage correctPDU(BinaryMessage message, long[] checksums, int crcStart)
{
long calculated = 0; //Starting value
int residual = calculated ^ checksum;
if( residual == 0 || residual == 0xFFFF )
{
message.setCRC( CRC.PASSED );
return message;
}
else
{
int errorLocation = getBitError( residual, CCITT_80_CHECKSUMS );
if( errorLocation >= 0 )
{
message.flip( errorLocation + messageStart );
message.setCRC( CRC.CORRECTED );
return message;
}
}
int messageStart = 160;
message.setCRC( CRC.FAILED_CRC );
return message;
}
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = message.nextSetBit(messageStart);
i >= messageStart && i < crcStart;
i = message.nextSetBit(i + 1))
{
calculated ^= checksums[i - messageStart];
}
/**
* Error detection for CRC-9 protected Confirmed Packet Data blocks. These
* data blocks have a slightly complicated structure because the checksum
* is located between bits 7-15, within a 144 bit block. The checksums
* were generated assuming that the message is contiguous from 0 - 134 bits.
* No data correction is performed.
*/
public static CRC checkCRC9( BinaryMessage message, int messageStart )
{
int calculated = 0x0; //Initial fill of all ones
long checksum = getLongChecksum(message, crcStart, 32);
/* Iterate the set bits and XOR running checksum with lookup value */
for (int i = message.nextSetBit( messageStart );
i >= messageStart && i < messageStart + 144;
i = message.nextSetBit( i+1 ) )
{
/* message bits before the CRC */
if( i < ( messageStart + 7 ) )
{
calculated ^= CRC9_CHECKSUMS[ i - messageStart ];
}
/* message bits after the CRC */
else if( i > ( messageStart + 15 ) )
{
calculated ^= CRC9_CHECKSUMS[ i - messageStart - 9 ];
}
}
int checksum = message.getInt( messageStart + 7, messageStart + 15 );
long error = calculated ^ checksum;
if(error == 0 || error == 0xFFFFFFFFl)
{
message.setCRC(CRC.PASSED);
return message;
}
else
{
int errorLocation = getBitError(error, checksums);
if(errorLocation >= 0)
{
message.flip(errorLocation + messageStart);
message.setCRC(CRC.CORRECTED);
return message;
}
}
message.setCRC(CRC.FAILED_CRC);
return message;
}
/**
* Error detection and correction of single-bit errors for CCITT 16-bit
* CRC protected 80-bit messages.
*/
public static BinaryMessage correctCCITT80(BinaryMessage message,
int messageStart,
int crcStart)
{
int calculated = 0; //Starting value
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = message.nextSetBit(messageStart);
i >= messageStart && i < crcStart;
i = message.nextSetBit(i + 1))
{
calculated ^= CCITT_80_CHECKSUMS[i - messageStart];
}
int checksum = getIntChecksum(message, crcStart, 16);
int residual = calculated ^ checksum;
if(residual == 0 || residual == 0xFFFF)
{
message.setCRC(CRC.PASSED);
return message;
}
else
{
int errorLocation = getBitError(residual, CCITT_80_CHECKSUMS);
if(errorLocation >= 0)
{
message.flip(errorLocation + messageStart);
message.setCRC(CRC.CORRECTED);
return message;
}
}
message.setCRC(CRC.FAILED_CRC);
return message;
}
/**
* Error detection and correction of single-bit errors for CCITT 16-bit
* CRC protected 80-bit messages.
*/
public static int correctCCITT80(CorrectedBinaryMessage message, int messageStart, int crcStart)
{
int calculated = 0xFFFF; //Starting value
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = message.nextSetBit(messageStart); i >= messageStart && i < crcStart; i = message.nextSetBit(i + 1))
{
calculated ^= CCITT_80_CHECKSUMS[i - messageStart];
}
int checksum = getIntChecksum(message, crcStart, 16);
int residual = calculated ^ checksum;
if(residual == 0 || residual == 0xFFFF)
{
return 0;
}
else
{
int errorLocation = getBitError(residual, CCITT_80_CHECKSUMS);
if(errorLocation >= 0)
{
message.flip(errorLocation + messageStart);
message.incrementCorrectedBitCount(1);
return 1;
}
}
//Message has at least 2 bit errors - ie uncorrectable
message.incrementCorrectedBitCount(2);
return 2;
}
/**
* Error detection for CRC-9 protected Confirmed Packet Data blocks. These
* data blocks have a slightly complicated structure because the checksum
* is located between bits 7-15, within a 144 bit block. The checksums
* were generated assuming that the message is contiguous from 0 - 134 bits.
* No data correction is performed.
*/
public static CRC checkCRC9(BinaryMessage message, int messageStart)
{
int calculated = 0x0; //Initial fill of all ones
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = message.nextSetBit(messageStart);
i >= messageStart && i < messageStart + 144;
i = message.nextSetBit(i + 1))
{
/* message bits before the CRC */
if(i < (messageStart + 7))
{
calculated ^= CRC9_CHECKSUMS[i - messageStart];
}
/* message bits after the CRC */
else if(i > (messageStart + 15))
{
calculated ^= CRC9_CHECKSUMS[i - messageStart - 9];
}
}
int checksum = message.getInt(messageStart + 7, messageStart + 15);
int residual = calculated ^ checksum;
int residual = calculated ^ checksum;
// mLog.debug( "CALC:" + calculated + " CHECK:" + checksum + " RESID:" + residual );
if( residual == 0 || residual == 0x1FF )
{
return CRC.PASSED;
}
return CRC.FAILED_CRC;
}
/**
* Performs Galois 24/12/7 error detection and correction against the 12
* encoded 24-bit message segments following the 64-bit NID in the message
*
* @return - true if all 12 segments of the message can be checked/corrected
*/
public static boolean correctGalois24( BinaryMessage tdulc )
{
boolean passes = true;
int x = 64;
while( x < tdulc.size() && passes )
{
tdulc = Golay24.checkAndCorrect( tdulc, x );
passes = tdulc.getCRC() == CRC.PASSED;
if(residual == 0 || residual == 0x1FF)
{
return CRC.PASSED;
}
x += 24;
}
return passes;
}
/**
* Calculates the value of the message checksum as a long
*/
public static long getLongChecksum( BinaryMessage message,
int crcStart, int crcLength )
{
return message.getLong( crcStart, crcStart + crcLength - 1 );
return CRC.FAILED_CRC;
}
/**
* Calculates the value of the message checksum as an integer
*/
public static int getIntChecksum( BinaryMessage message,
int crcStart, int crcLength )
/**
* Performs Galois 24/12/7 error detection and correction against the 12
* encoded 24-bit message segments following the 64-bit NID in the message
*
* @return - true if all 12 segments of the message can be checked/corrected
*/
public static boolean correctGalois24(CorrectedBinaryMessage tdulc)
{
return message.getInt( crcStart, crcStart + crcLength - 1 );
boolean passes = true;
int x = 64;
while(x < tdulc.size() && passes)
{
int errors = Golay24.checkAndCorrect(tdulc, x);
passes = errors < 2;
x += 24;
}
return passes;
}
/**
* Calculates the value of the message checksum as a long
*/
public static long getLongChecksum(BinaryMessage message,
int crcStart, int crcLength)
{
return message.getLong(crcStart, crcStart + crcLength - 1);
}
/**
* Calculates the value of the message checksum as an integer
*/
public static int getIntChecksum(BinaryMessage message,
int crcStart, int crcLength)
{
return message.getInt(crcStart, crcStart + crcLength - 1);
}
/**
* Identifies any single bit error position that matches the checksum error.
*/
public static int getBitError( long checksumError, long[] checksums )
public static int getBitError(long checksumError, long[] checksums)
{
for( int x = 0; x < checksums.length; x++ )
{
if( checksums[ x ] == checksumError )
{
return x;
}
}
for(int x = 0; x < checksums.length; x++)
{
if(checksums[x] == checksumError)
{
return x;
}
}
return -1;
return -1;
}
/**
* Identifies any single bit error position that matches the checksum error.
*/
public static int getBitError( int checksumError, int[] checksums )
public static int getBitError(int checksumError, int[] checksums)
{
for( int x = 0; x < checksums.length; x++ )
{
if( checksums[ x ] == checksumError )
{
return x;
}
}
for(int x = 0; x < checksums.length; x++)
{
if(checksums[x] == checksumError)
{
return x;
}
}
return -1;
return -1;
}
public static void main( String[] args )
public static void main(String[] args)
{
String raw = "000000001000001100000001010001111011000100001010010001111100000000000101000000000000000001000000000000110000000000000001101010101010101010101010";
BinaryMessage message = BinaryMessage.load( raw );
mLog.debug( "MSG:" + message.toString() );
String raw = "000000001000001100000001010001111011000100001010010001111100000000000101000000000000000001000000000000110000000000000001101010101010101010101010";
CRC results = checkCRC9( message, 0 );
BinaryMessage message = BinaryMessage.load(raw);
mLog.debug( "COR:" + message.toString() );
mLog.debug("MSG:" + message.toString());
mLog.debug( "Results: " + results.getDisplayText() );
CRC results = checkCRC9(message, 0);
mLog.debug("COR:" + message.toString());
mLog.debug("Results: " + results.getDisplayText());
}
}

View File

@@ -1,215 +1,224 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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/>
******************************************************************************/
/*
* ******************************************************************************
* 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.edac;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import java.util.BitSet;
/**
* Passport CRC checksum utility
*
*
* Passport message blocks are 68 bits in length as follows:
* 0 - 8: Sync
* 9 - 59: message bits
* 60 - 67: CRC-7 check bits plus 1 parity
*
* 0 - 8: Sync
* 9 - 59: message bits
* 60 - 67: CRC-7 check bits plus 1 parity
*
* Passport uses a CRC-7 (0x44) with an initial fill of 0x44 plus parity set.
*
*
* CRC-7 Generating Polynomial: x6 + x2 + 1 (0x44)
*/
public class CRCPassport
{
private static final byte sFILL_00 = (byte)0x00;
private static byte[] sCHECKSUMS = new byte[]
{
(byte)0x6E, //DCC 1
(byte)0xBF, //DCC 0
(byte)0xD6, //LCN 10
(byte)0xE3, //LCN 9
(byte)0xF8, //LCN 8
(byte)0x7C, //LCN 7
(byte)0x3E, //LCN 6
(byte)0x97, //LCN 5
(byte)0xC2, //LCN 4
(byte)0xE9, //LCN 3
(byte)0x75, //LCN 2
(byte)0x3B, //LCN 1
(byte)0x94, //LCN 0
(byte)0x4A, //SITE 6
(byte)0xAD, //SITE 5
(byte)0x57, //SITE 4
(byte)0xA2, //SITE 3
(byte)0xD9, //SITE 2
(byte)0x6D, //SITE 1
(byte)0x37, //SITE 0
(byte)0x92, //GROUP 15
(byte)0xC1, //GROUP 14
(byte)0x61, //GROUP 13
(byte)0x31, //GROUP 12
(byte)0x19, //GROUP 11
(byte)0x0D, //GROUP 10
(byte)0x07, //GROUP 9
(byte)0x8A, //GROUP 8
(byte)0xCD, //GROUP 7
(byte)0x67, //GROUP 6
(byte)0xBA, //GROUP 5
(byte)0xD5, //GROUP 4
(byte)0x6B, //GROUP 3
(byte)0xBC, //GROUP 2
(byte)0x5E, //GROUP 1
(byte)0xA7, //GROUP 0
(byte)0xDA, //TYPE 3
(byte)0xE5, //TYPE 2
(byte)0x73, //TYPE 1
(byte)0xB0, //TYPE 0
(byte)0x58, //FREE 10
(byte)0x2C, //FREE 9
(byte)0x16, //FREE 8
(byte)0x83, //FREE 7
(byte)0xC8, //FREE 6
(byte)0x64, //FREE 5
(byte)0x32, //FREE 4
(byte)0x91, //FREE 3
(byte)0x49, //FREE 2
(byte)0x25, //FREE 1
(byte)0x13 //FREE 0
};
private static final byte sFILL_00 = (byte)0x00;
/**
* Determines if message bits 9 - 59 pass the CRC checksum
* contained in bits 60 - 68, using a lookup table of CRC checksum values
* derived from the CRC-7 value and the final parity bit
*/
public static CRC check( BitSet msg )
{
CRC crc = CRC.UNKNOWN;
byte calculated = 0x0; //Starting value for an OSW
private static byte[] sCHECKSUMS = new byte[]
{
(byte)0x6E, //DCC 1
(byte)0xBF, //DCC 0
(byte)0xD6, //LCN 10
(byte)0xE3, //LCN 9
(byte)0xF8, //LCN 8
(byte)0x7C, //LCN 7
(byte)0x3E, //LCN 6
(byte)0x97, //LCN 5
(byte)0xC2, //LCN 4
(byte)0xE9, //LCN 3
(byte)0x75, //LCN 2
(byte)0x3B, //LCN 1
(byte)0x94, //LCN 0
(byte)0x4A, //SITE 6
(byte)0xAD, //SITE 5
(byte)0x57, //SITE 4
(byte)0xA2, //SITE 3
(byte)0xD9, //SITE 2
(byte)0x6D, //SITE 1
(byte)0x37, //SITE 0
(byte)0x92, //GROUP 15
(byte)0xC1, //GROUP 14
(byte)0x61, //GROUP 13
(byte)0x31, //GROUP 12
(byte)0x19, //GROUP 11
(byte)0x0D, //GROUP 10
(byte)0x07, //GROUP 9
(byte)0x8A, //GROUP 8
(byte)0xCD, //GROUP 7
(byte)0x67, //GROUP 6
(byte)0xBA, //GROUP 5
(byte)0xD5, //GROUP 4
(byte)0x6B, //GROUP 3
(byte)0xBC, //GROUP 2
(byte)0x5E, //GROUP 1
(byte)0xA7, //GROUP 0
(byte)0xDA, //TYPE 3
(byte)0xE5, //TYPE 2
(byte)0x73, //TYPE 1
(byte)0xB0, //TYPE 0
(byte)0x58, //FREE 10
(byte)0x2C, //FREE 9
(byte)0x16, //FREE 8
(byte)0x83, //FREE 7
(byte)0xC8, //FREE 6
(byte)0x64, //FREE 5
(byte)0x32, //FREE 4
(byte)0x91, //FREE 3
(byte)0x49, //FREE 2
(byte)0x25, //FREE 1
(byte)0x13 //FREE 0
};
/**
* Determines if message bits 9 - 59 pass the CRC checksum
* contained in bits 60 - 68, using a lookup table of CRC checksum values
* derived from the CRC-7 value and the final parity bit
*/
public static CRC check(BitSet msg)
{
CRC crc = CRC.UNKNOWN;
byte calculated = 0x0; //Starting value for an OSW
//Iterate bits that are set and XOR running checksum with lookup value
for (int i = msg.nextSetBit( 9 ); i >= 9 && i <= 59; i = msg.nextSetBit( i+1 ) )
{
calculated ^= sCHECKSUMS[ i - 9 ];
}
for(int i = msg.nextSetBit(9); i >= 9 && i <= 59; i = msg.nextSetBit(i + 1))
{
calculated ^= sCHECKSUMS[i - 9];
}
//Apply the message checksum to derive the residual
calculated ^= getChecksum( msg );
switch( (byte)calculated )
{
case sFILL_00:
crc = CRC.PASSED;
break;
default:
crc = CRC.FAILED_CRC;
}
return crc;
}
public static byte getResidual( BitSet msg )
//Apply the message checksum to derive the residual
calculated ^= getChecksum(msg);
switch((byte)calculated)
{
case sFILL_00:
crc = CRC.PASSED;
break;
default:
crc = CRC.FAILED_CRC;
}
return crc;
}
public static byte getResidual(BitSet msg)
{
byte calculated = 0x0; //Initial fill of zero
//Iterate bits that are set and XOR running checksum with lookup value
for (int i = msg.nextSetBit( 9 ); i >= 9 && i <= 59; i = msg.nextSetBit( i+1 ) )
for(int i = msg.nextSetBit(9); i >= 9 && i <= 59; i = msg.nextSetBit(i + 1))
{
calculated ^= sCHECKSUMS[ i - 9 ];
calculated ^= sCHECKSUMS[i - 9];
}
calculated ^= getChecksum( msg );
calculated ^= getChecksum(msg);
return calculated;
}
public static byte[] getChecks()
{
return sCHECKSUMS;
}
/**
* Returns the integer value of the 7 bit crc checksum
*/
public static byte getChecksum( BitSet msg )
public static byte[] getChecks()
{
return sCHECKSUMS;
}
/**
* Returns the integer value of the 7 bit crc checksum
*/
public static byte getChecksum(BitSet msg)
{
byte retVal = 0x0;
for( int x = 0; x < 8; x++ )
{
if( msg.get( x + 60 ) )
{
retVal ^= (byte)( 1<<( 7 - x ) );
}
}
return retVal;
for(int x = 0; x < 8; x++)
{
if(msg.get(x + 60))
{
retVal ^= (byte)(1 << (7 - x));
}
}
return retVal;
}
/**
* Initial take on error correction. The majority of the errors detected
* are in the final 2 bits, owing to the forward looking soft bit detection
* used in the decoder. For right now, correct any messages where the
* used in the decoder. For right now, correct any messages where the
* residual indicates that the final 1 or 2 bits are bad.
*/
public static BinaryMessage correct( BinaryMessage msg )
public static CorrectedBinaryMessage correct(CorrectedBinaryMessage msg)
{
int residual = (int)( 0xFF & getResidual( msg ) );
switch( residual )
{
case 1:
case 136:
msg.flip( 67 );
break;
case 3:
case 138:
msg.flip( 66 );
msg.flip( 67 );
break;
case 2:
case 139:
msg.flip( 66 );
break;
case 140:
msg.flip( 65 );
msg.flip( 67 );
break;
case 153:
msg.flip( 67 );
break;
case 142:
msg.flip( 65 );
msg.flip( 66 );
msg.flip( 67 );
break;
}
int residual = (int)(0xFF & getResidual(msg));
return msg;
switch(residual)
{
case 1:
case 136:
msg.flip(67);
msg.incrementCorrectedBitCount(1);
break;
case 3:
case 138:
msg.flip(66);
msg.flip(67);
msg.incrementCorrectedBitCount(2);
break;
case 2:
case 139:
msg.flip(66);
msg.incrementCorrectedBitCount(1);
break;
case 140:
msg.flip(65);
msg.flip(67);
msg.incrementCorrectedBitCount(2);
break;
case 153:
msg.flip(67);
msg.incrementCorrectedBitCount(1);
break;
case 142:
msg.flip(65);
msg.flip(66);
msg.flip(67);
msg.incrementCorrectedBitCount(3);
break;
}
return msg;
}
/**
* Performs an even parity check on the bitset. If the number of bits that
* are set is an even number, then it passes the even parity check
*/
public static boolean isEvenParity( BinaryMessage bits )
public static boolean isEvenParity(BinaryMessage bits)
{
return ( bits.cardinality() % 2 == 0 );
return (bits.cardinality() % 2 == 0);
}
}

View File

@@ -161,8 +161,8 @@ public class CRCUtil
// decode( message, 0, 135, polynomial, 9 );
//
// mLog.debug( message.toString() );
long[] table = generate( 135, 9, 0x259l, 0, false, Parity.NONE );
long[] table = CRCUtil.generate( 135, 9, 0x259l, 0x1FF, false, Parity.NONE );
mLog.debug( toCodeArray( table ) );
mLog.debug( "Finished" );
}

View File

@@ -1,23 +1,23 @@
package io.github.dsheirer.edac;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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/>
* -----------------------------------------------------------------------
@@ -32,22 +32,25 @@ import org.slf4j.LoggerFactory;
*/
public class Golay18
{
private final static Logger mLog = LoggerFactory.getLogger( Golay18.class );
private final static Logger mLog = LoggerFactory.getLogger(Golay18.class);
/**
* Performs error detection and correction.
*/
public static void checkAndCorrect( BinaryMessage message, int startIndex )
{
int value = message.getInt( startIndex, startIndex + 17 );
/**
* Performs error detection and correction.
*/
public static void checkAndCorrect(CorrectedBinaryMessage message, int startIndex)
{
int value = message.getInt(startIndex, startIndex + 17);
BinaryMessage temp = new BinaryMessage( 24 );
temp.load( 6, 18, value );
CorrectedBinaryMessage temp = new CorrectedBinaryMessage(24);
temp.load(6, 18, value);
BinaryMessage corrected = Golay24.checkAndCorrect( temp, 0 );
int errorsCorrected = Golay24.checkAndCorrect(temp, 0);
int correctedValue = corrected.getInt( 6, 23 );
message.load( startIndex, 18, correctedValue );
}
int correctedValue = temp.getInt(6, 23);
message.load(startIndex, 18, correctedValue);
int correctedBitCount = Integer.bitCount(value ^ correctedValue);
message.incrementCorrectedBitCount(correctedBitCount);
}
}

View File

@@ -1,23 +1,24 @@
package io.github.dsheirer.edac;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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/>
* -----------------------------------------------------------------------
@@ -30,138 +31,133 @@ import org.slf4j.LoggerFactory;
*/
public class Golay24
{
private final static Logger mLog = LoggerFactory.getLogger( Golay24.class );
private final static Logger mLog = LoggerFactory.getLogger(Golay24.class);
/**
* Galois 24/12 checksums generated by:
*
* CRCUtil.generate( 12, 11, 0xC75, 0x0, true );
*/
public static final int[] CHECKSUMS = new int[]
{
0x63A, 0x31D, 0x7B4, 0x3DA, 0x1ED, 0x6CC, 0x366, 0x1B3,
0x6E3, 0x54B, 0x49F, 0x475, 0x400, 0x200, 0x100, 0x080,
0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001
};
/**
* Galois 24/12 checksums generated by:
*
* CRCUtil.generate( 12, 11, 0xC75, 0x0, true );
*/
public static final int[] CHECKSUMS = new int[]
{
0x63A, 0x31D, 0x7B4, 0x3DA, 0x1ED, 0x6CC, 0x366, 0x1B3,
0x6E3, 0x54B, 0x49F, 0x475, 0x400, 0x200, 0x100, 0x080,
0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001
};
private static int calculateChecksum( BinaryMessage message, int startIndex )
{
int calculated = 0; //Starting value
private static int calculateChecksum(BinaryMessage message, int startIndex)
{
int calculated = 0; //Starting value
/* Iterate the set bits and XOR running checksum with lookup value */
for (int i = message.nextSetBit( startIndex );
i >= startIndex && i < startIndex + 12;
i = message.nextSetBit( i+1 ) )
{
calculated ^= CHECKSUMS[ i - startIndex ];
}
return calculated;
}
/**
* Performs error detection and returns a corrected copy of the 24-bit
* message that starts at the start index.
* @param message - source message containing startIndex + 24 bits length
* @param startIndex - start of the 24-bit galois 24 protected bit set
* @return - corrected 24-bit galois value
*/
public static BinaryMessage checkAndCorrect( BinaryMessage message, int startIndex )
{
boolean parityError = message.cardinality() % 2 != 0;
int syndrome = getSyndrome( message, startIndex );
/* No errors */
if( syndrome == 0 )
{
if( parityError )
{
message.flip( startIndex + 23 );
}
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = message.nextSetBit(startIndex);
i >= startIndex && i < startIndex + 12;
i = message.nextSetBit(i + 1))
{
calculated ^= CHECKSUMS[i - startIndex];
}
message.setCRC( CRC.PASSED );
return message;
}
return calculated;
}
/* Get original message value */
int original = message.getInt( 0, 22 );
int index = -1;
int syndromeWeight = 3;
int errors = 0;
while( index < 23 )
{
if( index != -1 )
{
/* restore the previous flipped bit */
if( index > 0 )
{
message.flip( index - 1 );
}
message.flip( index );
syndromeWeight = 2;
}
syndrome = getSyndrome( message, startIndex );
if( syndrome > 0 )
{
for( int i = 0; i < 23; i++ )
{
errors = Integer.bitCount( syndrome );
if( errors <= syndromeWeight )
{
message.xor( 12, 11, syndrome );
message.rotateRight( i, startIndex, startIndex + 22 );
/**
* Performs error detection and returns a corrected copy of the 24-bit
* message that starts at the start index.
*
* @param message - source message containing startIndex + 24 bits length
* @param startIndex - start of the 24-bit galois 24 protected bit set
* @return - corrected 24-bit galois value
*/
public static int checkAndCorrect(CorrectedBinaryMessage message, int startIndex)
{
boolean parityError = message.cardinality() % 2 != 0;
if( index >= 0 )
{
errors ++;
}
int syndrome = getSyndrome(message, startIndex);
int corrected = message.getInt( 0, 22 );
if( Integer.bitCount( original ^ corrected ) > 3 )
{
message.setCRC( CRC.FAILED_CRC );
return message;
}
message.setCRC( CRC.PASSED );
return message;
}
else
{
message.rotateLeft( startIndex, startIndex + 22 );
syndrome = getSyndrome( message, startIndex );
}
}
index++;
}
}
/* No errors */
if(syndrome == 0)
{
if(parityError)
{
message.flip(startIndex + 23);
message.incrementCorrectedBitCount(1);
return 1;
}
message.setCRC( CRC.FAILED_CRC );
return message;
}
return 0;
}
private static int getSyndrome( BinaryMessage message, int startIndex )
{
int calculated = calculateChecksum( message, startIndex );
int checksum = message.getInt( startIndex + 12, startIndex + 22 );
/* Get original message value */
int original = message.getInt(0, 22);
return ( checksum ^ calculated );
}
int index = -1;
int syndromeWeight = 3;
int errors = 0;
while(index < 23)
{
if(index != -1)
{
/* restore the previous flipped bit */
if(index > 0)
{
message.flip(index - 1);
}
message.flip(index);
syndromeWeight = 2;
}
syndrome = getSyndrome(message, startIndex);
if(syndrome > 0)
{
for(int i = 0; i < 23; i++)
{
errors = Integer.bitCount(syndrome);
if(errors <= syndromeWeight)
{
message.xor(12, 11, syndrome);
message.rotateRight(i, startIndex, startIndex + 22);
if(index >= 0)
{
errors++;
}
int corrected = message.getInt(0, 22);
if(Integer.bitCount(original ^ corrected) > 3)
{
return 2;
}
return 1;
}
else
{
message.rotateLeft(startIndex, startIndex + 22);
syndrome = getSyndrome(message, startIndex);
}
}
index++;
}
}
return 2;
}
private static int getSyndrome(BinaryMessage message, int startIndex)
{
int calculated = calculateChecksum(message, startIndex);
int checksum = message.getInt(startIndex + 12, startIndex + 22);
return (checksum ^ calculated);
}
}

View File

@@ -1,115 +1,124 @@
package io.github.dsheirer.edac;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hamming (10,6,3) error detection and correction utility. This is a truncated version of the Hamming15 class.
*/
public class Hamming10
{
private final static Logger mLog = LoggerFactory.getLogger( Hamming10.class );
private static int[] CHECKSUMS = new int[] { 0xE,0xD,0xB,0X7,0x3,0xC };
private final static Logger mLog = LoggerFactory.getLogger(Hamming10.class);
/**
* Performs error detection and correction of any single-bit errors. This
* is a truncated version of the Hamming15 class.
*
* @param frame - binary frame containing a Hamming(10,6,3) protected field
*
* @param startIndex - offset to the first bit of the field
*
* @return - 0 = no errors
* 1 = a single-bit error was corrected
*/
public static int checkAndCorrect( BinaryMessage frame, int startIndex )
{
int syndrome = getSyndrome( frame, startIndex );
private static int[] CHECKSUMS = new int[]{0xE, 0xD, 0xB, 0X7, 0x3, 0xC};
switch( syndrome )
{
case 0:
return 0;
case 1:
frame.flip( startIndex + 9 ); //Parity 1
return 1;
case 2:
frame.flip( startIndex + 8 ); //Parity 2
return 1;
case 3:
frame.flip( startIndex + 4 ); //Data 2
return 1;
case 4:
frame.flip( startIndex + 7 ); //Parity 4
return 1;
case 5:
return 2;
case 6:
return 2;
case 7:
frame.flip( startIndex + 3 ); //Data 3
return 1;
case 8:
frame.flip( startIndex + 6 ); //Parity 8
return 1;
case 9:
return 2;
case 10:
return 2;
case 11:
frame.flip( startIndex + 2 ); //Data 4
return 1;
case 12:
frame.flip( startIndex + 5 ); //Data 1
return 1;
case 13:
frame.flip( startIndex + 1 ); //Data 5
return 1;
case 14:
frame.flip( startIndex + 0 ); //Data 6
return 1;
case 15:
return 2;
}
/**
* Performs error detection and correction of any single-bit errors.
*
* @param frame - binary frame containing a Hamming(10,6,3) protected field
* @param startIndex - offset to the first bit of the field
* @return - 0 = no errors
* 1 = a single-bit error was corrected
* 2 = more than 1 bit error detected - unable to correct word
*/
public static int checkAndCorrect(CorrectedBinaryMessage frame, int startIndex)
{
int syndrome = getSyndrome(frame, startIndex);
/* We'll never get to here */
return 2;
}
switch(syndrome)
{
case 0:
return 0;
case 1:
frame.flip(startIndex + 9); //Parity 1
frame.incrementCorrectedBitCount(1);
return 1;
case 2:
frame.flip(startIndex + 8); //Parity 2
frame.incrementCorrectedBitCount(1);
return 1;
case 3:
frame.flip(startIndex + 4); //Data 2
frame.incrementCorrectedBitCount(1);
return 1;
case 4:
frame.flip(startIndex + 7); //Parity 4
frame.incrementCorrectedBitCount(1);
return 1;
case 5:
return 2;
case 6:
return 2;
case 7:
frame.flip(startIndex + 3); //Data 3
frame.incrementCorrectedBitCount(1);
return 1;
case 8:
frame.flip(startIndex + 6); //Parity 8
frame.incrementCorrectedBitCount(1);
return 1;
case 9:
return 2;
case 10:
return 2;
case 11:
frame.flip(startIndex + 2); //Data 4
frame.incrementCorrectedBitCount(1);
return 1;
case 12:
frame.flip(startIndex + 5); //Data 1
frame.incrementCorrectedBitCount(1);
return 1;
case 13:
frame.flip(startIndex + 1); //Data 5
frame.incrementCorrectedBitCount(1);
return 1;
case 14:
frame.flip(startIndex + 0); //Data 6
frame.incrementCorrectedBitCount(1);
return 1;
case 15:
return 2;
}
/**
* Calculates the checksum (Parity 8,4,2,1) for data (6 <> 1 ) bits.
* @param frame - frame containing hamming(10) protected word
* @param startIndex - start bit index of the hamming protected word
* @return parity value, 0 - 15
*/
private static int calculateChecksum( BinaryMessage frame, int startIndex )
{
int calculated = 0; //Starting value
/* We'll never get to here */
return 2;
}
/* Iterate the set bits and XOR running checksum with lookup value */
for (int i = frame.nextSetBit( startIndex );
i >= startIndex && i < startIndex + 6;
i = frame.nextSetBit( i+1 ) )
{
calculated ^= CHECKSUMS[ i - startIndex ];
}
return calculated;
}
/**
* Calculates the checksum (Parity 8,4,2,1) for data (6 <> 1 ) bits.
*
* @param frame - frame containing hamming(10) protected word
* @param startIndex - start bit index of the hamming protected word
* @return parity value, 0 - 15
*/
private static int calculateChecksum(BinaryMessage frame, int startIndex)
{
int calculated = 0; //Starting value
/**
* Calculates the syndrome - xor of the calculated checksum and the actual
* checksum.
*
* @param frame - binary frame containing a hamming(15,11,4) protected word
* @param startIndex - of bit 0 of the hamming protected word
* @return - 0 (no errors) or 1 (single bit error corrected)
*/
private static int getSyndrome( BinaryMessage frame, int startIndex )
{
int calculated = calculateChecksum( frame, startIndex );
int checksum = frame.getInt( startIndex + 6, startIndex + 9 );
/* Iterate the set bits and XOR running checksum with lookup value */
for(int i = frame.nextSetBit(startIndex); i >= startIndex && i < startIndex + 6; i = frame.nextSetBit(i + 1))
{
calculated ^= CHECKSUMS[i - startIndex];
}
return ( checksum ^ calculated );
}
return calculated;
}
/**
* Calculates the syndrome - xor of the calculated checksum and the actual
* checksum.
*
* @param frame - binary frame containing a hamming(15,11,4) protected word
* @param startIndex - of bit 0 of the hamming protected word
* @return - 0 (no errors) or 1 (single bit error corrected)
*/
private static int getSyndrome(BinaryMessage frame, int startIndex)
{
int calculated = calculateChecksum(frame, startIndex);
int checksum = frame.getInt(startIndex + 6, startIndex + 9);
return (checksum ^ calculated);
}
}

View File

@@ -1,38 +1,40 @@
package io.github.dsheirer.edac;
/*
* ******************************************************************************
* 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/>
* *****************************************************************************
*/
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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.edac;
public class ReedSolomon_63_47_17 extends BerlekempMassey_63
{
/**
* Reed-Solomon RS(63,47,17) decoder. This can also be used for error detection
* and correction of the following RS codes:
*
* RS(36,20,17) - max 8 errors
* RS(24,16,9) - max 4 errors
* RS(24,12,13) - max 6 errors
*
* The maximum correctable errors is determined by (n-k)/2, or hamming
* distance divided by 2.
*/
public ReedSolomon_63_47_17( int maximumCorrectableErrors )
/**
* Reed-Solomon RS(63,47,17) decoder. This can also be used for error detection
* and correction of the following RS codes:
*
* RS(36,20,17) - max 8 errors
* RS(24,16,9) - max 4 errors
* RS(24,12,13) - max 6 errors
*
* The maximum correctable errors is determined by (n-k)/2, or hamming
* distance divided by 2.
*/
public ReedSolomon_63_47_17(int maximumCorrectableErrors)
{
super( maximumCorrectableErrors );
super(maximumCorrectableErrors);
}
}

View File

@@ -18,7 +18,7 @@
******************************************************************************/
package io.github.dsheirer.edac.trellis;
public class DMRNode extends Node
public class DMR_3_4_Node extends Node
{
//Hamming error values indicating the number of bits set in each indexed value, 0-15
public static final int[] HAMMING_ERROR_COUNT = new int[]{0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
@@ -47,7 +47,7 @@ public class DMRNode extends Node
* @param inputValue for the trellis time instant
* @param transmittedOutputValue the actual four-bit output value that was transmitted.
*/
public DMRNode(int inputValue, int transmittedOutputValue)
public DMR_3_4_Node(int inputValue, int transmittedOutputValue)
{
super(inputValue, transmittedOutputValue);
}

View File

@@ -0,0 +1,85 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package io.github.dsheirer.edac.trellis;
public class P25_1_2_Node extends Node
{
/**
* Hamming error values indicating the number of bits set in each indexed value, 0-15. XOR the
* transmitted 4-bit value against the reference 4-bit value to obtain the lookup index to this array.
*/
public static final int[] HAMMING_ERROR_COUNT = new int[]{0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
/**
* P25 Finite State Machine 1/2 Rate transition matrix.
*
* Note: these transmitted bit values are translated from TIA-102 BAAA Table 7-2 encoder state
* table constellation values.
*/
public static final int[][] TRANSITION_MATRIX = new int[][]
{
{2,12,1,15},//0,15,12,3
{14,0,13,3},//4,11,8,7
{9,7,10,4}, //13,2,1,14
{5,11,6,8} //9,6,5,10
};
/**
* P25 1/2-rate Trellis Coded Modulation (TCM) node
*
* @param inputValue for the trellis time instant
* @param transmittedOutputValue the actual four-bit output value that was transmitted.
*/
public P25_1_2_Node(int inputValue, int transmittedOutputValue)
{
super(inputValue, transmittedOutputValue);
}
/**
* Calculates the error between the preceeding node and this node as the Hamming distance between the expected
* four-bit output value versus the actual transmitted output value.
*
* @param precedingNode that precedes this node
* @return error value for this node relative to the preceeding node argument
*/
@Override
public int getError(Node precedingNode)
{
if(precedingNode != null)
{
int expectedOutputValue = getOutputValue(precedingNode);
int errorMask = expectedOutputValue ^ getTransmittedOutputValue();
return HAMMING_ERROR_COUNT[errorMask];
}
return 0;
}
/**
* Expected output four-bit value when this node is preceeded by the argument node.
*
* @param precedingNode that precedes this node
* @return expected output value
*/
@Override
public int getOutputValue(Node precedingNode)
{
return TRANSITION_MATRIX[precedingNode.getInputValue()][getInputValue()];
}
}

View File

@@ -0,0 +1,84 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package io.github.dsheirer.edac.trellis;
public class P25_3_4_Node extends Node
{
//Hamming error values indicating the number of bits set in each indexed value, 0-15
public static final int[] HAMMING_ERROR_COUNT = new int[]{0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
/**
* Trellis encoder state transition table. Note: this table is converted from the ICD state
* transition table where the table symbol is converted to the transmitted bit value.
*/
public static final int[][] TRANSITION_MATRIX = new int[][]
{
{2,13,14,1,7,8,11,4},
{14,1,7,8,11,4,2,13},
{10,5,6,9,15,0,3,12},
{6,9,15,0,3,12,10,5},
{15,0,3,12,10,5,6,9},
{3,12,10,5,6,9,15,0},
{7,8,11,4,2,13,14,1},
{11,4,2,13,14,1,7,8}
};
/**
* Trellis Coded Modulation (TCM) 3/4-rate trellis node for decoding P25
*
* @param inputValue for the trellis time instant
* @param transmittedOutputValue the actual four-bit output value that was transmitted.
*/
public P25_3_4_Node(int inputValue, int transmittedOutputValue)
{
super(inputValue, transmittedOutputValue);
}
/**
* Calculates the error between the preceeding node and this node as the Hamming distance between the expected
* four-bit output value versus the actual transmitted output value.
*
* @param precedingNode that precedes this node
* @return error value for this node relative to the preceeding node argument
*/
@Override
public int getError(Node precedingNode)
{
if(precedingNode != null)
{
int expectedOutputValue = getOutputValue(precedingNode);
int errorMask = expectedOutputValue ^ getTransmittedOutputValue();
return HAMMING_ERROR_COUNT[errorMask];
}
return 0;
}
/**
* Expected output four-bit value when this node is preceeded by the argument node.
*
* @param precedingNode that precedes this node
* @return expected output value
*/
@Override
public int getOutputValue(Node precedingNode)
{
return TRANSITION_MATRIX[precedingNode.getInputValue()][getInputValue()];
}
}

View File

@@ -0,0 +1,154 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package io.github.dsheirer.edac.trellis;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import java.util.List;
/**
* Viterbi decoder for APCO-25 1/2 rate Trellis Coded Modulation (TCM) encoded messages.
*/
public class ViterbiDecoder_1_2_P25 extends ViterbiDecoder
{
public ViterbiDecoder_1_2_P25()
{
super(2,4);
}
/**
* Decodes a 1/2 rate trellis coded modulation (TCM) encoded P25 binary message containing 196 bits that have
* already been deinterleaved.
*
* @param encodedMessage to decode that has already been deinterleaved.
* @return decoded message
*/
public CorrectedBinaryMessage decode(BinaryMessage encodedMessage)
{
int[] symbols = getSymbols(encodedMessage);
Path mostLikelyPath = decode(symbols);
return getMessage(mostLikelyPath);
}
/**
* Extracts the decoded/corrected message from the surviving path argument.
*
* @param path to extract a message from
* @return corrected binary message.
*/
private CorrectedBinaryMessage getMessage(Path path)
{
List<Node> mNodes = path.getNodes();
//Each node contains an input value excluding the starting(0) and final flushing(0) nodes.
CorrectedBinaryMessage message = new CorrectedBinaryMessage((mNodes.size() - 2) * getInputBitLength());
if(mNodes.size() > 2)
{
for(int x = 1; x < mNodes.size() - 1; x++)
{
int inputValue = mNodes.get(x).getInputValue();
int messageOffset = getInputBitLength() * (x - 1);
if((inputValue & 2) == 2)
{
message.set(messageOffset);
}
if((inputValue & 1) == 1)
{
message.set(messageOffset + 1);
}
}
}
//Transfer the corrected error count to the message
message.setCorrectedBitCount(path.getError());
return message;
}
/**
* Extracts (49) four-bit symbols (196 bits / 4) from the deinterleaved P25 binary message
*
* @param encodedMessage that deinterleaved and contains 196-bits of 1/2 TCM encoding
* @return symbols
*/
public int[] getSymbols(BinaryMessage encodedMessage)
{
//Ensure we have an integral number of transmitted symbols (nibbles) in the message
if(encodedMessage.size() % getOutputBitLength() != 0)
{
throw new IllegalArgumentException("Encoded message must contain an integral number of 4-bit symbols -" +
" message size: " + encodedMessage.size());
}
int[] symbols = new int[encodedMessage.size() / getOutputBitLength()];
int index = 0;
int pointer = 0;
while(index < encodedMessage.size())
{
int symbol = encodedMessage.getInt(index, index + (getOutputBitLength() - 1));
symbols[pointer++] = symbol;
index += getOutputBitLength();
}
return symbols;
}
/**
* Creates a P25 node
* @param inputValue for the specific trellis node
* @param transmittedOutputValue the actual transmitted output value
* @return created node
*/
@Override
protected Node createNode(int inputValue, int transmittedOutputValue)
{
return new P25_1_2_Node(inputValue, transmittedOutputValue);
}
/**
* Creates a P25 flushing node. P25 uses an input value of zero to flush the final output value out of the
* encoder.
*
* @param transmittedOutputValue the actual transmitted output value
* @return
*/
@Override
protected Node createFlushingNode(int transmittedOutputValue)
{
return new P25_1_2_Node(0, transmittedOutputValue);
}
/**
* Creates a P25 starting node. P25 uses a starting input value of zero for the initial node.
*/
@Override
protected Node createStartingNode()
{
return new P25_1_2_Node(0,0);
}
}

View File

@@ -40,7 +40,7 @@ public class ViterbiDecoder_3_4_DMR extends ViterbiDecoder
* @param encodedMessage to decode that has already been deinterleaved.
* @return decoded message
*/
public BinaryMessage decode(BinaryMessage encodedMessage)
public CorrectedBinaryMessage decode(BinaryMessage encodedMessage)
{
int[] symbols = getSymbols(encodedMessage);
@@ -132,7 +132,7 @@ public class ViterbiDecoder_3_4_DMR extends ViterbiDecoder
@Override
protected Node createNode(int inputValue, int transmittedOutputValue)
{
return new DMRNode(inputValue, transmittedOutputValue);
return new DMR_3_4_Node(inputValue, transmittedOutputValue);
}
/**
@@ -145,7 +145,7 @@ public class ViterbiDecoder_3_4_DMR extends ViterbiDecoder
@Override
protected Node createFlushingNode(int transmittedOutputValue)
{
return new DMRNode(0, transmittedOutputValue);
return new DMR_3_4_Node(0, transmittedOutputValue);
}
/**
@@ -154,6 +154,6 @@ public class ViterbiDecoder_3_4_DMR extends ViterbiDecoder
@Override
protected Node createStartingNode()
{
return new DMRNode(0,0);
return new DMR_3_4_Node(0,0);
}
}

View File

@@ -0,0 +1,160 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package io.github.dsheirer.edac.trellis;
import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import java.util.List;
public class ViterbiDecoder_3_4_P25 extends ViterbiDecoder
{
/**
* Viterbi decoder for P25 3/4 rate Trellis Coded Modulation (TCM) encoded messages.
*/
public ViterbiDecoder_3_4_P25()
{
super(3, 4);
}
/**
* Decodes a 3/4 rate trellis coded modulation (TCM) encoded P25 binary message containing 196 bits that have
* already been deinterleaved.
*
* @param encodedMessage to decode that has already been deinterleaved.
* @return decoded message
*/
public CorrectedBinaryMessage decode(BinaryMessage encodedMessage)
{
int[] symbols = getSymbols(encodedMessage);
Path mostLikelyPath = decode(symbols);
return getMessage(mostLikelyPath);
}
/**
* Extracts the decoded/corrected message from the surviving path argument.
*
* @param path to extract a message from
* @return corrected binary message.
*/
private static CorrectedBinaryMessage getMessage(Path path)
{
List<Node> mNodes = path.getNodes();
//Each node contains an input value excluding the starting(0) and final flushing(0) nodes.
CorrectedBinaryMessage message = new CorrectedBinaryMessage((mNodes.size() - 2) * 3);
if(mNodes.size() > 2)
{
for(int x = 1; x < mNodes.size() - 1; x++)
{
int inputValue = mNodes.get(x).getInputValue();
int messageOffset = 3 * (x - 1);
if((inputValue & 4) == 4)
{
message.set(messageOffset);
}
if((inputValue & 2) == 2)
{
message.set(messageOffset + 1);
}
if((inputValue & 1) == 1)
{
message.set(messageOffset + 2);
}
}
}
//Transfer the corrected error count to the message
message.setCorrectedBitCount(path.getError());
return message;
}
/**
* Extracts (49) four-bit symbols (196 bits / 4) from the deinterleaved P25 binary message
*
* @param encodedMessage that deinterleaved and contains 196-bits of 3/4 TCM encoding
* @return symbols
*/
public int[] getSymbols(BinaryMessage encodedMessage)
{
//Ensure we have an integral number of transmitted symbols (nibbles) in the message
if(encodedMessage.size() % getOutputBitLength() != 0)
{
throw new IllegalArgumentException("Encoded message must contain an integral number of 4-bit symbols -" +
" message size: " + encodedMessage.size());
}
int[] symbols = new int[encodedMessage.size() / getOutputBitLength()];
int index = 0;
int pointer = 0;
while(index < encodedMessage.size())
{
int symbol = encodedMessage.getInt(index, index + (getOutputBitLength() - 1));
symbols[pointer++] = symbol;
index += getOutputBitLength();
}
return symbols;
}
/**
* Creates a P25 node
*
* @param inputValue for the specific trellis node
* @param transmittedOutputValue the actual transmitted output value
* @return created node
*/
@Override
protected Node createNode(int inputValue, int transmittedOutputValue)
{
return new P25_3_4_Node(inputValue, transmittedOutputValue);
}
/**
* Creates a P25 flushing node. P25 uses an input value of zero to flush the final output value out of the
* encoder.
*
* @param transmittedOutputValue the actual transmitted output value
* @return
*/
@Override
protected Node createFlushingNode(int transmittedOutputValue)
{
return new P25_3_4_Node(0, transmittedOutputValue);
}
/**
* Creates a P25 starting node. P25 uses a starting input value of zero for the initial node.
*/
@Override
protected Node createStartingNode()
{
return new P25_3_4_Node(0, 0);
}
}