mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Closes #7 NXDN Decoder * Implements: NXDN4800, NXDN9600, Type-C and Type-D decoding and trunk tracking. * Redesigns tuner and channel frequency error management.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -306,6 +306,15 @@ public class BinaryMessage extends BitSet
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return toHexString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Binary representation of the message
|
||||
* @return message in binary 0/1 format
|
||||
*/
|
||||
public String toBinaryString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -317,6 +326,10 @@ public class BinaryMessage extends BitSet
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hex string representation of the message
|
||||
* @return message in hex
|
||||
*/
|
||||
public String toHexString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -997,6 +1010,18 @@ public class BinaryMessage extends BitSet
|
||||
return String.format("%0" + width + "X", getInt(field));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long field formatted as a hex value using zero prefixes to pad the hex character count to fully
|
||||
* represent the size (width) of the field.
|
||||
* @param field to parse as hex
|
||||
* @return hex value.
|
||||
*/
|
||||
public String getHex(LongField field)
|
||||
{
|
||||
int width = Math.ceilDiv(field.width(), 4);
|
||||
return String.format("%0" + width + "X", getLong(field));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the byte value that starts at the specified index as hexadecimal. If the length of the message is less
|
||||
* than the start index plus 7 bits, then the value represents those bits as high-order bits with zero padding in
|
||||
@@ -1315,37 +1340,15 @@ public class BinaryMessage extends BitSet
|
||||
throw new IllegalArgumentException("Message must contain only 0-9 and A-F hexadecimal characters");
|
||||
}
|
||||
|
||||
int length = hex.length() / 2;
|
||||
BinaryMessage message = new BinaryMessage(hex.length() * 4);
|
||||
|
||||
if(length * 2 < hex.length())
|
||||
for(int x = 0; x < hex.length(); x++)
|
||||
{
|
||||
length++;
|
||||
String rawHex = hex.substring(x, x + 1);
|
||||
message.setInt(Integer.parseInt(rawHex, 16), IntField.length4(x * 4));
|
||||
}
|
||||
|
||||
BinaryMessage buffer = new BinaryMessage(length * 8);
|
||||
|
||||
int bufferOffset = 0;
|
||||
for(int x = 0; x < hex.length(); x += 2)
|
||||
{
|
||||
int endIndex = x + 2;
|
||||
if(endIndex > hex.length())
|
||||
{
|
||||
endIndex--;
|
||||
}
|
||||
|
||||
String rawHex = hex.substring(x, endIndex);
|
||||
|
||||
if(rawHex.length() == 1)
|
||||
{
|
||||
rawHex = rawHex + "0";
|
||||
}
|
||||
|
||||
int value = Integer.parseInt(rawHex, 16);
|
||||
buffer.setByte(bufferOffset, (byte)(value & 0xFF));
|
||||
bufferOffset += 8;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package io.github.dsheirer.bits;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.BitSet;
|
||||
|
||||
public class CorrectedBinaryMessage extends BinaryMessage
|
||||
@@ -54,6 +55,45 @@ public class CorrectedBinaryMessage extends BinaryMessage
|
||||
this.xor(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message loaded from the hexadecimal string
|
||||
* @param hex representing the bits of the message
|
||||
* @return new message
|
||||
*/
|
||||
public static CorrectedBinaryMessage loadHex(String hex)
|
||||
{
|
||||
return new CorrectedBinaryMessage(BinaryMessage.loadHex(hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloads the parent method to return this type.
|
||||
* @param binary message to load
|
||||
* @return loaded message
|
||||
*/
|
||||
public static CorrectedBinaryMessage load(String binary)
|
||||
{
|
||||
return new CorrectedBinaryMessage(BinaryMessage.load(binary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a binary frame from the byte array with length set to the
|
||||
* number of bits contained in the byte array
|
||||
*/
|
||||
public static CorrectedBinaryMessage from(byte[] data, ByteOrder byteOrder)
|
||||
{
|
||||
if(byteOrder == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return new CorrectedBinaryMessage(from(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
CorrectedBinaryMessage frame = new CorrectedBinaryMessage(data.length * 8);
|
||||
BitSet bitSet = BitSet.valueOf(data);
|
||||
frame.xor(bitSet);
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCorrectedBitCount()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -60,7 +60,27 @@ public record IntField(int start, int end)
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with one four bits of length.
|
||||
* Utility constructor method for a field with two bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length2(int start)
|
||||
{
|
||||
return new IntField(start, (start + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with three bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length3(int start)
|
||||
{
|
||||
return new IntField(start, (start + 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with four bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
@@ -70,7 +90,17 @@ public record IntField(int start, int end)
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with one four bits of length.
|
||||
* Utility constructor method for a field with five bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length5(int start)
|
||||
{
|
||||
return new IntField(start, (start + 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with six bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
@@ -79,6 +109,16 @@ public record IntField(int start, int end)
|
||||
return new IntField(start, (start + 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with seven bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length7(int start)
|
||||
{
|
||||
return new IntField(start, (start + 6));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with one octet of length.
|
||||
* @param start index (inclusive)
|
||||
@@ -89,6 +129,36 @@ public record IntField(int start, int end)
|
||||
return new IntField(start, (start + 7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with nine bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length9(int start)
|
||||
{
|
||||
return new IntField(start, (start + 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with ten bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length10(int start)
|
||||
{
|
||||
return new IntField(start, (start + 9));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with eleven bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length11(int start)
|
||||
{
|
||||
return new IntField(start, (start + 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with 12 bits of length.
|
||||
* @param start index (inclusive)
|
||||
@@ -99,6 +169,26 @@ public record IntField(int start, int end)
|
||||
return new IntField(start, (start + 11));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with 14 bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length14(int start)
|
||||
{
|
||||
return new IntField(start, (start + 13));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with 15 bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static IntField length15(int start)
|
||||
{
|
||||
return new IntField(start, (start + 14));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with two octets of length.
|
||||
* @param start index (inclusive)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -39,6 +39,15 @@ public record LongField(int start, int end)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Width of the field in bit positions
|
||||
* @return width
|
||||
*/
|
||||
public int width()
|
||||
{
|
||||
return end() - start() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method.
|
||||
* @param start index (inclusive)
|
||||
@@ -101,7 +110,17 @@ public record LongField(int start, int end)
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with two octets of length.
|
||||
* Utility constructor method for a field with 23 bits of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static LongField length23(int start)
|
||||
{
|
||||
return new LongField(start, (start + 22));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with three octets of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
@@ -111,7 +130,7 @@ public record LongField(int start, int end)
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with three octets of length.
|
||||
* Utility constructor method for a field with four octets of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
@@ -119,4 +138,24 @@ public record LongField(int start, int end)
|
||||
{
|
||||
return new LongField(start, (start + 31));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with seven octets of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static LongField length56(int start)
|
||||
{
|
||||
return new LongField(start, (start + 55));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility constructor method for a field with eight octets of length.
|
||||
* @param start index (inclusive)
|
||||
* @return constructed bit field.
|
||||
*/
|
||||
public static LongField length64(int start)
|
||||
{
|
||||
return new LongField(start, (start + 63));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user