Global rename of BitSetBuffer to BinaryMessage.

Corrected issue in P25 NID error correction.
This commit is contained in:
dennis.sheirer
2015-01-24 13:37:42 +00:00
parent 871705ece8
commit 9310fb0daf
148 changed files with 513 additions and 443 deletions

View File

@@ -1,9 +1,11 @@
package edac;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bits.BitSetBuffer;
import bits.BinaryMessage;
/*******************************************************************************
* SDR Trunk
@@ -43,18 +45,20 @@ public class BCH_63_16_11 extends BerlekempMassey_63
*
* @return - true = success, false = failure
*/
public CRC correctNID( BitSetBuffer message )
public BinaryMessage correctNID( BinaryMessage message )
{
CRC status = CRC.PASSED;
int[] original = message.toReverseIntegerArray();
int[] original = message.toReverseIntegerArray( 0, 62 );
int[] corrected = new int[ 63 ];
boolean irrecoverableErrors = decode( original, corrected );
if( irrecoverableErrors )
{
return CRC.FAILED_CRC;
message.setCRC( CRC.FAILED_CRC );
return message;
}
else
{
@@ -78,15 +82,17 @@ public class BCH_63_16_11 extends BerlekempMassey_63
}
}
return status;
message.setCRC( status );
return message;
}
public static void main( String[] args )
{
String orig = "001001100000110010100101011111010001010101101001111111001010110";
String error = "010110000000110010100101011011010001011101101001101111001110110";
// xxxxxx x x x x
BitSetBuffer errorMessage = BitSetBuffer.load( error );
String orig = "0010011000000011010010100000000110000111110011101010001010110000";
String error = "0001010100000011010010100000000110000111100011001010001010110000";
BinaryMessage errorMessage = BinaryMessage.load( error );
BCH_63_16_11 bch = new BCH_63_16_11();
@@ -94,10 +100,10 @@ public class BCH_63_16_11 extends BerlekempMassey_63
mLog.debug( " ERR:" + errorMessage.toString() );
mLog.debug( " " );
CRC status = bch.correctNID( errorMessage );
errorMessage = bch.correctNID( errorMessage );
mLog.debug( " CRC: " + status.name() );
mLog.debug( "CORR:" + errorMessage.toString().substring( 0, 16 ) );
mLog.debug( " CRC: " + errorMessage.getCRC().name() );
mLog.debug( "CORR:" + errorMessage.toString() );
mLog.debug( "ORIG:" + orig );
}
}

View File

@@ -180,7 +180,7 @@ public class BerlekempMassey_63
/**
* Decodes
* @param input
* @param recd
* @param output
* @return
*/
/* assume we have received bits grouped into mm-bit symbols in recd[i],
@@ -201,7 +201,7 @@ public class BerlekempMassey_63
symbols will be okay and that if we are in luck, the errors are in the
parity part of the transmitted codeword). Of course, these insoluble cases
can be returned as error flags to the calling routine if desired. */
public boolean decode( final int[] input, int[] recd ) //input, output
public boolean decode( final int[] input, int[] output ) //input, output
{
int u, q;
int[][] elp = new int[ NN - KK + 2 ][ NN - KK ];
@@ -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++ )
{
recd[ i ] = index_of[ input[ i ] ];
output[ i ] = index_of[ input[ i ] ];
}
/* first form the syndromes */
@@ -232,10 +232,10 @@ public class BerlekempMassey_63
for( int j = 0; j < NN; j++ )
{
if( recd[ j ] != -1 )
if( output[ j ] != -1 )
{
/* recd[j] in index form */
s[ i ] ^= alpha_to[ ( recd[ j ] + i * j ) % NN ];
s[ i ] ^= alpha_to[ ( output[ j ] + i * j ) % NN ];
}
}
@@ -455,13 +455,13 @@ public class BerlekempMassey_63
{
err[ i ] = 0;
if( recd[ i ] != -1 ) /* convert recd[] to polynomial form */
if( output[ i ] != -1 ) /* convert recd[] to polynomial form */
{
recd[ i ] = alpha_to[ recd[ i ] ];
output[ i ] = alpha_to[ output[ i ] ];
}
else
{
recd[ i ] = 0;
output[ i ] = 0;
}
}
@@ -493,7 +493,7 @@ public class BerlekempMassey_63
q = q % NN;
err[loc[i]] = alpha_to[(err[loc[i]] - q + NN) % NN];
recd[loc[i]] ^= err[loc[i]]; /*recd[i] must be in polynomial form */
output[loc[i]] ^= err[loc[i]]; /*recd[i] must be in polynomial form */
}
}
}
@@ -515,13 +515,13 @@ public class BerlekempMassey_63
/* no non-zero syndromes => no errors: output received codeword */
for (int i = 0; i < NN; i++)
{
if (recd[i] != -1) /* convert recd[] to polynomial form */
if (output[i] != -1) /* convert recd[] to polynomial form */
{
recd[i] = alpha_to[recd[i]];
output[i] = alpha_to[output[i]];
}
else
{
recd[i] = 0;
output[i] = 0;
}
}
}
@@ -530,13 +530,13 @@ public class BerlekempMassey_63
{
for (int i = 0; i < NN; i++) /* could return error flag if desired */
{
if (recd[i] != -1) /* convert recd[] to polynomial form */
if (output[i] != -1) /* convert recd[] to polynomial form */
{
recd[i] = alpha_to[recd[i]];
output[i] = alpha_to[output[i]];
}
else
{
recd[i] = 0; /* just output received codeword as is */
output[i] = 0; /* just output received codeword as is */
}
}
}

View File

@@ -22,7 +22,7 @@ import java.util.BitSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bits.BitSetBuffer;
import bits.BinaryMessage;
/**
* LJ CRC checksum utility
@@ -108,7 +108,7 @@ public class CRCLJ
* Determines if FUNCTION AND ADDRESS bits pass the LJ CRC checksum
* using a lookup table of CRC checksum values derived from the CRC-16 value
*/
public static CRC checkAndCorrect( BitSetBuffer message )
public static CRC checkAndCorrect( BinaryMessage message )
{
int calculated = 0; //Starting value
@@ -203,7 +203,7 @@ public class CRCLJ
public static void main( String[] args )
{
BitSetBuffer msg = BitSetBuffer.load( "01010101101010101010000100011000000000100001000110000000001000010001100000000010" );
BinaryMessage msg = BinaryMessage.load( "01010101101010101010000100011000000000100001000110000000001000010001100000000010" );
CRC crc = checkAndCorrect( msg );

View File

@@ -20,7 +20,7 @@ package edac;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bits.BitSetBuffer;
import bits.BinaryMessage;
/**
* P25 CRC check/correction methods
@@ -222,7 +222,7 @@ public class CRCP25
* Performs error detection and single-bit error correction against the
* data blocks of a PDU1 message.
*/
public static CRC correctPDU1( BitSetBuffer message )
public static BinaryMessage correctPDU1( BinaryMessage message )
{
return correctPDU( message, PDU1_CHECKSUMS, 224 );
}
@@ -231,7 +231,7 @@ public class CRCP25
* Performs error detection and single-bit error correction against the
* data blocks of a PDU2 message.
*/
public static CRC correctPDU2( BitSetBuffer message )
public static BinaryMessage correctPDU2( BinaryMessage message )
{
return correctPDU( message, PDU2_CHECKSUMS, 320 );
}
@@ -240,12 +240,12 @@ public class CRCP25
* Performs error detection and single-bit error correction against the
* data blocks of a PDU3 message.
*/
public static CRC correctPDU3( BitSetBuffer message )
public static BinaryMessage correctPDU3( BinaryMessage message )
{
return correctPDU( message, PDU3_CHECKSUMS, 416 );
}
public static CRC correctPDU( BitSetBuffer message, long[] checksums, int crcStart )
public static BinaryMessage correctPDU( BinaryMessage message, long[] checksums, int crcStart )
{
long calculated = 0; //Starting value
@@ -265,7 +265,9 @@ public class CRCP25
if( error == 0 || error == 0xFFFFFFFFl )
{
return CRC.PASSED;
message.setCRC( CRC.PASSED );
return message;
}
else
{
@@ -274,21 +276,25 @@ public class CRCP25
if( errorLocation >= 0 )
{
message.flip( errorLocation + messageStart );
message.setCRC( CRC.CORRECTED );
return CRC.CORRECTED;
return message;
}
}
return CRC.FAILED_CRC;
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 CRC correctCCITT80( BitSetBuffer message,
int messageStart,
int crcStart )
public static BinaryMessage correctCCITT80( BinaryMessage message,
int messageStart,
int crcStart )
{
int calculated = 0; //Starting value
@@ -306,7 +312,9 @@ public class CRCP25
if( residual == 0 || residual == 0xFFFF )
{
return CRC.PASSED;
message.setCRC( CRC.PASSED );
return message;
}
else
{
@@ -316,11 +324,15 @@ public class CRCP25
{
message.flip( errorLocation + messageStart );
return CRC.CORRECTED;
message.setCRC( CRC.CORRECTED );
return message;
}
}
return CRC.FAILED_CRC;
message.setCRC( CRC.FAILED_CRC );
return message;
}
/**
@@ -330,7 +342,7 @@ public class CRCP25
* were generated assuming that the message is contiguous from 0 - 134 bits.
* No data correction is performed.
*/
public static CRC checkCRC9( BitSetBuffer message, int messageStart )
public static CRC checkCRC9( BinaryMessage message, int messageStart )
{
int calculated = 0x0; //Initial fill of all ones
@@ -372,7 +384,7 @@ public class CRCP25
*
* @return - true if all 12 segments of the message can be checked/corrected
*/
public static boolean correctGalois24( BitSetBuffer tdulc )
public static boolean correctGalois24( BinaryMessage tdulc )
{
boolean passes = true;
@@ -380,7 +392,10 @@ public class CRCP25
while( x < tdulc.size() && passes )
{
passes = Galois24.checkAndCorrect( tdulc, x );
tdulc = Galois24.checkAndCorrect( tdulc, x );
passes = tdulc.getCRC() == CRC.PASSED;
x += 24;
}
@@ -392,7 +407,7 @@ public class CRCP25
/**
* Calculates the value of the message checksum as a long
*/
public static long getLongChecksum( BitSetBuffer message,
public static long getLongChecksum( BinaryMessage message,
int crcStart, int crcLength )
{
return message.getLong( crcStart, crcStart + crcLength - 1 );
@@ -401,7 +416,7 @@ public class CRCP25
/**
* Calculates the value of the message checksum as an integer
*/
public static int getIntChecksum( BitSetBuffer message,
public static int getIntChecksum( BinaryMessage message,
int crcStart, int crcLength )
{
return message.getInt( crcStart, crcStart + crcLength - 1 );
@@ -443,7 +458,7 @@ public class CRCP25
{
String raw = "000000001000001100000001010001111011000100001010010001111100000000000101000000000000000001000000000000110000000000000001101010101010101010101010";
BitSetBuffer message = BitSetBuffer.load( raw );
BinaryMessage message = BinaryMessage.load( raw );
mLog.debug( "MSG:" + message.toString() );

View File

@@ -19,7 +19,7 @@ package edac;
import java.util.BitSet;
import bits.BitSetBuffer;
import bits.BinaryMessage;
/**
* Passport CRC checksum utility
@@ -168,7 +168,7 @@ public class CRCPassport
* 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 BitSetBuffer correct( BitSetBuffer msg )
public static BinaryMessage correct( BinaryMessage msg )
{
int residual = (int)( 0xFF & getResidual( msg ) );
@@ -208,7 +208,7 @@ public class CRCPassport
* 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( BitSetBuffer bits )
public static boolean isEvenParity( BinaryMessage bits )
{
return ( bits.cardinality() % 2 == 0 );
}

View File

@@ -20,7 +20,7 @@ package edac;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bits.BitSetBuffer;
import bits.BinaryMessage;
public class CRCUtil
{
@@ -44,7 +44,7 @@ public class CRCUtil
for( int x = 0; x < messageSize; x++ )
{
BitSetBuffer message = new BitSetBuffer( messageSize + crcSize );
BinaryMessage message = new BinaryMessage( messageSize + crcSize );
message.load( messageSize, crcSize, initialFill );
@@ -130,7 +130,7 @@ public class CRCUtil
* @return message with all message bits zeroed out, and the remainder
* placed in the crc field which starts at index messageLength
*/
public static BitSetBuffer decode( BitSetBuffer message,
public static BinaryMessage decode( BinaryMessage message,
int messageStart,
int messageSize,
long polynomial,
@@ -140,7 +140,7 @@ public class CRCUtil
i >= messageStart && i < messageSize;
i = message.nextSetBit( i+1 ) )
{
BitSetBuffer polySet = new BitSetBuffer( crcSize + i + 1 );
BinaryMessage polySet = new BinaryMessage( crcSize + i + 1 );
polySet.load( i, crcSize + 1, polynomial );

View File

@@ -3,7 +3,7 @@ package edac;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bits.BitSetBuffer;
import bits.BinaryMessage;
/*******************************************************************************
* SDR Trunk
@@ -45,7 +45,7 @@ public class Galois24
0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001
};
private static int calculateChecksum( BitSetBuffer message, int startIndex )
private static int calculateChecksum( BinaryMessage message, int startIndex )
{
int calculated = 0; //Starting value
@@ -60,7 +60,7 @@ public class Galois24
return calculated;
}
public static boolean checkAndCorrect( BitSetBuffer message, int startIndex )
public static BinaryMessage checkAndCorrect( BinaryMessage message, int startIndex )
{
boolean parityError = message.cardinality() % 2 != 0;
@@ -73,8 +73,10 @@ public class Galois24
{
message.flip( startIndex + 23 );
}
message.setCRC( CRC.PASSED );
return true;
return message;
}
/* Get original message value */
@@ -123,10 +125,14 @@ public class Galois24
if( Integer.bitCount( original ^ corrected ) > 3 )
{
return false;
message.setCRC( CRC.FAILED_CRC );
return message;
}
return true;
message.setCRC( CRC.PASSED );
return message;
}
else
{
@@ -139,10 +145,12 @@ public class Galois24
}
}
return false;
message.setCRC( CRC.FAILED_CRC );
return message;
}
private static int getSyndrome( BitSetBuffer message, int startIndex )
private static int getSyndrome( BinaryMessage message, int startIndex )
{
int calculated = calculateChecksum( message, startIndex );
@@ -156,7 +164,7 @@ public class Galois24
/* NID + TDULC message */
String msg = "0010011000001111100100110011000100111010000111010001000000000000000000000000000000000000000000000100101010010111000000000000000000000000000010010111101111111111000000000000000000000000000000000000000000000000000110001011100001111101010110111001001011010010101111010010000010110011101111111100100000010001111100011010010100001101111001111001100000111000";
BitSetBuffer message = BitSetBuffer.load( msg );
BinaryMessage message = BinaryMessage.load( msg );
mLog.debug( "MSG: " + message.toString() );
@@ -164,9 +172,9 @@ public class Galois24
while( x < msg.length() )
{
boolean passes = checkAndCorrect( message, x );
message = checkAndCorrect( message, x );
mLog.debug( "X:" + x + " Pass:" + passes );
mLog.debug( "X:" + x + " Pass:" + ( message.getCRC()== CRC.PASSED ) );
x += 24;
}
}