Updates pull request from Roman Tsypuk to convert the build system from

ant to gradle.  Removes linux and windows application launch scripts and
produces an executable jar with all resources included.
This commit is contained in:
Denny
2017-12-17 07:28:03 -05:00
parent a1535c4157
commit 9316599dec
981 changed files with 8368 additions and 9049 deletions

View File

@@ -0,0 +1,901 @@
/*******************************************************************************
* 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.bits;
import io.github.dsheirer.edac.CRC;
import org.apache.commons.lang3.Validate;
import java.util.BitSet;
public class BinaryMessage extends BitSet
{
private static final long serialVersionUID = 1L;
/**
* Logical (ie constructed) size of this bitset, despite the actual size of
* the super bitset that this class is based on
*/
private int mSize = 0;
/**
* Pointer to the next fill index location, when adding bits to this bitset
* one at a time.
*/
private int mPointer = 0;
/**
* Bitset that buffers bits added one at a time, up to the size of the this
* bitset.
*
* Note: the super class bitset behind this class may have a size larger
* that the size parameter specified.
* @param size
*/
/**
* Used for temporary storage of CRC check results when we're passing this
* message to an EDAC function.
*/
private CRC mCRC;
public BinaryMessage( int size )
{
super( size );
mSize = size;
}
/**
* Constructs a bitset buffer and preloads it with the bits contained in
* the bitsToPreload parameter. If the bitsToPreload are longer than the
* size of the bitset, only those bits that fit will be preloaded
*
* @param size
* @param bitsToPreload
*/
public BinaryMessage( int size, boolean[] bitsToPreload )
{
this( size );
int pointer = 0;
while( !this.isFull() && pointer < bitsToPreload.length )
{
try
{
this.add( bitsToPreload[ pointer ] );
}
catch( BitSetFullException e )
{
e.printStackTrace();
}
pointer++;
}
}
/**
* Constructs a new BitSetBuffer from an existing one
*/
private BinaryMessage( BinaryMessage toCopyFrom )
{
this( toCopyFrom.size() );
this.or( toCopyFrom );
this.mPointer = toCopyFrom.pointer();
}
public BinaryMessage( BitSet bitset, int size )
{
this( size );
this.or( bitset );
this.mPointer = size - 1;
}
public BinaryMessage(byte[] data)
{
this(BitSet.valueOf(data), data.length * 8);
}
/**
* Returns a mew binary message containing the bits from (inclusive) to
* end (exclusive).
*
* @param start
* @param end
* @return
*/
public BinaryMessage getSubMessage( int start, int end )
{
BitSet subset = this.get( start, end );
return new BinaryMessage( subset, end - start );
}
public CRC getCRC()
{
return mCRC;
}
public void setCRC( CRC crc )
{
mCRC = crc;
}
/**
* Indicates the number of bit errors that were corrected in this message.
*
* @see CorrectedBinaryMessage subclass that supports setting this value
* @return number of corrected bits in this message
*/
public int getCorrectedBitCount()
{
return 0;
}
/**
* Current pointer index
*/
public int pointer()
{
return mPointer;
}
/**
* Sets the pointer to a specific value
* @param index
*/
public void setPointer( int index )
{
mPointer = index;
}
/**
* Moves the current pointer position left (negative adjustment) or
* right (positive adjustment)
*/
public void adjustPointer( int adjustment )
{
mPointer += adjustment;
}
/**
* Static method to construct a new BitSetBuffer, preloaded with the bits
* from the preload parameter, and then filled with the bits from the
* second bitsetbuffer parameter.
*
* @param preloadBits - boolean array of bits to be prepended to the new
* bitset
* @param bitsetToAppend - full bitset to be appended to the residual bits array
* @return - new Bitset preloaded with residual bits and new bitset
*/
public static BinaryMessage merge( boolean[] preloadBits, BinaryMessage bitsetToAppend )
{
BinaryMessage returnValue = new BinaryMessage( preloadBits.length + bitsetToAppend.size(), preloadBits );
int pointer = 0;
while( pointer < bitsetToAppend.size() && !returnValue.isFull() )
{
try
{
returnValue.add( bitsetToAppend.get( pointer ) );
}
catch( BitSetFullException e )
{
e.printStackTrace();
}
pointer++;
}
return returnValue;
}
/**
* Returns a (new) copy of this bitsetbuffer
* @return
*/
public BinaryMessage copy()
{
return new BinaryMessage( this );
}
public boolean isFull()
{
return mPointer >= mSize;
}
/**
* Overrides the in-build size() method of the bitset and returns the value
* specified at instantiation. The actual bitset size may be larger than
* this value, and that size is managed by the super class.
*/
@Override
public int size()
{
return mSize;
}
public void setSize( int size )
{
mSize = size;
}
/**
* Clears (sets to false or 0) the bits in this bitset and resets the
* pointer to zero.
*/
@Override
public void clear()
{
this.clear( 0, mSize );
mPointer = 0;
}
/**
* Adds a the bit parameters to this bitset, placing it in the index
* specified by mPointer, and incrementing mPointer to prepare for the next
* call to this method
* @param value
* @throws BitSetFullException - if the size specified at construction is
* exceeded. Invoke full() to determine if the bitset is full either before
* adding a new bit, or after adding a bit.
*/
public void add( boolean value ) throws BitSetFullException
{
if( !isFull() )
{
this.set( mPointer++, value );
}
else
{
throw new BitSetFullException( "bitset is full -- contains " +
( mPointer + 1 ) + "bits");
}
}
public String toString()
{
StringBuilder sb = new StringBuilder();
for( int x = 0; x < mSize; x++ )
{
sb.append( ( this.get( x ) ? "1" : "0" ) );
}
return sb.toString();
}
/**
* Returns this bitset as an array of integer ones and zeros
*/
public int[] toIntegerArray()
{
int[] values = new int[ mSize ];
for (int i = nextSetBit( 0 ); i >= 0 && i < mSize; i = nextSetBit( i+1 ) )
{
values[ i ] = 1;
}
return values;
}
/**
* Returns this message as a little endian byte array. Extra 0 bits will be padded to the end to make the overall
* length a multiple of 8.
* @return little endian message byte array
*/
public byte[] toByteArray()
{
int length = size() / 8;
if(length * 8 < size())
{
length ++;
}
byte[] bytes = new byte[length];
int pointer = 0;
for(int x = 0; x < length; x++)
{
bytes[x] = getByte(pointer);
pointer += 8;
}
return bytes;
}
/**
* Returns this bitset as a reversed bit order array of integer ones and zeros
* from the specified index range
*/
public int[] toReverseIntegerArray( int start, int end )
{
int[] values = new int[ end - start + 1 ];
for (int i = nextSetBit( start ); i >= start && i <= end; i = nextSetBit( i+1 ) )
{
values[ end - i ] = 1;
}
return values;
}
/**
* Returns a boolean array from startIndex to end of the bitset
*/
public boolean[] getBits( int startIndex )
{
return getBits( startIndex, mSize - 1 );
}
/**
* Returns a boolean array of the right-most bitCount number of bits
*/
public boolean[] right( int bitCount )
{
return getBits( mSize - bitCount - 1 );
}
/**
* Returns a boolean array representing the bits located from startIndex
* through endIndex
*/
public boolean[] getBits( int startIndex, int endIndex )
{
boolean[] returnValue = null;
if( startIndex >= 0 &&
startIndex < endIndex &&
endIndex < mSize )
{
returnValue = new boolean[ endIndex - startIndex + 1 ];
int bitsetPointer = startIndex;
int returnPointer = 0;
while( bitsetPointer <= endIndex )
{
returnValue[ returnPointer ] = this.get( bitsetPointer );
bitsetPointer++;
returnPointer++;
}
}
return returnValue;
}
/**
* Returns the integer value represented by the bit array
* @param bits - an array of bit positions that will be treated as if they
* were contiguous bits, with index 0 being the MSB and index
* length - 1 being the LSB
* @return - integer value of the bit array
*/
public int getInt( int[] bits )
{
if( bits.length > 32 )
{
throw new IllegalArgumentException( "Overflow - must be 32 bits "
+ "or less to fit into a primitive integer value" );
}
int value = 0;
for( int index: bits )
{
value = Integer.rotateLeft( value, 1 );
if( get( index ) )
{
value++;
}
}
return value;
}
public void setInt(int value, int[] indices)
{
for(int x = 0; x < indices.length; x++)
{
int mask = 1<<(indices.length - x - 1);
if((value & mask) == mask)
{
set(indices[x]);
}
else
{
clear(indices[x]);
}
}
}
/**
* Returns the byte value represented by the bit array
* @param bits - an array of bit positions that will be treated as if they
* were contiguous bits, with index 0 being the MSB and index
* length - 1 being the LSB
* @return - byte value of the bit array
*/
public byte getByte( int[] bits )
{
if( bits.length != 8 )
{
throw new IllegalArgumentException( "Invalid - there must be 8"
+ "indexes to form a proper byte" );
}
int value = 0;
for( int index: bits )
{
value = Integer.rotateLeft( value, 1 );
if( get( index ) )
{
value++;
}
}
return (byte)( value & 0xFF );
}
/**
* Returns the byte value contained between index and index + 7 bit positions
* @param index specifying the start of the byte value
* @return byte value contained at index <> index + 7 bit positions
*/
public byte getByte(int index)
{
Validate.isTrue((index + 7) <= size());
int value = 0;
for(int x = 0; x < 8; x++)
{
value = value << 1;
if(get(index + x))
{
value++;
}
}
return (byte)value;
}
/**
* Sets the byte value at index position through index + 7 position.
*
* @param index bit position where to write the MSB of the byte value
* @param value to write at the index through index + 7 bit positions
*/
public void setByte(int index, byte value)
{
Validate.isTrue((index + 8) <= size());
int mask = 0x80;
for(int x = 0; x < 8; x++)
{
if((mask & value) == mask)
{
set(index + x);
}
else
{
clear(index + x);
}
mask = mask >> 1;
}
}
/**
* Returns the long value represented by the bit array
* @param bits - an array of bit positions that will be treated as if they
* were contiguous bits, with index 0 being the MSB and index
* length - 1 being the LSB
* @return - integer value of the bit array
*/
public long getLong( int[] bits )
{
if( bits.length > 64 )
{
throw new IllegalArgumentException( "Overflow - must be 64 bits "
+ "or less to fit into a primitive long value" );
}
long value = 0;
for( int index: bits )
{
value = Long.rotateLeft( value, 1 );
if( get( index ) )
{
value++;
}
}
return value;
}
/**
* Converts up to 63 bits from the bit array into an integer and then
* formats the value into hexadecimal, prefixing the value with zeros to
* provide a total length of digitDisplayCount;
*
* @param bits
* @param digitDisplayCount
* @return
*/
public String getHex( int[] bits, int digitDisplayCount )
{
if( bits.length <= 32 )
{
int value = getInt( bits );
return String.format( "%0" + digitDisplayCount + "X", value );
}
else if( bits.length <= 64 )
{
long value = getLong( bits );
return String.format( "%0" + digitDisplayCount + "X", value );
}
else
{
throw new IllegalArgumentException( "BitSetBuffer.getHex() "
+ "maximum array length is 63 bits" );
}
}
public String getHex( int msb, int lsb, int digitDisplayCount )
{
int length = lsb - msb;
if( length <= 32 )
{
int value = getInt( msb, lsb );
return String.format( "%0" + digitDisplayCount + "X", value );
}
else if( length <= 64 )
{
long value = getLong( msb, lsb );
return String.format( "%0" + digitDisplayCount + "X", value );
}
else
{
throw new IllegalArgumentException( "BitSetBuffer.getHex() "
+ "maximum array length is 64 bits" );
}
}
/**
* Returns the int value represented by the bit range. This method will
* parse the bits in big endian or little endian format. The start value
* represents the MSB and the end value represents the LSB of the value.
*
* start < end: little endian interpretation
* end < start: big endian interpretation
*
* @param start - MSB of the value
* @param end - LSB of the value
*
* @return - int value of the bit range
*/
public int getInt( int start, int end )
{
if( Math.abs( end - start ) > 32 )
{
throw new IllegalArgumentException( "Overflow - must be 32 bits "
+ "or less to fit into a primitive integer value" );
}
int value = 0;
if( start < end )
{
for( int x = start; x <= end; x++ )
{
value = Integer.rotateLeft( value, 1 );
if( get( x ) )
{
value++;;
}
}
}
else
{
for( int x = end; x >= start; x-- )
{
value = Integer.rotateLeft( value, 1 );
if( get( x ) )
{
value++;;
}
}
}
return value;
}
/**
* Returns the long value represented by the bit range. This method will
* parse the bits in big endian or little endian format. The start value
* represents the MSB and the end value represents the LSB of the value.
*
* start < end: little endian interpretation
* end < start: big endian interpretation
*
* @param start - MSB of the value
* @param end - LSB of the value
*
* @return - long value of the bit range
*/
public long getLong( int start, int end )
{
if( Math.abs( end - start ) > 64 )
{
throw new IllegalArgumentException( "Overflow - must be 64 bits "
+ "or less to fit into a primitive long value" );
}
long value = 0;
if( start < end )
{
for( int x = start; x <= end; x++ )
{
value = Long.rotateLeft( value, 1 );
if( get( x ) )
{
value++;
}
}
}
else
{
for( int x = end; x >= start; x-- )
{
value = Long.rotateLeft( value, 1 );
if( get( x ) )
{
value++;
}
}
}
return value;
}
/**
* Creates a buffer of size=width and fills the buffer with the fill value
* @param width - size of the buffer
* @param fill - initial fill value
* @return - filled buffer
*/
public static BinaryMessage getBuffer( int width, long fill )
{
BinaryMessage buffer = new BinaryMessage( width );
buffer.load( 0, width, fill );
return buffer;
}
/**
* Loads the value into the buffer starting at the offset index, and
* assuming that the value represents (width) number of bits. The MSB of
* the value will be located at the offset and the LSB of the value will
* be located at ( offset + width ).
*
* @param offset - starting bit index for the MSB of the value
* @param width - representative bit width of the value
* @param value - value to be loaded into the buffer
*/
public void load( int offset, int width, long value )
{
for( int x = 0; x < width; x++ )
{
long mask = Long.rotateLeft( 1, width - x - 1 );
if( ( mask & value ) == mask )
{
set( offset + x );
}
else
{
clear( offset + x );
}
}
}
/**
* Generates an array of message bit position indexes to support accessing
* a contiguous field value
*
* @param start - starting bit position of the field
* @param length - field length
* @return - array of field indexes
*/
public static int[] getFieldIndexes( int start, int length, boolean bigEndian )
{
int[] checksumIndexes = new int[ length ];
for( int x = 0; x < length; x++ )
{
if( bigEndian )
{
checksumIndexes[ length - x - 1 ] = start + x;
}
else
{
checksumIndexes[ x ] = start + x;
}
}
return checksumIndexes;
}
/**
* Creates a bitsetbuffer loaded from a string of zeros and ones
*
* @param message - string containing only zeros and ones
* @return - loaded buffer
*/
public static BinaryMessage load( String message )
{
if( !message.matches( "[01]*" ) )
{
throw new IllegalArgumentException(
"Message must contain only zeros and ones" );
}
BinaryMessage buffer = new BinaryMessage( message.length() );
for( int x = 0; x < message.length(); x++ )
{
if( message.substring( x, x + 1 ).contentEquals( "1" ) )
{
buffer.set( x );
}
}
return buffer;
}
/**
* Left rotates the bits between start and end indices, number of places.
*/
public void rotateLeft( int places, int startIndex, int endIndex )
{
for( int x = 0; x < places; x++ )
{
rotateLeft( startIndex, endIndex );
}
}
/**
* Left rotates the bits between start and end and wraps the left-most
* bit around to the end.
*/
public void rotateLeft( int startIndex, int endIndex )
{
boolean wrapBit = get( startIndex );
for( int x = startIndex; x < endIndex; x++ )
{
if( get( x + 1 ) )
{
set( x );
}
else
{
clear( x );
}
}
if( wrapBit )
{
set( endIndex );
}
else
{
clear( endIndex );
}
}
/**
* Right rotates the bits between start and end indices, number of places.
*/
public void rotateRight( int places, int startIndex, int endIndex )
{
for( int x = 0; x < places; x++ )
{
rotateRight( startIndex, endIndex );
}
}
/**
* Right rotates the bits between start and end and wraps the right-most
* bit around to the start.
*/
public void rotateRight( int startIndex, int endIndex )
{
boolean wrapBit = get( endIndex );
for( int x = endIndex - 1; x >= startIndex; x-- )
{
if( get( x ) )
{
set( x + 1 );
}
else
{
clear( x + 1 );
}
}
if( wrapBit )
{
set( startIndex );
}
else
{
clear( startIndex );
}
}
/**
* Performs exclusive or of the value against this bitset starting at the
* offset position using width bits from the value.
*/
public void xor( int offset, int width, int value )
{
BinaryMessage mask = new BinaryMessage( this.size() );
mask.load( offset, width, value );
this.xor( mask );
}
public static void main(String[] args)
{
BinaryMessage b = new BinaryMessage(32);
int[] indices = {2,3,7,8};
b.setInt(0xF, indices);
System.out.println(b.toString());
}
}

View File

@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.bits;
public class BitSetFullException extends Exception
{
private static final long serialVersionUID = 1L;
public BitSetFullException( String text )
{
super( text );
}
}

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* 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.bits;
import java.util.BitSet;
public class CorrectedBinaryMessage extends BinaryMessage
{
private int mCorrectedBitCount;
/**
* Subclass of binary message class to allow capturing a corrected bits metric.
* @param size of message to create.
*/
public CorrectedBinaryMessage(int size)
{
super(size);
}
public CorrectedBinaryMessage(int size, boolean[] bitsToPreload)
{
super(size, bitsToPreload);
}
public CorrectedBinaryMessage(BitSet bitset, int size)
{
super(bitset, size);
}
public CorrectedBinaryMessage(byte[] data)
{
super(data);
}
@Override
public int getCorrectedBitCount()
{
return mCorrectedBitCount;
}
/**
* Sets the number of bits that were corrected in this message
* @param count of corrected bits
*/
public void setCorrectedBitCount(int count)
{
mCorrectedBitCount = count;
}
}

View File

@@ -0,0 +1,6 @@
package io.github.dsheirer.bits;
public interface ISyncDetectListener
{
public void syncDetected();
}

View File

@@ -0,0 +1,6 @@
package io.github.dsheirer.bits;
public interface ISyncProcessor
{
public void checkSync( long value );
}

View File

@@ -0,0 +1,243 @@
/*******************************************************************************
* 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.bits;
import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.dsp.symbol.SyncDetectListener;
import io.github.dsheirer.dsp.symbol.SyncDetectProvider;
import java.util.ArrayList;
import java.util.Iterator;
/**
* MessageFramer - processes bitsets looking for a sync pattern within
* the bits, and then extracts the message, including the sync
* pattern, for a total bit length of messageLength.
*
* Will extract multiple messages simultaneously, for each sync pattern that is
* encountered within the bitset bit stream.
*/
public class MessageFramer implements Listener<Boolean>,
SyncDetectProvider
{
private boolean[] mSyncPattern;
private int mMessageLength;
private SyncDetectListener mSyncDetectListener;
private Broadcaster<BinaryMessage> mBroadcaster =
new Broadcaster<BinaryMessage>();
private ArrayList<MessageAssembler> mMessageAssemblers =
new ArrayList<MessageAssembler>();
private ArrayList<MessageAssembler> mCompletedMessageAssemblers =
new ArrayList<MessageAssembler>();
private BinaryMessage mPreviousBuffer = null;
private SyncPatternMatcher mMatcher;
public MessageFramer( boolean[] syncPattern, int messageLength )
{
mSyncPattern = syncPattern;
mMatcher = new SyncPatternMatcher( syncPattern );
mMessageLength = messageLength;
}
public void reset()
{
for( MessageAssembler assembler: mMessageAssemblers )
{
assembler.dispose();
}
mMessageAssemblers.clear();
}
public void dispose()
{
mBroadcaster.dispose();
mCompletedMessageAssemblers.clear();
mMessageAssemblers.clear();
}
@Override
public void receive( Boolean bit )
{
mMatcher.receive( bit );
Iterator<MessageAssembler> it = mMessageAssemblers.iterator();
MessageAssembler assembler;
while( it.hasNext() )
{
assembler = it.next();
/* Dispose and remove any completed assemblers */
if( assembler.complete() )
{
assembler.dispose();
it.remove();
}
/* Otherwise, send them the bit */
else
{
assembler.receive( bit );
}
}
/* Check for sync match and add new message assembler */
if( mMatcher.matches() )
{
addMessageAssembler( new MessageAssembler( mMessageLength, mSyncPattern ) );
/* Notify any sync detect listener(s) */
if( mSyncDetectListener != null )
{
mSyncDetectListener.syncDetected();
}
}
}
/**
* Causes all messages currently under assembly to be forcibly
* sent (ie flushed) to all registered message listeners, and
* subsequently, all assemblers to be deleted
*/
public void flush()
{
for( MessageAssembler assembler: mMessageAssemblers )
{
assembler.flush();
}
}
@Override
public void setSyncDetectListener( SyncDetectListener listener )
{
mSyncDetectListener = listener;
}
/**
* Allow a message listener to register with this framer to receive
* all framed messages
*/
public void addMessageListener( Listener<BinaryMessage> listener )
{
mBroadcaster.addListener( listener );
}
public void removeMessageListener( Listener<BinaryMessage> listener )
{
mBroadcaster.removeListener( listener );
}
/*
* Adds a message assembler to receive bits from the bit stream
*/
private void addMessageAssembler( MessageAssembler assembler )
{
mMessageAssemblers.add( assembler );
}
@SuppressWarnings( "unused" )
private void removeMessageAssembler( MessageAssembler assembler )
{
mMessageAssemblers.remove( assembler );
}
/**
* Assembles a binary message, starting with the initial fill of the
* identified sync pattern, and every bit thereafter. Once the accumulated
* bits equal the message length, the message is sent and the assembler
* flags itself as complete.
*
* By design, multiple message assemblers can exist at the same time, each
* assembling different, overlapping potential messages
*/
private class MessageAssembler implements Listener<Boolean>
{
BinaryMessage mMessage;
boolean mComplete = false;
MessageAssembler( int messageLength )
{
mMessage = new BinaryMessage( messageLength );
}
MessageAssembler( int messageLength, boolean[] initialFill )
{
this( messageLength );
/* Pre-load the message with the sync pattern */
for( int x = 0; x < initialFill.length; x++ )
{
receive( initialFill[ x ] );
}
}
public void dispose()
{
mMessage = null;
}
@Override
/**
* Receives one bit at a time, and assembles them into a message
*/
public void receive( Boolean bit )
{
try
{
mMessage.add( bit );
}
catch( BitSetFullException e )
{
e.printStackTrace();
}
/* Once our message is complete (ie full), send it to all registered
* message listeners, and set complete flag so for auto-removal */
if( mMessage.isFull() )
{
mComplete = true;
flush();
}
}
/**
* Flushes/Sends the current message, or partial message, and sets
* complete flag to true, so that we can be auto-removed
*/
public void flush()
{
mBroadcaster.receive( mMessage );
mComplete = true;
}
/**
* Flag to indicate when this assembler has received all of the bits it
* is looking for (ie message length), and should then be removed from
* receiving any more bits
*/
public boolean complete()
{
return mComplete;
}
}
}

View File

@@ -0,0 +1,111 @@
/*******************************************************************************
* 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.bits;
import org.apache.commons.lang3.Validate;
import java.util.ArrayList;
import java.util.List;
/**
* Multi-Sync pattern matcher. Accepts multiple sync detector objects for
* comparision against the incoming bit stream.
*
* Note: works for sync patterns up to 63 bits (integer size - 1 ) long.
* If a 64 bit or larger sync pattern is applied, then the wrapping feature
* of the Long.rotate methods will wrap the MSB around to the LSB and
* corrupt the matching value.
*
*/
public class MultiSyncPatternMatcher
{
private List<ISyncProcessor> mSyncProcessors = new ArrayList<ISyncProcessor>();
private long mBits = 0;
private long mMask = 0;
public MultiSyncPatternMatcher( int syncSize )
{
Validate.isTrue(syncSize < 64);
//Setup a bit mask of all ones the length of the sync pattern
mMask = (long)( ( Math.pow( 2, syncSize ) ) - 1 );
}
public void dispose()
{
mSyncProcessors.clear();
}
/**
* Processes two bits before checking sync processors for a match.
*/
public void receive( boolean bit1, boolean bit2 )
{
mBits = Long.rotateLeft( mBits, 1 );
mBits &= mMask;
if( bit1 )
{
mBits += 1;
}
mBits = Long.rotateLeft( mBits, 1 );
mBits &= mMask;
if( bit2 )
{
mBits += 1;
}
for( ISyncProcessor processor: mSyncProcessors )
{
processor.checkSync( mBits );
}
}
/**
* Processes one bit before checking sync processors for a match.
*/
public void receive( boolean bit )
{
mBits = Long.rotateLeft( mBits, 1 );
mBits &= mMask;
if( bit )
{
mBits += 1;
}
for( ISyncProcessor processor: mSyncProcessors )
{
processor.checkSync( mBits );
}
}
/**
* Adds a sync processor to receive the bit stream.
*/
public void add( ISyncProcessor processor )
{
mSyncProcessors.add( processor );
}
}

View File

@@ -0,0 +1,48 @@
package io.github.dsheirer.bits;
public class SoftSyncDetector implements ISyncProcessor
{
private ISyncDetectListener mListener;
private long mPattern;
private int mThreshold;
public SoftSyncDetector( ISyncDetectListener listener, long pattern, int threshold )
{
this( pattern, threshold );
mListener = listener;
}
public SoftSyncDetector( long pattern, int threshold )
{
mPattern = pattern;
mThreshold = threshold;
}
public void dispose()
{
mListener = null;
}
@Override
public void checkSync( long value )
{
long difference = value ^ mPattern;
if( ( difference == 0 || Long.bitCount( difference ) <= mThreshold ) &&
mListener != null )
{
mListener.syncDetected();
}
}
public void setThreshold( int threshold )
{
mThreshold = threshold;
}
public void setListener( ISyncDetectListener listener )
{
mListener = listener;
}
}

View File

@@ -0,0 +1,33 @@
package io.github.dsheirer.bits;
public class SyncDetector implements ISyncProcessor
{
private long mPattern;
private ISyncDetectListener mListener;
public SyncDetector( long pattern )
{
mPattern = pattern;
}
public SyncDetector( long pattern, ISyncDetectListener listener )
{
this( pattern );
mListener = listener;
}
public void setListener( ISyncDetectListener listener )
{
mListener = listener;
}
@Override
public void checkSync( long value )
{
if( value == mPattern && mListener != null )
{
mListener.syncDetected();
}
}
}

View File

@@ -0,0 +1,186 @@
/*******************************************************************************
* 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.bits;
public enum SyncPattern
{
/* Revs (0xAA) and Sync (0x7650) = 01010 0111011001010000 */
FLEETSYNC1( new boolean[]
{
false, true, false, true, false, //end of revs
false, true, true, true, //0111 0x7
false, true, true, false, //0110 0x6
false, true, false, true, //0101 0x5
false, false, false, false //0000 0x0
} ),
/* Revs (0x0A) and Sync (0x23EB) = 10101 0010001111101011 */
FLEETSYNC2( new boolean[]
{
false, true, false, true, false, //End of bit revs
false, false, true, false, //0010 0x2
false, false, true, true, //0011 0x3
true, true, true, false, //1110 0xE
true, false, true, true //1011 0xB
} ),
/* 0x550F */
LJ1200( new boolean[]
{
false, true, false,true,
false, true, false,true,
false, false, false, false,
true, true, true, true
}),
/* 0x2AD5 */
LJ1200_TRANSPONDER( new boolean[]
{
false, false, true, false,
true, false, true, false,
true, true, false, true,
false, true, false, true
}),
/**
* Note: we use a truncated portion of the NRZ-I encoded sync pattern.
* The truncated version seems to work well enough for detecting the burst,
* while limiting falsing.
*
* Sync: .... .... 0000 0111 0000 1001 0010 1010 0100 0100 0110 1111
* Rev & Sync: ...1 0101 0000 0111 0000 1001 0010 1010 0100 0100 0110 1111
* NRZ-I: .... 1111 1000 0100 1000 1101 1011 1111 0110 0110 0101 1000
* This: .... .... 1000 0100 1000 1101 1011 1111 .... .... .... ....
*/
/* Sync (0x07092A446F) = 0000011100001001001010100100010001101111 */
MDC1200( new boolean[]
{
false, false, false, false,//0000 0x0
false, true, true, true, //0111 0x7
false, false, false, false,//0000 0x0
true, false, false, true, //1001 0x9
false, false, true, false, //0010 0x2
true, false, true, false, //1010 0xA
false, true, false, false, //0100 0x4
false, true, false, false, //0100 0x4
false, true, true, false, //0110 0x6
true, true, true, true //1111 0xF
} ),
/* Revs (0xA) and Sync(0xA4D7) = 1010 1100010011010111 */
MPT1327_CONTROL( new boolean[]
{
true, false, true, false, //Includes 4 of 16 rev bits
true, true, false, false, //1100 0xA
false, true, false, false, //0100 0x4
true, true, false, true, //1101 0xD
false, true, true, true //0111 0x7
}),
/**
* French variant of MPT-1327. This variant uses the following a different
* sync pattern:
*
* SYNC: 1011 0100 0011 0011
*/
MPT1327_CONTROL_FRENCH( new boolean[]
{
true, false, true, false, //Includes final 4 of 16 rev bits
true, false, true, true, //1011 0xB
false, true, false, false, //0100 0x4
false, false, true, true, //0011 0x3
false, false, true, true //0011 0x3
}),
/* Revs (0xA) and Sync(0x3B28) = 1010 0011101100101000 */
MPT1327_TRAFFIC( new boolean[]
{
true, false, true, false, //1010 Includes 4 of 16 rev bits
false, false, true, true, //0011 0x3
true, false, true, true, //1011 0xB
false, false, true, false, //0010 0x2
true, false, false, false //1000 0x8
}),
/**
* French variant of MPT-1327. This variant uses the following a different
* sync pattern:
*
* SYNT: 0100 1011 1100 1100
*/
MPT1327_TRAFFIC_FRENCH( new boolean[]
{
true, false, true, false, //Includes final 4 of 16 rev bits
false, true, false, false, //0100 0x4
true, false, true, true, //1011 0xB
true, true, false, false, //1100 0xC
true, true, false, false //1100 0xC
}),
/* Sync (0x158) = 1101011000 */
PASSPORT( new boolean[]
{
true, //0001 0x1
false, true, false, true, //0101 0x5
true, false, false, false //1000 0x8
} ),
LTR_STANDARD_OSW( new boolean[]
{
true,false,true,false,true,true,false,false,false
} ),
LTR_STANDARD_ISW( new boolean[]
{
false, true, false, true,false, false, true, true, true
} ),
TAIT_CCDI_GPS_MESSAGE( new boolean[]
{
true,false,true,false,
false,false,false,true,
false,true,false,false,
true,true,false,true,
true,true,false,false
}),
TAIT_SELCAL_MESSAGE( new boolean[]
{
// true,false,true,false,
// false,false,false,false,
// true,true,false,false,
// false,true,true,true,
// false,true,true,true
false,true,false,false,
false,false,false,true,
true,false,false,false,
true,true,true,false,
true,true,true,false
});
boolean[] mBits;
private SyncPattern( boolean[] bits )
{
mBits = bits;
}
public boolean[] getPattern()
{
return mBits;
}
}

View File

@@ -0,0 +1,132 @@
/*******************************************************************************
* 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.bits;
/**
* Sync pattern matcher.
*
* Note: works for sync patterns up to 63 bits (integer size - 1 ) long.
* If a 64 bit or larger sync pattern is applied, then the wrapping feature
* of the Long.rotate methods will wrap the MSB around to the LSB and
* corrupt the matching value.
*
*/
public class SyncPatternMatcher
{
private long mBits = 0;
private long mMask = 0;
private long mSync = 0;
private boolean mSoftMode = false;
private int mSoftModeErrorThreshold = 0;
public SyncPatternMatcher( boolean[] syncPattern )
{
//Setup a bit mask of all ones the length of the sync pattern
mMask = (long)( ( Math.pow( 2, syncPattern.length ) ) - 1 );
//Convert the sync bits into a long value for comparison
for( int x = 0; x < syncPattern.length; x++ )
{
if( syncPattern[ x ] )
{
mSync += 1l << ( syncPattern.length - 1 - x );
}
}
}
public SyncPatternMatcher( long sync )
{
mSync = sync;
mMask = getMask( sync );
}
/**
* Constructs the sync pattern matcher and defines the soft mode maximum
* number of bit errors to allow in the pattern match.
*
* @param sync pattern
* @param softModeErrorThreshold - maximum bit errors (ie pattern mismatch
* positions) when considering a sync match
*/
public SyncPatternMatcher( long sync, int softModeErrorThreshold )
{
this( sync );
mSoftModeErrorThreshold = softModeErrorThreshold;
}
/**
* Generates an all ones mask corresponding to the sync pattern
*/
private static long getMask( long sync )
{
long mask = sync;
for( int x = 1; x < 64; x *= 2 )
{
mask |= ( mask >> x );
}
return mask;
}
public void receive( boolean bit )
{
//Left shift the previous value
mBits = Long.rotateLeft( mBits, 1 );
//Apply the mask to erase the previous MSB
mBits &= mMask;
//Add in the new bit
if( bit )
{
mBits += 1;
}
}
/**
* Indicates if the most recently received bit sequence matches the
* sync pattern
*/
public boolean matches()
{
if( mSoftMode )
{
long difference = mBits ^ mSync;
return difference == 0 ||
Long.bitCount( difference ) <= mSoftModeErrorThreshold;
}
else
{
return ( mBits == mSync );
}
}
/**
* Sets the sync pattern matcher in soft mode which allows up to the soft
* mode threshold number of bit errors when considering a sync pattern match
*/
public void setSoftMode( boolean softMode )
{
mSoftMode = softMode;
}
}