Skip to content

Commit 8718d04

Browse files
DSheirerDennis Sheirer
and
Dennis Sheirer
authored
#2162 APCO25 NID BCH decoder implementation. (#2163)
Co-authored-by: Dennis Sheirer <[email protected]>
1 parent 4e367bb commit 8718d04

File tree

6 files changed

+1513
-13
lines changed

6 files changed

+1513
-13
lines changed

src/main/java/io/github/dsheirer/bits/BinaryMessage.java

+35-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2024 Dennis Sheirer
3+
* Copyright (C) 2014-2025 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -415,8 +415,8 @@ public boolean[] getBits(int startIndex, int endIndex)
415415
boolean[] returnValue = null;
416416

417417
if(startIndex >= 0 &&
418-
startIndex < endIndex &&
419-
endIndex < mSize)
418+
startIndex < endIndex &&
419+
endIndex < mSize)
420420
{
421421
returnValue = new boolean[endIndex - startIndex + 1];
422422

@@ -447,7 +447,7 @@ public int getInt(int[] bits)
447447
if(bits.length > 32)
448448
{
449449
throw new IllegalArgumentException("Overflow - must be 32 bits "
450-
+ "or less to fit into a primitive integer value");
450+
+ "or less to fit into a primitive integer value");
451451
}
452452

453453
int value = 0;
@@ -676,7 +676,7 @@ public int getInt(int[] bits, int offset)
676676
if(bits.length > 32)
677677
{
678678
throw new IllegalArgumentException("Overflow - must be 32 bits "
679-
+ "or less to fit into a primitive integer value");
679+
+ "or less to fit into a primitive integer value");
680680
}
681681

682682
int value = 0;
@@ -711,6 +711,28 @@ public void setInt(int value, int[] indices)
711711
}
712712
}
713713

714+
/**
715+
* Sets the integer value to the field described by the argument.
716+
* @param value to set
717+
* @param intField describing the indices of the field.
718+
*/
719+
public void setInt(int value, IntField intField)
720+
{
721+
for(int x = 0; x < intField.width(); x++)
722+
{
723+
int mask = 1 << (intField.width() - x - 1);
724+
725+
if((value & mask) == mask)
726+
{
727+
set(intField.start() + x);
728+
}
729+
else
730+
{
731+
clear(intField.start() + x);
732+
}
733+
}
734+
}
735+
714736
/**
715737
* Returns the byte value represented by the bit array
716738
*
@@ -724,7 +746,7 @@ public byte getByte(int[] bits)
724746
if(bits.length != 8)
725747
{
726748
throw new IllegalArgumentException("Invalid - there must be 8"
727-
+ "indexes to form a proper byte");
749+
+ "indexes to form a proper byte");
728750
}
729751

730752
int value = 0;
@@ -756,7 +778,7 @@ public byte getByte(int[] bits, int offset)
756778
if(bits.length != 8)
757779
{
758780
throw new IllegalArgumentException("Invalid - there must be 8"
759-
+ "indexes to form a proper byte");
781+
+ "indexes to form a proper byte");
760782
}
761783

762784
int value = 0;
@@ -884,7 +906,7 @@ public long getLong(int[] bits)
884906
if(bits.length > 64)
885907
{
886908
throw new IllegalArgumentException("Overflow - must be 64 bits "
887-
+ "or less to fit into a primitive long value");
909+
+ "or less to fit into a primitive long value");
888910
}
889911

890912
long value = 0;
@@ -916,7 +938,7 @@ public long getLong(int[] bits, int offset)
916938
if(bits.length > 64)
917939
{
918940
throw new IllegalArgumentException("Overflow - must be 64 bits "
919-
+ "or less to fit into a primitive long value");
941+
+ "or less to fit into a primitive long value");
920942
}
921943

922944
long value = 0;
@@ -1004,7 +1026,7 @@ else if(bits.length <= 64)
10041026
else
10051027
{
10061028
throw new IllegalArgumentException("BitSetBuffer.getHex() "
1007-
+ "maximum array length is 63 bits");
1029+
+ "maximum array length is 63 bits");
10081030
}
10091031
}
10101032

@@ -1025,7 +1047,7 @@ public int getInt(int start, int end)
10251047
if(FastMath.abs(end - start) > 32)
10261048
{
10271049
throw new IllegalArgumentException("Overflow - must be 32 bits "
1028-
+ "or less to fit into a primitive integer value");
1050+
+ "or less to fit into a primitive integer value");
10291051
}
10301052

10311053
int value = 0;
@@ -1100,7 +1122,7 @@ public long getLong(int start, int end)
11001122
if(FastMath.abs(end - start) > 64)
11011123
{
11021124
throw new IllegalArgumentException("Overflow - must be 64 bits "
1103-
+ "or less to fit into a primitive long value");
1125+
+ "or less to fit into a primitive long value");
11041126
}
11051127

11061128
long value = 0;
@@ -1255,7 +1277,7 @@ public static BinaryMessage load(String message)
12551277
if(!message.matches("[01]*"))
12561278
{
12571279
throw new IllegalArgumentException(
1258-
"Message must contain only zeros and ones");
1280+
"Message must contain only zeros and ones");
12591281
}
12601282

12611283
BinaryMessage buffer = new BinaryMessage(message.length());

0 commit comments

Comments
 (0)